Added a method to set properties on the spring component.
[utils] / system / spring / src / test / java / org / wamblee / system / spring / SpringComponentTest.java
similarity index 72%
rename from system/spring/src/test/java/org/wamblee/system/spring/SpringSystemTest.java
rename to system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java
index 1543b7ab8cd39067b6d9a9aa64450c9a733a8669..dc7a5845c659f68c47bbcd7db8f855bd3fa1c5b2 100644 (file)
@@ -1,10 +1,13 @@
 package org.wamblee.system.spring;
 
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Properties;
 
 import junit.framework.TestCase;
 
+import org.wamblee.io.ClassPathResource;
 import org.wamblee.system.AbstractInterfaceDescriptor;
 import org.wamblee.system.DefaultProvidedInterfaceDescriptor;
 import org.wamblee.system.DefaultRequiredInterfaceDescriptor;
@@ -16,10 +19,12 @@ import org.wamblee.system.InterfaceDescriptor;
 import org.wamblee.system.ServiceRegistry;
 import org.wamblee.system.SystemAssemblyException;
 
-public class SpringSystemTest extends TestCase {
+public class SpringComponentTest extends TestCase {
 
        private static final String HELLO_SERVICE_SPRING_XML = "test.org.wamblee.system.spring.xml";
        private static final String HELLO_SERVICE_SPRING_WITH_REQS_XML = "test.org.wamblee.system.springWithRequirements.xml";
+       private static final String HELLO_SERVICE_SPRING_WITH_PROPERTIES_XML = "test.org.wamblee.system.springWithProperties.xml";
+    private static final String PROPERTY_FILE = "test.org.wamblee.system.spring.properties";
 
        private ServiceRegistry _registry;
 
@@ -30,7 +35,7 @@ public class SpringSystemTest extends TestCase {
        }
 
        public void testBlackboxSystem() {
-               SpringSystem system = new SpringSystem("system", _registry,
+               SpringComponent system = new SpringComponent("system", _registry,
                                new String[] { HELLO_SERVICE_SPRING_XML },
                                new HashMap<String, ProvidedInterfaceDescriptor>(),
                                new HashMap<RequiredInterfaceDescriptor, String>());
@@ -46,7 +51,7 @@ public class SpringSystemTest extends TestCase {
                provided.put("helloService", new DefaultProvidedInterfaceDescriptor(
                                "hello", HelloService.class));
 
-               SpringSystem system = new SpringSystem("system", _registry,
+               SpringComponent system = new SpringComponent("system", _registry,
                                new String[] { HELLO_SERVICE_SPRING_XML }, provided,
                                new HashMap<RequiredInterfaceDescriptor, String>());
                system.start("Hello", new Service[0]);
@@ -57,10 +62,27 @@ public class SpringSystemTest extends TestCase {
                                .say());
                system.stop();
        }
+       
+       public void testWithProperties() throws IOException {
+               Map<String, ProvidedInterfaceDescriptor> provided = new HashMap<String, ProvidedInterfaceDescriptor>();
+               provided.put("helloService", new DefaultProvidedInterfaceDescriptor(
+                               "hello", HelloService.class));
+               SpringComponent system = new SpringComponent("system", _registry,
+                               new String[] { HELLO_SERVICE_SPRING_WITH_PROPERTIES_XML },
+                               provided,
+                               new HashMap<RequiredInterfaceDescriptor, String>());
+               Properties props = new Properties();
+               props.load(new ClassPathResource(PROPERTY_FILE).getInputStream());
+               system.addProperties(props);
+               
+               system.start("Hello", new Service[0]);
+               Service[] services = system.getRunningServices();
+               assertEquals("Property Value", services[0].reference(HelloService.class).say());
+       }
 
-       public void testWithMissingRequiremnt() {
+       public void testWithMissingRequirement() {
                try {
-                       SpringSystem system = new SpringSystem("system", _registry,
+                       SpringComponent system = new SpringComponent("system", _registry,
                                        new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
                                        new HashMap<String, ProvidedInterfaceDescriptor>(),
                                        new HashMap<RequiredInterfaceDescriptor, String>());
@@ -76,7 +98,7 @@ public class SpringSystemTest extends TestCase {
                Map<RequiredInterfaceDescriptor, String> required = new HashMap<RequiredInterfaceDescriptor, String>();
                required.put(new DefaultRequiredInterfaceDescriptor("hello", HelloService.class),
                                "helloService");
-               SpringSystem system = new SpringSystem("system", _registry,
+               SpringComponent system = new SpringComponent("system", _registry,
                                new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
                                new HashMap<String, ProvidedInterfaceDescriptor>(), required);
                
@@ -94,7 +116,7 @@ public class SpringSystemTest extends TestCase {
                provided.put("blaService", new DefaultProvidedInterfaceDescriptor("bla",
                                BlaService.class));
 
-               SpringSystem system = new SpringSystem("system", _registry,
+               SpringComponent system = new SpringComponent("system", _registry,
                                new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
                                provided, required);