Search in sources :

Example 1 with TestRunner

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

the class ITDeleteS3Object method testDeleteFolder.

@Test
public void testDeleteFolder() throws IOException {
    // Prepares for this test
    putTestFile("folder/delete-me", getFileFromResourceName(SAMPLE_FILE_RESOURCE_NAME));
    final TestRunner runner = TestRunners.newTestRunner(new DeleteS3Object());
    runner.setProperty(DeleteS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE);
    runner.setProperty(DeleteS3Object.REGION, REGION);
    runner.setProperty(DeleteS3Object.BUCKET, BUCKET_NAME);
    final Map<String, String> attrs = new HashMap<>();
    attrs.put("filename", "folder/delete-me");
    runner.enqueue(new byte[0], attrs);
    runner.run(1);
    runner.assertAllFlowFilesTransferred(DeleteS3Object.REL_SUCCESS, 1);
}
Also used : HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 2 with TestRunner

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

the class ITDeleteS3Object method testDeleteFolderUsingCredentialsProviderService.

@Test
public void testDeleteFolderUsingCredentialsProviderService() throws Throwable {
    // Prepares for this test
    putTestFile("folder/delete-me", getFileFromResourceName(SAMPLE_FILE_RESOURCE_NAME));
    final TestRunner runner = TestRunners.newTestRunner(new DeleteS3Object());
    final AWSCredentialsProviderControllerService serviceImpl = new AWSCredentialsProviderControllerService();
    runner.addControllerService("awsCredentialsProvider", serviceImpl);
    runner.setProperty(serviceImpl, AbstractAWSProcessor.CREDENTIALS_FILE, System.getProperty("user.home") + "/aws-credentials.properties");
    runner.enableControllerService(serviceImpl);
    runner.assertValid(serviceImpl);
    runner.setProperty(DeleteS3Object.AWS_CREDENTIALS_PROVIDER_SERVICE, "awsCredentialsProvider");
    runner.setProperty(DeleteS3Object.REGION, REGION);
    runner.setProperty(DeleteS3Object.BUCKET, BUCKET_NAME);
    final Map<String, String> attrs = new HashMap<>();
    attrs.put("filename", "folder/delete-me");
    runner.enqueue(new byte[0], attrs);
    runner.run(1);
    runner.assertAllFlowFilesTransferred(DeleteS3Object.REL_SUCCESS, 1);
}
Also used : AWSCredentialsProviderControllerService(org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService) HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 3 with TestRunner

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

the class ITDeleteS3Object method testTryToDeleteNotExistingFile.

@Test
public void testTryToDeleteNotExistingFile() throws IOException {
    final TestRunner runner = TestRunners.newTestRunner(new DeleteS3Object());
    runner.setProperty(DeleteS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE);
    runner.setProperty(DeleteS3Object.REGION, REGION);
    runner.setProperty(DeleteS3Object.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(DeleteS3Object.REL_SUCCESS, 1);
}
Also used : HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 4 with TestRunner

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

the class ITDeleteS3Object method testDeleteFolderNoExpressionLanguage.

@Test
public void testDeleteFolderNoExpressionLanguage() throws IOException {
    // Prepares for this test
    putTestFile("folder/delete-me", getFileFromResourceName(SAMPLE_FILE_RESOURCE_NAME));
    final TestRunner runner = TestRunners.newTestRunner(new DeleteS3Object());
    runner.setProperty(DeleteS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE);
    runner.setProperty(DeleteS3Object.REGION, REGION);
    runner.setProperty(DeleteS3Object.BUCKET, BUCKET_NAME);
    runner.setProperty(DeleteS3Object.KEY, "folder/delete-me");
    final Map<String, String> attrs = new HashMap<>();
    attrs.put("filename", "a-different-name");
    runner.enqueue(new byte[0], attrs);
    runner.run(1);
    runner.assertAllFlowFilesTransferred(DeleteS3Object.REL_SUCCESS, 1);
}
Also used : HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 5 with TestRunner

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

the class ITFetchS3Object method testFetchS3ObjectUsingCredentialsProviderService.

@Test
public void testFetchS3ObjectUsingCredentialsProviderService() throws Throwable {
    putTestFile("test-file", getFileFromResourceName(SAMPLE_FILE_RESOURCE_NAME));
    final TestRunner runner = TestRunners.newTestRunner(new FetchS3Object());
    final AWSCredentialsProviderControllerService serviceImpl = new AWSCredentialsProviderControllerService();
    runner.addControllerService("awsCredentialsProvider", serviceImpl);
    runner.setProperty(serviceImpl, AbstractAWSProcessor.CREDENTIALS_FILE, System.getProperty("user.home") + "/aws-credentials.properties");
    runner.enableControllerService(serviceImpl);
    runner.assertValid(serviceImpl);
    runner.setProperty(FetchS3Object.AWS_CREDENTIALS_PROVIDER_SERVICE, "awsCredentialsProvider");
    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);
}
Also used : AWSCredentialsProviderControllerService(org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService) HashMap(java.util.HashMap) 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