Esempio n. 1
0
 public void execute(S2Container container) throws Exception {
   logger.debug("HttpServletTestInclude.execute()");
   setMockContext(container);
   container.setExternalContextComponentDefRegister(
       new HttpServletExternalContextComponentDefRegister());
   ComponentDeployerFactory.setProvider(new ExternalComponentDeployerProvider());
 }
  /** @throws Exception */
  public void testComponent() throws Exception {
    S2Container container = S2ContainerFactory.create(PATH);
    ComponentDeployerFactory.setProvider(new ExternalComponentDeployerProvider());
    MockServletContextImpl ctx = new MockServletContextImpl("s2jsf-example");
    HttpServletRequest request = ctx.createRequest("/hello.html");
    ExternalContext extCtx = new HttpServletExternalContext();
    extCtx.setRequest(request);
    extCtx.setApplication(ctx);
    container.setExternalContext(extCtx);

    container.init();
    assertNotNull(container.getComponent(List.class));
    assertNotNull(container.getComponent("aaa"));
    assertEquals(new Integer(1), container.getComponent("bbb"));
    assertEquals(true, container.getComponent("ccc") != container.getComponent("ccc"));
    ComponentDef cd = container.getComponentDef("ddd");
    assertEquals(AutoBindingDefFactory.NONE, cd.getAutoBindingDef());
    Map map = new HashMap();
    container.injectDependency(map, "eee");
    assertEquals("111", map.get("aaa"));
    assertNotNull(container.getComponent("fff"));
    assertNotNull(container.getComponent("ggg"));

    assertNotNull(container.getComponent("hhh"));
    assertNotNull(container.getComponent("iii"));
    assertEquals("jjj", container.getComponent("jjj"));
    request.setAttribute("name", "aaa");
    cd = container.getComponentDef("kkk");
    assertEquals(true, cd.isExternalBinding());
    Kkk kkk = (Kkk) cd.getComponent();
    assertEquals("aaa", kkk.getName());
  }
 protected void tearDown() throws Exception {
   S2ContainerFactory.configurationContainer_ = null;
   S2ContainerFactory.setProvider(new S2ContainerFactory.DefaultProvider());
   S2ContainerFactory.setDefaultBuilder(new XmlS2ContainerBuilder());
   S2ContainerBehavior.setProvider(new S2ContainerBehavior.DefaultProvider());
   ComponentDeployerFactory.setProvider(new ComponentDeployerFactory.DefaultProvider());
   AssemblerFactory.setProvider(new AssemblerFactory.DefaultProvider());
 }