Created
February 18, 2020 22:58
-
-
Save pvillard31/309bd30b185b04b6918a69d59145b2a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testNoMatchingRecords() throws InitializationException { | |
TestRunner runner = getRunner(); | |
final JsonTreeReader jsonReader = new JsonTreeReader(); | |
runner.addControllerService("reader", jsonReader); | |
runner.setProperty(jsonReader, SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY, SchemaInferenceUtil.INFER_SCHEMA); | |
final JsonRecordSetWriter jsonWriter = new JsonRecordSetWriter(); | |
runner.addControllerService("writer", jsonWriter); | |
runner.setProperty(jsonWriter, SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY, SchemaAccessUtils.INHERIT_RECORD_SCHEMA); | |
runner.enableControllerService(jsonReader); | |
runner.enableControllerService(jsonWriter); | |
runner.setProperty(REL_NAME, "select * from FLOWFILE WHERE event LIKE '%ERROR%'"); | |
runner.setProperty(QueryRecord.RECORD_READER_FACTORY, "reader"); | |
runner.setProperty(QueryRecord.RECORD_WRITER_FACTORY, "writer"); | |
// Test 1 | |
runner.setProperty(QueryRecord.INCLUDE_ZERO_RECORD_FLOWFILES, "false"); | |
runner.enqueue("[{\"event\": \"test - INFO - test\"}, {\"event\": \"test - INFO - test\"}]"); | |
runner.run(); | |
// no matching record, and does not include zero record flow file, should be 0 | |
runner.assertTransferCount(REL_NAME, 0); | |
// Test 2 | |
runner.clearTransferState(); | |
runner.setProperty(QueryRecord.INCLUDE_ZERO_RECORD_FLOWFILES, "true"); | |
runner.enqueue("[{\"event\": \"test - INFO - test\"}]"); | |
runner.run(); | |
// no matching record, but includes zero record flow file, should be 1 with record.count = 0 | |
runner.assertTransferCount(REL_NAME, 1); | |
MockFlowFile flowFileOut = runner.getFlowFilesForRelationship(REL_NAME).get(0); | |
flowFileOut.assertAttributeEquals("record.count", "0"); | |
flowFileOut.assertContentEquals("[]"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment