Search in sources :

Example 46 with StandardPropertyValue

use of org.apache.nifi.attribute.expression.language.StandardPropertyValue in project nifi by apache.

the class TestWriteAheadLocalStateProvider method setup.

@Before
public void setup() throws IOException {
    provider = new WriteAheadLocalStateProvider();
    final Map<PropertyDescriptor, PropertyValue> properties = new HashMap<>();
    properties.put(WriteAheadLocalStateProvider.PATH, new StandardPropertyValue("target/local-state-provider/" + UUID.randomUUID().toString(), null));
    properties.put(WriteAheadLocalStateProvider.ALWAYS_SYNC, new StandardPropertyValue("false", null));
    properties.put(WriteAheadLocalStateProvider.CHECKPOINT_INTERVAL, new StandardPropertyValue("2 mins", null));
    properties.put(WriteAheadLocalStateProvider.NUM_PARTITIONS, new StandardPropertyValue("16", null));
    provider.initialize(new StateProviderInitializationContext() {

        @Override
        public String getIdentifier() {
            return "Unit Test Provider Initialization Context";
        }

        @Override
        public Map<PropertyDescriptor, PropertyValue> getProperties() {
            return Collections.unmodifiableMap(properties);
        }

        @Override
        public Map<String, String> getAllProperties() {
            final Map<String, String> propValueMap = new LinkedHashMap<>();
            for (final Map.Entry<PropertyDescriptor, PropertyValue> entry : getProperties().entrySet()) {
                propValueMap.put(entry.getKey().getName(), entry.getValue().getValue());
            }
            return propValueMap;
        }

        @Override
        public PropertyValue getProperty(final PropertyDescriptor property) {
            final PropertyValue prop = properties.get(property);
            if (prop == null) {
                return new StandardPropertyValue(null, null);
            }
            return prop;
        }

        @Override
        public SSLContext getSSLContext() {
            return null;
        }

        @Override
        public ComponentLog getLogger() {
            return null;
        }
    });
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) SSLContext(javax.net.ssl.SSLContext) ComponentLog(org.apache.nifi.logging.ComponentLog) StateProviderInitializationContext(org.apache.nifi.components.state.StateProviderInitializationContext) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Before(org.junit.Before)

Example 47 with StandardPropertyValue

use of org.apache.nifi.attribute.expression.language.StandardPropertyValue in project nifi by apache.

the class TestStandardPropertyValue method testSubstituteAttributesWithNoMatch.

@Test
public void testSubstituteAttributesWithNoMatch() {
    final PropertyValue value = new StandardPropertyValue("Hello, ${audience}${comma}${question:replaceNull('')}!", lookup);
    final Map<String, String> attributes = new HashMap<>();
    assertEquals("Hello, !", value.evaluateAttributeExpressions(createFlowFile(attributes)).getValue());
}
Also used : HashMap(java.util.HashMap) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) Test(org.junit.Test)

Example 48 with StandardPropertyValue

use of org.apache.nifi.attribute.expression.language.StandardPropertyValue in project nifi by apache.

the class TestStandardPropertyValue method testMissingEndBraceEvaluatesToStringLiteral.

@Test
public void testMissingEndBraceEvaluatesToStringLiteral() {
    final PropertyValue value = new StandardPropertyValue("Hello, ${audience!", lookup);
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("audience", "World");
    assertEquals("Hello, ${audience!", value.evaluateAttributeExpressions(createFlowFile(attributes)).getValue());
}
Also used : HashMap(java.util.HashMap) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) Test(org.junit.Test)

Example 49 with StandardPropertyValue

use of org.apache.nifi.attribute.expression.language.StandardPropertyValue in project nifi by apache.

the class TestStandardPropertyValue method testSubstituteAttributesWithMultipleMatchingArgs.

@Test
public void testSubstituteAttributesWithMultipleMatchingArgs() {
    final PropertyValue value = new StandardPropertyValue("Hello, ${audience}${comma}${question}!", lookup);
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("audience", "World");
    attributes.put("comma", ",");
    attributes.put("question", " how are you?");
    assertEquals("Hello, World, how are you?!", value.evaluateAttributeExpressions(createFlowFile(attributes)).getValue());
}
Also used : HashMap(java.util.HashMap) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) Test(org.junit.Test)

Example 50 with StandardPropertyValue

use of org.apache.nifi.attribute.expression.language.StandardPropertyValue in project nifi by apache.

the class StandardManagedAuthorizerTest method getStandardManagedAuthorizer.

private StandardManagedAuthorizer getStandardManagedAuthorizer(final AccessPolicyProvider accessPolicyProvider) {
    final StandardManagedAuthorizer managedAuthorizer = new StandardManagedAuthorizer();
    final AuthorizerConfigurationContext configurationContext = mock(AuthorizerConfigurationContext.class);
    when(configurationContext.getProperty("Access Policy Provider")).thenReturn(new StandardPropertyValue("access-policy-provider", null));
    final AccessPolicyProviderLookup accessPolicyProviderLookup = mock(AccessPolicyProviderLookup.class);
    when(accessPolicyProviderLookup.getAccessPolicyProvider("access-policy-provider")).thenReturn(accessPolicyProvider);
    final AuthorizerInitializationContext initializationContext = mock(AuthorizerInitializationContext.class);
    when(initializationContext.getAccessPolicyProviderLookup()).thenReturn(accessPolicyProviderLookup);
    managedAuthorizer.initialize(initializationContext);
    managedAuthorizer.onConfigured(configurationContext);
    return managedAuthorizer;
}
Also used : StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue)

Aggregations

StandardPropertyValue (org.apache.nifi.attribute.expression.language.StandardPropertyValue)91 Test (org.junit.Test)78 AuthorizerConfigurationContext (org.apache.nifi.authorization.AuthorizerConfigurationContext)33 Matchers.anyString (org.mockito.Matchers.anyString)30 NiFiProperties (org.apache.nifi.util.NiFiProperties)24 PropertyValue (org.apache.nifi.components.PropertyValue)17 HashMap (java.util.HashMap)16 Properties (java.util.Properties)15 Group (org.apache.nifi.authorization.Group)12 Before (org.junit.Before)12 Set (java.util.Set)10 UserAndGroups (org.apache.nifi.authorization.UserAndGroups)10 AuthorizerCreationException (org.apache.nifi.authorization.exception.AuthorizerCreationException)9 CreateLdapServer (org.apache.directory.server.annotations.CreateLdapServer)8 CreateTransport (org.apache.directory.server.annotations.CreateTransport)8 ApplyLdifFiles (org.apache.directory.server.core.annotations.ApplyLdifFiles)8 CreateDS (org.apache.directory.server.core.annotations.CreateDS)8 CreatePartition (org.apache.directory.server.core.annotations.CreatePartition)8 AbstractLdapTestUnit (org.apache.directory.server.core.integ.AbstractLdapTestUnit)8 FrameworkRunner (org.apache.directory.server.core.integ.FrameworkRunner)8