Search in sources :

Example 6 with PropertyValue

use of org.apache.nifi.components.PropertyValue 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 7 with PropertyValue

use of org.apache.nifi.components.PropertyValue 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)

Example 8 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class TestStandardPropertyValue method testSubstituteAttributesRecursively.

@Test
public void testSubstituteAttributesRecursively() {
    final PropertyValue value = new StandardPropertyValue("Hello, ${'${a}${b}'}!", lookup);
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("a", "b");
    attributes.put("b", "World");
    attributes.put("bWorld", "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 9 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class TestStandardPropertyValue method testGetValueAsIntegerAfterSubstitutingWithNonInteger.

@Test(expected = NumberFormatException.class)
public void testGetValueAsIntegerAfterSubstitutingWithNonInteger() {
    final PropertyValue value = new StandardPropertyValue("1${value}", lookup);
    final Map<String, String> attributes = new HashMap<>();
    attributes.put("value", "Yes");
    final PropertyValue substituted = value.evaluateAttributeExpressions(createFlowFile(attributes));
    substituted.asInteger();
}
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 10 with PropertyValue

use of org.apache.nifi.components.PropertyValue in project nifi by apache.

the class AbstractMQTTProcessor method buildClient.

protected void buildClient(ProcessContext context) {
    try {
        broker = context.getProperty(PROP_BROKER_URI).getValue();
        clientID = context.getProperty(PROP_CLIENTID).getValue();
        connOpts = new MqttConnectOptions();
        connOpts.setCleanSession(context.getProperty(PROP_CLEAN_SESSION).asBoolean());
        connOpts.setKeepAliveInterval(context.getProperty(PROP_KEEP_ALIVE_INTERVAL).asInteger());
        connOpts.setMqttVersion(context.getProperty(PROP_MQTT_VERSION).asInteger());
        connOpts.setConnectionTimeout(context.getProperty(PROP_CONN_TIMEOUT).asInteger());
        PropertyValue sslProp = context.getProperty(PROP_SSL_CONTEXT_SERVICE);
        if (sslProp.isSet()) {
            Properties sslProps = transformSSLContextService((SSLContextService) sslProp.asControllerService());
            connOpts.setSSLProperties(sslProps);
        }
        PropertyValue lastWillTopicProp = context.getProperty(PROP_LAST_WILL_TOPIC);
        if (lastWillTopicProp.isSet()) {
            String lastWillMessage = context.getProperty(PROP_LAST_WILL_MESSAGE).getValue();
            PropertyValue lastWillRetain = context.getProperty(PROP_LAST_WILL_RETAIN);
            Integer lastWillQOS = context.getProperty(PROP_LAST_WILL_QOS).asInteger();
            connOpts.setWill(lastWillTopicProp.getValue(), lastWillMessage.getBytes(), lastWillQOS, lastWillRetain.isSet() ? lastWillRetain.asBoolean() : false);
        }
        PropertyValue usernameProp = context.getProperty(PROP_USERNAME);
        if (usernameProp.isSet()) {
            connOpts.setUserName(usernameProp.getValue());
            connOpts.setPassword(context.getProperty(PROP_PASSWORD).getValue().toCharArray());
        }
        mqttClientConnectLock.writeLock().lock();
        try {
            mqttClient = getMqttClient(broker, clientID, persistence);
        } finally {
            mqttClientConnectLock.writeLock().unlock();
        }
    } catch (MqttException me) {
        logger.error("Failed to initialize the connection to the  " + me.getMessage());
    }
}
Also used : MqttConnectOptions(org.eclipse.paho.client.mqttv3.MqttConnectOptions) MqttException(org.eclipse.paho.client.mqttv3.MqttException) PropertyValue(org.apache.nifi.components.PropertyValue) Properties(java.util.Properties)

Aggregations

PropertyValue (org.apache.nifi.components.PropertyValue)73 HashMap (java.util.HashMap)29 Test (org.junit.Test)22 StandardPropertyValue (org.apache.nifi.attribute.expression.language.StandardPropertyValue)21 ComponentLog (org.apache.nifi.logging.ComponentLog)18 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)16 IOException (java.io.IOException)15 Map (java.util.Map)13 FlowFile (org.apache.nifi.flowfile.FlowFile)11 ProcessException (org.apache.nifi.processor.exception.ProcessException)11 MockPropertyValue (org.apache.nifi.util.MockPropertyValue)11 ArrayList (java.util.ArrayList)9 SSLContext (javax.net.ssl.SSLContext)7 Relationship (org.apache.nifi.processor.Relationship)7 AuthorizerCreationException (org.apache.nifi.authorization.exception.AuthorizerCreationException)6 File (java.io.File)5 DynamicRelationship (org.apache.nifi.annotation.behavior.DynamicRelationship)5 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)5 SchemaIdentifier (org.apache.nifi.serialization.record.SchemaIdentifier)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5