Search in sources :

Example 1 with StandardPropertyValue

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

the class TestStandardPropertyValue method testEscaped.

@Test
public void testEscaped() {
    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 2 with StandardPropertyValue

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

the class TestStandardPropertyValue method testGetValueAsIntegerAfterSubstitute.

@Test
public void testGetValueAsIntegerAfterSubstitute() {
    final PropertyValue value = new StandardPropertyValue("1${value}", lookup);
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("value", "39");
    assertEquals(139, value.evaluateAttributeExpressions(createFlowFile(attributes)).asInteger().intValue());
}
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 3 with StandardPropertyValue

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

the class TestStandardPropertyValue method testFlowFileEntryYear.

@Test
public void testFlowFileEntryYear() {
    final Calendar now = Calendar.getInstance();
    final int year = now.get(Calendar.YEAR);
    final PropertyValue value = new StandardPropertyValue("${entryDate:toNumber():toDate():format('yyyy')}", lookup);
    final FlowFile flowFile = new StandardFlowFileRecord.Builder().entryDate(now.getTimeInMillis()).build();
    final int val = value.evaluateAttributeExpressions(flowFile).asInteger().intValue();
    assertEquals(year, val);
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) Calendar(java.util.Calendar) 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 4 with StandardPropertyValue

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

the class TestStandardPropertyValue method testSubstituteAttributesWithOneMatchingArg.

@Test
public void testSubstituteAttributesWithOneMatchingArg() {
    final PropertyValue value = new StandardPropertyValue("Hello, ${audience}!", lookup);
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("audience", "World");
    assertEquals("Hello, World!", 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 5 with StandardPropertyValue

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

the class TestStandardPropertyValue method testFileSize.

@Test
public void testFileSize() {
    final PropertyValue value = new StandardPropertyValue("${fileSize}", lookup);
    final FlowFile flowFile = new StandardFlowFileRecord.Builder().size(1024 * 1024L).build();
    final long val = value.evaluateAttributeExpressions(flowFile).asLong().longValue();
    assertEquals(1024 * 1024L, val);
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) 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)

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