diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/AbstractDynamoDBTest.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/AbstractDynamoDBTest.java
new file mode 100644
index 0000000000..486bc31221
--- /dev/null
+++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/AbstractDynamoDBTest.java
@@ -0,0 +1,41 @@
+/**
+ * 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.dynamodb;
+
+import com.amazonaws.AmazonServiceException;
+import com.amazonaws.AmazonServiceException.ErrorType;
+
+/**
+ * Provides reused elements and utilities for the AWS DynamoDB related tests
+ *
+ * @see GetDynamoDBTest
+ * @see PutDynamoDBTest
+ * @see DeleteDynamoDBTest
+ */
+public abstract class AbstractDynamoDBTest {
+
+ protected AmazonServiceException getSampleAwsServiceException() {
+ final AmazonServiceException testServiceException = new AmazonServiceException("Test AWS Service Exception");
+ testServiceException.setErrorCode("8673509");
+ testServiceException.setErrorMessage("This request cannot be serviced right now.");
+ testServiceException.setErrorType(ErrorType.Service);
+ testServiceException.setServiceName("Dynamo DB");
+ testServiceException.setRequestId("TestRequestId-1234567890");
+
+ return testServiceException;
+ }
+}
diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/DeleteDynamoDBTest.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/DeleteDynamoDBTest.java
index fa0e605060..56067e7053 100644
--- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/DeleteDynamoDBTest.java
+++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/DeleteDynamoDBTest.java
@@ -26,6 +26,14 @@ 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.Before;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.regions.Regions;
@@ -42,7 +50,7 @@ import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.Before;
import org.junit.Test;
-public class DeleteDynamoDBTest {
+public class DeleteDynamoDBTest extends AbstractDynamoDBTest{
protected DeleteDynamoDB deleteDynamoDB;
protected BatchWriteItemResult result = new BatchWriteItemResult();
@@ -70,9 +78,21 @@ public class DeleteDynamoDBTest {
@Test
public void testStringHashStringRangeDeleteOnlyHashFailure() {
- final TestRunner deleteRunner = TestRunners.newTestRunner(DeleteDynamoDB.class);
+ // Inject a mock DynamoDB to create the exception condition
+ final DynamoDB mockDynamoDb = Mockito.mock(DynamoDB.class);
+ // When writing, mock thrown service exception from AWS
+ Mockito.when(mockDynamoDb.batchWriteItem(Matchers.anyVararg())).thenThrow(getSampleAwsServiceException());
- deleteRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY,"abcd");
+ deleteDynamoDB = new DeleteDynamoDB() {
+ @Override
+ protected DynamoDB getDynamoDB() {
+ return mockDynamoDb;
+ }
+ };
+
+ final TestRunner deleteRunner = TestRunners.newTestRunner(deleteDynamoDB);
+
+ deleteRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY, "abcd");
deleteRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
deleteRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
deleteRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/GetDynamoDBTest.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/GetDynamoDBTest.java
index e360c84a1f..5bc3360724 100644
--- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/GetDynamoDBTest.java
+++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/GetDynamoDBTest.java
@@ -33,6 +33,8 @@ import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
@@ -46,7 +48,7 @@ import com.amazonaws.services.dynamodbv2.model.KeysAndAttributes;
import com.amazonaws.util.json.JSONException;
import com.amazonaws.util.json.JSONObject;
-public class GetDynamoDBTest {
+public class GetDynamoDBTest extends AbstractDynamoDBTest {
protected GetDynamoDB getDynamoDB;
protected BatchGetItemOutcome outcome;
protected BatchGetItemResult result = new BatchGetItemResult();
@@ -401,7 +403,19 @@ public class GetDynamoDBTest {
@Test
public void testStringHashStringRangeGetOnlyHashFailure() {
- final TestRunner getRunner = TestRunners.newTestRunner(GetDynamoDB.class);
+ // Inject a mock DynamoDB to create the exception condition
+ final DynamoDB mockDynamoDb = Mockito.mock(DynamoDB.class);
+ // When writing, mock thrown service exception from AWS
+ Mockito.when(mockDynamoDb.batchGetItem(Matchers.anyVararg())).thenThrow(getSampleAwsServiceException());
+
+ getDynamoDB = new GetDynamoDB() {
+ @Override
+ protected DynamoDB getDynamoDB() {
+ return mockDynamoDb;
+ }
+ };
+
+ final TestRunner getRunner = TestRunners.newTestRunner(getDynamoDB);
getRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY,"abcd");
getRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/PutDynamoDBTest.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/PutDynamoDBTest.java
index 39b560992c..c68c15cbf6 100644
--- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/PutDynamoDBTest.java
+++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/PutDynamoDBTest.java
@@ -31,6 +31,8 @@ import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
@@ -43,7 +45,7 @@ import com.amazonaws.services.dynamodbv2.model.BatchWriteItemResult;
import com.amazonaws.services.dynamodbv2.model.PutRequest;
import com.amazonaws.services.dynamodbv2.model.WriteRequest;
-public class PutDynamoDBTest {
+public class PutDynamoDBTest extends AbstractDynamoDBTest {
protected PutDynamoDB putDynamoDB;
protected BatchWriteItemResult result = new BatchWriteItemResult();
@@ -71,7 +73,19 @@ public class PutDynamoDBTest {
@Test
public void testStringHashStringRangePutOnlyHashFailure() {
- final TestRunner putRunner = TestRunners.newTestRunner(PutDynamoDB.class);
+ // Inject a mock DynamoDB to create the exception condition
+ final DynamoDB mockDynamoDb = Mockito.mock(DynamoDB.class);
+ // When writing, mock thrown service exception from AWS
+ Mockito.when(mockDynamoDb.batchWriteItem(Matchers.anyVararg())).thenThrow(getSampleAwsServiceException());
+
+ putDynamoDB = new PutDynamoDB() {
+ @Override
+ protected DynamoDB getDynamoDB() {
+ return mockDynamoDb;
+ }
+ };
+
+ final TestRunner putRunner = TestRunners.newTestRunner(putDynamoDB);
putRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY,"abcd");
putRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
diff --git a/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/java/org/apache/nifi/AbstractHTMLTest.java b/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/java/org/apache/nifi/AbstractHTMLTest.java
index 10bc33ea16..53ce645dd0 100644
--- a/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/java/org/apache/nifi/AbstractHTMLTest.java
+++ b/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/java/org/apache/nifi/AbstractHTMLTest.java
@@ -22,7 +22,7 @@ public abstract class AbstractHTMLTest {
protected final String GDR_WEATHER_TEXT = "Grand Rapids Weather ";
protected final String ATL_WEATHER_LINK = "http://w1.weather.gov/obhistory/KPDK.html";
protected final String GR_WEATHER_LINK = "http://w1.weather.gov/obhistory/KGRR.html";
- protected final String AUTHOR_NAME = "Jeremy Dyer";
+ protected final String AUTHOR_NAME = "Apache NiFi Community";
protected final String ATL_ID = "ATL";
protected final String GDR_ID = "GDR";
}
diff --git a/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/java/org/apache/nifi/TestGetHTMLElement.java b/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/java/org/apache/nifi/TestGetHTMLElement.java
index 4839fcefec..4b215fda8e 100644
--- a/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/java/org/apache/nifi/TestGetHTMLElement.java
+++ b/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/java/org/apache/nifi/TestGetHTMLElement.java
@@ -16,6 +16,11 @@
*/
package org.apache.nifi;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
@@ -25,12 +30,6 @@ import org.jsoup.select.Selector;
import org.junit.Before;
import org.junit.Test;
-import java.io.File;
-import java.io.IOException;
-import java.lang.Exception;
-import java.net.URL;
-import java.util.List;
-
public class TestGetHTMLElement extends AbstractHTMLTest {
private TestRunner testRunner;
@@ -44,14 +43,10 @@ public class TestGetHTMLElement extends AbstractHTMLTest {
testRunner.setProperty(GetHTMLElement.HTML_CHARSET, "UTF-8");
}
- @Test
+ @Test(expected = Selector.SelectorParseException.class)
public void testCSSSelectorSyntaxValidator() throws IOException {
- Document doc = Jsoup.parse(new URL("http://www.google.com"), 5000);
- try {
- doc.select("---jeremy");
- } catch (Selector.SelectorParseException ex) {
- ex.printStackTrace();
- }
+ Document doc = Jsoup.parse(new File("src/test/resources/Weather.html"), StandardCharsets.UTF_8.name());
+ doc.select("---invalidCssSelector");
}
@Test
diff --git a/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/resources/Weather.html b/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/resources/Weather.html
index 673f7cb055..a715a1dd67 100644
--- a/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/resources/Weather.html
+++ b/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/resources/Weather.html
@@ -4,7 +4,7 @@
NiFi HTML Parsing Demo
-
+