Java Code Examples for org.apache.nifi.util.TestRunner#getFlowFilesForRelationship()

The following examples show how to use org.apache.nifi.util.TestRunner#getFlowFilesForRelationship() . 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: ITListS3.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleList() throws IOException {
    putTestFile("a", getFileFromResourceName(SAMPLE_FILE_RESOURCE_NAME));
    putTestFile("b/c", getFileFromResourceName(SAMPLE_FILE_RESOURCE_NAME));
    putTestFile("d/e", getFileFromResourceName(SAMPLE_FILE_RESOURCE_NAME));

    final TestRunner runner = TestRunners.newTestRunner(new ListS3());

    runner.setProperty(ListS3.CREDENTIALS_FILE, CREDENTIALS_FILE);
    runner.setProperty(ListS3.REGION, REGION);
    runner.setProperty(ListS3.BUCKET, BUCKET_NAME);

    runner.run();

    runner.assertAllFlowFilesTransferred(ListS3.REL_SUCCESS, 3);
    List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(ListS3.REL_SUCCESS);
    flowFiles.get(0).assertAttributeEquals("filename", "a");
    flowFiles.get(1).assertAttributeEquals("filename", "b/c");
    flowFiles.get(2).assertAttributeEquals("filename", "d/e");
}
 
Example 2
Source File: TestUpdateAttribute.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegexGroupDelete() {
    final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute());
    runner.setProperty(UpdateAttribute.DELETE_ATTRIBUTES, "(attribute\\.[2-5]|sample.*)");

    final Map<String, String> attributes = new HashMap<>();
    attributes.put("attribute.1", "value.1");
    attributes.put("attribute.2", "value.2");
    attributes.put("attribute.6", "value.6");
    attributes.put("sampleSize", "value.size");
    attributes.put("sample.1", "value.sample.1");
    attributes.put("simple.1", "value.simple.1");
    runner.enqueue(new byte[0], attributes);

    runner.run();

    runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 1);
    final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS);
    result.get(0).assertAttributeEquals("attribute.1", "value.1");
    result.get(0).assertAttributeNotExists("attribute.2");
    result.get(0).assertAttributeExists("attribute.6");
    result.get(0).assertAttributeNotExists("sampleSize");
    result.get(0).assertAttributeNotExists("sample.1");
    result.get(0).assertAttributeExists("simple.1");
}
 
Example 3
Source File: TestUpdateAttribute.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegexDotDelete() {
    final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute());
    runner.setProperty(UpdateAttribute.DELETE_ATTRIBUTES, "attribute.2");

    final Map<String, String> attributes = new HashMap<>();
    attributes.put("attribute.1", "value.1");
    attributes.put("attribute.2", "value.2");
    attributes.put("attributex2", "valuex2");
    runner.enqueue(new byte[0], attributes);

    runner.run();

    runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 1);
    final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS);
    result.get(0).assertAttributeEquals("attribute.1", "value.1");
    result.get(0).assertAttributeNotExists("attribute.2");
    result.get(0).assertAttributeNotExists("attributex2");
}
 
Example 4
Source File: TestEnforceOrder.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testSort() {
    final TestRunner runner = TestRunners.newTestRunner(EnforceOrder.class);

    runner.setProperty(EnforceOrder.GROUP_IDENTIFIER, "${group}");
    runner.setProperty(EnforceOrder.ORDER_ATTRIBUTE, "index");
    runner.assertValid();
    Ordered.enqueue(runner, "b", 0);
    Ordered.enqueue(runner, "a", 1);
    Ordered.enqueue(runner, "a", 0);

    runner.run();

    runner.assertAllFlowFilesTransferred(EnforceOrder.REL_SUCCESS, 3);

    final List<MockFlowFile> succeeded = runner.getFlowFilesForRelationship(EnforceOrder.REL_SUCCESS);
    succeeded.sort(new FirstInFirstOutPrioritizer());
    succeeded.get(0).assertContentEquals("a.0");
    succeeded.get(1).assertContentEquals("a.1");
    succeeded.get(2).assertContentEquals("b.0");
}
 
Example 5
Source File: TestParseUri.java    From nifi-scripting-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Parses domain from url
 * @throws Exception
 */
@Test
public void testParseUriSimple() throws Exception {
    final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
    runner.setValidateExpressionUsage(false);
    runner.setProperty(SCRIPT_ENGINE, "Groovy");
    runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/misc/parse_uri.groovy");
    runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
    runner.assertValid();

    final Map<String, String> attributes = new HashMap<>();
    attributes.put("input.url", "http://batchiq.com/foobar");
    runner.enqueue("nothing".getBytes(StandardCharsets.UTF_8), attributes);
    runner.run();

    runner.assertAllFlowFilesTransferred("success", 1);
    final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship("success");
    MockFlowFile result = successFlowFiles.get(0);
    result.assertAttributeEquals("url.protocol", "http");
    result.assertAttributeEquals("url.host", "batchiq.com");
    result.assertAttributeEquals("url.path", "/foobar");
    result.assertAttributeEquals("input.url", "http://batchiq.com/foobar");
}
 
Example 6
Source File: GetHDFSTest.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testDirectoryUsesValidEL() throws IOException {
    GetHDFS proc = new TestableGetHDFS(kerberosProperties);
    TestRunner runner = TestRunners.newTestRunner(proc);
    runner.setProperty(PutHDFS.DIRECTORY, "src/test/resources/${literal('testdata'):substring(0,8)}");
    runner.setProperty(GetHDFS.FILE_FILTER_REGEX, ".*.zip");
    runner.setProperty(GetHDFS.KEEP_SOURCE_FILE, "true");
    runner.setProperty(GetHDFS.COMPRESSION_CODEC, "AUTOMATIC");
    runner.run();

    List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(GetHDFS.REL_SUCCESS);
    assertEquals(1, flowFiles.size());

    MockFlowFile flowFile = flowFiles.get(0);
    assertTrue(flowFile.getAttribute(CoreAttributes.FILENAME.key()).equals("13545423550275052.zip"));
    InputStream expected = getClass().getResourceAsStream("/testdata/13545423550275052.zip");
    flowFile.assertContentEquals(expected);
}
 
Example 7
Source File: TestUnpackContent.java    From nifi with Apache License 2.0 6 votes vote down vote up
@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 8
Source File: TestExecuteStreamCommand.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Ignore
@Test
public void testExecuteTouch() throws Exception {
    File testFile = new File("target/test.txt");
    testFile.delete();
    File dummy = new File("src/test/resources/ExecuteCommand/1000bytes.txt");
    final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class);
    controller.setValidateExpressionUsage(false);
    controller.enqueue(dummy.toPath());
    controller.enqueue(dummy.toPath());
    controller.enqueue(dummy.toPath());
    controller.enqueue(dummy.toPath());
    controller.enqueue(dummy.toPath());
    controller.setProperty(ExecuteStreamCommand.WORKING_DIR, "target/xx1");
    controller.setThreadCount(6);
    controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "c:\\cygwin\\bin\\touch");
    controller.setProperty(ExecuteStreamCommand.EXECUTION_ARGUMENTS, "test.txt");
    controller.assertValid();
    controller.run(6);
    List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP);
    assertEquals(5, flowFiles.size());
    assertEquals(0, flowFiles.get(0).getSize());

}
 
Example 9
Source File: DeleteDynamoDBTest.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testStringHashStringRangeDeleteOnlyHashWithRangeNameNoRangeValueFailure() {
    final TestRunner deleteRunner = TestRunners.newTestRunner(DeleteDynamoDB.class);

    deleteRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY,"abcd");
    deleteRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
    deleteRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
    deleteRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
    deleteRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS");
    deleteRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS");
    deleteRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
    deleteRunner.enqueue(new byte[] {});

    deleteRunner.run(1);

    deleteRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_FAILURE, 1);

    List<MockFlowFile> flowFiles = deleteRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_FAILURE);
    for (MockFlowFile flowFile : flowFiles) {
        assertNotNull(flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_RANGE_KEY_VALUE_ERROR));
    }
}
 
Example 10
Source File: GetHDFSTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetFilesWithFilter() {
    GetHDFS proc = new TestableGetHDFS(kerberosProperties);
    TestRunner runner = TestRunners.newTestRunner(proc);
    runner.setProperty(PutHDFS.DIRECTORY, "src/test/resources/testdata");
    runner.setProperty(GetHDFS.FILE_FILTER_REGEX, "random.*");
    runner.setProperty(GetHDFS.KEEP_SOURCE_FILE, "true");
    runner.run();
    List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(GetHDFS.REL_SUCCESS);
    assertEquals(4, flowFiles.size());
    for (MockFlowFile flowFile : flowFiles) {
        assertTrue(flowFile.getAttribute(CoreAttributes.FILENAME.key()).startsWith("random"));
    }
}
 
Example 11
Source File: TestConsumeEmail.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testConsumePOP3() throws Exception {

    final TestRunner runner = TestRunners.newTestRunner(new ConsumePOP3());
    runner.setProperty(ConsumeIMAP.HOST, ServerSetupTest.POP3.getBindAddress());
    runner.setProperty(ConsumeIMAP.PORT, String.valueOf(ServerSetupTest.POP3.getPort()));
    runner.setProperty(ConsumeIMAP.USER, "nifiUserPop");
    runner.setProperty(ConsumeIMAP.PASSWORD, "nifiPassword");
    runner.setProperty(ConsumeIMAP.FOLDER, "INBOX");
    runner.setProperty(ConsumeIMAP.USE_SSL, "false");

    addMessage("testConsumePop1", popUser);
    addMessage("testConsumePop2", popUser);

    runner.run();

    runner.assertTransferCount(ConsumePOP3.REL_SUCCESS, 2);
    final List<MockFlowFile> messages = runner.getFlowFilesForRelationship(ConsumePOP3.REL_SUCCESS);
    String result = new String(runner.getContentAsByteArray(messages.get(0)));

    // Verify body
    Assert.assertTrue(result.contains("test test test chocolate"));

    // Verify sender
    Assert.assertTrue(result.contains("[email protected]"));

    // Verify subject
    Assert.assertTrue(result.contains("Pop1"));

}
 
Example 12
Source File: TestParseSyslog5424.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testIncludeBodyAttributeTrue() {
    final TestRunner runner = TestRunners.newTestRunner(new ParseSyslog5424());
    runner.setProperty(ParseSyslog5424.NIL_POLICY,NilPolicy.DASH.name());
    runner.setProperty(ParseSyslog5424.INCLUDE_BODY_IN_ATTRIBUTES,"true");
    runner.enqueue(SYSLOG_LINE_NILS.getBytes());
    runner.run();
    runner.assertAllFlowFilesTransferred(ParseSyslog5424.REL_SUCCESS,1);
    List<MockFlowFile> results = runner.getFlowFilesForRelationship(ParseSyslog5424.REL_SUCCESS);
    Assert.assertNotNull(results.get(0).getAttribute(SyslogAttributes.SYSLOG_BODY.key()));
}
 
Example 13
Source File: DeleteDynamoDBTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testStringHashStringRangeDeleteThrowsRuntimeException() {
    final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {
        @Override
        public BatchWriteItemOutcome batchWriteItem(TableWriteItems... tableWriteItems) {
            throw new RuntimeException("runtimeException");
        }
    };

    deleteDynamoDB = new DeleteDynamoDB() {
        @Override
        protected DynamoDB getDynamoDB() {
            return mockDynamoDB;
        }
    };
    final TestRunner deleteRunner = TestRunners.newTestRunner(deleteDynamoDB);

    deleteRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY,"abcd");
    deleteRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
    deleteRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
    deleteRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
    deleteRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS");
    deleteRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
    deleteRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS");
    deleteRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "r1");

    deleteRunner.enqueue(new byte[] {});

    deleteRunner.run(1);

    deleteRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_FAILURE, 1);
    List<MockFlowFile> flowFiles = deleteRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_FAILURE);
    for (MockFlowFile flowFile : flowFiles) {
        assertEquals("runtimeException", flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_ERROR_EXCEPTION_MESSAGE));
    }

}
 
Example 14
Source File: TestSplitText.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testOneLineSplitWithoutHeader() throws IOException {
    final TestRunner runner = TestRunners.newTestRunner(new SplitText());
    runner.setProperty(SplitText.HEADER_LINE_COUNT, "0");
    runner.setProperty(SplitText.LINE_SPLIT_COUNT, "1");

    runner.enqueue(TEST_INPUT_DATA);
    runner.run();

    runner.assertTransferCount(SplitText.REL_FAILURE, 0);
    runner.assertTransferCount(SplitText.REL_ORIGINAL, 1);
    runner.getFlowFilesForRelationship(SplitText.REL_ORIGINAL).get(0).assertAttributeEquals(SplitText.FRAGMENT_COUNT, "11");
    runner.assertTransferCount(SplitText.REL_SPLITS, 11);

    final List<MockFlowFile> splits = runner.getFlowFilesForRelationship(SplitText.REL_SPLITS);

    splits.get(0).assertContentEquals("HeaderLine1");
    splits.get(1).assertContentEquals("Line2SpacesAtEnd  ");
    splits.get(2).assertContentEquals("Line3");
    splits.get(3).assertContentEquals("Line4");
    splits.get(4).assertContentEquals("Line8");
    splits.get(5).assertContentEquals("Line9");
    splits.get(6).assertContentEquals("13");
    splits.get(7).assertContentEquals("14");
    splits.get(8).assertContentEquals("15    EndofLine15");
    splits.get(9).assertContentEquals("16");
    splits.get(10).assertContentEquals("LastLine");
}
 
Example 15
Source File: TestUpdateAttribute.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testRuleHitWithStateWithDefault() throws Exception {
    final Criteria criteria = getCriteria();
    addRule(criteria, "rule", Arrays.asList(
            // conditions
            "${getStateValue('maxValue'):lt(${value})}"), getMap(
            // actions
            "maxValue", "${value}"));

    TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute());
    runner.setProperty(UpdateAttribute.STORE_STATE, STORE_STATE_LOCALLY);
    runner.setProperty(UpdateAttribute.STATEFUL_VARIABLES_INIT_VALUE, "0");
    runner.setAnnotationData(serialize(criteria));
    runner.setProperty("maxValue", "${getStateValue('maxValue')}");

    final Map<String, String> attributes = new HashMap<>();
    attributes.put("value", "1");
    runner.enqueue(new byte[0], attributes);
    runner.run();
    attributes.put("value", "2");
    runner.enqueue(new byte[0], attributes);
    runner.run();
    attributes.put("value", "4");
    runner.enqueue(new byte[0], attributes);
    runner.run();
    attributes.put("value", "1");
    runner.enqueue(new byte[0], attributes);
    runner.run();

    runner.assertAllFlowFilesTransferred(UpdateAttribute.REL_SUCCESS, 4);
    final List<MockFlowFile> result = runner.getFlowFilesForRelationship(UpdateAttribute.REL_SUCCESS);
    result.get(2).assertAttributeEquals("maxValue", "4");
    result.get(3).assertAttributeEquals("maxValue", "4");
}
 
Example 16
Source File: TestInvokeGRPC.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testServerConnectionFail() throws Exception {

    final int port = TestGRPCServer.randomPort();

    // should be no gRPC server running @ that port, so processor will fail
    final TestRunner runner = TestRunners.newTestRunner(InvokeGRPC.class);
    runner.setProperty(InvokeGRPC.PROP_SERVICE_HOST, TestGRPCServer.HOST);
    runner.setProperty(InvokeGRPC.PROP_SERVICE_PORT, Integer.toString(port));

    final MockFlowFile mockFlowFile = new MockFlowFile(SUCCESS);
    runner.enqueue(mockFlowFile);
    runner.run();

    runner.assertTransferCount(InvokeGRPC.REL_RESPONSE, 0);
    runner.assertTransferCount(InvokeGRPC.REL_SUCCESS_REQ, 0);
    runner.assertTransferCount(InvokeGRPC.REL_RETRY, 0);
    runner.assertTransferCount(InvokeGRPC.REL_NO_RETRY, 0);
    runner.assertTransferCount(InvokeGRPC.REL_FAILURE, 1);

    final List<MockFlowFile> responseFiles = runner.getFlowFilesForRelationship(InvokeGRPC.REL_FAILURE);
    assertThat(responseFiles.size(), equalTo(1));
    final MockFlowFile response = responseFiles.get(0);
    response.assertAttributeEquals(InvokeGRPC.SERVICE_HOST, TestGRPCServer.HOST);
    response.assertAttributeEquals(InvokeGRPC.SERVICE_PORT, Integer.toString(port));
    response.assertAttributeEquals(InvokeGRPC.EXCEPTION_CLASS, "io.grpc.StatusRuntimeException");

}
 
Example 17
Source File: TestAttributesToCSV.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testAttrListNoCoreNullOffOverrideCoreByAttrListToAttribute() throws IOException {
    final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
    testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
    testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
    testRunner.setProperty(AttributesToCSV.ATTRIBUTES_LIST, "beach-name,beach-location,beach-endorsement,uuid");
    testRunner.setProperty(AttributesToCSV.NULL_VALUE_FOR_EMPTY_STRING, "false");

    Map<String, String> attrs = new HashMap<String, String>(){{
        put("beach-name", "Malibu Beach");
        put("beach-location", "California, US");
        put("beach-endorsement", "This is our family's favorite beach. We highly recommend it. \n\nThanks, Jim");
        put("attribute-should-be-eliminated", "This should not be in CSVData!");
    }};

    testRunner.enqueue(new byte[0], attrs);
    testRunner.run();

    List<MockFlowFile> flowFilesForRelationship = testRunner.getFlowFilesForRelationship(AttributesToCSV.REL_SUCCESS);

    testRunner.assertTransferCount(AttributesToCSV.REL_FAILURE, 0);
    testRunner.assertTransferCount(AttributesToCSV.REL_SUCCESS, 1);

    MockFlowFile flowFile = flowFilesForRelationship.get(0);

    assertNull(flowFile.getAttribute(CoreAttributes.MIME_TYPE.key()));

    final String attributeData = flowFile.getAttribute(OUTPUT_ATTRIBUTE_NAME);

    Set<String> CSVDataValues = new HashSet<>(getStrings(attributeData));

    assertEquals(4, CSVDataValues.size());

    assertTrue(CSVDataValues.contains("Malibu Beach"));
    assertTrue(CSVDataValues.contains("\"California, US\""));
    assertTrue(CSVDataValues.contains("\"This is our family's favorite beach. We highly recommend it. \n\nThanks, Jim\""));


    assertTrue(!CSVDataValues.contains(flowFile.getAttribute("filename")));
    assertTrue(!CSVDataValues.contains(flowFile.getAttribute("path")));
    assertTrue(CSVDataValues.contains(flowFile.getAttribute("uuid")));
}
 
Example 18
Source File: ITPutS3Object.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private void testPutThenFetch(String sseAlgorithm) throws IOException {

        // Put
        TestRunner runner = TestRunners.newTestRunner(new PutS3Object());

        runner.setProperty(PutS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE);
        runner.setProperty(PutS3Object.REGION, REGION);
        runner.setProperty(PutS3Object.BUCKET, BUCKET_NAME);
        if(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION.equals(sseAlgorithm)){
            runner.setProperty(PutS3Object.SERVER_SIDE_ENCRYPTION, sseAlgorithm);
        }

        final Map<String, String> attrs = new HashMap<>();
        attrs.put("filename",  "filename-on-s3.txt");
        runner.enqueue(getResourcePath(SAMPLE_FILE_RESOURCE_NAME), attrs);
        runner.run();

        runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS, 1);
        List<MockFlowFile> ffs = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS);
        if(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION.equals(sseAlgorithm)){
            ffs.get(0).assertAttributeEquals(PutS3Object.S3_SSE_ALGORITHM, ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
        } else {
            ffs.get(0).assertAttributeNotExists(PutS3Object.S3_SSE_ALGORITHM);
        }

        // Fetch
        runner = TestRunners.newTestRunner(new FetchS3Object());

        runner.setProperty(FetchS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE);
        runner.setProperty(FetchS3Object.REGION, REGION);
        runner.setProperty(FetchS3Object.BUCKET, BUCKET_NAME);

        runner.enqueue(new byte[0], attrs);

        runner.run(1);

        runner.assertAllFlowFilesTransferred(FetchS3Object.REL_SUCCESS, 1);
        ffs = runner.getFlowFilesForRelationship(FetchS3Object.REL_SUCCESS);
        MockFlowFile ff = ffs.get(0);
        ff.assertContentEquals(getFileFromResourceName(SAMPLE_FILE_RESOURCE_NAME));

        if(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION.equals(sseAlgorithm)){
            ff.assertAttributeEquals(PutS3Object.S3_SSE_ALGORITHM, ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
        } else {
            ff.assertAttributeNotExists(PutS3Object.S3_SSE_ALGORITHM);
        }

    }
 
Example 19
Source File: ITPutS3Object.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@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 20
Source File: ListGCSBucketTest.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Test
public void testSuccessfulList() throws Exception {
    reset(storage, mockBlobPages);
    final ListGCSBucket processor = getProcessor();
    final TestRunner runner = buildNewRunner(processor);
    addRequiredPropertiesToRunner(runner);
    runner.assertValid();

    final Iterable<Blob> mockList = ImmutableList.of(
            buildMockBlob("blob-bucket-1", "blob-key-1", 2L),
            buildMockBlob("blob-bucket-2", "blob-key-2", 3L)
    );

    when(mockBlobPages.getValues())
            .thenReturn(mockList);

    when(mockBlobPages.getNextPage()).thenReturn(null);

    when(storage.list(anyString(), any(Storage.BlobListOption[].class)))
            .thenReturn(mockBlobPages);

    runner.enqueue("test");
    runner.run();

    runner.assertAllFlowFilesTransferred(ListGCSBucket.REL_SUCCESS);
    runner.assertTransferCount(ListGCSBucket.REL_SUCCESS, 2);

    final List<MockFlowFile> successes = runner.getFlowFilesForRelationship(ListGCSBucket.REL_SUCCESS);

    MockFlowFile flowFile = successes.get(0);
    assertEquals(
            "blob-bucket-1",
            flowFile.getAttribute(BUCKET_ATTR)
    );

    assertEquals(
            "blob-key-1",
            flowFile.getAttribute(KEY_ATTR)
    );

    assertEquals(
            "2",
            flowFile.getAttribute(UPDATE_TIME_ATTR)
    );

    flowFile = successes.get(1);
    assertEquals(
            "blob-bucket-2",
            flowFile.getAttribute(BUCKET_ATTR)
    );

    assertEquals(
            "blob-key-2",
            flowFile.getAttribute(KEY_ATTR)
    );

    assertEquals(
            "3",
            flowFile.getAttribute(UPDATE_TIME_ATTR)
    );

    assertEquals(
            3L,
            processor.currentTimestamp
    );

    assertEquals(
            ImmutableSet.of(
                    "blob-key-2"
            ),
            processor.currentKeys
    );

}