Java Code Examples for org.apache.nifi.util.MockFlowFile#assertContentEquals()
The following examples show how to use
org.apache.nifi.util.MockFlowFile#assertContentEquals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestPutDistributedMapCache.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testMaxCacheEntrySize() throws InitializationException, IOException { runner.setProperty(PutDistributedMapCache.CACHE_ENTRY_IDENTIFIER, "${uuid}"); runner.setProperty(PutDistributedMapCache.CACHE_ENTRY_MAX_BYTES, "10 B"); // max length is 10 bytes, flow file content is 20 bytes String flowFileContent = "contentwhichistoobig"; runner.enqueue(flowFileContent.getBytes("UTF-8")); runner.run(); // no cache key attribute runner.assertAllFlowFilesTransferred(PutDistributedMapCache.REL_FAILURE, 1); runner.assertTransferCount(PutDistributedMapCache.REL_FAILURE, 1); final MockFlowFile outputFlowFile = runner.getFlowFilesForRelationship(PutDistributedMapCache.REL_FAILURE).get(0); outputFlowFile.assertAttributeNotExists("cached"); outputFlowFile.assertContentEquals(flowFileContent); runner.clearTransferState(); runner.setProperty(PutDistributedMapCache.CACHE_ENTRY_MAX_BYTES, "1 MB"); }
Example 2
Source File: TestReplaceText.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testAlwaysReplaceLineByLine() { final TestRunner runner = getRunner(); runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE); runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.ALWAYS_REPLACE); runner.setProperty(ReplaceText.SEARCH_VALUE, "i do not exist anywhere in the text"); runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${filename}"); final Map<String, String> attributes = new HashMap<>(); attributes.put("filename", "abc.txt"); runner.enqueue("Hello\nWorld!\r\ntoday!\n".getBytes(), attributes); runner.run(); runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1); final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0); out.assertContentEquals("abc.txt\nabc.txt\r\nabc.txt\n"); }
Example 3
Source File: TestRouteText.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testSimpleDefaultContainRegularExpression() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new RouteText()); runner.setProperty(RouteText.MATCH_STRATEGY, RouteText.CONTAINS_REGULAR_EXPRESSION); runner.setProperty("simple", "(m.d)"); runner.enqueue("start middle end\nnot match".getBytes("UTF-8")); runner.run(); runner.assertTransferCount("simple", 1); runner.assertTransferCount("unmatched", 1); runner.assertTransferCount("original", 1); final MockFlowFile outMatched = runner.getFlowFilesForRelationship("simple").get(0); outMatched.assertContentEquals("start middle end\n".getBytes("UTF-8")); final MockFlowFile outUnmatched = runner.getFlowFilesForRelationship("unmatched").get(0); outUnmatched.assertContentEquals("not match".getBytes("UTF-8")); }
Example 4
Source File: TestPutSplunk.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testTCPSendDelimitedMessages() { final String delimiter = "DD"; runner.setProperty(PutSplunk.MESSAGE_DELIMITER, delimiter); runner.setProperty(PutSplunk.PROTOCOL, PutSplunk.TCP_VALUE.getValue()); // no delimiter at end final String message = "This is message 1DDThis is message 2DDThis is message 3"; runner.enqueue(message); runner.run(1); runner.assertAllFlowFilesTransferred(PutSplunk.REL_SUCCESS, 1); final MockFlowFile mockFlowFile = runner.getFlowFilesForRelationship(PutSplunk.REL_SUCCESS).get(0); mockFlowFile.assertContentEquals(message); Assert.assertEquals(3, sender.getMessages().size()); Assert.assertEquals("This is message 1\n", sender.getMessages().get(0)); Assert.assertEquals("This is message 2\n", sender.getMessages().get(1)); Assert.assertEquals("This is message 3\n", sender.getMessages().get(2)); }
Example 5
Source File: TestPutSplunk.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testUDPSendDelimitedMessages() { runner.setProperty(PutSplunk.PROTOCOL, PutSplunk.UDP_VALUE.getValue()); final String delimiter = "DD"; runner.setProperty(PutSplunk.MESSAGE_DELIMITER, delimiter); final String message = "This is message 1DDThis is message 2DDThis is message 3"; runner.enqueue(message); runner.run(1); runner.assertAllFlowFilesTransferred(PutSplunk.REL_SUCCESS, 1); final MockFlowFile mockFlowFile = runner.getFlowFilesForRelationship(PutSplunk.REL_SUCCESS).get(0); mockFlowFile.assertContentEquals(message); Assert.assertEquals(3, sender.getMessages().size()); Assert.assertEquals("This is message 1", sender.getMessages().get(0)); Assert.assertEquals("This is message 2", sender.getMessages().get(1)); Assert.assertEquals("This is message 3", sender.getMessages().get(2)); }
Example 6
Source File: TestFetchHDFS.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testAutomaticDecompression() throws IOException { FetchHDFS proc = new TestableFetchHDFS(kerberosProperties); TestRunner runner = TestRunners.newTestRunner(proc); runner.setProperty(FetchHDFS.FILENAME, "src/test/resources/testdata/randombytes-1.gz"); runner.setProperty(FetchHDFS.COMPRESSION_CODEC, "AUTOMATIC"); runner.enqueue(new String("trigger flow file")); runner.run(); List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(FetchHDFS.REL_SUCCESS); assertEquals(1, flowFiles.size()); MockFlowFile flowFile = flowFiles.get(0); assertTrue(flowFile.getAttribute(CoreAttributes.FILENAME.key()).equals("randombytes-1")); InputStream expected = getClass().getResourceAsStream("/testdata/randombytes-1"); flowFile.assertContentEquals(expected); }
Example 7
Source File: TestConvertAvroToJSON.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testZeroRecords() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new ConvertAvroToJSON()); final Schema schema = new Schema.Parser().parse(new File("src/test/resources/user.avsc")); final DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<>(schema); final ByteArrayOutputStream out1 = serializeAvroRecord(schema, datumWriter); runner.enqueue(out1.toByteArray()); runner.run(); runner.assertAllFlowFilesTransferred(ConvertAvroToJSON.REL_SUCCESS, 1); final MockFlowFile out = runner.getFlowFilesForRelationship(ConvertAvroToJSON.REL_SUCCESS).get(0); out.assertContentEquals("{}"); }
Example 8
Source File: ITPutKinesisFirehose.java From localization_nifi with Apache License 2.0 | 6 votes |
/** * Comment out ignore for integration tests (requires creds files) */ @Test public void testIntegrationSuccess() throws Exception { runner = TestRunners.newTestRunner(PutKinesisFirehose.class); runner.setProperty(PutKinesisFirehose.CREDENTIALS_FILE, CREDENTIALS_FILE); runner.setProperty(PutKinesisFirehose.KINESIS_FIREHOSE_DELIVERY_STREAM_NAME, "testkinesis"); runner.assertValid(); runner.enqueue("test".getBytes()); runner.run(1); runner.assertAllFlowFilesTransferred(PutKinesisFirehose.REL_SUCCESS, 1); final List<MockFlowFile> ffs = runner.getFlowFilesForRelationship(FetchS3Object.REL_SUCCESS); final MockFlowFile out = ffs.iterator().next(); out.assertContentEquals("test".getBytes()); }
Example 9
Source File: TestUnpackContent.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testFlowFileStreamV2() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new UnpackContent()); runner.setProperty(UnpackContent.PACKAGING_FORMAT, UnpackContent.PackageFormat.FLOWFILE_STREAM_FORMAT_V2.toString()); runner.enqueue(dataPath.resolve("data.flowfilev2")); runner.enqueue(dataPath.resolve("data.flowfilev2")); runner.run(2); runner.assertTransferCount(UnpackContent.REL_SUCCESS, 4); runner.assertTransferCount(UnpackContent.REL_ORIGINAL, 2); runner.getFlowFilesForRelationship(UnpackContent.REL_ORIGINAL).get(0).assertAttributeEquals(FRAGMENT_COUNT, "2"); runner.getFlowFilesForRelationship(UnpackContent.REL_ORIGINAL).get(1).assertAttributeEquals(FRAGMENT_COUNT, "2"); runner.assertTransferCount(UnpackContent.REL_FAILURE, 0); final List<MockFlowFile> unpacked = runner.getFlowFilesForRelationship(UnpackContent.REL_SUCCESS); for (final MockFlowFile flowFile : unpacked) { final String filename = flowFile.getAttribute(CoreAttributes.FILENAME.key()); final String folder = flowFile.getAttribute(CoreAttributes.PATH.key()); final Path path = dataPath.resolve(folder).resolve(filename); assertTrue(Files.exists(path)); flowFile.assertContentEquals(path.toFile()); } }
Example 10
Source File: TestModifyBytes.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testRemoveFooter() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new ModifyBytes()); runner.setProperty(ModifyBytes.START_OFFSET, "0 B"); runner.setProperty(ModifyBytes.END_OFFSET, "12 B"); runner.enqueue(testFilePath); runner.run(); runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1); final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0); final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8); System.out.println(outContent); out.assertContentEquals(noFooterFile); }
Example 11
Source File: TestEncryptContent.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testPGPDecrypt() throws IOException { final TestRunner runner = TestRunners.newTestRunner(EncryptContent.class); runner.setProperty(EncryptContent.MODE, EncryptContent.DECRYPT_MODE); runner.setProperty(EncryptContent.ENCRYPTION_ALGORITHM, EncryptionMethod.PGP_ASCII_ARMOR.name()); runner.setProperty(EncryptContent.PASSWORD, "Hello, World!"); runner.enqueue(Paths.get("src/test/resources/TestEncryptContent/text.txt.asc")); runner.run(); runner.assertAllFlowFilesTransferred(EncryptContent.REL_SUCCESS, 1); final MockFlowFile flowFile = runner.getFlowFilesForRelationship(EncryptContent.REL_SUCCESS).get(0); flowFile.assertContentEquals(Paths.get("src/test/resources/TestEncryptContent/text.txt")); }
Example 12
Source File: TestInvokeHttpCommon.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testMultipleSameHeaders() throws Exception { addHandler(new GetMultipleHeaderHandler()); runner.setProperty(InvokeHTTP.PROP_URL, url + "/status/200"); createFlowFiles(runner); runner.run(); runner.assertTransferCount(InvokeHTTP.REL_SUCCESS_REQ, 1); runner.assertTransferCount(InvokeHTTP.REL_RESPONSE, 1); runner.assertTransferCount(InvokeHTTP.REL_RETRY, 0); runner.assertTransferCount(InvokeHTTP.REL_NO_RETRY, 0); runner.assertTransferCount(InvokeHTTP.REL_FAILURE, 0); runner.assertPenalizeCount(0); // expected in request status.code and status.message // original flow file (+attributes) final MockFlowFile bundle = runner.getFlowFilesForRelationship(InvokeHTTP.REL_SUCCESS_REQ).get(0); bundle.assertContentEquals("Hello".getBytes("UTF-8")); bundle.assertAttributeEquals(InvokeHTTP.STATUS_CODE, "200"); bundle.assertAttributeEquals(InvokeHTTP.STATUS_MESSAGE, "OK"); bundle.assertAttributeEquals("Foo", "Bar"); // expected in response // status code, status message, all headers from server response --> ff attributes // server response message body into payload of ff final MockFlowFile bundle1 = runner.getFlowFilesForRelationship(InvokeHTTP.REL_RESPONSE).get(0); bundle1.assertContentEquals("/status/200".getBytes("UTF-8")); bundle1.assertAttributeEquals(InvokeHTTP.STATUS_CODE, "200"); bundle1.assertAttributeEquals(InvokeHTTP.STATUS_MESSAGE, "OK"); bundle1.assertAttributeEquals("Foo", "Bar"); bundle1.assertAttributeEquals("double", "1, 2"); bundle1.assertAttributeEquals("Content-Type", "text/plain;charset=iso-8859-1"); }
Example 13
Source File: TestConvertAvroToJSON.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testSingleSchemalessAvroMessage() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new ConvertAvroToJSON()); Schema schema = new Schema.Parser().parse(new File("src/test/resources/user.avsc")); String stringSchema = schema.toString(); runner.setProperty(ConvertAvroToJSON.SCHEMA, stringSchema); final GenericRecord user1 = new GenericData.Record(schema); user1.put("name", "Alyssa"); user1.put("favorite_number", 256); final ByteArrayOutputStream out1 = new ByteArrayOutputStream(); final BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(out1, null); final DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<>(schema); datumWriter.write(user1, encoder); encoder.flush(); out1.flush(); byte[] test = out1.toByteArray(); runner.enqueue(test); runner.run(); runner.assertAllFlowFilesTransferred(ConvertAvroToJSON.REL_SUCCESS, 1); final MockFlowFile out = runner.getFlowFilesForRelationship(ConvertAvroToJSON.REL_SUCCESS).get(0); out.assertContentEquals("{\"name\": \"Alyssa\", \"favorite_number\": 256, \"favorite_color\": null}"); }
Example 14
Source File: ConvertExcelToCSVProcessorTest.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testCustomDelimiters() throws Exception { testRunner.enqueue(new File("src/test/resources/dataformatting.xlsx").toPath()); testRunner.setProperty(CSVUtils.VALUE_SEPARATOR, "|"); testRunner.setProperty(CSVUtils.RECORD_SEPARATOR, "\\r\\n"); testRunner.setProperty(ConvertExcelToCSVProcessor.FORMAT_VALUES, "true"); testRunner.run(); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.SUCCESS, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.ORIGINAL, 1); testRunner.assertTransferCount(ConvertExcelToCSVProcessor.FAILURE, 0); MockFlowFile ff = testRunner.getFlowFilesForRelationship(ConvertExcelToCSVProcessor.SUCCESS).get(0); Long rowsSheet = new Long(ff.getAttribute(ConvertExcelToCSVProcessor.ROW_NUM)); assertTrue(rowsSheet == 9); LocalDateTime localDt = LocalDateTime.of(2017, 1, 1, 12, 0, 0); DecimalFormatSymbols decimalFormatSymbols = DecimalFormatSymbols.getInstance(); String valueSeparator = testRunner.getProcessContext().getProperty(CSVUtils.VALUE_SEPARATOR).evaluateAttributeExpressions(ff).getValue(); String decimalSeparator = (String.valueOf(decimalFormatSymbols.getDecimalSeparator()).equals(valueSeparator)) ? ("\\" + decimalFormatSymbols.getDecimalSeparator()) : String.valueOf(decimalFormatSymbols.getDecimalSeparator()); String groupingSeparator = String.valueOf(decimalFormatSymbols.getGroupingSeparator()).equals(valueSeparator) ? "\\" + decimalFormatSymbols.getGroupingSeparator() : String.valueOf(decimalFormatSymbols.getGroupingSeparator()); ff.assertContentEquals(String.format("Numbers|Timestamps|Money\r\n" + "1234%1$s456|" + DateTimeFormatter.ofPattern("d/M/yy").format(localDt) + "|$ 123%1$s45\r\n" + "1234%1$s46|" + DateTimeFormatter.ofPattern("hh:mm:ss a").format(localDt) + "|£ 123%1$s45\r\n" + "1234%1$s5|" + DateTimeFormatter.ofPattern("EEEE, MMMM dd, yyyy").format(localDt) + "|¥ 123%1$s45\r\n" + "1%2$s234%1$s46|" + DateTimeFormatter.ofPattern("d/M/yy HH:mm").format(localDt) + "|$ 1%2$s023%1$s45\r\n" + "1%2$s234%1$s4560|" + DateTimeFormatter.ofPattern("hh:mm a").format(localDt) + "|£ 1%2$s023%1$s45\r\n" + "9%1$s88E+08|" + DateTimeFormatter.ofPattern("yyyy/MM/dd/ HH:mm").format(localDt) + "|¥ 1%2$s023%1$s45\r\n" + "9%1$s877E+08||\r\n" + "9%1$s8765E+08||\r\n", decimalSeparator, groupingSeparator)); }
Example 15
Source File: TestYandexTranslate.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testTranslateContentAndMultipleAttributes() { final TestRunner testRunner = createTestRunner(200); testRunner.setProperty(YandexTranslate.KEY, "A"); testRunner.setProperty(YandexTranslate.SOURCE_LANGUAGE, "fr"); testRunner.setProperty(YandexTranslate.TARGET_LANGUAGE, "en"); testRunner.setProperty(YandexTranslate.TRANSLATE_CONTENT, "true"); testRunner.setProperty(YandexTranslate.CHARACTER_SET, "UTF-8"); testRunner.setProperty("hello", "bonjour"); testRunner.setProperty("translate", "traduire"); testRunner.setProperty("fun", "amusant"); testRunner.setProperty("nifi", "nifi"); testRunner.enqueue("ordinateur".getBytes()); testRunner.run(); testRunner.assertAllFlowFilesTransferred(YandexTranslate.REL_SUCCESS, 1); final MockFlowFile out = testRunner.getFlowFilesForRelationship(YandexTranslate.REL_SUCCESS).get(0); out.assertContentEquals("computer"); out.assertAttributeEquals("hello", "hello"); out.assertAttributeEquals("translate", "translate"); out.assertAttributeEquals("fun", "fun"); out.assertAttributeEquals("nifi", "nifi"); }
Example 16
Source File: TestInvokeHttpCommon.java From localization_nifi with Apache License 2.0 | 4 votes |
@Test public void testArbitraryRequest() throws Exception { addHandler(new FetchHandler()); runner.setProperty(InvokeHTTP.PROP_URL, url + "/status/200"); runner.setProperty(InvokeHTTP.PROP_METHOD,"FETCH"); createFlowFiles(runner); runner.run(); runner.assertTransferCount(InvokeHTTP.REL_SUCCESS_REQ, 1); runner.assertTransferCount(InvokeHTTP.REL_RESPONSE, 1); runner.assertTransferCount(InvokeHTTP.REL_RETRY, 0); runner.assertTransferCount(InvokeHTTP.REL_NO_RETRY, 0); runner.assertTransferCount(InvokeHTTP.REL_FAILURE, 0); runner.assertPenalizeCount(0); //expected in request status.code and status.message //original flow file (+attributes) final MockFlowFile bundle = runner.getFlowFilesForRelationship(InvokeHTTP.REL_SUCCESS_REQ).get(0); bundle.assertAttributeEquals(InvokeHTTP.STATUS_CODE, "200"); bundle.assertAttributeEquals(InvokeHTTP.STATUS_MESSAGE, "OK"); final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); final String expected = "Hello"; Assert.assertEquals(expected, actual); bundle.assertAttributeEquals("Foo", "Bar"); //expected in response //status code, status message, all headers from server response --> ff attributes //server response message body into payload of ff final MockFlowFile bundle1 = runner.getFlowFilesForRelationship(InvokeHTTP.REL_RESPONSE).get(0); bundle1.assertContentEquals("/status/200".getBytes("UTF-8")); bundle1.assertAttributeEquals(InvokeHTTP.STATUS_CODE, "200"); bundle1.assertAttributeEquals(InvokeHTTP.STATUS_MESSAGE, "OK"); bundle1.assertAttributeEquals("Foo", "Bar"); bundle1.assertAttributeEquals("Content-Type", "text/plain;charset=iso-8859-1"); final String actual1 = new String(bundle1.toByteArray(), StandardCharsets.UTF_8); final String expected1 = "/status/200"; Assert.assertEquals(expected1, actual1); }
Example 17
Source File: TestTailFile.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testMigrateFrom100To110() throws IOException { assumeFalse(isWindowsEnvironment()); runner.setProperty(TailFile.FILENAME, "target/existing-log.txt"); final MockStateManager stateManager = runner.getStateManager(); // Before NiFi 1.1.0, TailFile only handles single file // and state key doesn't have index in it. final Map<String, String> state = new HashMap<>(); state.put("filename", "target/existing-log.txt"); // Simulate that it has been tailed up to the 2nd line. state.put("checksum", "2279929157"); state.put("position", "14"); state.put("timestamp", "1480639134000"); stateManager.setState(state, Scope.LOCAL); runner.run(); runner.assertAllFlowFilesTransferred(TailFile.REL_SUCCESS, 1); final MockFlowFile flowFile = runner.getFlowFilesForRelationship(TailFile.REL_SUCCESS).iterator().next(); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(bos))) { writer.write("Line 3"); writer.newLine(); } flowFile.assertContentEquals(bos.toByteArray()); // The old states should be replaced with new ones. final StateMap updatedState = stateManager.getState(Scope.LOCAL); assertNull(updatedState.get("filename")); assertNull(updatedState.get("checksum")); assertNull(updatedState.get("position")); assertNull(updatedState.get("timestamp")); assertEquals("target/existing-log.txt", updatedState.get("file.0.filename")); assertEquals("3380848603", updatedState.get("file.0.checksum")); assertEquals("21", updatedState.get("file.0.position")); assertNotNull(updatedState.get("file.0.timestamp")); // When it runs again, the state is already migrated, so it shouldn't emit any flow files. runner.clearTransferState(); runner.run(); runner.assertAllFlowFilesTransferred(TailFile.REL_SUCCESS, 0); }
Example 18
Source File: TestUpdateAttribute.java From localization_nifi with Apache License 2.0 | 4 votes |
@Test public void testMultipleRuleHitsWithUseClone() throws Exception { final Criteria criteria = getCriteria(); criteria.setFlowFilePolicy(FlowFilePolicy.USE_CLONE); addRule(criteria, "rule 1", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.2", "value.2")); addRule(criteria, "rule 2", Arrays.asList( // conditions "${attribute.1:equals('value.1')}"), getMap( // actions "attribute.3", "value.3")); final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setAnnotationData(serialize(criteria)); runner.setProperty("attribute.2", "default.value.2"); final Map<String, String> attributes = new HashMap<>(); attributes.put("attribute.1", "value.1"); runner.enqueue(TEST_CONTENT.getBytes(StandardCharsets.UTF_8), attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 2); final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS); final MockFlowFile flowfile1 = result.get(0); final MockFlowFile flowfile2 = result.get(1); // ensure the attributes are as expected if ("rule 1".equals(flowfile1.getAttribute(runner.getProcessor().getClass().getSimpleName() + ".matchedRule"))) { flowfile1.assertAttributeEquals("attribute.2", "value.2"); flowfile2.assertAttributeEquals("attribute.3", "value.3"); flowfile2.assertAttributeEquals("attribute.2", "default.value.2"); } else { flowfile2.assertAttributeEquals("attribute.2", "value.2"); flowfile1.assertAttributeEquals("attribute.3", "value.3"); flowfile1.assertAttributeEquals("attribute.2", "default.value.2"); } // ensure the content was copied as well flowfile1.assertContentEquals(TEST_CONTENT.getBytes(StandardCharsets.UTF_8)); flowfile2.assertContentEquals(TEST_CONTENT.getBytes(StandardCharsets.UTF_8)); }
Example 19
Source File: ITPutIgniteCache.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testPutIgniteCacheOnTriggerNoConfigurationTwoFlowFile() throws IOException, InterruptedException { runner = TestRunners.newTestRunner(putIgniteCache); runner.setProperty(PutIgniteCache.BATCH_SIZE, "5"); runner.setProperty(PutIgniteCache.CACHE_NAME, CACHE_NAME); runner.setProperty(PutIgniteCache.DATA_STREAMER_PER_NODE_BUFFER_SIZE, "1"); runner.setProperty(PutIgniteCache.IGNITE_CACHE_ENTRY_KEY, "${igniteKey}"); runner.assertValid(); properties1.put("igniteKey", "key51"); runner.enqueue("test1".getBytes(),properties1); properties2.put("igniteKey", "key52"); runner.enqueue("test2".getBytes(),properties2); runner.run(1, false, true); runner.assertAllFlowFilesTransferred(PutIgniteCache.REL_SUCCESS, 2); List<MockFlowFile> sucessfulFlowFiles = runner.getFlowFilesForRelationship(PutIgniteCache.REL_SUCCESS); assertEquals(2, sucessfulFlowFiles.size()); List<MockFlowFile> failureFlowFiles = runner.getFlowFilesForRelationship(PutIgniteCache.REL_FAILURE); assertEquals(0, failureFlowFiles.size()); final MockFlowFile out = runner.getFlowFilesForRelationship(PutIgniteCache.REL_SUCCESS).get(0); out.assertAttributeEquals(PutIgniteCache.IGNITE_BATCH_FLOW_FILE_SUCCESSFUL_ITEM_NUMBER, "0"); out.assertAttributeEquals(PutIgniteCache.IGNITE_BATCH_FLOW_FILE_TOTAL_COUNT, "2"); out.assertAttributeEquals(PutIgniteCache.IGNITE_BATCH_FLOW_FILE_SUCCESSFUL_COUNT, "2"); out.assertAttributeEquals(PutIgniteCache.IGNITE_BATCH_FLOW_FILE_ITEM_NUMBER, "0"); out.assertContentEquals("test1".getBytes()); System.out.println("value was " + new String(putIgniteCache.getIgniteCache().get("key51"))); Assert.assertArrayEquals("test1".getBytes(),(byte[])putIgniteCache.getIgniteCache().get("key51")); final MockFlowFile out2 = runner.getFlowFilesForRelationship(PutIgniteCache.REL_SUCCESS).get(1); out2.assertAttributeEquals(PutIgniteCache.IGNITE_BATCH_FLOW_FILE_SUCCESSFUL_ITEM_NUMBER, "1"); out2.assertAttributeEquals(PutIgniteCache.IGNITE_BATCH_FLOW_FILE_TOTAL_COUNT, "2"); out2.assertAttributeEquals(PutIgniteCache.IGNITE_BATCH_FLOW_FILE_SUCCESSFUL_COUNT, "2"); out2.assertAttributeEquals(PutIgniteCache.IGNITE_BATCH_FLOW_FILE_ITEM_NUMBER, "1"); out2.assertContentEquals("test2".getBytes()); Assert.assertArrayEquals("test2".getBytes(),(byte[])putIgniteCache.getIgniteCache().get("key52")); putIgniteCache.getIgniteCache().remove("key52"); putIgniteCache.getIgniteCache().remove("key51"); }
Example 20
Source File: TestPutJMS.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testPutGetAttributesAndProps() throws JMSException { final PutJMS putJMS = spy(new PutJMS()); final TestRunner runnerPut = TestRunners.newTestRunner(putJMS); runnerPut.setProperty(JmsProperties.JMS_PROVIDER, TEST_PROVIDER); runnerPut.setProperty(JmsProperties.URL, TEST_URL); runnerPut.setProperty(JmsProperties.DESTINATION_TYPE, TEST_DEST_TYPE); runnerPut.setProperty(JmsProperties.DESTINATION_NAME, TEST_DEST_NAME + testQueueSuffix()); runnerPut.setProperty(JmsProperties.REPLY_TO_QUEUE, TEST_DEST_NAME + testQueueSuffix() + ".reply"); runnerPut.setProperty(JmsProperties.ATTRIBUTES_TO_JMS_PROPS, "true"); runnerPut.run(); final Map<String, String> attributes = new HashMap<>(); attributes.put("filename", "file1.txt"); attributes.put("jms.string", "banana"); attributes.put("jms.integer", "50"); attributes.put("jms.integer.type", "integer"); attributes.put("jms.float", "3.14159"); attributes.put("jms.float.type", "float"); attributes.put("jms.boolean", "true"); attributes.put("jms.boolean.type", "boolean"); attributes.put("jms.long", "123456789"); attributes.put("jms.long.type", "long"); attributes.put("jms.short", "16384"); attributes.put("jms.short.type", "short"); attributes.put("jms.byte", "127"); attributes.put("jms.byte.type", "byte"); attributes.put("jms.double", "3.1415626547"); attributes.put("jms.double.type", "double"); attributes.put("jms.object", "{\"id\":215, \"name\": \"john doe\"}"); attributes.put("jms.object.type", "object"); attributes.put("jms.eyes", "blue"); attributes.put("jms.eyes.type", "color"); attributes.put("jms.badinteger", "3.14"); attributes.put("jms.badinteger.type", "integer"); runnerPut.enqueue("putGetMessage".getBytes(), attributes); runnerPut.run(); assertEquals(0, runnerPut.getFlowFilesForRelationship(PutJMS.REL_FAILURE).size()); assertEquals(1, runnerPut.getFlowFilesForRelationship(PutJMS.REL_SUCCESS).size()); final GetJMSQueue getJmsQueue = new GetJMSQueue(); final TestRunner runnerGet = TestRunners.newTestRunner(getJmsQueue); runnerGet.setProperty(JmsProperties.JMS_PROVIDER, TEST_PROVIDER); runnerGet.setProperty(JmsProperties.URL, TEST_URL); runnerGet.setProperty(JmsProperties.DESTINATION_NAME, TEST_DEST_NAME + testQueueSuffix()); runnerGet.setProperty(JmsProperties.ACKNOWLEDGEMENT_MODE, TEST_ACK_MODE); runnerGet.setProperty(JmsProperties.JMS_PROPS_TO_ATTRIBUTES, "true"); runnerGet.run(); assertEquals(1, runnerGet.getFlowFilesForRelationship(GetJMSQueue.REL_SUCCESS).size()); final List<MockFlowFile> flowFilesGet = runnerGet.getFlowFilesForRelationship(GetJMSQueue.REL_SUCCESS); assertEquals(1, flowFilesGet.size()); final MockFlowFile successFlowFile = flowFilesGet.get(0); successFlowFile.assertContentEquals("putGetMessage"); successFlowFile.assertAttributeEquals("jms.JMSDestination", TEST_DEST_NAME + testQueueSuffix()); successFlowFile.assertAttributeEquals("jms.JMSReplyTo", "queue://" + TEST_DEST_NAME + testQueueSuffix() + ".reply"); successFlowFile.assertAttributeEquals("jms.string", "banana"); successFlowFile.assertAttributeEquals("jms.integer", "50"); successFlowFile.assertAttributeEquals("jms.float", "3.14159"); successFlowFile.assertAttributeEquals("jms.boolean", "true"); successFlowFile.assertAttributeEquals("jms.long", "123456789"); successFlowFile.assertAttributeEquals("jms.short", "16384"); successFlowFile.assertAttributeEquals("jms.byte", "127"); successFlowFile.assertAttributeEquals("jms.double", "3.1415626547"); successFlowFile.assertAttributeEquals("jms.object", "{\"id\":215, \"name\": \"john doe\"}"); successFlowFile.assertAttributeEquals("jms.eyes", null); successFlowFile.assertAttributeEquals("jms.badinteger", null); }