public TestRunner getRunner() { TestRunner runner = TestRunners.newTestRunner(ReplaceText.class); /** * we have to disable validation of expression language because the scope of the evaluation * for the search value depends of another property (the evaluation mode). If not disabling * the validation, it'll throw an error about the eval */ runner.setValidateExpressionUsage(false); return runner; }
@Before public void setup() { processor = new PutEmailExtension(); runner = TestRunners.newTestRunner(processor); }
@Before public void before() throws InitializationException { testableLogMessage = new TestableLogMessage(); runner = TestRunners.newTestRunner(testableLogMessage); }
@Test public void testIncorrectJOLTSpec() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON()); final String chainrSpec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/chainrSpec.json"))); runner.setProperty(JoltTransformJSON.JOLT_SPEC, chainrSpec); runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.SHIFTR); runner.assertNotValid(); }
@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); }
@Test public void testCustomTransformationWithInvalidClassName() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON()); final String customJarPath = "src/test/resources/TestJoltTransformJson/TestCustomJoltTransform.jar"; final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/chainrSpec.json"))); runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec); runner.setProperty(JoltTransformJSON.CUSTOM_CLASS,"FakeCustomJoltTransform"); runner.setProperty(JoltTransformJSON.MODULES,customJarPath); runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM,JoltTransformJSON.CUSTOMR); runner.enqueue(JSON_INPUT); runner.assertNotValid(); }
@Test public void testInvalidJOLTSpec() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON()); final String spec = "[{}]"; runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec); runner.assertNotValid(); }
@Test public void notFound() throws IOException { final File sourceFile = new File("notFound"); final TestRunner runner = TestRunners.newTestRunner(new FetchFile()); runner.setProperty(FetchFile.FILENAME, sourceFile.getAbsolutePath()); runner.setProperty(FetchFile.COMPLETION_STRATEGY, FetchFile.COMPLETION_NONE.getValue()); runner.enqueue(new byte[0]); runner.run(); runner.assertAllFlowFilesTransferred(FetchFile.REL_NOT_FOUND, 1); }
@Test(expected = java.lang.AssertionError.class) public void testNoXQueryContent() throws XPathFactoryConfigurationException, IOException { final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery()); testRunner.setProperty(EvaluateXQuery.DESTINATION, EvaluateXQuery.DESTINATION_CONTENT); testRunner.enqueue(XML_SNIPPET); testRunner.run(); }
@Test public void testSpecIsEmpty() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON()); runner.setProperty(JoltTransformJSON.JOLT_SPEC, StringUtils.EMPTY); runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.SHIFTR); runner.assertNotValid(); }
@Before public void setUp() throws Exception { processor = new GenerateTableFetch(); //Mock the DBCP Controller Service so we can control the Results dbcp = spy(new DBCPServiceSimpleImpl()); final Map<String, String> dbcpProperties = new HashMap<>(); runner = TestRunners.newTestRunner(processor); runner.addControllerService("dbcp", dbcp, dbcpProperties); runner.enableControllerService(dbcp); runner.setProperty(GenerateTableFetch.DBCP_SERVICE, "dbcp"); runner.setProperty(DB_TYPE, new DerbyDatabaseAdapter().getName()); }
@Test(expected = AssertionError.class) public void testInvalidJsonPath() { final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath()); testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_ATTRIBUTE); testRunner.setProperty("invalid.jsonPath", "$.."); Assert.fail("An improper JsonPath expression was not detected as being invalid."); }
@Test public void testFailDecodeNotBase64() throws IOException { final TestRunner testRunner = TestRunners.newTestRunner(new EncodeContent()); testRunner.setProperty(EncodeContent.MODE, EncodeContent.DECODE_MODE); testRunner.setProperty(EncodeContent.ENCODING, EncodeContent.BASE64_ENCODING); testRunner.enqueue(Paths.get("src/test/resources/hello.txt")); testRunner.clearTransferState(); testRunner.run(); testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_FAILURE, 1); }
@Test public void testFailDecodeNotBase64ButIsAMultipleOfFourBytes() throws IOException { final TestRunner testRunner = TestRunners.newTestRunner(new EncodeContent()); testRunner.setProperty(EncodeContent.MODE, EncodeContent.DECODE_MODE); testRunner.setProperty(EncodeContent.ENCODING, EncodeContent.BASE64_ENCODING); testRunner.enqueue("four@@@@multiple".getBytes()); testRunner.clearTransferState(); testRunner.run(); testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_FAILURE, 1); }
@Test public void testFailDecodeNotBase32() throws IOException { final TestRunner testRunner = TestRunners.newTestRunner(new EncodeContent()); testRunner.setProperty(EncodeContent.MODE, EncodeContent.DECODE_MODE); testRunner.setProperty(EncodeContent.ENCODING, EncodeContent.BASE32_ENCODING); testRunner.enqueue(Paths.get("src/test/resources/hello.txt")); testRunner.clearTransferState(); testRunner.run(); testRunner.assertAllFlowFilesTransferred(EncodeContent.REL_FAILURE, 1); }
@Test public void testFilenameUpdatedOnCompress() throws IOException { final TestRunner runner = TestRunners.newTestRunner(CompressContent.class); runner.setProperty(CompressContent.MODE, "compress"); runner.setProperty(CompressContent.COMPRESSION_FORMAT, "gzip"); assertTrue(runner.setProperty(CompressContent.UPDATE_FILENAME, "true").isValid()); runner.enqueue(Paths.get("src/test/resources/CompressedData/SampleFile.txt")); runner.run(); runner.assertAllFlowFilesTransferred(CompressContent.REL_SUCCESS, 1); MockFlowFile flowFile = runner.getFlowFilesForRelationship(CompressContent.REL_SUCCESS).get(0); flowFile.assertAttributeEquals("filename", "SampleFile.txt.gz"); }
@Test public void testReturnSameFile() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new ModifyBytes()); runner.setProperty(ModifyBytes.START_OFFSET, "0 MB"); runner.setProperty(ModifyBytes.END_OFFSET, "0 MB"); runner.enqueue(testFilePath); runner.run(); runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1); final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0); out.assertContentEquals(testFile); }
@Test public void testInvalidDelimiter() throws Exception { final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class); controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "echo"); controller.assertValid(); controller.setProperty(ExecuteStreamCommand.ARG_DELIMITER, "foo"); controller.assertNotValid(); controller.setProperty(ExecuteStreamCommand.ARG_DELIMITER, "f"); controller.assertValid(); }
@Test public void testClusterMonitorInvalidReportingNode() throws Exception { final TestRunner runner = TestRunners.newTestRunner(new TestableProcessor(100)); runner.setClustered(true); runner.setPrimaryNode(false); runner.setProperty(MonitorActivity.MONITORING_SCOPE, MonitorActivity.SCOPE_NODE); runner.setProperty(MonitorActivity.REPORTING_NODE, MonitorActivity.REPORT_NODE_PRIMARY); runner.assertNotValid(); }
@Test public void testRemoveAllOverridesWhenSet() throws IOException { final TestRunner runner = TestRunners.newTestRunner(new ModifyBytes()); runner.setProperty(ModifyBytes.START_OFFSET, "10 B"); runner.setProperty(ModifyBytes.END_OFFSET, "10 B"); runner.setProperty(ModifyBytes.REMOVE_ALL, "true"); runner.enqueue(testFilePath); runner.run(); runner.assertAllFlowFilesTransferred(ModifyBytes.REL_SUCCESS, 1); final MockFlowFile out = runner.getFlowFilesForRelationship(ModifyBytes.REL_SUCCESS).get(0); assertEquals(0L, out.getSize()); }