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());
}
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);
}
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());
}
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();
}
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());
}
}
Aggregations