Package org.jboss.seam.contexts

Examples of org.jboss.seam.contexts.ApplicationContext


      ExternalContext externalContext = new MockExternalContext();
      MockFacesContext facesContext = new MockFacesContext( externalContext, new MockApplication() );
      facesContext.setCurrent().createViewRoot();
      facesContext.getApplication().setStateManager( new SeamStateManager( facesContext.getApplication().getStateManager() ) );
     
      Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
      installComponents(appContext);
      return facesContext;
   }
View Full Code Here


   public void testBijectionInterceptor() throws Exception
   {
      MockServletContext servletContext = new MockServletContext();
      ServletLifecycle.beginApplication(servletContext);
      MockExternalContext externalContext = new MockExternalContext(servletContext);
      Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
      appContext.set( Seam.getComponentName(Init.class), new Init() );
      appContext.set(
            Seam.getComponentName(ConversationEntries.class) + ".component",
            new Component(ConversationEntries.class, appContext)
         );
      appContext.set(
            Seam.getComponentName(Manager.class) + ".component",
            new Component(Manager.class, appContext)
         );
      appContext.set(
            Seam.getComponentName(Foo.class) + ".component",
            new Component(Foo.class, appContext)
         );
      appContext.set(
            Seam.getComponentName(Factory.class) + ".component",
            new Component(Factory.class, appContext)
         );

      FacesLifecycle.beginRequest(externalContext);
View Full Code Here

   public void testReentrantBijection() throws Exception
   {
      MockServletContext servletContext = new MockServletContext();
      ServletLifecycle.beginApplication(servletContext);
      final MockExternalContext externalContext = new MockExternalContext(servletContext);
      Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
      appContext.set( Seam.getComponentName(Init.class), new Init() );
      appContext.set( Seam.getComponentName(ConversationEntries.class) + ".component",
            new Component(ConversationEntries.class, appContext) );
      appContext.set( Seam.getComponentName(Manager.class) + ".component",
            new Component(Manager.class, appContext) );
      appContext.set( Seam.getComponentName(Foo.class) + ".component",
            new Component(Foo.class, appContext) );
      appContext.set( Seam.getComponentName(FooBar.class) + ".component",
            new Component(FooBar.class, appContext) );          
     
      final Foo foo = new Foo();
      final FooBar fooBar = new FooBar();
     
View Full Code Here

   public void testCyclicDependencyThowsException() throws Exception
   {
      MockServletContext servletContext = new MockServletContext();
      ServletLifecycle.beginApplication(servletContext);
      MockExternalContext externalContext = new MockExternalContext(servletContext);
      Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
      appContext.set( Seam.getComponentName(Init.class), new Init() );
      appContext.set(
            Seam.getComponentName(ConversationEntries.class) + ".component",
            new Component(ConversationEntries.class, appContext)
         );
      appContext.set(
            Seam.getComponentName(Manager.class) + ".component",
            new Component(Manager.class, appContext)
         );
      appContext.set(
            Seam.getComponentName(CyclicFoo.class) + ".component",
            new Component(CyclicFoo.class, appContext)
         );
      appContext.set(
            Seam.getComponentName(CyclicBar.class) + ".component",
            new Component(CyclicBar.class, appContext)
      );

      FacesLifecycle.beginRequest(externalContext);
      Manager.instance().setCurrentConversationId("1");
      FacesLifecycle.resumeConversation(externalContext);
      FacesLifecycle.setPhaseId(PhaseId.RENDER_RESPONSE);
     
      final CyclicFoo cyclicFoo = new CyclicFoo();
      final CyclicBar cyclicBar = new CyclicBar();
     
      final BijectionInterceptor cyclicFooBijectionInterceptor = new BijectionInterceptor();
      cyclicFooBijectionInterceptor.setComponent( new Component(CyclicFoo.class, appContext) );
      final Method cyclicFooGetName = CyclicFoo.class.getMethod("getName");
      final MockInvocationContext callGetName = new MockInvocationContext() {
         @Override
         public Object getTarget()
         {
            return cyclicFoo;
         }

         @Override
         public Object proceed() throws Exception
         {
            return cyclicFoo.getName();
         }
        
         @Override
         public Method getMethod()
         {
            return cyclicFooGetName;
         }
      };
     
      final Method cyclicFooGetFooBar = CyclicFoo.class.getMethod("getFooBar");
      final MockInvocationContext callGetCyclicFooBar = new MockInvocationContext() {
         @Override
         public Object getTarget()
         {
            return cyclicFoo;
         }
        
         @Override
         public Object proceed() throws Exception
         {
            return cyclicFoo.getFooBar();
         }
        
         @Override
         public Method getMethod()
         {
            return cyclicFooGetFooBar;
         }
      };
     
      CyclicFoo cyclicFooProxy = new CyclicFoo()
      {
         @Override
         public String getName() throws Exception
         {
            return (String) cyclicFooBijectionInterceptor.aroundInvoke(callGetName);
         }
        
         @Override
         public String getFooBar() throws Exception
         {
            return (String) cyclicFooBijectionInterceptor.aroundInvoke(callGetCyclicFooBar);
         }
      };
     
     
      final BijectionInterceptor cyclicBarBijectionInterceptor = new BijectionInterceptor();
      cyclicBarBijectionInterceptor.setComponent( new Component(CyclicBar.class, appContext) );
      final Method cyclicBarProvideCyclicFooBar = CyclicBar.class.getMethod("provideCyclicFooBar");
      final MockInvocationContext callProvideCyclicFooBar = new MockInvocationContext() {
         @Override
         public Object getTarget()
         {
            return cyclicBar;
         }

         @Override
         public Object proceed() throws Exception
         {
            return cyclicBar.provideCyclicFooBar();
         }
        
         @Override
         public Method getMethod()
         {
            return cyclicBarProvideCyclicFooBar;
         }
      };
     
      final CyclicBar cyclicBarProxy = new CyclicBarProxy(callProvideCyclicFooBar, cyclicBarBijectionInterceptor);
     
     
      appContext.set("cyclicFoo", cyclicFooProxy);
      appContext.set("cyclicBar", cyclicBarProxy);
     
      try
      {
         cyclicFooProxy.getFooBar();
         assert false : "cyclic dependency not detected";
View Full Code Here

   public void testConversationInterceptor() throws Exception
   {
      MockServletContext servletContext = new MockServletContext();
      ServletLifecycle.beginApplication(servletContext);
      MockExternalContext externalContext = new MockExternalContext(servletContext);
      Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
      appContext.set( Seam.getComponentName(Init.class), new Init() );
      appContext.set(
            Seam.getComponentName(ConversationEntries.class) + ".component",
            new Component(ConversationEntries.class, appContext)
         );
      appContext.set(
            Seam.getComponentName(PersistenceContexts.class) + ".component",
            new Component(PersistenceContexts.class, appContext)
         );
      appContext.set(
            Seam.getComponentName(Manager.class) + ".component",
            new Component(Manager.class, appContext)
         );
      FacesLifecycle.beginRequest( externalContext );
      Manager.instance().setCurrentConversationId("1");
View Full Code Here

   public void testConversationalInterceptor() throws Exception
   {
      MockServletContext servletContext = new MockServletContext();
      ServletLifecycle.beginApplication(servletContext);
      MockExternalContext externalContext = new MockExternalContext(servletContext);
      Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
      appContext.set( Seam.getComponentName(Init.class), new Init() );
      appContext.set(
            Seam.getComponentName(ConversationEntries.class) + ".component",
            new Component(ConversationEntries.class, appContext)
         );
      appContext.set(
            Seam.getComponentName(Manager.class) + ".component",
            new Component(Manager.class, appContext)
         );
      appContext.set(
            Seam.getComponentName(FacesMessages.class) + ".component",
            new Component(FacesMessages.class, appContext)
         );
      appContext.set(
               Seam.getComponentName(Events.class) + ".component",
               new Component(Events.class, appContext)
            );
      FacesLifecycle.setPhaseId(PhaseId.INVOKE_APPLICATION);
      FacesLifecycle.beginRequest( externalContext );
View Full Code Here

      MockServletContext servletContext = new MockServletContext();
      ServletLifecycle.beginApplication(servletContext);
      ExternalContext externalContext = new MockExternalContext(servletContext);
      new MockFacesContext( externalContext, new MockApplication() ).setCurrent().createViewRoot();
     
      Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
      appContext.set( Seam.getComponentName(Init.class), new Init() );
      appContext.set(
            Seam.getComponentName(ConversationEntries.class) + ".component",
            new Component(ConversationEntries.class, appContext)
         );
      appContext.set(
            Seam.getComponentName(Manager.class) + ".component",
            new Component(Manager.class, appContext)
         );
      appContext.set(
            Seam.getComponentName(FacesMessages.class) + ".component",
            new Component(FacesMessages.class, appContext)
         );
      appContext.set(
            Seam.getComponentName(Interpolator.class) + ".component",
            new Component(Interpolator.class, appContext)
         );
      FacesLifecycle.setPhaseId(PhaseId.INVOKE_APPLICATION);
      FacesLifecycle.beginRequest(externalContext);
View Full Code Here

   public void testRemoveInterceptor() throws Exception
   {
      MockServletContext servletContext = new MockServletContext();
      ServletLifecycle.beginApplication(servletContext);
      MockExternalContext externalContext = new MockExternalContext(servletContext);
      Context appContext = new ApplicationContext( externalContext.getApplicationMap() );
      appContext.set( Seam.getComponentName(Init.class), new Init() );
      appContext.set(
            Seam.getComponentName(ConversationEntries.class) + ".component",
            new Component(ConversationEntries.class, appContext)
         );
      appContext.set(
            Seam.getComponentName(Manager.class) + ".component",
            new Component(Manager.class, appContext)
         );

      FacesLifecycle.beginRequest( externalContext );
View Full Code Here

        MockServletContext servletContext = new MockServletContext();
        ServletLifecycle.beginApplication(servletContext);
        MockExternalContext externalContext = new MockExternalContext(
                servletContext);
        Context appContext = new ApplicationContext(externalContext
                .getApplicationMap());
        // appContext.set( Seam.getComponentName(Init.class), new Init() );
        installComponent(appContext, ConversationEntries.class);
        installComponent(appContext, Manager.class);
        installComponent(appContext, Session.class);
        installComponent(appContext, ServletContexts.class);
        installComponent(appContext, Parameters.class);
        appContext.set(Seam.getComponentName(Init.class), new Init());

        installComponent(appContext, Bar.class);
        installComponent(appContext, Foo.class);
        appContext.set("otherFoo", new Foo());

        assert !Contexts.isEventContextActive();
        assert !Contexts.isSessionContextActive();
        assert !Contexts.isConversationContextActive();
        assert !Contexts.isApplicationContextActive();
View Full Code Here

        MockHttpServletRequest request = new MockHttpServletRequest(session);
        final ExternalContext externalContext = new MockExternalContext(
                servletContext, request);
        final Map sessionAdaptor = new ServletRequestSessionMap(request);
        Map requestAdaptor = new ServletRequestMap(request);
        Context appContext = new ApplicationContext(externalContext
                .getApplicationMap());
        installComponent(appContext, ConversationEntries.class);
        installComponent(appContext, Manager.class);
        appContext.set(Seam.getComponentName(Init.class), new Init());
        FacesLifecycle.beginRequest(externalContext);
        Manager.instance().setLongRunningConversation(true);
        testContext(new ApplicationContext(externalContext.getApplicationMap()));
        testContext(new SessionContext(sessionAdaptor));
        testContext(new EventContext(requestAdaptor));
        testContext(new ServerConversationContext(sessionAdaptor, "1"));
        testEquivalence(new ContextCreator() {
            public Context createContext() {
                return new ServerConversationContext(sessionAdaptor, "1");
            }
        });
        testEquivalence(new ContextCreator() {
            public Context createContext() {
                return new SessionContext(sessionAdaptor);
            }
        });
        testEquivalence(new ContextCreator() {
            public Context createContext() {
                return new ApplicationContext(externalContext.getApplicationMap());
            }
        });
        testIsolation(new ServerConversationContext(sessionAdaptor, "1"),
                new ServerConversationContext(sessionAdaptor, "2"));
        // testIsolation( new WebSessionContext(externalContext), new
View Full Code Here

TOP

Related Classes of org.jboss.seam.contexts.ApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.