Java Code Examples for org.apache.nifi.util.TestRunner#assertAllFlowFilesTransferred()
The following examples show how to use
org.apache.nifi.util.TestRunner#assertAllFlowFilesTransferred() .
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: TestReplaceText.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testAlwaysReplaceLineByLine() { final TestRunner runner = TestRunners.newTestRunner(new ReplaceText()); runner.setValidateExpressionUsage(false); 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 2
Source File: TestConvertJSONToSQL.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testUpdateWithMalformedJson() throws InitializationException, ProcessException, SQLException, IOException { final TestRunner runner = TestRunners.newTestRunner(ConvertJSONToSQL.class); final File tempDir = folder.getRoot(); final File dbDir = new File(tempDir, "db"); final DBCPService service = new MockDBCPService(dbDir.getAbsolutePath()); runner.addControllerService("dbcp", service); runner.enableControllerService(service); try (final Connection conn = service.getConnection()) { try (final Statement stmt = conn.createStatement()) { stmt.executeUpdate(createPersons); } } runner.setProperty(ConvertJSONToSQL.CONNECTION_POOL, "dbcp"); runner.setProperty(ConvertJSONToSQL.TABLE_NAME, "PERSONS"); runner.setProperty(ConvertJSONToSQL.STATEMENT_TYPE, "UPDATE"); runner.setProperty(ConvertJSONToSQL.UPDATE_KEY, "name, code"); runner.enqueue(Paths.get("src/test/resources/TestConvertJSONToSQL/malformed-person-extra-comma.json")); runner.run(); runner.assertAllFlowFilesTransferred(ConvertJSONToSQL.REL_FAILURE, 1); }
Example 3
Source File: TestCompressContent.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testBzip2Decompress() throws Exception { final TestRunner runner = TestRunners.newTestRunner(CompressContent.class); runner.setProperty(CompressContent.MODE, "decompress"); runner.setProperty(CompressContent.COMPRESSION_FORMAT, "bzip2"); runner.setProperty(CompressContent.UPDATE_FILENAME, "true"); runner.enqueue(Paths.get("src/test/resources/CompressedData/SampleFile.txt.bz2")); runner.run(); runner.assertAllFlowFilesTransferred(CompressContent.REL_SUCCESS, 1); MockFlowFile flowFile = runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).get(0); flowFile.assertContentEquals(Paths.get("src/test/resources/CompressedData/SampleFile.txt")); flowFile.assertAttributeEquals("filename", "SampleFile.txt"); runner.clearTransferState(); runner.enqueue(Paths.get("src/test/resources/CompressedData/SampleFile1.txt.bz2")); runner.run(); runner.assertAllFlowFilesTransferred(CompressContent.REL_SUCCESS, 1); flowFile = runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).get(0); flowFile.assertContentEquals(Paths.get("src/test/resources/CompressedData/SampleFile.txt")); flowFile.assertAttributeEquals("filename", "SampleFile1.txt"); }
Example 4
Source File: TestValidateCsv.java From localization_nifi with Apache License 2.0 | 6 votes |
@Test public void testDMinMaxForbidSubStrLMinMax() { final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv()); runner.setProperty(ValidateCsv.DELIMITER_CHARACTER, ","); runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "\r\n"); runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "\""); runner.setProperty(ValidateCsv.HEADER, "false"); runner.setProperty(ValidateCsv.SCHEMA, "DMinMax(10,100),LMinMax(10,100),ForbidSubStr(\"test\", \"tset\")"); runner.enqueue("50.001,50,hello"); runner.run(); runner.assertAllFlowFilesTransferred(ValidateCsv.REL_VALID, 1); runner.enqueue("10,10,testapache.org"); runner.run(); runner.assertTransferCount(ValidateCsv.REL_INVALID, 1); }
Example 5
Source File: TestReplaceText.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testEscapingDollarSign() throws IOException { final TestRunner runner = getRunner(); runner.setProperty(ReplaceText.SEARCH_VALUE, "(ell)"); runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "\\$1"); final Map<String, String> attributes = new HashMap<>(); attributes.put("replaceKey", "H.*o"); attributes.put("replaceValue", "Good-bye"); runner.enqueue(Paths.get("src/test/resources/hello.txt"), attributes); runner.run(); runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1); final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0); out.assertContentEquals("H$1o, World!"); }
Example 6
Source File: TestTransformXml.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testTransformWithXsltNotFoundInController() throws IOException, InitializationException { final TestRunner runner = TestRunners.newTestRunner(new TransformXml()); final SimpleKeyValueLookupService service = new SimpleKeyValueLookupService(); runner.addControllerService("simple-key-value-lookup-service", service); runner.enableControllerService(service); runner.assertValid(service); runner.setProperty(TransformXml.XSLT_CONTROLLER, "simple-key-value-lookup-service"); runner.setProperty(TransformXml.XSLT_CONTROLLER_KEY, "${xslt}"); runner.setProperty("header", "Test for mod"); final Map<String, String> attributes = new HashMap<>(); attributes.put("xslt", "math"); runner.enqueue(Paths.get("src/test/resources/TestTransformXml/math.xml"), attributes); runner.run(); runner.assertAllFlowFilesTransferred(TransformXml.REL_FAILURE); }
Example 7
Source File: TestFetchFileTransfer.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testFilenameContainsPath() { final String filenameWithPath = "./here/is/my/path/hello.txt"; final TestableFetchFileTransfer proc = new TestableFetchFileTransfer(); final TestRunner runner = TestRunners.newTestRunner(proc); runner.setProperty(FetchFileTransfer.HOSTNAME, "localhost"); runner.setProperty(FetchFileTransfer.UNDEFAULTED_PORT, "11"); runner.setProperty(FetchFileTransfer.REMOTE_FILENAME, "${filename}"); proc.addContent(filenameWithPath, "world".getBytes()); final Map<String, String> attrs = new HashMap<>(); attrs.put("filename", filenameWithPath); runner.enqueue(new byte[0], attrs); runner.run(1, false, false); runner.assertAllFlowFilesTransferred(FetchFileTransfer.REL_SUCCESS, 1); assertFalse(proc.closed); MockFlowFile transferredFlowFile = runner.getFlowFilesForRelationship(FetchFileTransfer.REL_SUCCESS).get(0); transferredFlowFile.assertContentEquals("world"); transferredFlowFile.assertAttributeExists(CoreAttributes.PATH.key()); transferredFlowFile.assertAttributeEquals(CoreAttributes.PATH.key(), "./here/is/my/path"); }
Example 8
Source File: TestTransformXml.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testTransformCsv() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new TransformXml()); runner.setProperty(TransformXml.XSLT_FILE_NAME, "src/test/resources/TestTransformXml/tokens.xsl"); runner.setProperty("uuid_0", "${uuid_0}"); runner.setProperty("uuid_1", "${uuid_1}"); final Map<String, String> attributes = new HashMap<>(); attributes.put("uuid_0", "uuid_0"); attributes.put("uuid_1", "uuid_1"); StringBuilder builder = new StringBuilder(); builder.append("<data>\n"); try(BufferedReader reader = new BufferedReader(new InputStreamReader( new FileInputStream(new File("src/test/resources/TestTransformXml/tokens.csv"))))){ String line = null; while ((line = reader.readLine()) != null) { builder.append(line).append("\n"); } builder.append("</data>"); String data = builder.toString(); runner.enqueue(data.getBytes(), attributes); runner.run(); runner.assertAllFlowFilesTransferred(TransformXml.REL_SUCCESS); final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).get(0); final String expectedContent = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformXml/tokens.xml"))); transformed.assertContentEquals(expectedContent); } }
Example 9
Source File: TestPutSolrRecord.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testIOExceptionShouldRouteToConnectionFailure() throws IOException, SolrServerException, InitializationException { final Throwable throwable = new IOException("Error communicating with Solr"); final ExceptionThrowingProcessor proc = new ExceptionThrowingProcessor(throwable); final TestRunner runner = createDefaultTestRunner(proc); runner.setProperty(PutSolrRecord.UPDATE_PATH, "/update"); MockRecordParser recordParser = new MockRecordParser(); recordParser.addRecord(1, "Abhinav","R",8,"Chemistry","term1", 98); runner.addControllerService("parser", recordParser); runner.enableControllerService(recordParser); runner.setProperty(PutSolrRecord.RECORD_READER, "parser"); try { runner.enqueue(new byte[0], new HashMap<String, String>() {{ put("id", "1"); }}); runner.run(); runner.assertAllFlowFilesTransferred(PutSolrRecord.REL_CONNECTION_FAILURE, 1); verify(proc.getSolrClient(), times(1)).request(any(SolrRequest.class), eq(null)); }finally { try { proc.getSolrClient().close(); } catch (Exception e) { e.printStackTrace(); } } }
Example 10
Source File: TestPutSQL.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testInsertWithGeneratedKeys() throws InitializationException, ProcessException, SQLException, IOException { final TestRunner runner = TestRunners.newTestRunner(PutSQL.class); runner.addControllerService("dbcp", service); runner.enableControllerService(service); runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "true"); runner.setProperty(PutSQL.CONNECTION_POOL, "dbcp"); recreateTable("PERSONS_AI",createPersonsAutoId); runner.enqueue("INSERT INTO PERSONS_AI (NAME, CODE) VALUES ('Mark', 84)".getBytes()); runner.run(); runner.assertAllFlowFilesTransferred(PutSQL.REL_SUCCESS, 1); final MockFlowFile mff = runner.getFlowFilesForRelationship(PutSQL.REL_SUCCESS).get(0); mff.assertAttributeEquals("sql.generated.key", "1"); try (final Connection conn = service.getConnection()) { try (final Statement stmt = conn.createStatement()) { final ResultSet rs = stmt.executeQuery("SELECT * FROM PERSONS_AI"); assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); assertEquals("Mark", rs.getString(2)); assertEquals(84, rs.getInt(3)); assertFalse(rs.next()); } } }
Example 11
Source File: TestJoltTransformJSON.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testCustomTransformationWithNoModule() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON()); runner.setValidateExpressionUsage(false); final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/customChainrSpec.json"))); runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec); runner.setProperty(JoltTransformJSON.CUSTOM_CLASS, "TestCustomJoltTransform"); runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.CUSTOMR); runner.enqueue(JSON_INPUT); runner.run(); runner.assertAllFlowFilesTransferred(JoltTransformJSON.REL_SUCCESS); }
Example 12
Source File: TestUpdateAttribute.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testDefaultAddAttribute() throws Exception { final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute()); runner.setProperty("NewAttr", "${one:plus(${two})}"); final Map<String, String> attributes = new HashMap<>(); attributes.put("one", "1"); attributes.put("two", "2"); runner.enqueue(new byte[0], attributes); runner.run(); runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 1); runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS).get(0).assertAttributeEquals("NewAttr", "3"); }
Example 13
Source File: TestReplaceText.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testWithMultipleMatches() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new ReplaceText()); runner.setValidateExpressionUsage(false); runner.setProperty(ReplaceText.SEARCH_VALUE, "l"); runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "R"); runner.enqueue(Paths.get("src/test/resources/hello.txt")); runner.run(); runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1); final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0); out.assertContentEquals("HeRRo, WorRd!"); }
Example 14
Source File: PutDynamoDBTest.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testStringHashStringRangePutThrowsRuntimeException() { final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) { @Override public BatchWriteItemOutcome batchWriteItem(TableWriteItems... tableWriteItems) { throw new RuntimeException("runtimeException"); } }; putDynamoDB = new PutDynamoDB() { @Override protected DynamoDB getDynamoDB() { return mockDynamoDB; } }; final TestRunner putRunner = TestRunners.newTestRunner(putDynamoDB); putRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY,"abcd"); putRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef"); putRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION); putRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName); putRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS"); putRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1"); putRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS"); putRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "r1"); putRunner.setProperty(AbstractWriteDynamoDBProcessor.JSON_DOCUMENT, "document"); String document = "{\"name\":\"john\"}"; putRunner.enqueue(document.getBytes()); putRunner.run(1); putRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_FAILURE, 1); List<MockFlowFile> flowFiles = putRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_FAILURE); for (MockFlowFile flowFile : flowFiles) { assertEquals("runtimeException", flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_ERROR_EXCEPTION_MESSAGE)); } }
Example 15
Source File: TestParseCEF.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void testInvalidMessage() { final TestRunner runner = TestRunners.newTestRunner(new ParseCEF()); runner.enqueue("test test test chocolate\n".getBytes()); runner.run(); runner.assertAllFlowFilesTransferred(ParseCEF.REL_FAILURE, 1); }
Example 16
Source File: TestDetectDuplicate.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testDuplicateNoCache() throws InitializationException { final TestRunner runner = TestRunners.newTestRunner(DetectDuplicate.class); final DistributedMapCacheClientImpl client = createClient(); final Map<String, String> clientProperties = new HashMap<>(); clientProperties.put(DistributedMapCacheClientService.HOSTNAME.getName(), "localhost"); runner.addControllerService("client", client, clientProperties); runner.setProperty(DetectDuplicate.DISTRIBUTED_CACHE_SERVICE, "client"); runner.setProperty(DetectDuplicate.FLOWFILE_DESCRIPTION, "The original flow file"); runner.setProperty(DetectDuplicate.AGE_OFF_DURATION, "48 hours"); runner.setProperty(DetectDuplicate.CACHE_IDENTIFIER, "false"); final Map<String, String> props = new HashMap<>(); props.put("hash.value", "1000"); runner.enqueue(new byte[]{}, props); runner.enableControllerService(client); runner.run(); runner.assertAllFlowFilesTransferred(DetectDuplicate.REL_NON_DUPLICATE, 1); runner.clearTransferState(); runner.setProperty(DetectDuplicate.CACHE_IDENTIFIER, "true"); runner.enqueue(new byte[]{}, props); runner.run(); runner.assertAllFlowFilesTransferred(DetectDuplicate.REL_NON_DUPLICATE, 1); runner.assertTransferCount(DetectDuplicate.REL_DUPLICATE, 0); runner.assertTransferCount(DetectDuplicate.REL_FAILURE, 0); runner.clearTransferState(); runner.enqueue(new byte[]{}, props); runner.run(); runner.assertAllFlowFilesTransferred(DetectDuplicate.REL_DUPLICATE, 1); runner.assertTransferCount(DetectDuplicate.REL_NON_DUPLICATE, 0); runner.assertTransferCount(DetectDuplicate.REL_FAILURE, 0); }
Example 17
Source File: PutKafkaTest.java From localization_nifi with Apache License 2.0 | 5 votes |
@Test public void validateDeprecatedPartitionStrategy() { String topicName = "validateDeprecatedPartitionStrategy"; PutKafka putKafka = new PutKafka(); TestRunner runner = TestRunners.newTestRunner(putKafka); runner.setProperty(PutKafka.TOPIC, topicName); runner.setProperty(PutKafka.CLIENT_NAME, "foo"); runner.setProperty(PutKafka.KEY, "key1"); runner.setProperty(PutKafka.SEED_BROKERS, "localhost:" + kafkaLocal.getKafkaPort()); runner.setProperty(PutKafka.MESSAGE_DELIMITER, "\n"); // Old configuration using deprecated property still work. runner.setProperty(PutKafka.PARTITION_STRATEGY, PutKafka.USER_DEFINED_PARTITIONING); runner.setProperty(PutKafka.PARTITION, "${partition}"); runner.assertValid(); final Map<String, String> attributes = new HashMap<>(); attributes.put("partition", "0"); runner.enqueue("Hello World\nGoodbye".getBytes(StandardCharsets.UTF_8), attributes); runner.run(1, false); runner.assertAllFlowFilesTransferred(PutKafka.REL_SUCCESS, 1); ConsumerIterator<byte[], byte[]> consumer = this.buildConsumer(topicName); assertEquals("Hello World", new String(consumer.next().message(), StandardCharsets.UTF_8)); assertEquals("Goodbye", new String(consumer.next().message(), StandardCharsets.UTF_8)); runner.shutdown(); }
Example 18
Source File: ITPutS3Object.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testMultipartSmallerThanMinimum() throws IOException { final String FILE1_NAME = "file1"; final byte[] megabyte = new byte[1024 * 1024]; final Path tempFile = Files.createTempFile("s3mulitpart", "tmp"); final FileOutputStream tempOut = new FileOutputStream(tempFile.toFile()); long tempByteCount = 0; for (int i = 0; i < 5; i++) { tempOut.write(megabyte); tempByteCount += megabyte.length; } tempOut.close(); System.out.println("file size: " + tempByteCount); Assert.assertTrue(tempByteCount < S3_MINIMUM_PART_SIZE); Assert.assertTrue(megabyte.length < S3_MINIMUM_PART_SIZE); Assert.assertTrue(TEST_PARTSIZE_LONG >= S3_MINIMUM_PART_SIZE && TEST_PARTSIZE_LONG <= S3_MAXIMUM_OBJECT_SIZE); final PutS3Object processor = new PutS3Object(); final TestRunner runner = TestRunners.newTestRunner(processor); runner.setProperty(PutS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE); runner.setProperty(PutS3Object.REGION, REGION); runner.setProperty(PutS3Object.BUCKET, BUCKET_NAME); runner.setProperty(PutS3Object.MULTIPART_PART_SIZE, TEST_PARTSIZE_STRING); Map<String, String> attributes = new HashMap<>(); attributes.put(CoreAttributes.FILENAME.key(), FILE1_NAME); runner.enqueue(new FileInputStream(tempFile.toFile()), attributes); runner.assertValid(); runner.run(); runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS); final List<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS); Assert.assertEquals(1, successFiles.size()); final List<MockFlowFile> failureFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_FAILURE); Assert.assertEquals(0, failureFiles.size()); MockFlowFile ff1 = successFiles.get(0); Assert.assertEquals(PutS3Object.S3_API_METHOD_PUTOBJECT, ff1.getAttribute(PutS3Object.S3_API_METHOD_ATTR_KEY)); Assert.assertEquals(FILE1_NAME, ff1.getAttribute(CoreAttributes.FILENAME.key())); Assert.assertEquals(BUCKET_NAME, ff1.getAttribute(PutS3Object.S3_BUCKET_KEY)); Assert.assertEquals(FILE1_NAME, ff1.getAttribute(PutS3Object.S3_OBJECT_KEY)); Assert.assertTrue(reS3ETag.matcher(ff1.getAttribute(PutS3Object.S3_ETAG_ATTR_KEY)).matches()); Assert.assertEquals(tempByteCount, ff1.getSize()); }
Example 19
Source File: PutGCSObjectTest.java From localization_nifi with Apache License 2.0 | 4 votes |
@Test public void testSuccessfulPutOperationWithUserMetadata() throws Exception { reset(storage, blob); final PutGCSObject processor = getProcessor(); final TestRunner runner = buildNewRunner(processor); addRequiredPropertiesToRunner(runner); runner.setProperty( "testMetadataKey1", "testMetadataValue1" ); runner.setProperty( "testMetadataKey2", "testMetadataValue2" ); runner.assertValid(); when(storage.create(blobInfoArgumentCaptor.capture(), inputStreamArgumentCaptor.capture(), blobWriteOptionArgumentCaptor.capture())).thenReturn(blob); runner.enqueue("test"); runner.run(); runner.assertAllFlowFilesTransferred(PutGCSObject.REL_SUCCESS); runner.assertTransferCount(PutGCSObject.REL_SUCCESS, 1); /* String text; try (final Reader reader = new InputStreamReader(inputStreamArgumentCaptor.getValue())) { text = CharStreams.toString(reader); } assertEquals( "FlowFile content should be equal to the Blob content", "test", text ); */ final BlobInfo blobInfo = blobInfoArgumentCaptor.getValue(); final Map<String, String> metadata = blobInfo.getMetadata(); assertNotNull(metadata); assertEquals( 2, metadata.size() ); assertEquals( "testMetadataValue1", metadata.get("testMetadataKey1") ); assertEquals( "testMetadataValue2", metadata.get("testMetadataKey2") ); }
Example 20
Source File: TestQuerySolr.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testRelationshipRoutings() throws IOException { SolrClient solrClient = createSolrClient(); TestRunner runner = createRunnerWithSolrClient(solrClient); runner.setProperty("facet", "true"); runner.setProperty("stats", "true"); // Set request handler for request failure runner.setProperty(QuerySolr.SOLR_PARAM_REQUEST_HANDLER, "/nonexistentrequesthandler"); // Processor has no input connection and fails runner.setNonLoopConnection(false); runner.run(1, false); runner.assertAllFlowFilesTransferred(QuerySolr.FAILURE, 1); MockFlowFile flowFile = runner.getFlowFilesForRelationship(QuerySolr.FAILURE).get(0); flowFile.assertAttributeExists(QuerySolr.EXCEPTION); flowFile.assertAttributeExists(QuerySolr.EXCEPTION_MESSAGE); runner.clearTransferState(); // Processor has an input connection and fails runner.setNonLoopConnection(true); runner.enqueue(new byte[0]); runner.run(1, false); runner.assertAllFlowFilesTransferred(QuerySolr.FAILURE, 1); flowFile = runner.getFlowFilesForRelationship(QuerySolr.FAILURE).get(0); flowFile.assertAttributeExists(QuerySolr.EXCEPTION); flowFile.assertAttributeExists(QuerySolr.EXCEPTION_MESSAGE); runner.clearTransferState(); // Set request handler for successful request runner.setProperty(QuerySolr.SOLR_PARAM_REQUEST_HANDLER, "/select"); // Processor has no input connection and succeeds runner.setNonLoopConnection(false); runner.run(1, false); runner.assertTransferCount(QuerySolr.RESULTS, 1); runner.assertTransferCount(QuerySolr.FACETS, 1); runner.assertTransferCount(QuerySolr.STATS, 1); flowFile = runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME); runner.clearTransferState(); // Processor has an input connection and succeeds runner.setNonLoopConnection(true); runner.enqueue(new byte[0]); runner.run(1, true); runner.assertTransferCount(QuerySolr.RESULTS, 1); runner.assertTransferCount(QuerySolr.FACETS, 1); runner.assertTransferCount(QuerySolr.STATS, 1); runner.assertTransferCount(QuerySolr.ORIGINAL, 1); runner.assertAllFlowFilesContainAttribute(QuerySolr.ATTRIBUTE_SOLR_CONNECT); flowFile = runner.getFlowFilesForRelationship(QuerySolr.RESULTS).get(0); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME); flowFile = runner.getFlowFilesForRelationship(QuerySolr.FACETS).get(0); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME); flowFile = runner.getFlowFilesForRelationship(QuerySolr.STATS).get(0); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_CONNECT); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_SOLR_STATUS); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_CURSOR_MARK); flowFile.assertAttributeExists(QuerySolr.ATTRIBUTE_QUERY_TIME); runner.clearTransferState(); solrClient.close(); }