public void testGetComponentForArgDef() throws Exception {
   S2Container container = new S2ContainerImpl();
   ComponentDefImpl cd = new ComponentDefImpl(BigDecimal.class, "num");
   cd.addArgDef(new ArgDefImpl("123"));
   container.register(cd);
   assertEquals("1", new BigDecimal(123), container.getComponent("num"));
 }
 public void testGetComponentForExpression() throws Exception {
   S2Container container = new S2ContainerImpl();
   container.register(Object.class, "obj");
   ComponentDefImpl cd = new ComponentDefImpl(null, "hash");
   cd.setExpression("obj.hashCode()");
   container.register(cd);
   assertNotNull("1", container.getComponent("hash"));
 }
 public void testGetComponentForProperyDef() throws Exception {
   S2Container container = new S2ContainerImpl();
   ComponentDefImpl cd = new ComponentDefImpl(A2.class);
   cd.addPropertyDef(new PropertyDefImpl("hoge", new B()));
   container.register(cd);
   A2 a2 = (A2) container.getComponent(A2.class);
   assertEquals("1", "B", a2.getHogeName());
 }
 public void testInitForHotswap() throws Exception {
   S2Container container = new S2ContainerImpl();
   container.setHotswapMode(true);
   ComponentDefImpl cd = new ComponentDefImpl(FooImpl.class);
   container.register(cd);
   container.init();
   assertNotNull("1", cd.getHotswap());
 }
 public void testGetComponentForAspectDef() throws Exception {
   S2Container container = new S2ContainerImpl();
   ComponentDefImpl cd = new ComponentDefImpl(A.class);
   cd.addAspectDef(new AspectDefImpl(new TraceInterceptor()));
   container.register(cd);
   container.register(B.class);
   A a = (A) container.getComponent(A.class);
   assertEquals("1", "B", a.getHogeName());
 }
 public void testInjectDependency() throws Exception {
   ComponentDefImpl cd = new ComponentDefImpl(HashMap.class);
   InitMethodDef md = new InitMethodDefImpl("put");
   md.addArgDef(new ArgDefImpl("aaa"));
   md.addArgDef(new ArgDefImpl("hoge"));
   cd.addInitMethodDef(md);
   ComponentDeployer deployer = new OuterComponentDeployer(cd);
   HashMap myMap = new HashMap();
   deployer.injectDependency(myMap);
   assertEquals("1", "hoge", myMap.get("aaa"));
 }
 public void testGetComponentForMethodDef() throws Exception {
   S2Container container = new S2ContainerImpl();
   ComponentDefImpl cd = new ComponentDefImpl(HashMap.class, "myMap");
   InitMethodDef md = new InitMethodDefImpl("put");
   md.addArgDef(new ArgDefImpl("aaa"));
   md.addArgDef(new ArgDefImpl("hoge"));
   cd.addInitMethodDef(md);
   container.register(cd);
   HashMap myMap = (HashMap) container.getComponent("myMap");
   assertEquals("1", "hoge", myMap.get("aaa"));
 }
Пример #8
0
 /** @throws Exception */
 public void testBindWarning() throws Exception {
   BeanDesc beanDesc = BeanDescFactory.getBeanDesc(A.class);
   PropertyDesc propDesc = beanDesc.getPropertyDesc("hoge");
   S2Container container = new S2ContainerImpl();
   ComponentDefImpl cd = new ComponentDefImpl(A.class);
   PropertyDef propDef = new PropertyDefImpl("hoge");
   cd.addPropertyDef(propDef);
   container.register(cd);
   A a = new A();
   BindingTypeDefFactory.MAY.bind(cd, propDef, propDesc, a);
 }
 public void testGetComponentClassForHotswap() throws Exception {
   S2Container container = new S2ContainerImpl();
   container.setHotswapMode(true);
   ComponentDefImpl cd = new ComponentDefImpl(FooImpl.class);
   container.register(cd);
   container.init();
   Hotswap hotswap = cd.getHotswap();
   Thread.sleep(500);
   assertSame("1", FooImpl.class, cd.getComponentClass());
   hotswap.getFile().setLastModified(new Date().getTime());
   assertNotSame("2", FooImpl.class, cd.getComponentClass());
 }
 public void testGetComponentForHotswap() throws Exception {
   S2Container container = new S2ContainerImpl();
   container.setHotswapMode(true);
   ComponentDefImpl cd = new ComponentDefImpl(FooImpl.class);
   cd.setInstanceDef(InstanceDefFactory.PROTOTYPE);
   container.register(cd);
   container.init();
   Hotswap hotswap = cd.getHotswap();
   Thread.sleep(500);
   Foo foo = (Foo) container.getComponent(Foo.class);
   hotswap.getFile().setLastModified(new Date().getTime());
   Foo foo2 = (Foo) container.getComponent(Foo.class);
   assertNotSame("1", foo.getClass(), foo2.getClass());
   assertFalse("1", foo2 instanceof FooImpl);
 }
 public void testInjectDependency2() throws Exception {
   ComponentDefImpl cd = new ComponentDefImpl(ArrayMap.class);
   InitMethodDef md = new InitMethodDefImpl("put");
   md.addArgDef(new ArgDefImpl("aaa"));
   md.addArgDef(new ArgDefImpl("hoge"));
   cd.addInitMethodDef(md);
   ComponentDeployer deployer = new OuterComponentDeployer(cd);
   Map myMap = new CaseInsensitiveMap();
   deployer.injectDependency(myMap);
   assertEquals("1", "hoge", myMap.get("aaa"));
   try {
     Map myMap2 = new HashMap();
     deployer.injectDependency(myMap2);
     fail("1");
   } catch (ClassUnmatchRuntimeException ex) {
     System.out.println(ex);
   }
 }