Search in sources :

Example 1 with AWSCredentialsProviderControllerService

use of org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService 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 2 with AWSCredentialsProviderControllerService

use of org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService 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)

Example 3 with AWSCredentialsProviderControllerService

use of org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService in project nifi by apache.

the class ITListS3 method testSimpleListUsingCredentialsProviderService.

@Test
public void testSimpleListUsingCredentialsProviderService() 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());
    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(ListS3.AWS_CREDENTIALS_PROVIDER_SERVICE, "awsCredentialsProvider");
    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");
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) AWSCredentialsProviderControllerService(org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 4 with AWSCredentialsProviderControllerService

use of org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService in project nifi by apache.

the class ITGetSQS method testSimpleGetUsingCredentialsProviderService.

@Test
public void testSimpleGetUsingCredentialsProviderService() throws Throwable {
    final TestRunner runner = TestRunners.newTestRunner(new GetSQS());
    runner.setProperty(GetSQS.TIMEOUT, "30 secs");
    String queueUrl = "Add queue url here";
    runner.setProperty(GetSQS.QUEUE_URL, queueUrl);
    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(GetSQS.AWS_CREDENTIALS_PROVIDER_SERVICE, "awsCredentialsProvider");
    runner.run(1);
    final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(GetSQS.REL_SUCCESS);
    for (final MockFlowFile mff : flowFiles) {
        System.out.println(mff.getAttributes());
        System.out.println(new String(mff.toByteArray()));
    }
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) AWSCredentialsProviderControllerService(org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService) TestRunner(org.apache.nifi.util.TestRunner) Test(org.junit.Test)

Example 5 with AWSCredentialsProviderControllerService

use of org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService in project nifi by apache.

the class TestAWSCredentials method testCredentialsProviderControllerService.

@Test
public void testCredentialsProviderControllerService() throws InitializationException {
    final AWSCredentialsProviderControllerService credsService = new AWSCredentialsProviderControllerService();
    runner.addControllerService("awsCredentialsProvider", credsService);
    runner.setProperty(credsService, AbstractAWSProcessor.ACCESS_KEY, "awsAccessKey");
    runner.setProperty(credsService, AbstractAWSProcessor.SECRET_KEY, "awsSecretKey");
    runner.enableControllerService(credsService);
    runner.setProperty(AbstractAWSCredentialsProviderProcessor.AWS_CREDENTIALS_PROVIDER_SERVICE, "awsCredentialsProvider");
    runner.assertValid();
    runner.run(1);
    assertEquals(StaticCredentialsProvider.class, awsCredentialsProvider.getClass());
    assertNull(awsCredentials);
}
Also used : AWSCredentialsProviderControllerService(org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService) Test(org.junit.Test)

Aggregations

AWSCredentialsProviderControllerService (org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService)9 Test (org.junit.Test)9 TestRunner (org.apache.nifi.util.TestRunner)8 HashMap (java.util.HashMap)5 MockFlowFile (org.apache.nifi.util.MockFlowFile)3