本文整理汇总了Java中org.apache.nifi.util.MockFlowFile.assertAttributeExists方法的典型用法代码示例。如果您正苦于以下问题:Java MockFlowFile.assertAttributeExists方法的具体用法?Java MockFlowFile.assertAttributeExists怎么用?Java MockFlowFile.assertAttributeExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.nifi.util.MockFlowFile
的用法示例。
在下文中一共展示了MockFlowFile.assertAttributeExists方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPmmlScoreJsonData
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@SuppressWarnings("serial")
@Test
public void testPmmlScoreJsonData() throws IOException {
TestRunner runner = TestRunners.newTestRunner(OpenScoringProcessor.class);
InputStream in = getClass().getResourceAsStream(JSON_SNIPPET);
runner.enqueue(in, new HashMap<String, String>() {
{
put("mime.type", "text/json");
}
});
testPmmlScore(runner);
for (MockFlowFile f : runner.getFlowFilesForRelationship(OpenScoringProcessor.SUCCESS)) {
f.assertAttributeExists("class");
f.assertAttributeEquals("class", "Iris-setosa");
}
}
示例2: testFailure
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testFailure() {
runner.setProperty(DuplicateByAttribute.ATTRIBUTE_TO_DUPLICATE_BY, "list_of_things");
runner.setProperty(DuplicateByAttribute.OUTPUT_ATTRIBUTE, "thing");
final Map<String, String> attributes = new HashMap<String, String>();
attributes.put("list_of_things", "\"lions,\"tigers\",\"bears\"");
runner.enqueue("some content".getBytes(), attributes);
runner.run();
runner.assertTransferCount(DuplicateByAttribute.REL_SUCCESS, 0);
runner.assertTransferCount(DuplicateByAttribute.REL_FAILURE, 1);
runner.assertTransferCount(DuplicateByAttribute.REL_ORIGINAL, 0);
for (final MockFlowFile flowFile : runner.getFlowFilesForRelationship(DuplicateByAttribute.REL_FAILURE)) {
flowFile.assertAttributeExists("list_of_things");
flowFile.assertAttributeEquals("list_of_things", "\"lions,\"tigers\",\"bears\"");
flowFile.assertAttributeNotExists("thing");
flowFile.assertContentEquals("some content");
}
}
示例3: testSimpleTemplate
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testSimpleTemplate() throws Exception {
final TestRunner testRunner = TestRunners.newTestRunner(new PutFileFromTemplate());
testRunner.setProperty(PutFileFromTemplate.TEMPLATE_PROPERTY, "hello");
ProcessSession session = testRunner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
testRunner.enqueue(ff);
testRunner.run();
MockFlowFile successFlowFile = testRunner.getFlowFilesForRelationship(PutFileFromTemplate.SUCCESS_RELATIONSHIP).get(0);
successFlowFile.assertAttributeExists(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String outputFilePath = successFlowFile.getAttribute(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String renderedTemplate = FileUtils.readFileToString(new File(outputFilePath));
assertEquals(renderedTemplate, "hello");
testRunner.assertTransferCount(PutFileFromTemplate.SUCCESS_RELATIONSHIP, 1);
testRunner.assertTransferCount(PutFileFromTemplate.FAILURE_RELATIONSHIP, 0);
testRunner.assertTransferCount(PutFileFromTemplate.JSON_PARSING_FAILURE_RELATIONSHIP, 0);
}
示例4: testSimpleTemplateFromPath
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testSimpleTemplateFromPath() throws Exception {
final TestRunner testRunner = TestRunners.newTestRunner(new PutFileFromTemplate());
testRunner.setProperty(PutFileFromTemplate.TEMPLATE_PATH_PROPERTY, Paths.get("src/test/resources/simple.j2").toAbsolutePath().toString());
ProcessSession session = testRunner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
testRunner.enqueue(ff);
testRunner.run();
MockFlowFile successFlowFile = testRunner.getFlowFilesForRelationship(PutFileFromTemplate.SUCCESS_RELATIONSHIP).get(0);
successFlowFile.assertAttributeExists(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String outputFilePath = successFlowFile.getAttribute(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String renderedTemplate = FileUtils.readFileToString(new File(outputFilePath));
assertEquals(renderedTemplate, "hello");
testRunner.assertTransferCount(PutFileFromTemplate.SUCCESS_RELATIONSHIP, 1);
testRunner.assertTransferCount(PutFileFromTemplate.FAILURE_RELATIONSHIP, 0);
testRunner.assertTransferCount(PutFileFromTemplate.JSON_PARSING_FAILURE_RELATIONSHIP, 0);
}
示例5: testSimpleTemplateFromPathWithIncludes
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testSimpleTemplateFromPathWithIncludes() throws Exception {
final TestRunner testRunner = TestRunners.newTestRunner(new PutFileFromTemplate());
testRunner.setProperty(PutFileFromTemplate.TEMPLATE_PATH_PROPERTY, Paths.get("src/test/resources/including.j2").toAbsolutePath().toString());
ProcessSession session = testRunner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
testRunner.enqueue(ff);
testRunner.run();
MockFlowFile successFlowFile = testRunner.getFlowFilesForRelationship(PutFileFromTemplate.SUCCESS_RELATIONSHIP).get(0);
successFlowFile.assertAttributeExists(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String outputFilePath = successFlowFile.getAttribute(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String renderedTemplate = FileUtils.readFileToString(new File(outputFilePath));
assertEquals(renderedTemplate, "including: YES\nincluded: YES");
testRunner.assertTransferCount(PutFileFromTemplate.SUCCESS_RELATIONSHIP, 1);
testRunner.assertTransferCount(PutFileFromTemplate.FAILURE_RELATIONSHIP, 0);
testRunner.assertTransferCount(PutFileFromTemplate.JSON_PARSING_FAILURE_RELATIONSHIP, 0);
}
示例6: testSimpleTemplateFromPathWithIncludesFromResourcePath
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testSimpleTemplateFromPathWithIncludesFromResourcePath() throws Exception {
final TestRunner testRunner = TestRunners.newTestRunner(new PutFileFromTemplate());
testRunner.setProperty(PutFileFromTemplate.TEMPLATE_PATH_PROPERTY, Paths.get("src/test/resources/including.j2").toAbsolutePath().toString());
testRunner.setProperty(PutFileFromTemplate.TEMPLATE_RESOURCES_PATH_PROPERTY, Paths.get("src/test/resources/include-test").toAbsolutePath().toString());
ProcessSession session = testRunner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
testRunner.enqueue(ff);
testRunner.run();
MockFlowFile successFlowFile = testRunner.getFlowFilesForRelationship(PutFileFromTemplate.SUCCESS_RELATIONSHIP).get(0);
successFlowFile.assertAttributeExists(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String outputFilePath = successFlowFile.getAttribute(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String renderedTemplate = FileUtils.readFileToString(new File(outputFilePath));
assertEquals(renderedTemplate, "including: YES\nincluded: YES from include-test");
testRunner.assertTransferCount(PutFileFromTemplate.SUCCESS_RELATIONSHIP, 1);
testRunner.assertTransferCount(PutFileFromTemplate.FAILURE_RELATIONSHIP, 0);
testRunner.assertTransferCount(PutFileFromTemplate.JSON_PARSING_FAILURE_RELATIONSHIP, 0);
}
示例7: testAttributesInTemplate
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testAttributesInTemplate() throws Exception {
final TestRunner testRunner = TestRunners.newTestRunner(new PutFileFromTemplate());
testRunner.setProperty(PutFileFromTemplate.TEMPLATE_PROPERTY, "hello_{{ attributes.attr }}");
ProcessSession session = testRunner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
ff = session.putAttribute(ff, "attr", "test");
testRunner.enqueue(ff);
testRunner.run();
MockFlowFile successFlowFile = testRunner.getFlowFilesForRelationship(PutFileFromTemplate.SUCCESS_RELATIONSHIP).get(0);
successFlowFile.assertAttributeExists(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String outputFilePath = successFlowFile.getAttribute(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String renderedTemplate = FileUtils.readFileToString(new File(outputFilePath));
assertEquals(renderedTemplate, "hello_test");
testRunner.assertTransferCount(PutFileFromTemplate.SUCCESS_RELATIONSHIP, 1);
testRunner.assertTransferCount(PutFileFromTemplate.FAILURE_RELATIONSHIP, 0);
testRunner.assertTransferCount(PutFileFromTemplate.JSON_PARSING_FAILURE_RELATIONSHIP, 0);
}
示例8: testMissingAttributesInTemplate
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testMissingAttributesInTemplate() throws Exception {
final TestRunner testRunner = TestRunners.newTestRunner(new PutFileFromTemplate());
testRunner.setProperty(PutFileFromTemplate.TEMPLATE_PROPERTY, "hello_{{ attributes.attr }}");
ProcessSession session = testRunner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
testRunner.enqueue(ff);
testRunner.run();
MockFlowFile successFlowFile = testRunner.getFlowFilesForRelationship(PutFileFromTemplate.SUCCESS_RELATIONSHIP).get(0);
successFlowFile.assertAttributeExists(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String outputFilePath = successFlowFile.getAttribute(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String renderedTemplate = FileUtils.readFileToString(new File(outputFilePath));
assertEquals(renderedTemplate, "hello_");
testRunner.assertTransferCount(PutFileFromTemplate.SUCCESS_RELATIONSHIP, 1);
testRunner.assertTransferCount(PutFileFromTemplate.FAILURE_RELATIONSHIP, 0);
testRunner.assertTransferCount(PutFileFromTemplate.JSON_PARSING_FAILURE_RELATIONSHIP, 0);
}
示例9: testValidJSONObjectContent
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testValidJSONObjectContent() throws Exception {
final TestRunner testRunner = TestRunners.newTestRunner(new PutFileFromTemplate());
testRunner.setProperty(PutFileFromTemplate.TEMPLATE_PROPERTY, "hello_{{ content.array[0].text }}_{{ content.array[1].text }}_{{ content.object.text }}");
testRunner.setProperty(PutFileFromTemplate.PARSE_JSON_CONTENT_PROPERTY, "true");
testRunner.enqueue(Paths.get("src/test/resources/valid_object.json"));
testRunner.run();
MockFlowFile successFlowFile = testRunner.getFlowFilesForRelationship(PutFileFromTemplate.SUCCESS_RELATIONSHIP).get(0);
successFlowFile.assertAttributeExists(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String outputFilePath = successFlowFile.getAttribute(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String renderedTemplate = FileUtils.readFileToString(new File(outputFilePath));
assertEquals(renderedTemplate, "hello_sample array 1_sample array 2_sample object");
testRunner.assertTransferCount(PutFileFromTemplate.SUCCESS_RELATIONSHIP, 1);
testRunner.assertTransferCount(PutFileFromTemplate.FAILURE_RELATIONSHIP, 0);
testRunner.assertTransferCount(PutFileFromTemplate.JSON_PARSING_FAILURE_RELATIONSHIP, 0);
}
示例10: validateSuccessfulConsumeAndTransferToSuccess
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void validateSuccessfulConsumeAndTransferToSuccess() throws Exception {
final String destinationName = "cooQueue";
JmsTemplate jmsTemplate = CommonTest.buildJmsTemplateForDestination(false);
JMSPublisher sender = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
final Map<String, String> senderAttributes = new HashMap<>();
senderAttributes.put("filename", "message.txt");
senderAttributes.put("attribute_from_sender", "some value");
sender.publish(destinationName, "Hey dude!".getBytes(), senderAttributes);
TestRunner runner = TestRunners.newTestRunner(new ConsumeJMS());
JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
when(cs.getIdentifier()).thenReturn("cfProvider");
when(cs.getConnectionFactory()).thenReturn(jmsTemplate.getConnectionFactory());
runner.addControllerService("cfProvider", cs);
runner.enableControllerService(cs);
runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
runner.setProperty(ConsumeJMS.DESTINATION, destinationName);
runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.QUEUE);
runner.run(1, false);
//
final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0);
assertNotNull(successFF);
successFF.assertAttributeExists(JmsHeaders.DESTINATION);
successFF.assertAttributeEquals(JmsHeaders.DESTINATION, destinationName);
successFF.assertAttributeExists("filename");
successFF.assertAttributeEquals("filename", "message.txt");
successFF.assertAttributeExists("attribute_from_sender");
successFF.assertAttributeEquals("attribute_from_sender", "some value");
successFF.assertContentEquals("Hey dude!".getBytes());
String sourceDestination = successFF.getAttribute(ConsumeJMS.JMS_SOURCE_DESTINATION_NAME);
assertNotNull(sourceDestination);
((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
}
示例11: testPrefixSuffix
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testPrefixSuffix() throws Exception {
final TestRunner testRunner = TestRunners.newTestRunner(new PutFileFromTemplate());
testRunner.setProperty(PutFileFromTemplate.TEMPLATE_PROPERTY, "hello");
testRunner.setProperty(PutFileFromTemplate.FILE_PREFIX_PROPERTY, "prefix");
testRunner.setProperty(PutFileFromTemplate.FILE_SUFFIX_PROPERTY, ".suffix");
ProcessSession session = testRunner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
testRunner.enqueue(ff);
testRunner.run();
MockFlowFile successFlowFile = testRunner.getFlowFilesForRelationship(PutFileFromTemplate.SUCCESS_RELATIONSHIP).get(0);
successFlowFile.assertAttributeExists(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
String outputFilePath = successFlowFile.getAttribute(PutFileFromTemplate.DEFAULT_OUTPUT_PATH_SAVED_IN_ATTRIBUTE);
Path p = Paths.get(outputFilePath);
assertTrue(p.getFileName().toString().startsWith("prefix"));
assertTrue(p.getFileName().toString().endsWith(".suffix"));
// Ensure something more than just prefix and suffix.
assertNotEquals(outputFilePath, "prefix.suffix");
testRunner.assertTransferCount(PutFileFromTemplate.SUCCESS_RELATIONSHIP, 1);
testRunner.assertTransferCount(PutFileFromTemplate.FAILURE_RELATIONSHIP, 0);
testRunner.assertTransferCount(PutFileFromTemplate.JSON_PARSING_FAILURE_RELATIONSHIP, 0);
}
示例12: validateSuccessfulConsumeAndTransferToSuccessOverJNDI
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void validateSuccessfulConsumeAndTransferToSuccessOverJNDI() {
final String destinationName = "cooQueue";
try {
JmsTemplate jmsTemplate = CommonTest.buildJmsJndiTemplateForDestination(false);
JMSPublisher sender = new JMSPublisher(jmsTemplate, mock(ComponentLog.class));
final Map<String, String> senderAttributes = new HashMap<>();
senderAttributes.put("filename", "message.txt");
senderAttributes.put("attribute_from_sender", "some value");
sender.publish(destinationName, "Hey dude!".getBytes(), senderAttributes);
TestRunner runner = TestRunners.newTestRunner(new ConsumeJMS());
JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
when(cs.getIdentifier()).thenReturn("cfProvider");
when(cs.getConnectionFactory()).thenReturn(jmsTemplate.getConnectionFactory());
runner.addControllerService("cfProvider", cs);
runner.enableControllerService(cs);
runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
runner.setProperty(ConsumeJMS.DESTINATION, destinationName);
runner.setProperty(ConsumeJMS.DESTINATION_TYPE, ConsumeJMS.QUEUE);
runner.run(1, false);
//
final MockFlowFile successFF = runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).get(0);
assertNotNull(successFF);
successFF.assertAttributeExists(JmsHeaders.DESTINATION);
successFF.assertAttributeEquals(JmsHeaders.DESTINATION, destinationName);
successFF.assertAttributeExists("filename");
successFF.assertAttributeEquals("filename", "message.txt");
successFF.assertAttributeExists("attribute_from_sender");
successFF.assertAttributeEquals("attribute_from_sender", "some value");
successFF.assertContentEquals("Hey dude!".getBytes());
String sourceDestination = successFF.getAttribute(ConsumeJMS.JMS_SOURCE_DESTINATION_NAME);
assertNotNull(sourceDestination);
((CachingConnectionFactory) jmsTemplate.getConnectionFactory()).destroy();
} catch (Exception ex) {
Logger.getLogger(ConsumeJMSTest.class.getName()).log(Level.SEVERE, null, ex);
}
}