1 package org.wamblee.system.spring;
3 import java.util.HashMap;
6 import junit.framework.TestCase;
8 import org.wamblee.system.DefaultServiceDescriptor;
9 import org.wamblee.system.DefaultServiceRegistry;
10 import org.wamblee.system.Service;
11 import org.wamblee.system.ServiceDescriptor;
12 import org.wamblee.system.ServiceRegistry;
13 import org.wamblee.system.SystemAssemblyException;
15 public class SpringSystemTest extends TestCase {
17 private static final String HELLO_SERVICE_SPRING_XML = "test.org.wamblee.system.spring.xml";
18 private static final String HELLO_SERVICE_SPRING_WITH_REQS_XML = "test.org.wamblee.system.springWithRequirements.xml";
20 private ServiceRegistry _registry;
23 protected void setUp() throws Exception {
25 _registry = new DefaultServiceRegistry();
28 public void testBlackboxSystem() {
29 SpringSystem system = new SpringSystem("system", _registry,
30 new String[] { HELLO_SERVICE_SPRING_XML },
31 new HashMap<String, ServiceDescriptor>(),
32 new HashMap<ServiceDescriptor, String>());
33 system.start("Hello", new Service[0]);
34 Service[] services = system.getRunningServices();
35 assertEquals(0, services.length);
40 public void testOneProvidedService() {
41 Map<String, ServiceDescriptor> provided = new HashMap<String, ServiceDescriptor>();
42 provided.put("helloService", new DefaultServiceDescriptor(
45 SpringSystem system = new SpringSystem("system", _registry,
46 new String[] { HELLO_SERVICE_SPRING_XML }, provided,
47 new HashMap<ServiceDescriptor, String>());
48 system.start("Hello", new Service[0]);
49 Service[] services = system.getRunningServices();
50 assertEquals(1, services.length);
51 assertTrue(services[0].reference(HelloService.class) instanceof HelloService);
52 assertEquals("Hello world!", services[0].reference(HelloService.class)
57 public void testWithMissingRequiremnt() {
59 SpringSystem system = new SpringSystem("system", _registry,
60 new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
61 new HashMap<String, ServiceDescriptor>(),
62 new HashMap<ServiceDescriptor, String>());
63 system.start("Bla", new Service[0]);
64 } catch (SystemAssemblyException e) {
65 //e.printStackTrace();
71 public void testWithRequirement() {
72 Map<ServiceDescriptor, String> required = new HashMap<ServiceDescriptor, String>();
73 required.put(new DefaultServiceDescriptor(HelloService.class),
75 SpringSystem system = new SpringSystem("system", _registry,
76 new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
77 new HashMap<String, ServiceDescriptor>(), required);
79 HelloService helloObject = new HelloService("ladida");
80 Service helloService = _registry.register(new DefaultServiceDescriptor(HelloService.class), helloObject);
81 system.start("Bla", new Service[] { helloService } );
85 public void testWithRequirementAndProvidedService() {
86 Map<ServiceDescriptor, String> required = new HashMap<ServiceDescriptor, String>();
87 required.put(new DefaultServiceDescriptor(HelloService.class),
89 Map<String,ServiceDescriptor> provided = new HashMap<String, ServiceDescriptor>();
90 provided.put("blaService", new DefaultServiceDescriptor(
93 SpringSystem system = new SpringSystem("system", _registry,
94 new String[] { HELLO_SERVICE_SPRING_WITH_REQS_XML },
97 HelloService helloObject = new HelloService("ladida");
98 Service helloService = _registry.register(new DefaultServiceDescriptor(HelloService.class), helloObject);
99 Service[] services = system.start("Bla", new Service[] { helloService } );
100 assertEquals(1, services.length);
102 assertTrue(services[0].reference(BlaService.class) instanceof BlaService);
103 assertEquals("ladida", services[0].reference(BlaService.class)