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 <joewitt@apache.org>
This commit is contained in:
Aldrin Piri 2016-04-10 15:59:51 -04:00 committed by joewitt
parent 95dda1d920
commit e76a75c26b
7 changed files with 106 additions and 22 deletions

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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");

View File

@ -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");

View File

@ -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";
}

View File

@ -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

View File

@ -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]>