renamed class and removed unused imports
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/ad39b1c4 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/ad39b1c4 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/ad39b1c4 Branch: refs/heads/master Commit: ad39b1c41f83d88d34e074fcb35bfa2604662f24 Parents: 528c4bc Author: mans2singh <[email protected]> Authored: Tue Feb 16 13:25:28 2016 -0800 Committer: mans2singh <[email protected]> Committed: Tue Feb 16 13:25:28 2016 -0800 ---------------------------------------------------------------------- .../nifi/processors/aws/lambda/PutLambda.java | 1 - .../nifi/processors/aws/lambda/ITPutLambda.java | 145 ++++++++++++++++++ .../processors/aws/lambda/ITPutLambdaTest.java | 146 ------------------- 3 files changed, 145 insertions(+), 147 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/ad39b1c4/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/lambda/PutLambda.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/lambda/PutLambda.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/lambda/PutLambda.java index e3ff46b..a20f9e1 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/lambda/PutLambda.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/lambda/PutLambda.java @@ -46,7 +46,6 @@ import com.amazonaws.services.lambda.model.InvokeResult; import com.amazonaws.services.lambda.model.LogType; import com.amazonaws.services.lambda.model.RequestTooLargeException; import com.amazonaws.services.lambda.model.ResourceNotFoundException; -import com.amazonaws.services.lambda.model.ServiceException; import com.amazonaws.services.lambda.model.TooManyRequestsException; import com.amazonaws.services.lambda.model.UnsupportedMediaTypeException; import com.amazonaws.util.Base64; http://git-wip-us.apache.org/repos/asf/nifi/blob/ad39b1c4/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/ITPutLambda.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/ITPutLambda.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/ITPutLambda.java new file mode 100644 index 0000000..841c157 --- /dev/null +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/ITPutLambda.java @@ -0,0 +1,145 @@ +/* + * 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.lambda; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.apache.nifi.util.MockFlowFile; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +/** + * This test contains both unit and integration test (integration tests are ignored by default) + */ +public class ITPutLambda { + + private TestRunner runner; + protected final static String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; + + @Before + public void setUp() throws Exception { + runner = TestRunners.newTestRunner(PutLambda.class); + runner.setProperty(PutLambda.ACCESS_KEY, "abcd"); + runner.setProperty(PutLambda.SECRET_KEY, "secret key"); + runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "functionName"); + runner.assertValid(); + } + + @After + public void tearDown() throws Exception { + runner = null; + } + + @Test + public void testSizeGreaterThan6MB() throws Exception { + runner = TestRunners.newTestRunner(PutLambda.class); + runner.setProperty(PutLambda.CREDENTIALS_FILE, CREDENTIALS_FILE); + runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "hello"); + runner.assertValid(); + byte [] largeInput = new byte[6000001]; + for (int i = 0; i < 6000001; i++) { + largeInput[i] = 'a'; + } + runner.enqueue(largeInput); + runner.run(1); + + runner.assertAllFlowFilesTransferred(PutLambda.REL_FAILURE, 1); + } + + /** + * Comment out ignore for integration tests (requires creds files) + */ + @Test + @Ignore + public void testIntegrationSuccess() throws Exception { + runner = TestRunners.newTestRunner(PutLambda.class); + runner.setProperty(PutLambda.CREDENTIALS_FILE, CREDENTIALS_FILE); + runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "hello"); + runner.assertValid(); + + runner.enqueue("{\"test\":\"hi\"}".getBytes()); + runner.run(1); + + runner.assertAllFlowFilesTransferred(PutLambda.REL_SUCCESS, 1); + + final List<MockFlowFile> ffs = runner.getFlowFilesForRelationship(PutLambda.REL_SUCCESS); + final MockFlowFile out = ffs.iterator().next(); + assertNull("Function error should be null " + out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR), out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR)); + assertNotNull("log should not be null", out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_LOG)); + assertEquals("Status should be equal", "200",out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_STATUS_CODE)); + } + + /** + * Comment out ignore for integration tests (requires creds files) + */ + @Test + @Ignore + public void testIntegrationClientErrorBadMessageBody() throws Exception { + runner = TestRunners.newTestRunner(PutLambda.class); + runner.setProperty(PutLambda.CREDENTIALS_FILE, CREDENTIALS_FILE); + runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "hello"); + runner.assertValid(); + + runner.enqueue("badbod".getBytes()); + runner.run(1); + + runner.assertAllFlowFilesTransferred(PutLambda.REL_FAILURE, 1); + final List<MockFlowFile> ffs = runner.getFlowFilesForRelationship(PutLambda.REL_FAILURE); + final MockFlowFile out = ffs.iterator().next(); + assertNull("Function error should be null since there is exception" + + out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR), out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR)); + assertNull("log should not be null", out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_LOG)); + assertEquals("Status should be equal", null,out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_STATUS_CODE)); + assertEquals("exception error code should be equal", "InvalidRequestContentException",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_ERROR_CODE)); + assertEquals("exception exception error type should be equal", "Client",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_ERROR_TYPE)); + assertEquals("exception exception error code should be equal", "400",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_STATUS_CODE)); + assertTrue("exception exception error message should be start with",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_MESSAGE) + .startsWith("Could not parse request body into json: Unrecognized token 'badbod': was expecting ('true', 'false' or 'null')")); + } + + /** + * Comment out ignore for integration tests (requires creds files) + */ + @Test + @Ignore + public void testIntegrationFailedBadStreamName() throws Exception { + runner = TestRunners.newTestRunner(PutLambda.class); + runner.setProperty(PutLambda.CREDENTIALS_FILE, CREDENTIALS_FILE); + runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "bad-function-name"); + runner.assertValid(); + + runner.enqueue("{\"test\":\"hi\"}".getBytes()); + runner.run(1); + + runner.assertAllFlowFilesTransferred(PutLambda.REL_FAILURE, 1); + final List<MockFlowFile> ffs = runner.getFlowFilesForRelationship(PutLambda.REL_FAILURE); + final MockFlowFile out = ffs.iterator().next(); + assertNull("Function error should be null since there is exception" + + out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR), out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR)); + assertNull("log should not be null", out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_LOG)); + assertEquals("Status should be equal", null,out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_STATUS_CODE)); + + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/ad39b1c4/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/ITPutLambdaTest.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/ITPutLambdaTest.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/ITPutLambdaTest.java deleted file mode 100644 index ae3050a..0000000 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/ITPutLambdaTest.java +++ /dev/null @@ -1,146 +0,0 @@ -package org.apache.nifi.processors.aws.lambda; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -/* - * 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. - */ -import java.util.List; - -import org.apache.nifi.processors.aws.s3.FetchS3Object; -import org.apache.nifi.util.MockFlowFile; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -/** - * This test contains both unit and integration test (integration tests are ignored by default) - */ -public class ITPutLambdaTest { - - private TestRunner runner; - protected final static String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; - - @Before - public void setUp() throws Exception { - runner = TestRunners.newTestRunner(PutLambda.class); - runner.setProperty(PutLambda.ACCESS_KEY, "abcd"); - runner.setProperty(PutLambda.SECRET_KEY, "secret key"); - runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "functionName"); - runner.assertValid(); - } - - @After - public void tearDown() throws Exception { - runner = null; - } - - @Test - public void testSizeGreaterThan6MB() throws Exception { - runner = TestRunners.newTestRunner(PutLambda.class); - runner.setProperty(PutLambda.CREDENTIALS_FILE, CREDENTIALS_FILE); - runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "hello"); - runner.assertValid(); - byte [] largeInput = new byte[6000001]; - for (int i = 0; i < 6000001; i++) { - largeInput[i] = 'a'; - } - runner.enqueue(largeInput); - runner.run(1); - - runner.assertAllFlowFilesTransferred(PutLambda.REL_FAILURE, 1); - } - - /** - * Comment out ignore for integration tests (requires creds files) - */ - @Test - @Ignore - public void testIntegrationSuccess() throws Exception { - runner = TestRunners.newTestRunner(PutLambda.class); - runner.setProperty(PutLambda.CREDENTIALS_FILE, CREDENTIALS_FILE); - runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "hello"); - runner.assertValid(); - - runner.enqueue("{\"test\":\"hi\"}".getBytes()); - runner.run(1); - - runner.assertAllFlowFilesTransferred(PutLambda.REL_SUCCESS, 1); - - final List<MockFlowFile> ffs = runner.getFlowFilesForRelationship(FetchS3Object.REL_SUCCESS); - final MockFlowFile out = ffs.iterator().next(); - assertNull("Function error should be null " + out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR), out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR)); - assertNotNull("log should not be null", out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_LOG)); - assertEquals("Status should be equal", "200",out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_STATUS_CODE)); - } - - /** - * Comment out ignore for integration tests (requires creds files) - */ - @Test - @Ignore - public void testIntegrationClientErrorBadMessageBody() throws Exception { - runner = TestRunners.newTestRunner(PutLambda.class); - runner.setProperty(PutLambda.CREDENTIALS_FILE, CREDENTIALS_FILE); - runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "hello"); - runner.assertValid(); - - runner.enqueue("badbod".getBytes()); - runner.run(1); - - runner.assertAllFlowFilesTransferred(PutLambda.REL_FAILURE, 1); - final List<MockFlowFile> ffs = runner.getFlowFilesForRelationship(FetchS3Object.REL_FAILURE); - final MockFlowFile out = ffs.iterator().next(); - assertNull("Function error should be null since there is exception" - + out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR), out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR)); - assertNull("log should not be null", out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_LOG)); - assertEquals("Status should be equal", null,out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_STATUS_CODE)); - assertEquals("exception error code should be equal", "InvalidRequestContentException",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_ERROR_CODE)); - assertEquals("exception exception error type should be equal", "Client",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_ERROR_TYPE)); - assertEquals("exception exception error code should be equal", "400",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_STATUS_CODE)); - assertTrue("exception exception error message should be start with",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_MESSAGE) - .startsWith("Could not parse request body into json: Unrecognized token 'badbod': was expecting ('true', 'false' or 'null')")); - } - - /** - * Comment out ignore for integration tests (requires creds files) - */ - @Test - @Ignore - public void testIntegrationFailedBadStreamName() throws Exception { - runner = TestRunners.newTestRunner(PutLambda.class); - runner.setProperty(PutLambda.CREDENTIALS_FILE, CREDENTIALS_FILE); - runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "bad-function-name"); - runner.assertValid(); - - runner.enqueue("{\"test\":\"hi\"}".getBytes()); - runner.run(1); - - runner.assertAllFlowFilesTransferred(PutLambda.REL_FAILURE, 1); - final List<MockFlowFile> ffs = runner.getFlowFilesForRelationship(FetchS3Object.REL_FAILURE); - final MockFlowFile out = ffs.iterator().next(); - assertNull("Function error should be null since there is exception" - + out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR), out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR)); - assertNull("log should not be null", out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_LOG)); - assertEquals("Status should be equal", null,out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_STATUS_CODE)); - - } -}
