Search in sources :

Example 6 with TestRunner

use of org.apache.nifi.util.TestRunner in project nifi by apache.

the class ITFetchS3Object method testTryToFetchNotExistingFile.

@Test
public void testTryToFetchNotExistingFile() throws IOException {
    final TestRunner runner = TestRunners.newTestRunner(new FetchS3Object());
    runner.setProperty(FetchS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE);
    runner.setProperty(FetchS3Object.REGION, REGION);
    runner.setProperty(FetchS3Object.BUCKET, BUCKET_NAME);
    final Map<String, String> attrs = new HashMap<>();
    attrs.put("filename", "no-such-a-file");
    runner.enqueue(new byte[0], attrs);
    runner.run(1);
    runner.assertAllFlowFilesTransferred(FetchS3Object.REL_FAILURE, 1);
}
Also used : HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 7 with TestRunner

use of org.apache.nifi.util.TestRunner in project nifi by apache.

the class ITFetchS3Object method testContentsOfFileRetrieved.

@Test
public void testContentsOfFileRetrieved() throws IOException {
    String key = "folder/1.txt";
    putTestFile(key, getFileFromResourceName(SAMPLE_FILE_RESOURCE_NAME));
    final TestRunner runner = TestRunners.newTestRunner(new FetchS3Object());
    runner.setProperty(FetchS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE);
    runner.setProperty(FetchS3Object.REGION, REGION);
    runner.setProperty(FetchS3Object.BUCKET, BUCKET_NAME);
    final Map<String, String> attrs = new HashMap<>();
    attrs.put("filename", key);
    runner.enqueue(new byte[0], attrs);
    runner.run(1);
    runner.assertAllFlowFilesTransferred(FetchS3Object.REL_SUCCESS, 1);
    final List<MockFlowFile> ffs = runner.getFlowFilesForRelationship(FetchS3Object.REL_SUCCESS);
    final MockFlowFile out = ffs.iterator().next();
    final byte[] expectedBytes = Files.readAllBytes(getResourcePath(SAMPLE_FILE_RESOURCE_NAME));
    out.assertContentEquals(new String(expectedBytes));
    for (final Map.Entry<String, String> entry : out.getAttributes().entrySet()) {
        System.out.println(entry.getKey() + " : " + entry.getValue());
    }
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with TestRunner

use of org.apache.nifi.util.TestRunner in project nifi by apache.

the class ITFetchS3Object method testSimpleGetEncrypted.

@Test
public void testSimpleGetEncrypted() throws IOException {
    putTestFileEncrypted("test-file", getFileFromResourceName(SAMPLE_FILE_RESOURCE_NAME));
    final TestRunner runner = TestRunners.newTestRunner(new FetchS3Object());
    runner.setProperty(FetchS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE);
    runner.setProperty(FetchS3Object.REGION, REGION);
    runner.setProperty(FetchS3Object.BUCKET, BUCKET_NAME);
    final Map<String, String> attrs = new HashMap<>();
    attrs.put("filename", "test-file");
    runner.enqueue(new byte[0], attrs);
    runner.run(1);
    runner.assertAllFlowFilesTransferred(FetchS3Object.REL_SUCCESS, 1);
    final List<MockFlowFile> ffs = runner.getFlowFilesForRelationship(FetchS3Object.REL_SUCCESS);
    MockFlowFile ff = ffs.get(0);
    ff.assertAttributeEquals(PutS3Object.S3_SSE_ALGORITHM, ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
    ff.assertContentEquals(getFileFromResourceName(SAMPLE_FILE_RESOURCE_NAME));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 9 with TestRunner

use of org.apache.nifi.util.TestRunner in project nifi by apache.

the class ITListS3 method testSimpleListWithPrefix.

@Test
public void testSimpleListWithPrefix() throws Throwable {
    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.setProperty(ListS3.PREFIX, "b/");
    runner.run();
    runner.assertAllFlowFilesTransferred(ListS3.REL_SUCCESS, 1);
    List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(ListS3.REL_SUCCESS);
    flowFiles.get(0).assertAttributeEquals("filename", "b/c");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 10 with TestRunner

use of org.apache.nifi.util.TestRunner in project nifi by apache.

the class ITListS3 method testSimpleListWithPrefixAndVersions.

@Test
public void testSimpleListWithPrefixAndVersions() throws Throwable {
    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.setProperty(ListS3.PREFIX, "b/");
    runner.setProperty(ListS3.USE_VERSIONS, "true");
    runner.run();
    runner.assertAllFlowFilesTransferred(ListS3.REL_SUCCESS, 1);
    List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(ListS3.REL_SUCCESS);
    flowFiles.get(0).assertAttributeEquals("filename", "b/c");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Aggregations

TestRunner (org.apache.nifi.util.TestRunner)1425 Test (org.junit.Test)1401 MockFlowFile (org.apache.nifi.util.MockFlowFile)753 HashMap (java.util.HashMap)304 File (java.io.File)138 ProcessContext (org.apache.nifi.processor.ProcessContext)56 ValidationResult (org.apache.nifi.components.ValidationResult)46 Connection (java.sql.Connection)44 Statement (java.sql.Statement)37 MockComponentLog (org.apache.nifi.util.MockComponentLog)35 TdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService)33 UpdateAttribute (org.apache.nifi.processors.attributes.UpdateAttribute)32 ProcessSession (org.apache.nifi.processor.ProcessSession)31 ResultSet (java.sql.ResultSet)30 LogMessage (org.apache.nifi.util.LogMessage)29 Schema (org.apache.avro.Schema)28 DevTdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DevTdchConnectionService)27 DummyTdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService)27 Relationship (org.apache.nifi.processor.Relationship)27 ByteArrayOutputStream (org.apache.nifi.stream.io.ByteArrayOutputStream)27