From 3af6bf2c5ad3dfe77eb5f5e6dd646c4ddb449891 Mon Sep 17 00:00:00 2001
From: Nelson Tavares de Sousa <stu103017@mail.uni-kiel.de>
Date: Wed, 29 Oct 2014 16:43:41 +0100
Subject: [PATCH] Added DummyFactory for test purposes Added test configuration
 enhanched tests to verify merge behavior of PipeFactoryRegistry

---
 .../teetime/framework/FileSearcherTest.java   | 27 ++++++++++++++++++-
 .../teetime/framework/pipe/DummyFactory.java  |  5 ++++
 src/test/resources/data/normal-test.conf      |  1 +
 3 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 src/test/java/teetime/framework/pipe/DummyFactory.java
 create mode 100644 src/test/resources/data/normal-test.conf

diff --git a/src/test/java/teetime/framework/FileSearcherTest.java b/src/test/java/teetime/framework/FileSearcherTest.java
index 5caf5d57..1712da57 100644
--- a/src/test/java/teetime/framework/FileSearcherTest.java
+++ b/src/test/java/teetime/framework/FileSearcherTest.java
@@ -49,7 +49,7 @@ public class FileSearcherTest {
 	}
 
 	@Test
-	public void multipleConfigs() throws IOException {
+	public void multipleConfigs() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
 		List<URL> files = new ArrayList<URL>();
 		File pipeConfig = new File("conf/pipe-factories.conf");
 		File testConfig = new File("src/test/resources/data/normal-test.conf");
@@ -65,7 +65,32 @@ public class FileSearcherTest {
 			Assert.assertTrue(contents.indexOf(iPipeFactory.getClass().getCanonicalName()) != -1);
 		}
 
+		// Second part of the test: PipeFactoryRegistry
 		PipeFactoryRegistry pipeRegistry = PipeFactoryRegistry.INSTANCE;
+
+		// Look for the "normal" pipes
+		for (String string : readConf(pipeConfig)) {
+			IPipeFactory pipeFactory = getClassByString(string);
+			IPipeFactory returnedFactory = pipeRegistry.getPipeFactory(pipeFactory.getThreadCommunication(), pipeFactory.getOrdering(), pipeFactory.isGrowable());
+			Assert.assertEquals(pipeFactory.getClass().getCanonicalName(), returnedFactory.getClass().getCanonicalName());
+		}
+		// Second "and a half" part
+		for (String string : readConf(testConfig)) {
+			IPipeFactory pipeFactory = getClassByString(string);
+			// Still old factory
+			IPipeFactory returnedFactory = pipeRegistry.getPipeFactory(pipeFactory.getThreadCommunication(), pipeFactory.getOrdering(), pipeFactory.isGrowable());
+			Assert.assertNotEquals(pipeFactory.getClass().getCanonicalName(), returnedFactory.getClass().getCanonicalName());
+			// Overload factory and check for the new one
+			pipeRegistry.register(pipeFactory);
+			returnedFactory = pipeRegistry.getPipeFactory(pipeFactory.getThreadCommunication(), pipeFactory.getOrdering(), pipeFactory.isGrowable());
+			Assert.assertEquals(pipeFactory.getClass().getCanonicalName(), returnedFactory.getClass().getCanonicalName());
+		}
+	}
+
+	private IPipeFactory getClassByString(final String string) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
+		Class<?> clazz = Class.forName(string); // TODO: try-catch
+		Class<? extends IPipeFactory> pipeFactoryClass = clazz.asSubclass(IPipeFactory.class);
+		return pipeFactoryClass.newInstance();
 	}
 
 	@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
diff --git a/src/test/java/teetime/framework/pipe/DummyFactory.java b/src/test/java/teetime/framework/pipe/DummyFactory.java
new file mode 100644
index 00000000..e4a40def
--- /dev/null
+++ b/src/test/java/teetime/framework/pipe/DummyFactory.java
@@ -0,0 +1,5 @@
+package teetime.framework.pipe;
+
+public class DummyFactory extends SpScPipeFactory {
+
+}
diff --git a/src/test/resources/data/normal-test.conf b/src/test/resources/data/normal-test.conf
new file mode 100644
index 00000000..6d95eb2d
--- /dev/null
+++ b/src/test/resources/data/normal-test.conf
@@ -0,0 +1 @@
+teetime.framework.pipe.DummyFactory
\ No newline at end of file
-- 
GitLab