package com.rackspacecloud.blueflood.utils;

import com.rackspacecloud.blueflood.io.DiscoveryIO;
import com.rackspacecloud.blueflood.io.EventsIO;
import com.rackspacecloud.blueflood.service.CoreConfig;
import org.junit.Assert;
import org.junit.Test;


public class ModuleLoaderTest {

    @Test
    public void getInstanceShouldReturnCorrectInstance(){
        System.setProperty("EVENTS_MODULES", "");
        Assert.assertNull(ModuleLoader.getInstance(EventsIO.class, CoreConfig.EVENTS_MODULES));

        System.setProperty("DISCOVERY_MODULES", "com.rackspacecloud.blueflood.io.ElasticIO");
        Assert.assertTrue((ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES)) instanceof DiscoveryIO);

        System.setProperty("EVENTS_MODULES", "com.rackspacecloud.blueflood.io.EventElasticSearchIO");
        Assert.assertTrue((ModuleLoader.getInstance(EventsIO.class, CoreConfig.EVENTS_MODULES)) instanceof EventsIO);

        Assert.assertFalse((ModuleLoader.getInstance(EventsIO.class, CoreConfig.EVENTS_MODULES)) instanceof DiscoveryIO);
        Assert.assertFalse((ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES)) instanceof EventsIO);
    }

}
@@ -135,24 +135,83 @@
 o.EventsIO;%0A
+import com.rackspacecloud.blueflood.service.Configuration;%0A
 import com.r
@@ -407,171 +407,64 @@
 ce()
-%7B%0A        System.setProperty(%22EVENTS_MODULES%22, %22%22);%0A        Assert.assertNull(ModuleLoader.getInstance(EventsIO.class, CoreConfig.EVENTS_MODULES));%0A%0A        System
+ throws Exception %7B%0A%0A        Configuration.getInstance()
 .set
@@ -547,35 +547,28 @@
         
-Assert.assertTrue((
+Object dm = 
 ModuleLo
@@ -624,33 +624,191 @@
 SCOVERY_MODULES)
-)
+;%0A        Assert.assertTrue(%22ModuleLoader did not return DiscoveryIO instance for DISCOVERY_MODULES and instead returned: %22 + dm.getClass(),%0A                dm
  instanceof Disc
@@ -830,14 +830,35 @@
     
-System
+Configuration.getInstance()
 .set
@@ -953,27 +953,20 @@
     
-Assert.assertTrue((
+Object em = 
 Modu
@@ -1032,60 +1032,293 @@
 LES)
-) instanceof EventsIO);%0A%0A        Assert.assertFalse(
+;%0A        Assert.assertTrue(%22ModuleLoader did not return EventsIO instance for EVENTS_MODULES and instead returned: %22 + em.getClass(),%0A                em instanceof EventsIO);%0A%0A        Assert.assertFalse(%22ModuleLoader returned DiscoveryIO instance for EVENTS_MODULES%22,%0A                
 (Mod
@@ -1404,24 +1404,25 @@
 scoveryIO);%0A
+%0A
         Asse
@@ -1436,16 +1436,97 @@
 rtFalse(
+%22ModuleLoader returned EventsIO instance for DISCOVERY_MODULES%22,%0A                
 (ModuleL
@@ -1619,12 +1619,13 @@
 O);%0A
+%0A
     %7D%0A%0A%7D
@@ -1624,8 +1624,9 @@
     %7D%0A%0A%7D
+%0A

remove null check from ModuleLoaderTest, which was causing interminent test failures