diff --git a/src/test/java/teetime/framework/FileSearcherTest.java b/src/test/java/teetime/framework/FileSearcherTest.java index 5caf5d57f84a5710a458a07e5aeaaab63d92a2ed..1712da579a033a71934fd1fcdc8539dc47ae9830 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 0000000000000000000000000000000000000000..e4a40def390d22ac9bb8ff907e13b15438a220fb --- /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 0000000000000000000000000000000000000000..6d95eb2d6c422d03c98078f8849b3c1c39886416 --- /dev/null +++ b/src/test/resources/data/normal-test.conf @@ -0,0 +1 @@ +teetime.framework.pipe.DummyFactory \ No newline at end of file