本文整理汇总了Java中org.apache.nifi.util.MockFlowFile.assertAttributeEquals方法的典型用法代码示例。如果您正苦于以下问题:Java MockFlowFile.assertAttributeEquals方法的具体用法?Java MockFlowFile.assertAttributeEquals怎么用?Java MockFlowFile.assertAttributeEquals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.nifi.util.MockFlowFile
的用法示例。
在下文中一共展示了MockFlowFile.assertAttributeEquals方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: singleAttributeTest
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void singleAttributeTest() {
TestRunner runner = TestRunners.newTestRunner(Md5HashAttributes.class);
runner.setProperty("hash", "${attribute1}");
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
ff = session.putAttribute(ff, "attribute1", "pbs.twimg.com/media/ClvFsHiUgAE4fT6.jpg");
runner.enqueue(ff);
runner.run();
// All results were processed with out failure
runner.assertQueueEmpty();
runner.assertTransferCount(Md5HashAttributes.REL_SUCCESS, 1);
// If you need to read or do additional tests on results you can access the content
List<MockFlowFile> results = runner.getFlowFilesForRelationship(Md5HashAttributes.REL_SUCCESS);
assertTrue("1 match", results.size() == 1);
MockFlowFile result = results.get(0);
result.assertAttributeEquals("hash", "e2c26a2479f497562a615a42ecb1ef7e");
}
示例2: 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");
}
}
示例3: 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");
}
}
示例4: testPropertiesJavascript
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
/**
* Demonstrates reading values from nifi.properties
* @throws Exception
*/
@Test
public void testPropertiesJavascript() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, "src/test/resources/executescript/properties/nifi.properties");
NiFiPropertiesLoader nifiPropertiesLoader = new NiFiPropertiesLoader();
NiFiProperties nifiProperties = nifiPropertiesLoader.get();
runner.setValidateExpressionUsage(false);
runner.setProperty(SCRIPT_ENGINE, "ECMAScript");
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/properties/properties.js");
runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
runner.assertValid();
final Map<String, String> attributes = new HashMap<>();
attributes.put("property-name", "nifi.version");
runner.enqueue("sample text".getBytes(StandardCharsets.UTF_8), attributes);
runner.run();
runner.assertAllFlowFilesTransferred("success", 1);
final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
MockFlowFile result = successFlowFiles.get(0);
result.assertAttributeEquals("property-value", nifiProperties.getProperty("nifi.version"));
}
示例5: testPropertiesPython
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
/**
* Demonstrates reading values from nifi.properties
* @throws Exception
*/
@Test
public void testPropertiesPython() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, "src/test/resources/executescript/properties/nifi.properties");
NiFiPropertiesLoader nifiPropertiesLoader = new NiFiPropertiesLoader();
NiFiProperties nifiProperties = nifiPropertiesLoader.get();
runner.setValidateExpressionUsage(false);
runner.setProperty(SCRIPT_ENGINE, "python");
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/properties/properties.py");
runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
runner.assertValid();
final Map<String, String> attributes = new HashMap<>();
attributes.put("property-name", "nifi.version");
runner.enqueue("sample text".getBytes(StandardCharsets.UTF_8), attributes);
runner.run();
runner.assertAllFlowFilesTransferred("success", 1);
final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
MockFlowFile result = successFlowFiles.get(0);
result.assertAttributeEquals("property-value", nifiProperties.getProperty("nifi.version"));
}
示例6: testAttributeAccessJavascript
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
/**
* Demonstrates logging from within scripts
* @throws Exception
*/
@Test
public void testAttributeAccessJavascript() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
runner.setValidateExpressionUsage(false);
runner.setProperty(SCRIPT_ENGINE, "ECMAScript");
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/attributes/attributes.js");
runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
runner.assertValid();
final Map<String, String> attributes = new HashMap<>();
attributes.put("greeting", "Hello");
runner.enqueue("nothing".getBytes(StandardCharsets.UTF_8), attributes);
runner.run();
runner.assertAllFlowFilesTransferred("success", 1);
final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
MockFlowFile result = successFlowFiles.get(0);
result.assertAttributeEquals("message", "Hello, Script!");
result.assertAttributeEquals("attribute.one", "true");
result.assertAttributeEquals("attribute.two", "2");
}
示例7: testAttributesPython
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
/**
* Demonstrates logging from within scripts
* @throws Exception
*/
@Test
public void testAttributesPython() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
runner.setValidateExpressionUsage(false);
runner.setProperty(SCRIPT_ENGINE, "python");
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/attributes/attributes.py");
runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
runner.assertValid();
final Map<String, String> attributes = new HashMap<>();
attributes.put("greeting", "Hello");
runner.enqueue("nothing".getBytes(StandardCharsets.UTF_8), attributes);
runner.run();
runner.assertAllFlowFilesTransferred("success", 1);
final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
MockFlowFile result = successFlowFiles.get(0);
result.assertAttributeEquals("message", "Hello, Script!");
result.assertAttributeEquals("attribute.one", "true");
result.assertAttributeEquals("attribute.two", "2");
}
示例8: 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();
}
示例9: multipleAttributeTest
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void multipleAttributeTest() {
TestRunner runner = TestRunners.newTestRunner(Md5HashAttributes.class);
runner.setProperty("hash", "${attribute1}");
runner.setProperty("hash2", "${attribute2}");
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
ff = session.putAttribute(ff, "attribute1", "pbs.twimg.com/media/ClvFsHiUgAE4fT6.jpg");
ff = session.putAttribute(ff, "attribute2", "");
runner.enqueue(ff);
runner.run();
// All results were processed with out failure
runner.assertQueueEmpty();
runner.assertTransferCount(Md5HashAttributes.REL_SUCCESS, 1);
// If you need to read or do additional tests on results you can access the content
List<MockFlowFile> results = runner.getFlowFilesForRelationship(Md5HashAttributes.REL_SUCCESS);
assertTrue("1 match", results.size() == 1);
MockFlowFile result = results.get(0);
result.assertAttributeEquals("hash", "e2c26a2479f497562a615a42ecb1ef7e");
result.assertAttributeEquals("hash2", "d41d8cd98f00b204e9800998ecf8427e");
}
示例10: testSplitJavascript
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
/**
* Demonstrates splitting an array in a single incoming FlowFile into multiple output FlowFiles
* @throws Exception
*/
@Test
public void testSplitJavascript() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
runner.setValidateExpressionUsage(false);
runner.setProperty(SCRIPT_ENGINE, "ECMAScript");
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/content/split.js");
runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
runner.assertValid();
String inputContent = "[";
inputContent += "{ \"color\": \"blue\" },";
inputContent += "{ \"color\": \"green\" },";
inputContent += "{ \"color\": \"red\" }";
inputContent += "]";
runner.enqueue(inputContent.getBytes(StandardCharsets.UTF_8));
runner.run();
MockComponentLog log = runner.getLogger();
List<LogMessage> infoMessages = log.getInfoMessages();
runner.assertAllFlowFilesTransferred("success", 3);
final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
MockFlowFile blueFlowFile = successFlowFiles.get(0);
blueFlowFile.assertAttributeEquals("color", "blue");
MockFlowFile greenFlowFile = successFlowFiles.get(1);
greenFlowFile.assertAttributeEquals("color", "green");
MockFlowFile redFlowFile = successFlowFiles.get(2);
redFlowFile.assertAttributeEquals("color", "red");
}
示例11: testSplitPython
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
/**
* Demonstrates splitting an array in a single incoming FlowFile into multiple output FlowFiles
* @throws Exception
*/
@Test
public void testSplitPython() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
runner.setValidateExpressionUsage(false);
runner.setProperty(SCRIPT_ENGINE, "python");
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/content/split.py");
runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
runner.assertValid();
String inputContent = "[";
inputContent += "{ \"color\": \"blue\" },";
inputContent += "{ \"color\": \"green\" },";
inputContent += "{ \"color\": \"red\" }";
inputContent += "]";
runner.enqueue(inputContent.getBytes(StandardCharsets.UTF_8));
runner.run();
MockComponentLog log = runner.getLogger();
List<LogMessage> infoMessages = log.getInfoMessages();
runner.assertAllFlowFilesTransferred("success", 3);
final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
MockFlowFile blueFlowFile = successFlowFiles.get(0);
blueFlowFile.assertAttributeEquals("color", "blue");
MockFlowFile greenFlowFile = successFlowFiles.get(1);
greenFlowFile.assertAttributeEquals("color", "green");
MockFlowFile redFlowFile = successFlowFiles.get(2);
redFlowFile.assertAttributeEquals("color", "red");
}
示例12: testHasFace
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testHasFace() {
runTest(face_resource_path);
testRunner.assertAllFlowFilesTransferred(ExtractFaces.REL_MATCH);
List<MockFlowFile> flowFilesForRelationship = testRunner.getFlowFilesForRelationship(ExtractFaces.REL_MATCH);
for (MockFlowFile flowFile : flowFilesForRelationship) {
flowFile.assertAttributeEquals("faces.count", "1");
}
}
示例13: testMarksFace
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void testMarksFace() {
testRunner.setProperty(ExtractFaces.MARK_FACES, "true");
runTest(face_resource_path);
testRunner.assertAllFlowFilesTransferred(ExtractFaces.REL_MATCH);
List<MockFlowFile> flowFilesForRelationship = testRunner.getFlowFilesForRelationship(ExtractFaces.REL_MATCH);
for (MockFlowFile flowFile : flowFilesForRelationship) {
flowFile.assertAttributeEquals("faces.count", "1");
}
}
示例14: 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);
}
}