You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jo...@apache.org on 2016/04/11 19:31:26 UTC

nifi git commit: NIFI-1749 This closes #342. Adjusting tests that fail without a connection to the Internet and removing attributable elements from test resources.

Repository: nifi
Updated Branches:
  refs/heads/master 95dda1d92 -> e76a75c26


NIFI-1749 This closes #342. Adjusting tests that fail without a connection to the Internet and removing attributable elements from test resources.

Signed-off-by: joewitt <jo...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/e76a75c2
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/e76a75c2
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/e76a75c2

Branch: refs/heads/master
Commit: e76a75c26bbe64adc8a35fa1f8846c3fd45f632d
Parents: 95dda1d
Author: Aldrin Piri <al...@apache.org>
Authored: Sun Apr 10 15:59:51 2016 -0400
Committer: joewitt <jo...@apache.org>
Committed: Mon Apr 11 13:22:00 2016 -0400

----------------------------------------------------------------------
 .../aws/dynamodb/AbstractDynamoDBTest.java      | 41 ++++++++++++++++++++
 .../aws/dynamodb/DeleteDynamoDBTest.java        | 26 +++++++++++--
 .../aws/dynamodb/GetDynamoDBTest.java           | 18 ++++++++-
 .../aws/dynamodb/PutDynamoDBTest.java           | 18 ++++++++-
 .../java/org/apache/nifi/AbstractHTMLTest.java  |  2 +-
 .../org/apache/nifi/TestGetHTMLElement.java     | 21 ++++------
 .../src/test/resources/Weather.html             |  2 +-
 7 files changed, 106 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/e76a75c2/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/AbstractDynamoDBTest.java
----------------------------------------------------------------------
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 0000000..486bc31
--- /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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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;
+    }
+}

http://git-wip-us.apache.org/repos/asf/nifi/blob/e76a75c2/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/DeleteDynamoDBTest.java
----------------------------------------------------------------------
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 fa0e605..56067e7 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.<TableWriteItems>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);

http://git-wip-us.apache.org/repos/asf/nifi/blob/e76a75c2/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/GetDynamoDBTest.java
----------------------------------------------------------------------
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 e360c84..5bc3360 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.<TableKeysAndAttributes>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");

http://git-wip-us.apache.org/repos/asf/nifi/blob/e76a75c2/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/PutDynamoDBTest.java
----------------------------------------------------------------------
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 39b5609..c68c15c 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.<TableWriteItems>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");

http://git-wip-us.apache.org/repos/asf/nifi/blob/e76a75c2/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/java/org/apache/nifi/AbstractHTMLTest.java
----------------------------------------------------------------------
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 10bc33e..53ce645 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 = "<i>Grand Rapids Weather</i>";
     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";
 }

http://git-wip-us.apache.org/repos/asf/nifi/blob/e76a75c2/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/java/org/apache/nifi/TestGetHTMLElement.java
----------------------------------------------------------------------
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 4839fce..4b215fd 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

http://git-wip-us.apache.org/repos/asf/nifi/blob/e76a75c2/nifi-nar-bundles/nifi-html-bundle/nifi-html-processors/src/test/resources/Weather.html
----------------------------------------------------------------------
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 673f7cb..a715a1d 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 @@
         <title>NiFi HTML Parsing Demo</title>
         <meta charset="utf-8">
         <meta name="description" content="NiFi HTML Parsing Demo">
-        <meta name="author" content="Jeremy Dyer">
+        <meta name="author" content="Apache NiFi Community">
         <link rel="stylesheet" href="css/styles.css?v=1.0">
 
         <!--[if lt IE 9]>