You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2015/01/26 15:19:39 UTC
[15/48] incubator-nifi git commit: NIFI-268: Updated unit tests
NIFI-268: Updated unit tests
Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/1b1f45fa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/1b1f45fa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/1b1f45fa
Branch: refs/heads/NIFI-250
Commit: 1b1f45faac1dc611a6df38abd6cdfb51ba382023
Parents: bd29001
Author: Mark Payne <ma...@hotmail.com>
Authored: Tue Jan 20 13:02:59 2015 -0500
Committer: Mark Payne <ma...@hotmail.com>
Committed: Tue Jan 20 13:02:59 2015 -0500
----------------------------------------------------------------------
.../standard/TestDetectDuplicate.java | 6 +-
.../nifi/processors/standard/TestGetHTTP.java | 15 +-
.../processors/standard/TestInvokeHTTP.java | 4 +-
.../apache/nifi/ssl/SSLContextServiceTest.java | 182 ++++++++-----------
4 files changed, 83 insertions(+), 124 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/1b1f45fa/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDetectDuplicate.java
----------------------------------------------------------------------
diff --git a/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDetectDuplicate.java b/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDetectDuplicate.java
index 6296f7d..4a74416 100644
--- a/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDetectDuplicate.java
+++ b/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDetectDuplicate.java
@@ -55,7 +55,6 @@ public class TestDetectDuplicate {
@Test
public void testDuplicate() throws InitializationException {
-
TestRunner runner = TestRunners.newTestRunner(DetectDuplicate.class);
final DistributedMapCacheClientImpl client = createClient();
final Map<String, String> clientProperties = new HashMap<>();
@@ -67,6 +66,8 @@ public class TestDetectDuplicate {
Map<String, String> props = new HashMap<>();
props.put("hash.value", "1000");
runner.enqueue(new byte[]{}, props);
+ runner.enableControllerService(client);
+
runner.run();
runner.assertAllFlowFilesTransferred(DetectDuplicate.REL_NON_DUPLICATE, 1);
runner.clearTransferState();
@@ -89,9 +90,12 @@ public class TestDetectDuplicate {
runner.setProperty(DetectDuplicate.DISTRIBUTED_CACHE_SERVICE, "client");
runner.setProperty(DetectDuplicate.FLOWFILE_DESCRIPTION, "The original flow file");
runner.setProperty(DetectDuplicate.AGE_OFF_DURATION, "2 secs");
+ runner.enableControllerService(client);
+
Map<String, String> props = new HashMap<>();
props.put("hash.value", "1000");
runner.enqueue(new byte[]{}, props);
+
runner.run();
runner.assertAllFlowFilesTransferred(DetectDuplicate.REL_NON_DUPLICATE, 1);
runner.clearTransferState();
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/1b1f45fa/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetHTTP.java
----------------------------------------------------------------------
diff --git a/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetHTTP.java b/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetHTTP.java
index cf6530a..f52b212 100644
--- a/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetHTTP.java
+++ b/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetHTTP.java
@@ -40,8 +40,6 @@ import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* @author unattributed
@@ -49,7 +47,6 @@ import org.slf4j.LoggerFactory;
*/
public class TestGetHTTP {
- private static Logger LOGGER;
private TestRunner controller;
@BeforeClass
@@ -58,7 +55,6 @@ public class TestGetHTTP {
System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.GetHTTP", "debug");
System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.TestGetHTTP", "debug");
- LOGGER = LoggerFactory.getLogger(TestGetHTTP.class);
File confDir = new File("conf");
if (!confDir.exists()) {
confDir.mkdir();
@@ -77,16 +73,6 @@ public class TestGetHTTP {
assertTrue(confDir.delete());
}
- private static Map<String, String> createSslProperties() {
- Map<String, String> map = new HashMap<String, String>();
- map.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
- map.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
- map.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS");
- map.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
- map.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
- map.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
- return map;
- }
@Test
public final void testContentModified() throws Exception {
@@ -308,6 +294,7 @@ public class TestGetHTTP {
final SSLContextService service = new StandardSSLContextService();
try {
controller.addControllerService("ssl-service", service, getSslProperties());
+ controller.enableControllerService(service);
} catch (InitializationException ex) {
ex.printStackTrace();
Assert.fail("Could not create SSL Context Service");
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/1b1f45fa/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java
----------------------------------------------------------------------
diff --git a/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java b/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java
index b98ba13..e5950cd 100644
--- a/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java
+++ b/nifi/nar-bundles/standard-bundle/standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java
@@ -83,7 +83,9 @@ public class TestInvokeHTTP {
@Before
public void before() throws Exception {
runner = TestRunners.newTestRunner(InvokeHTTP.class);
- runner.addControllerService("ssl-context", new StandardSSLContextService(), sslProperties);
+ final StandardSSLContextService sslService = new StandardSSLContextService();
+ runner.addControllerService("ssl-context", sslService, sslProperties);
+ runner.enableControllerService(sslService);
runner.setProperty(Config.PROP_SSL_CONTEXT_SERVICE, "ssl-context");
server.clearHandlers();
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/1b1f45fa/nifi/nar-bundles/standard-services/ssl-context-bundle/ssl-context-service/src/test/java/org/apache/nifi/ssl/SSLContextServiceTest.java
----------------------------------------------------------------------
diff --git a/nifi/nar-bundles/standard-services/ssl-context-bundle/ssl-context-service/src/test/java/org/apache/nifi/ssl/SSLContextServiceTest.java b/nifi/nar-bundles/standard-services/ssl-context-bundle/ssl-context-service/src/test/java/org/apache/nifi/ssl/SSLContextServiceTest.java
index 5d583ca..7d191fb 100644
--- a/nifi/nar-bundles/standard-services/ssl-context-bundle/ssl-context-service/src/test/java/org/apache/nifi/ssl/SSLContextServiceTest.java
+++ b/nifi/nar-bundles/standard-services/ssl-context-bundle/ssl-context-service/src/test/java/org/apache/nifi/ssl/SSLContextServiceTest.java
@@ -16,141 +16,103 @@
*/
package org.apache.nifi.ssl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import java.util.HashMap;
+import java.util.Map;
-import org.apache.nifi.controller.ControllerService;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.ssl.SSLContextService.ClientAuth;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-
import org.junit.Assert;
import org.junit.Test;
public class SSLContextServiceTest {
@Test
- public void testBad1() {
- try {
- TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
- SSLContextService service = new StandardSSLContextService();
- HashMap<String, String> properties = new HashMap<String, String>();
- runner.addControllerService("test-bad1", service, properties);
- Assert.fail("Should have thrown an Exception");
- } catch (InitializationException e) {
- assertEquals(
- "org.apache.nifi.reporting.InitializationException: SSLContextService[id=test-bad1] does not have the KeyStore or the TrustStore populated",
- e.getCause().getCause().toString());
- }
+ public void testBad1() throws InitializationException {
+ final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
+ final SSLContextService service = new StandardSSLContextService();
+ final Map<String, String> properties = new HashMap<String, String>();
+ runner.addControllerService("test-bad1", service, properties);
+ runner.assertNotValid(service);
}
@Test
- public void testBad2() {
- try {
- TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
- SSLContextService service = new StandardSSLContextService();
- HashMap<String, String> properties = new HashMap<String, String>();
- properties.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
- properties.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
- runner.addControllerService("test-bad2", service, properties);
- Assert.fail("Should have thrown an Exception");
- } catch (InitializationException e) {
- assertEquals(
- "org.apache.nifi.reporting.InitializationException: SSLContextService[id=test-bad2] is not valid due to:\n'Keystore Properties' is invalid because Must set either 0 or 3 properties for Keystore",
- e.getCause().getCause().toString());
- }
+ public void testBad2() throws InitializationException {
+ final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
+ final SSLContextService service = new StandardSSLContextService();
+ final Map<String, String> properties = new HashMap<String, String>();
+ properties.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
+ properties.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
+ runner.addControllerService("test-bad2", service, properties);
+ runner.assertNotValid(service);
}
@Test
- public void testBad3() {
- try {
- TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
- SSLContextService service = new StandardSSLContextService();
- HashMap<String, String> properties = new HashMap<String, String>();
- properties.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
- properties.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
- properties.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS");
- properties.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
- runner.addControllerService("test-bad3", service, properties);
- Assert.fail("Should have thrown an Exception");
- } catch (InitializationException e) {
- assertEquals(
- "org.apache.nifi.reporting.InitializationException: SSLContextService[id=test-bad3] is not valid due to:\n'Truststore Properties' is invalid because Must set either 0 or 3 properties for Truststore",
- e.getCause().getCause().toString());
- }
+ public void testBad3() throws InitializationException {
+ final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
+ final SSLContextService service = new StandardSSLContextService();
+ final Map<String, String> properties = new HashMap<String, String>();
+ properties.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
+ properties.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
+ properties.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS");
+ properties.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
+ runner.addControllerService("test-bad3", service, properties);
+ runner.assertNotValid(service);
}
@Test
- public void testBad4() {
- try {
- TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
- SSLContextService service = new StandardSSLContextService();
- HashMap<String, String> properties = new HashMap<String, String>();
- properties.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
- properties.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "wrongpassword");
- properties.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "PKCS12");
- properties.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
- properties.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "wrongpassword");
- properties.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
- runner.addControllerService("test-bad4", service, properties);
- Assert.fail("Should have thrown an Exception");
- } catch (InitializationException e) {
- assertEquals(
- "org.apache.nifi.reporting.InitializationException: SSLContextService[id=test-bad4] is not valid due to:\n"
- + "'Keystore Properties' is invalid because Invalid KeyStore Password or Type specified for file src/test/resources/localhost-ks.jks\n"
- + "'Truststore Properties' is invalid because Invalid KeyStore Password or Type specified for file src/test/resources/localhost-ts.jks",
- e.getCause().getCause().toString());
- }
+ public void testBad4() throws InitializationException {
+ final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
+ final SSLContextService service = new StandardSSLContextService();
+ final Map<String, String> properties = new HashMap<String, String>();
+ properties.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
+ properties.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "wrongpassword");
+ properties.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "PKCS12");
+ properties.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
+ properties.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "wrongpassword");
+ properties.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
+ runner.addControllerService("test-bad4", service, properties);
+
+ runner.assertNotValid(service);
}
@Test
- public void testBad5() {
- try {
- TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
- SSLContextService service = new StandardSSLContextService();
- HashMap<String, String> properties = new HashMap<String, String>();
- properties.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/DOES-NOT-EXIST.jks");
- properties.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
- properties.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "PKCS12");
- properties.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
- properties.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
- properties.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
- runner.addControllerService("test-bad5", service, properties);
- Assert.fail("Should have thrown an Exception");
- } catch (InitializationException e) {
- assertTrue(e.getCause().getCause().toString().startsWith("org.apache.nifi.reporting.InitializationException: "
- + "SSLContextService[id=test-bad5] is not valid due to:\n'Keystore Properties' is invalid "
- + "because Cannot access file"));
- }
+ public void testBad5() throws InitializationException {
+ final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
+ final SSLContextService service = new StandardSSLContextService();
+ final Map<String, String> properties = new HashMap<String, String>();
+ properties.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/DOES-NOT-EXIST.jks");
+ properties.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
+ properties.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "PKCS12");
+ properties.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
+ properties.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
+ properties.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
+ runner.addControllerService("test-bad5", service, properties);
+ runner.assertNotValid(service);
}
@Test
- public void testGood() {
- try {
- TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
- ControllerService service = new StandardSSLContextService();
- HashMap<String, String> properties = new HashMap<String, String>();
- properties.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
- properties.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
- properties.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "PKCS12");
- properties.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
- properties.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
- properties.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
- runner.addControllerService("test-good1", service, properties);
- runner.setProperty("SSL Context Svc ID", "test-good1");
- runner.assertValid();
- service = runner.getProcessContext().getControllerServiceLookup().getControllerService("test-good1");
- Assert.assertNotNull(service);
- Assert.assertTrue(service instanceof StandardSSLContextService);
- SSLContextService sslService = (SSLContextService) service;
- sslService.createSSLContext(ClientAuth.REQUIRED);
- sslService.createSSLContext(ClientAuth.WANT);
- sslService.createSSLContext(ClientAuth.NONE);
- } catch (InitializationException e) {
- }
+ public void testGood() throws InitializationException {
+ final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
+ SSLContextService service = new StandardSSLContextService();
+ runner.addControllerService("test-good1", service);
+ runner.setProperty(service, StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
+ runner.setProperty(service, StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
+ runner.setProperty(service, StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS");
+ runner.setProperty(service, StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
+ runner.setProperty(service, StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
+ runner.setProperty(service, StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
+ runner.enableControllerService(service);
+
+ runner.setProperty("SSL Context Svc ID", "test-good1");
+ runner.assertValid(service);
+ service = (SSLContextService) runner.getProcessContext().getControllerServiceLookup().getControllerService("test-good1");
+ Assert.assertNotNull(service);
+ SSLContextService sslService = (SSLContextService) service;
+ sslService.createSSLContext(ClientAuth.REQUIRED);
+ sslService.createSSLContext(ClientAuth.WANT);
+ sslService.createSSLContext(ClientAuth.NONE);
}
@Test
@@ -163,6 +125,8 @@ public class SSLContextServiceTest {
properties.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
properties.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
runner.addControllerService("test-good2", service, properties);
+ runner.enableControllerService(service);
+
runner.setProperty("SSL Context Svc ID", "test-good2");
runner.assertValid();
Assert.assertNotNull(service);
@@ -182,6 +146,8 @@ public class SSLContextServiceTest {
properties.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
properties.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS");
runner.addControllerService("test-good3", service, properties);
+ runner.enableControllerService(service);
+
runner.setProperty("SSL Context Svc ID", "test-good3");
runner.assertValid();
Assert.assertNotNull(service);