now distinguishing between provided and required service and added
[utils] / system / spring / src / test / java / org / wamblee / system / spring / SpringSystemTest.java
index 092a5bc11e47907ce74c93387388893ef8e55873..e12e0113a46e2d9a2b42e7f1b9ca3929d3cc64f2 100644 (file)
@@ -5,8 +5,12 @@ import java.util.Map;
 
 import junit.framework.TestCase;
 
-import org.wamblee.system.DefaultServiceDescriptor;
+import org.wamblee.system.AbstractServiceDescriptor;
+import org.wamblee.system.DefaultProvidedServiceDescriptor;
+import org.wamblee.system.DefaultRequiredServiceDescriptor;
 import org.wamblee.system.DefaultServiceRegistry;
+import org.wamblee.system.ProvidedServiceDescriptor;
+import org.wamblee.system.RequiredServiceDescriptor;
 import org.wamblee.system.Service;
 import org.wamblee.system.ServiceDescriptor;
 import org.wamblee.system.ServiceRegistry;
@@ -28,8 +32,8 @@ public class SpringSystemTest extends TestCase {
        public void testBlackboxSystem() {
                SpringSystem system = new SpringSystem("system", _registry,
                                new String[] { HELLO_SERVICE_SPRING_XML },
-                               new HashMap<String, ServiceDescriptor>(),
-                               new HashMap<ServiceDescriptor, String>());
+                               new HashMap<String, ProvidedServiceDescriptor>(),
+                               new HashMap<RequiredServiceDescriptor, String>());
                system.start("Hello", new Service[0]);
                Service[] services = system.getRunningServices();
                assertEquals(0, services.length);
@@ -38,13 +42,13 @@ public class SpringSystemTest extends TestCase {
        }
 
        public void testOneProvidedService() {
-               Map<String, ServiceDescriptor> provided = new HashMap<String, ServiceDescriptor>();
-               provided.put("helloService", new DefaultServiceDescriptor(
-                               HelloService.class));
+               Map<String, ProvidedServiceDescriptor> provided = new HashMap<String, ProvidedServiceDescriptor>();
+               provided.put("helloService", new DefaultProvidedServiceDescriptor(
+                               "hello", HelloService.class));
 
                SpringSystem system = new SpringSystem("system", _registry,
                                new String[] { HELLO_SERVICE_SPRING_XML }, provided,
-                               new HashMap<ServiceDescriptor, String>());
+                               new HashMap<RequiredServiceDescriptor, String>());
                system.start("Hello", new Service[0]);
                Service[] services = system.getRunningServices();
                assertEquals(1, services.length);
@@ -58,8 +62,8 @@ public class SpringSystemTest extends TestCase {
                try {
                        SpringSystem system = new SpringSystem("system", _registry,
                                        new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
-                                       new HashMap<String, ServiceDescriptor>(),
-                                       new HashMap<ServiceDescriptor, String>());
+                                       new HashMap<String, ProvidedServiceDescriptor>(),
+                                       new HashMap<RequiredServiceDescriptor, String>());
                        system.start("Bla", new Service[0]);
                } catch (SystemAssemblyException e) {
                        //e.printStackTrace();
@@ -69,25 +73,25 @@ public class SpringSystemTest extends TestCase {
        }
 
        public void testWithRequirement() {
-               Map<ServiceDescriptor, String> required = new HashMap<ServiceDescriptor, String>();
-               required.put(new DefaultServiceDescriptor(HelloService.class),
+               Map<RequiredServiceDescriptor, String> required = new HashMap<RequiredServiceDescriptor, String>();
+               required.put(new DefaultRequiredServiceDescriptor("hello", HelloService.class),
                                "helloService");
                SpringSystem system = new SpringSystem("system", _registry,
                                new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
-                               new HashMap<String, ServiceDescriptor>(), required);
+                               new HashMap<String, ProvidedServiceDescriptor>(), required);
                
                HelloService helloObject = new HelloService("ladida"); 
-               Service helloService = _registry.register(new DefaultServiceDescriptor(HelloService.class), helloObject);
+               Service helloService = _registry.register(new DefaultProvidedServiceDescriptor("hello", HelloService.class), helloObject);
                system.start("Bla", new Service[] { helloService } );
                system.stop();
        }
        
        public void testWithRequirementAndProvidedService() {
-               Map<ServiceDescriptor, String> required = new HashMap<ServiceDescriptor, String>();
-               required.put(new DefaultServiceDescriptor(HelloService.class),
+               Map<RequiredServiceDescriptor, String> required = new HashMap<RequiredServiceDescriptor, String>();
+               required.put(new DefaultRequiredServiceDescriptor("hello", HelloService.class),
                                "helloService");
-               Map<String,ServiceDescriptor> provided = new HashMap<String, ServiceDescriptor>();
-               provided.put("blaService", new DefaultServiceDescriptor(
+               Map<String,ProvidedServiceDescriptor> provided = new HashMap<String, ProvidedServiceDescriptor>();
+               provided.put("blaService", new DefaultProvidedServiceDescriptor("bla",
                                BlaService.class));
 
                SpringSystem system = new SpringSystem("system", _registry,
@@ -95,7 +99,7 @@ public class SpringSystemTest extends TestCase {
                                provided, required);
                
                HelloService helloObject = new HelloService("ladida"); 
-               Service helloService = _registry.register(new DefaultServiceDescriptor(HelloService.class), helloObject);
+               Service helloService = _registry.register(new DefaultProvidedServiceDescriptor("hello", HelloService.class), helloObject);
                Service[] services = system.start("Bla", new Service[] { helloService } );
                assertEquals(1, services.length);