Repository: nifi Updated Branches: refs/heads/master ecb81ec11 -> f53aaed12
NIFI-569 Introducing the maven-failsafe-plugin to the root pom.xml. Refactoring AWS integration level tests to make use of the IT* prefix and removing @Ignore from these classes. This closes #173 Signed-off-by: Matt Gilman <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/f53aaed1 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/f53aaed1 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/f53aaed1 Branch: refs/heads/master Commit: f53aaed122bc859472735bd3aec68689ceee0014 Parents: ecb81ec Author: Aldrin Piri <[email protected]> Authored: Wed Jan 13 14:13:30 2016 -0500 Committer: Matt Gilman <[email protected]> Committed: Tue Jan 19 09:09:24 2016 -0500 ---------------------------------------------------------------------- .../nifi/processors/aws/s3/AbstractS3IT.java | 154 +++++++++++++++++++ .../nifi/processors/aws/s3/AbstractS3Test.java | 151 ------------------ .../processors/aws/s3/ITDeleteS3Object.java | 110 +++++++++++++ .../nifi/processors/aws/s3/ITFetchS3Object.java | 99 ++++++++++++ .../nifi/processors/aws/s3/ITPutS3Object.java | 140 +++++++++++++++++ .../processors/aws/s3/TestDeleteS3Object.java | 109 ------------- .../processors/aws/s3/TestFetchS3Object.java | 98 ------------ .../nifi/processors/aws/s3/TestPutS3Object.java | 140 ----------------- .../nifi/processors/aws/sns/ITPutSNS.java | 52 +++++++ .../nifi/processors/aws/sns/TestPutSNS.java | 51 ------ pom.xml | 27 ++++ 11 files changed, 582 insertions(+), 549 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/f53aaed1/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/AbstractS3IT.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/AbstractS3IT.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/AbstractS3IT.java new file mode 100644 index 0000000..d0dafb8 --- /dev/null +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/AbstractS3IT.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.processors.aws.s3; + +import com.amazonaws.auth.PropertiesCredentials; +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.model.AmazonS3Exception; +import com.amazonaws.services.s3.model.CreateBucketRequest; +import com.amazonaws.services.s3.model.DeleteBucketRequest; +import com.amazonaws.services.s3.model.ObjectListing; +import com.amazonaws.services.s3.model.PutObjectRequest; +import com.amazonaws.services.s3.model.S3ObjectSummary; +import org.apache.nifi.util.file.FileUtils; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Iterator; + +import static org.junit.Assert.fail; + +/** + * Base class for S3 Integration Tests. Establishes a bucket and helper methods for creating test scenarios + * + * @see ITDeleteS3Object + * @see ITFetchS3Object + * @see ITPutS3Object + */ +public abstract class AbstractS3IT { + protected final static String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; + protected final static String BUCKET_NAME = "test-bucket-00000000-0000-0000-0000-123456789021"; + protected final static String SAMPLE_FILE_RESOURCE_NAME = "/hello.txt"; + protected final static String REGION = "eu-west-1"; + + // Static so multiple Tests can use same client + protected static AmazonS3Client client; + + @BeforeClass + public static void oneTimeSetup() { + // Creates a client and bucket for this test + + final FileInputStream fis; + try { + fis = new FileInputStream(CREDENTIALS_FILE); + } catch (FileNotFoundException e1) { + fail("Could not open credentials file " + CREDENTIALS_FILE + ": " + e1.getLocalizedMessage()); + return; + } + try { + final PropertiesCredentials credentials = new PropertiesCredentials(fis); + client = new AmazonS3Client(credentials); + + if (client.doesBucketExist(BUCKET_NAME)) { + fail("Bucket " + BUCKET_NAME + " exists. Choose a different bucket name to continue test"); + } + + CreateBucketRequest request = new CreateBucketRequest(BUCKET_NAME, REGION); + client.createBucket(request); + + } catch (final AmazonS3Exception e) { + fail("Can't create the key " + BUCKET_NAME + ": " + e.getLocalizedMessage()); + } catch (final IOException e) { + fail("Caught IOException preparing tests: " + e.getLocalizedMessage()); + } finally { + FileUtils.closeQuietly(fis); + } + + if (!client.doesBucketExist(BUCKET_NAME)) { + fail("Setup incomplete, tests will fail"); + } + } + + @AfterClass + public static void oneTimeTearDown() { + // Empty the bucket before deleting it. + try { + ObjectListing objectListing = client.listObjects(BUCKET_NAME); + + while (true) { + for (Iterator<?> iterator = objectListing.getObjectSummaries().iterator(); iterator.hasNext(); ) { + S3ObjectSummary objectSummary = (S3ObjectSummary) iterator.next(); + client.deleteObject(BUCKET_NAME, objectSummary.getKey()); + } + + if (objectListing.isTruncated()) { + objectListing = client.listNextBatchOfObjects(objectListing); + } else { + break; + } + } + + DeleteBucketRequest dbr = new DeleteBucketRequest(BUCKET_NAME); + client.deleteBucket(dbr); + } catch (final AmazonS3Exception e) { + System.err.println("Unable to delete bucket " + BUCKET_NAME + e.toString()); + } + + if (client.doesBucketExist(BUCKET_NAME)) { + Assert.fail("Incomplete teardown, subsequent tests might fail"); + } + + } + + protected void putTestFile(String key, File file) throws AmazonS3Exception { + PutObjectRequest putRequest = new PutObjectRequest(BUCKET_NAME, key, file); + + client.putObject(putRequest); + } + + protected Path getResourcePath(String resourceName) { + Path path = null; + + try { + path = Paths.get(getClass().getResource(resourceName).toURI()); + } catch (URISyntaxException e) { + Assert.fail("Resource: " + resourceName + " does not exist" + e.getLocalizedMessage()); + } + + return path; + } + + protected File getFileFromResourceName(String resourceName) { + URI uri = null; + try { + uri = this.getClass().getResource(resourceName).toURI(); + } catch (URISyntaxException e) { + Assert.fail("Cannot proceed without File : " + resourceName); + } + + return new File(uri); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/f53aaed1/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/AbstractS3Test.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/AbstractS3Test.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/AbstractS3Test.java deleted file mode 100644 index 167c16b..0000000 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/AbstractS3Test.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.aws.s3; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Iterator; - -import org.apache.nifi.util.file.FileUtils; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; - -import static org.junit.Assert.fail; - -import com.amazonaws.auth.PropertiesCredentials; -import com.amazonaws.services.s3.AmazonS3Client; -import com.amazonaws.services.s3.model.AmazonS3Exception; -import com.amazonaws.services.s3.model.CreateBucketRequest; -import com.amazonaws.services.s3.model.DeleteBucketRequest; -import com.amazonaws.services.s3.model.ObjectListing; -import com.amazonaws.services.s3.model.PutObjectRequest; -import com.amazonaws.services.s3.model.S3ObjectSummary; - -/** - * Base class for S3 tests. Establishes a bucket and helper methods for creating test scenarios - */ -public abstract class AbstractS3Test { - protected final static String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; - protected final static String BUCKET_NAME = "test-bucket-00000000-0000-0000-0000-123456789021"; - protected final static String SAMPLE_FILE_RESOURCE_NAME = "/hello.txt"; - protected final static String REGION = "eu-west-1"; - - // Static so multiple Tests can use same client - protected static AmazonS3Client client; - - @BeforeClass - public static void oneTimeSetup() { - // Creates a client and bucket for this test - - final FileInputStream fis; - try { - fis = new FileInputStream(CREDENTIALS_FILE); - } catch (FileNotFoundException e1) { - fail("Could not open credentials file " + CREDENTIALS_FILE + ": " + e1.getLocalizedMessage()); - return; - } - try { - final PropertiesCredentials credentials = new PropertiesCredentials(fis); - client = new AmazonS3Client(credentials); - - if (client.doesBucketExist(BUCKET_NAME)) { - fail("Bucket " + BUCKET_NAME + " exists. Choose a different bucket name to continue test"); - } - - CreateBucketRequest request = new CreateBucketRequest(BUCKET_NAME, REGION); - client.createBucket(request); - - } catch (final AmazonS3Exception e) { - fail("Can't create the key " + BUCKET_NAME + ": " + e.getLocalizedMessage()); - } catch (final IOException e) { - fail("Caught IOException preparing tests: " + e.getLocalizedMessage()); - } finally { - FileUtils.closeQuietly(fis); - } - - if (!client.doesBucketExist(BUCKET_NAME)) { - fail("Setup incomplete, tests will fail"); - } - } - - @AfterClass - public static void oneTimeTearDown() { - // Empty the bucket before deleting it. - try { - ObjectListing objectListing = client.listObjects(BUCKET_NAME); - - while (true) { - for (Iterator<?> iterator = objectListing.getObjectSummaries().iterator(); iterator.hasNext(); ) { - S3ObjectSummary objectSummary = (S3ObjectSummary) iterator.next(); - client.deleteObject(BUCKET_NAME, objectSummary.getKey()); - } - - if (objectListing.isTruncated()) { - objectListing = client.listNextBatchOfObjects(objectListing); - } else { - break; - } - } - - DeleteBucketRequest dbr = new DeleteBucketRequest(BUCKET_NAME); - client.deleteBucket(dbr); - } catch (final AmazonS3Exception e) { - System.err.println("Unable to delete bucket " + BUCKET_NAME + e.toString()); - } - - if (client.doesBucketExist(BUCKET_NAME)) { - Assert.fail("Incomplete teardown, subsequent tests might fail"); - } - - } - - protected void putTestFile(String key, File file) throws AmazonS3Exception { - PutObjectRequest putRequest = new PutObjectRequest(BUCKET_NAME, key, file); - - client.putObject(putRequest); - } - - protected Path getResourcePath(String resourceName) { - Path path = null; - - try { - path = Paths.get(getClass().getResource(resourceName).toURI()); - } catch (URISyntaxException e) { - Assert.fail("Resource: " + resourceName + " does not exist" + e.getLocalizedMessage()); - } - - return path; - } - - protected File getFileFromResourceName(String resourceName) { - URI uri = null; - try { - uri = this.getClass().getResource(resourceName).toURI(); - } catch (URISyntaxException e) { - Assert.fail("Cannot proceed without File : " + resourceName); - } - - return new File(uri); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/f53aaed1/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITDeleteS3Object.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITDeleteS3Object.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITDeleteS3Object.java new file mode 100644 index 0000000..77eb2a3 --- /dev/null +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITDeleteS3Object.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.processors.aws.s3; + +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.Test; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * Provides integration level testing with actual AWS S3 resources for {@link DeleteS3Object} and requires additional configuration and resources to work. + */ +public class ITDeleteS3Object extends AbstractS3IT { + + @Test + public void testSimpleDelete() throws IOException { + // Prepares for this test + putTestFile("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", "delete-me"); + runner.enqueue(new byte[0], attrs); + + runner.run(1); + + runner.assertAllFlowFilesTransferred(DeleteS3Object.REL_SUCCESS, 1); + } + + @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); + } + + @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); + } + + @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); + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/f53aaed1/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITFetchS3Object.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITFetchS3Object.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITFetchS3Object.java new file mode 100644 index 0000000..3fc5f17 --- /dev/null +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITFetchS3Object.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.processors.aws.s3; + +import org.apache.nifi.util.MockFlowFile; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.Test; + +import java.io.IOException; +import java.nio.file.Files; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Provides integration level testing with actual AWS S3 resources for {@link FetchS3Object} and requires additional configuration and resources to work. + */ +public class ITFetchS3Object extends AbstractS3IT { + @Test + public void testSimpleGet() throws IOException { + putTestFile("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); + } + + @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); + } + + @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()); + } + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/f53aaed1/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITPutS3Object.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITPutS3Object.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITPutS3Object.java new file mode 100644 index 0000000..7bc684d --- /dev/null +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITPutS3Object.java @@ -0,0 +1,140 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.processors.aws.s3; + +import com.amazonaws.services.s3.model.StorageClass; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.util.MockFlowFile; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Provides integration level testing with actual AWS S3 resources for {@link PutS3Object} and requires additional configuration and resources to work. + */ +public class ITPutS3Object extends AbstractS3IT { + + @Test + public void testSimplePut() throws IOException { + final TestRunner runner = TestRunners.newTestRunner(new PutS3Object()); + + runner.setProperty(PutS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE); + runner.setProperty(PutS3Object.REGION, REGION); + runner.setProperty(PutS3Object.BUCKET, BUCKET_NAME); + + Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); + + for (int i = 0; i < 3; i++) { + final Map<String, String> attrs = new HashMap<>(); + attrs.put("filename", String.valueOf(i) + ".txt"); + runner.enqueue(getResourcePath(SAMPLE_FILE_RESOURCE_NAME), attrs); + } + runner.run(3); + + runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS, 3); + } + + @Test + public void testMetaData() throws IOException { + 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); + PropertyDescriptor prop1 = processor.getSupportedDynamicPropertyDescriptor("TEST-PROP-1"); + runner.setProperty(prop1, "TESTING-1-2-3"); + PropertyDescriptor prop2 = processor.getSupportedDynamicPropertyDescriptor("TEST-PROP-2"); + runner.setProperty(prop2, "TESTING-4-5-6"); + + final Map<String, String> attrs = new HashMap<>(); + attrs.put("filename", "meta.txt"); + runner.enqueue(getResourcePath(SAMPLE_FILE_RESOURCE_NAME), attrs); + + runner.run(); + + runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS, 1); + List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS); + MockFlowFile ff1 = flowFiles.get(0); + for (Map.Entry attrib : ff1.getAttributes().entrySet()) { + System.out.println(attrib.getKey() + " = " + attrib.getValue()); + } + } + + @Test + public void testPutInFolder() throws IOException { + final TestRunner runner = TestRunners.newTestRunner(new PutS3Object()); + + runner.setProperty(PutS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE); + runner.setProperty(PutS3Object.REGION, REGION); + runner.setProperty(PutS3Object.BUCKET, BUCKET_NAME); + + Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); + + final Map<String, String> attrs = new HashMap<>(); + attrs.put("filename", "folder/1.txt"); + runner.enqueue(getResourcePath(SAMPLE_FILE_RESOURCE_NAME), attrs); + + runner.run(); + + runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS, 1); + } + + @Test + public void testStorageClass() throws IOException { + final TestRunner runner = TestRunners.newTestRunner(new PutS3Object()); + + runner.setProperty(PutS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE); + runner.setProperty(PutS3Object.REGION, REGION); + runner.setProperty(PutS3Object.BUCKET, BUCKET_NAME); + runner.setProperty(PutS3Object.STORAGE_CLASS, StorageClass.ReducedRedundancy.name()); + + Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); + + final Map<String, String> attrs = new HashMap<>(); + attrs.put("filename", "folder/2.txt"); + runner.enqueue(getResourcePath(SAMPLE_FILE_RESOURCE_NAME), attrs); + + runner.run(); + + runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS, 1); + } + + @Test + public void testPermissions() throws IOException { + final TestRunner runner = TestRunners.newTestRunner(new PutS3Object()); + + runner.setProperty(PutS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE); + runner.setProperty(PutS3Object.BUCKET, BUCKET_NAME); + runner.setProperty(PutS3Object.FULL_CONTROL_USER_LIST,"28545acd76c35c7e91f8409b95fd1aa0c0914bfa1ac60975d9f48bc3c5e090b5"); + runner.setProperty(PutS3Object.REGION, REGION); + + final Map<String, String> attrs = new HashMap<>(); + attrs.put("filename", "folder/4.txt"); + runner.enqueue(getResourcePath(SAMPLE_FILE_RESOURCE_NAME), attrs); + + runner.run(); + + runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS, 1); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/f53aaed1/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestDeleteS3Object.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestDeleteS3Object.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestDeleteS3Object.java deleted file mode 100644 index a51eddd..0000000 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestDeleteS3Object.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.aws.s3; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore("For local testing only - interacts with S3 so the credentials file must be configured and all necessary buckets created") -public class TestDeleteS3Object extends AbstractS3Test { - - @Test - public void testSimpleDelete() throws IOException { - // Prepares for this test - putTestFile("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", "delete-me"); - runner.enqueue(new byte[0], attrs); - - runner.run(1); - - runner.assertAllFlowFilesTransferred(DeleteS3Object.REL_SUCCESS, 1); - } - - @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); - } - - @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); - } - - @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); - } - -} http://git-wip-us.apache.org/repos/asf/nifi/blob/f53aaed1/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestFetchS3Object.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestFetchS3Object.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestFetchS3Object.java deleted file mode 100644 index b4ab911..0000000 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestFetchS3Object.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.aws.s3; - -import java.io.IOException; -import java.nio.file.Files; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.nifi.util.MockFlowFile; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore("For local testing only - interacts with S3 so the credentials file must be configured and all necessary buckets created") -public class TestFetchS3Object extends AbstractS3Test { - @Test - public void testSimpleGet() throws IOException { - putTestFile("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); - } - - @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); - } - - @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()); - } - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/f53aaed1/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestPutS3Object.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestPutS3Object.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestPutS3Object.java deleted file mode 100644 index a65bda3..0000000 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestPutS3Object.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.aws.s3; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.nifi.components.PropertyDescriptor; -import org.apache.nifi.util.MockFlowFile; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -import com.amazonaws.services.s3.model.StorageClass; - -@Ignore("For local testing only - interacts with S3 so the credentials file must be configured and all necessary buckets created") -public class TestPutS3Object extends AbstractS3Test { - - @Test - public void testSimplePut() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new PutS3Object()); - - runner.setProperty(PutS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE); - runner.setProperty(PutS3Object.REGION, REGION); - runner.setProperty(PutS3Object.BUCKET, BUCKET_NAME); - - Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); - - for (int i = 0; i < 3; i++) { - final Map<String, String> attrs = new HashMap<>(); - attrs.put("filename", String.valueOf(i) + ".txt"); - runner.enqueue(getResourcePath(SAMPLE_FILE_RESOURCE_NAME), attrs); - } - runner.run(3); - - runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS, 3); - } - - @Test - public void testMetaData() throws IOException { - 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); - PropertyDescriptor prop1 = processor.getSupportedDynamicPropertyDescriptor("TEST-PROP-1"); - runner.setProperty(prop1, "TESTING-1-2-3"); - PropertyDescriptor prop2 = processor.getSupportedDynamicPropertyDescriptor("TEST-PROP-2"); - runner.setProperty(prop2, "TESTING-4-5-6"); - - final Map<String, String> attrs = new HashMap<>(); - attrs.put("filename", "meta.txt"); - runner.enqueue(getResourcePath(SAMPLE_FILE_RESOURCE_NAME), attrs); - - runner.run(); - - runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS, 1); - List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS); - MockFlowFile ff1 = flowFiles.get(0); - for (Map.Entry attrib : ff1.getAttributes().entrySet()) { - System.out.println(attrib.getKey() + " = " + attrib.getValue()); - } - } - - @Test - public void testPutInFolder() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new PutS3Object()); - - runner.setProperty(PutS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE); - runner.setProperty(PutS3Object.REGION, REGION); - runner.setProperty(PutS3Object.BUCKET, BUCKET_NAME); - - Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); - - final Map<String, String> attrs = new HashMap<>(); - attrs.put("filename", "folder/1.txt"); - runner.enqueue(getResourcePath(SAMPLE_FILE_RESOURCE_NAME), attrs); - - runner.run(); - - runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS, 1); - } - - @Test - public void testStorageClass() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new PutS3Object()); - - runner.setProperty(PutS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE); - runner.setProperty(PutS3Object.REGION, REGION); - runner.setProperty(PutS3Object.BUCKET, BUCKET_NAME); - runner.setProperty(PutS3Object.STORAGE_CLASS, StorageClass.ReducedRedundancy.name()); - - Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); - - final Map<String, String> attrs = new HashMap<>(); - attrs.put("filename", "folder/2.txt"); - runner.enqueue(getResourcePath(SAMPLE_FILE_RESOURCE_NAME), attrs); - - runner.run(); - - runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS, 1); - } - - @Test - public void testPermissions() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new PutS3Object()); - - runner.setProperty(PutS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE); - runner.setProperty(PutS3Object.BUCKET, BUCKET_NAME); - runner.setProperty(PutS3Object.FULL_CONTROL_USER_LIST,"28545acd76c35c7e91f8409b95fd1aa0c0914bfa1ac60975d9f48bc3c5e090b5"); - runner.setProperty(PutS3Object.REGION, REGION); - - final Map<String, String> attrs = new HashMap<>(); - attrs.put("filename", "folder/4.txt"); - runner.enqueue(getResourcePath(SAMPLE_FILE_RESOURCE_NAME), attrs); - - runner.run(); - - runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS, 1); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/f53aaed1/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/ITPutSNS.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/ITPutSNS.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/ITPutSNS.java new file mode 100644 index 0000000..be36ce0 --- /dev/null +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/ITPutSNS.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.processors.aws.sns; + +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.Test; + +import java.io.IOException; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertTrue; + +/** + * Provides integration level testing with actual AWS S3 resources for {@link PutSNS} and requires additional configuration and resources to work. + */ +public class ITPutSNS { + + private final String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; + + @Test + public void testPublish() throws IOException { + final TestRunner runner = TestRunners.newTestRunner(new PutSNS()); + runner.setProperty(PutSNS.CREDENTIALS_FILE, CREDENTIALS_FILE); + runner.setProperty(PutSNS.ARN, "arn:aws:sns:us-west-2:100515378163:test-topic-1"); + assertTrue(runner.setProperty("DynamicProperty", "hello!").isValid()); + + final Map<String, String> attrs = new HashMap<>(); + attrs.put("filename", "1.txt"); + runner.enqueue(Paths.get("src/test/resources/hello.txt"), attrs); + runner.run(); + + runner.assertAllFlowFilesTransferred(PutSNS.REL_SUCCESS, 1); + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/f53aaed1/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/TestPutSNS.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/TestPutSNS.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/TestPutSNS.java deleted file mode 100644 index b1b7643..0000000 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/TestPutSNS.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.aws.sns; - -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; - -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore("For local testing only - interacts with S3 so the credentials file must be configured and all necessary buckets created") -public class TestPutSNS { - - private final String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; - - @Test - public void testPublish() throws IOException { - final TestRunner runner = TestRunners.newTestRunner(new PutSNS()); - runner.setProperty(PutSNS.CREDENTIALS_FILE, CREDENTIALS_FILE); - runner.setProperty(PutSNS.ARN, "arn:aws:sns:us-west-2:100515378163:test-topic-1"); - assertTrue(runner.setProperty("DynamicProperty", "hello!").isValid()); - - final Map<String, String> attrs = new HashMap<>(); - attrs.put("filename", "1.txt"); - runner.enqueue(Paths.get("src/test/resources/hello.txt"), attrs); - runner.run(); - - runner.assertAllFlowFilesTransferred(PutSNS.REL_SUCCESS, 1); - } - -} http://git-wip-us.apache.org/repos/asf/nifi/blob/f53aaed1/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 95a86ec..213888b 100644 --- a/pom.xml +++ b/pom.xml @@ -1140,6 +1140,11 @@ language governing permissions and limitations under the License. --> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <version>2.18</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.5.2</version> <configuration> @@ -1392,6 +1397,28 @@ language governing permissions and limitations under the License. --> </build> <profiles> <profile> + <!-- Performs execution of Integration Tests using the Maven FailSafe Plugin. The view of integration tests in this context + are those tests interfacing with external sources and services requiring additional resources or credentials that cannot + be explicitly provided. --> + <id>integration-tests</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + <profile> <!-- Checks style and licensing requirements. This is a good idea to run for contributions and for the release process. While it would be nice to run always these plugins can considerably slow the build and have proven
