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;
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;
}
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>());
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]);
.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>());
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);
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);