### Question:
NiFiAuthenticationProvider implements AuthenticationProvider { public List<IdentityMapping> getMappings() { return mappings; } NiFiAuthenticationProvider(final NiFiProperties properties); List<IdentityMapping> getMappings();  }### Answer:
@Test public void testValidPropertiesProvided() { final String pattern = "^cn=(.*?),dc=(.*?),dc=(.*?)$"; final String value = "$1@$2.$3"; Properties properties = new Properties(); properties.setProperty("nifi.security.identity.mapping.pattern.dn", pattern); properties.setProperty("nifi.security.identity.mapping.value.dn", value); final NiFiProperties nifiProperties = getNiFiProperties(properties); TestableNiFiAuthenticationProvider provider = new TestableNiFiAuthenticationProvider(nifiProperties); List<IdentityMapping> mappings = provider.getMappings(); assertEquals(1, mappings.size()); assertEquals("dn", mappings.get(0).getKey()); assertEquals(pattern, mappings.get(0).getPattern().pattern()); assertEquals(value, mappings.get(0).getReplacementValue()); }
@Test public void testPatternPropertyWithNoValue() { Properties properties = new Properties(); properties.setProperty("nifi.security.identity.mapping.pattern.dn", ""); properties.setProperty("nifi.security.identity.mapping.value.dn", "value"); final NiFiProperties nifiProperties = getNiFiProperties(properties); TestableNiFiAuthenticationProvider provider = new TestableNiFiAuthenticationProvider(nifiProperties); List<IdentityMapping> mappings = provider.getMappings(); assertEquals(0, mappings.size()); }
@Test public void testPatternPropertyWithNoCorrespondingValueProperty() { Properties properties = new Properties(); properties.setProperty("nifi.security.identity.mapping.pattern.dn", ""); final NiFiProperties nifiProperties = getNiFiProperties(properties); TestableNiFiAuthenticationProvider provider = new TestableNiFiAuthenticationProvider(nifiProperties); List<IdentityMapping> mappings = provider.getMappings(); assertEquals(0, mappings.size()); }
@Test public void testMultipleMappings() { Properties properties = new Properties(); properties.setProperty("nifi.security.identity.mapping.pattern.1", "pattern1"); properties.setProperty("nifi.security.identity.mapping.value.1", "value1"); properties.setProperty("nifi.security.identity.mapping.pattern.2", "pattern2"); properties.setProperty("nifi.security.identity.mapping.value.2", "value2"); properties.setProperty("nifi.security.identity.mapping.pattern.3", "pattern3"); properties.setProperty("nifi.security.identity.mapping.value.3", "value3"); final NiFiProperties nifiProperties = getNiFiProperties(properties); TestableNiFiAuthenticationProvider provider = new TestableNiFiAuthenticationProvider(nifiProperties); List<IdentityMapping> mappings = provider.getMappings(); assertEquals(3, mappings.size()); }