本文整理汇总了Java中org.apache.nifi.util.MockFlowFile.toByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java MockFlowFile.toByteArray方法的具体用法?Java MockFlowFile.toByteArray怎么用?Java MockFlowFile.toByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.nifi.util.MockFlowFile
的用法示例。
在下文中一共展示了MockFlowFile.toByteArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: payloadWithMissingAttributes
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void payloadWithMissingAttributes() {
String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"boolean\": {{boolean}}}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "\"[email protected]\"");
props.put("pi", "3.14");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"boolean\": null}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例2: payloadWithTokenAttributes
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void payloadWithTokenAttributes() {
String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"text\": {{text}}}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "\"[email protected]\"");
props.put("pi", "3.14");
props.put("text", "\"here is some {{text}}\"");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"text\": \"here is some {{text}}\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例3: payloadWithSpecialCharacters
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void payloadWithSpecialCharacters() {
String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"text\": {{text}}}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "\"[email protected]\"");
props.put("pi", "3.14");
props.put("text", "\"here is some &$^()}{{}[email protected]#\"");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"text\": \"here is some &$^()}{{}[email protected]#\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例4: payloadWithDoubleQuotes
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void payloadWithDoubleQuotes() {
String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"text\": {{text}}}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "\"[email protected]\"");
props.put("pi", "3.14");
props.put("text", "\"here is some \"text\"\"");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"text\": \"here is some \"text\"\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例5: payloadWithSpacesWithinDelimiters
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void payloadWithSpacesWithinDelimiters() {
String payload = "{\"a\": {{ from}}, \"pi\": {{pi }}, \"text\": {{ text }}}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "\"[email protected]\"");
props.put("pi", "3.14");
props.put("text", "\"here is some text\"");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"text\": \"here is some text\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例6: payloadWithSpanishCharacters
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void payloadWithSpanishCharacters() {
String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"text\": {{text}}}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "\"[email protected]\"");
props.put("pi", "3.14");
props.put("text", "\"Mañana se me va un amigo capas el mejor que tuve y que voy a tener, te re quiero turrasdf Pasa que cada cosa que pienso/hago quiero contarle a mi él. Quiero gelatina y la bastarda no se hace mas -.-\"");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"text\": \"Mañana se me va un amigo capas el mejor que tuve y que voy a tener, te re quiero turrasdf Pasa que cada cosa que pienso/hago quiero contarle a mi él. Quiero gelatina y la bastarda no se hace mas -.-\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例7: payloadWithMissingAttributes
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void payloadWithMissingAttributes() {
String payload = "{\"a\": \"{{from}}\", \"pi\": \"{{pi:float}}\", \"boolean\": \"{{boolean:bool}}\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "[email protected]");
props.put("pi", "3.14");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
String expected = "{\"a\":\"[email protected]\",\"pi\":3.14,\"boolean\":null}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例8: payloadWithTokenAttributes
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void payloadWithTokenAttributes() {
String payload = "{\"a\": \"{{from}}\", \"pi\": \"{{pi:float}}\", \"text\": \"{{text}}\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "[email protected]");
props.put("pi", "3.14");
props.put("text", "\"here is some {{text}}\"");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
String expected = "{\"a\":\"[email protected]\",\"pi\":3.14,\"text\":\"\\\"here is some {{text}}\\\"\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例9: payloadWithSpecialCharacters
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void payloadWithSpecialCharacters() {
String payload = "{\"a\": \"{{from}}\", \"pi\": \"{{pi:float}}\", \"text\": \"{{text}}\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "[email protected]");
props.put("pi", "3.14");
props.put("text", "\"here is some &$^()}{{}[email protected]#\"");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
String expected = "{\"a\":\"[email protected]\",\"pi\":3.14,\"text\":\"\\\"here is some &$^()}{{}[email protected]#\\\"\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例10: payloadWithDoubleQuotes
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void payloadWithDoubleQuotes() {
String payload = "{\"a\": \"{{from}}\", \"pi\": \"{{pi:float}}\", \"text\": \"{{text}}\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "[email protected]");
props.put("pi", "3.14");
props.put("text", "here is some \"text\"");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
String expected = "{\"a\":\"[email protected]\",\"pi\":3.14,\"text\":\"here is some \\\"text\\\"\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例11: payloadWithSpacesWithinDelimiters
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void payloadWithSpacesWithinDelimiters() {
String payload = "{\"a\": \"{{ from}}\", \"pi\": \"{{pi }}\", \"text\": \" {{ text }} \"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "[email protected]");
props.put("pi", "3.14");
props.put("text", "here is some text");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
String expected = "{\"a\":\"[email protected]\",\"pi\":\"3.14\",\"text\":\"here is some text\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例12: payloadWithSpanishCharacters
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void payloadWithSpanishCharacters() {
String payload = "{\"a\": \"{{from}}\", \"pi\": \"{{pi}}\", \"text\": \"{{text}}\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "[email protected]");
props.put("pi", "3.14"); // This should be a string representation of the number 3.14
props.put("text", "Mañana se me va un amigo capas el mejor que tuve y que voy a tener, te re quiero turrasdf Pasa que cada cosa que pienso/hago quiero contarle a mi él. Quiero gelatina y la bastarda no se hace mas -.-");
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
String expected = "{\"a\":\"[email protected]\",\"pi\":\"3.14\",\"text\":\"Mañana se me va un amigo capas el mejor que tuve y que voy a tener, te re quiero turrasdf Pasa que cada cosa que pienso/hago quiero contarle a mi él. Quiero gelatina y la bastarda no se hace mas -.-\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例13: payloadWithUnicode
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void payloadWithUnicode() {
StringBuffer sb = new StringBuffer();
sb.append("\"");
sb.append(Character.toChars(127467));
sb.append(Character.toChars(127479));
sb.append("\"");
String payload = "{\"a\": {{from}}, \"pi\": {{pi}}, \"text\": {{text}}}";
final TestRunner runner = TestRunners.newTestRunner(new CreateContent());
runner.setProperty(CreateContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "\"[email protected]\"");
props.put("pi", "3.14");
props.put("text", sb.toString());
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateContent.REL_ORIGINAL, 1);
String expected = "{\"a\": \"[email protected]\", \"pi\": 3.14, \"text\": " + sb.toString() + "}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例14: payloadWithUnicode
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
@Test
public void payloadWithUnicode() {
StringBuffer sb = new StringBuffer();
sb.append(Character.toChars(127467));
sb.append(Character.toChars(127479));
String payload = "{\"a\": \"{{from}}\", \"pi\": \"{{pi:float}}\", \"text\": \"{{text}}\"}";
final TestRunner runner = TestRunners.newTestRunner(new CreateJsonContent());
runner.setProperty(CreateJsonContent.CONTENT_FIELD, payload);
ProcessSession session = runner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
Map<String, String> props = new HashMap<>();
props.put("from", "[email protected]");
props.put("pi", "3.14");
props.put("text", sb.toString());
ff = session.putAllAttributes(ff, props);
runner.enqueue(ff);
runner.run();
runner.assertTransferCount(CreateJsonContent.REL_FAILURE, 0);
runner.assertTransferCount(CreateJsonContent.REL_SUCCESS, 1);
runner.assertTransferCount(CreateJsonContent.REL_ORIGINAL, 1);
String expected = "{\"a\":\"[email protected]\",\"pi\":3.14,\"text\":\"" + sb.toString() + "\"}";
MockFlowFile out = runner.getFlowFilesForRelationship(CreateJsonContent.REL_SUCCESS).get(0);
String actual = new String(out.toByteArray());
assertEquals(expected, actual);
}
示例15: testTransformJavascript
import org.apache.nifi.util.MockFlowFile; //导入方法依赖的package包/类
/**
* Demonstrates transforming the JSON object in an incoming FlowFile to output
* @throws Exception
*/
@Test
public void testTransformJavascript() 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/transform.js");
runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
runner.assertValid();
InputObject inputJsonObject = new InputObject();
inputJsonObject.value = 3;
ObjectMapper mapper = new ObjectMapper();
byte[] jsonBytes = mapper.writeValueAsBytes(inputJsonObject);
runner.enqueue(jsonBytes);
runner.run();
runner.assertAllFlowFilesTransferred("success", 1);
final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
MockFlowFile result = successFlowFiles.get(0);
byte[] flowFileBytes = result.toByteArray();
OutputObject outputJsonObject = mapper.readValue(flowFileBytes, OutputObject.class);
Assert.assertEquals(9, outputJsonObject.value);
Assert.assertEquals("Hello", outputJsonObject.message);
}