Package javax.servlet

Examples of javax.servlet.ServletContext


  @Test
  public void test()
  {

    HttpServletRequest request = createStrictMock(HttpServletRequest.class);
    ServletContext context = createStrictMock(ServletContext.class);

    InjectionAnnotationReader c = new InjectionAnnotationReader();
    ActionWithWebHelper action = new ActionWithWebHelper();

    c.readAnnotations(action.getClass());
View Full Code Here


  @Test
  public void testSource()
  {
    Class actionBeanClass = TestAction.class;

    ServletContext servletContext = createStrictMock(ServletContext.class);
    WebApplicationContext wac = createStrictMock(WebApplicationContext.class);

    expect(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE))
        .andReturn(wac);
    expect(wac.isSingleton("beanName")).andReturn(false);
    expect(wac.getBean("beanName", TestAction.class)).andReturn(new TestAction());

    // second call - note that isSingleton is not called second time
    expect(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE))
        .andReturn(wac);
    expect(wac.getBean("beanName", TestAction.class)).andReturn(new TestAction());

    replay(servletContext);
    replay(wac);
View Full Code Here

  @Test
  public void testNoWac()
  {
    Class actionBeanClass = TestAction.class;

    ServletContext servletContext = createStrictMock(ServletContext.class);

    expect(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)).andReturn(
        null);

    replay(servletContext);

    SpringActionBeanSource source = new SpringActionBeanSource(actionBeanClass, "beanName");
View Full Code Here

  public void testNoBeanRegistered()
  {

    Class actionBeanClass = TestAction.class;

    ServletContext servletContext = createStrictMock(ServletContext.class);
    WebApplicationContext wac = createStrictMock(WebApplicationContext.class);

    expect(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE))
        .andReturn(wac);
    expect(wac.isSingleton("beanName")).andReturn(false);
    expect(wac.getBean("beanName", TestAction.class)).andThrow(
        new NoSuchBeanDefinitionException("beanName", "message"));
View Full Code Here

    ActionForm actionForm = newMock(ActionForm.class);
    ActionContext actionContext = newMock(ActionContext.class);
    ActionForward forwardConfig = newMock(ActionForward.class);
    HttpServletRequest request = newMock(HttpServletRequest.class);
    HttpServletResponse response = newMock(HttpServletResponse.class);
    ServletContext servletContext = newMock(ServletContext.class);
   
    expect(sac.getRequest()).andReturn(request);
    expect(sac.getResponse()).andReturn(response);
    expect(sac.getContext()).andReturn(servletContext);
    expect(factory.createActionContext(request, response, servletContext, actionForm, actionConfig)).andReturn(actionContext);
View Full Code Here

    ActionMapping mapping = createMock(ActionMapping.class);
    HttpServletRequest request = createMock(HttpServletRequest.class);
    HttpSession session = createMock(HttpSession.class);
    ModuleConfig moduleConfig = createMock(ModuleConfig.class);
    ActionServlet servlet = createMock(ActionServlet.class);
    ServletContext context = createMock(ServletContext.class);
    MessageResources messageResources = createMock(MessageResources.class);
    DelegatingForm form = createStrictMock(DelegatingForm.class);
   
    action.setServlet(servlet);

    actionBean.preBind();
    form.bindInwards(actionBean);
    expect(request.getAttribute(Globals.CANCEL_KEY)).andReturn(null);
    expect(mapping.getParameter()).andReturn("method");
    expect(request.getParameter("method")).andReturn("Insert Stuff Here");
    expect(request.getSession(false)).andReturn(session);
    expect(session.getAttribute(Globals.LOCALE_KEY)).andReturn(Locale.getDefault());
    expect(request.getAttribute(Globals.MODULE_KEY)).andReturn(moduleConfig);
    expect(moduleConfig.findMessageResourcesConfigs()).andReturn(new MessageResourcesConfig[]
    {
      new MessageResourcesConfig()
    });
    expect(servlet.getServletContext()).andReturn(context);
    expect(request.getAttribute(Globals.MODULE_KEY)).andReturn(moduleConfig);
    expect(moduleConfig.getPrefix()).andReturn("");
    expect(context.getAttribute(Globals.MESSAGES_KEY)).andReturn(messageResources);
    expect(messageResources.getMessage(Locale.getDefault(), "insert.key")).andReturn("Insert Stuff Here");
    expect(actionBean.insert()).andReturn("inserted");
    expect(mapping.findForward("inserted")).andReturn(actionForward);

    replay(actionBean);
View Full Code Here

    ActionMapping mapping = createMock(ActionMapping.class);
    HttpServletRequest request = createMock(HttpServletRequest.class);
    HttpSession session = createMock(HttpSession.class);
    ModuleConfig moduleConfig = createMock(ModuleConfig.class);
    ActionServlet servlet = createMock(ActionServlet.class);
    ServletContext context = createMock(ServletContext.class);
    MessageResources messageResources = createMock(MessageResources.class);

    action.setServlet(servlet);

    expect(request.getAttribute(Globals.CANCEL_KEY)).andReturn(null);
    expect(mapping.getParameter()).andReturn("method");
    expect(request.getParameter("method")).andReturn("Insert Stuff Here");
    expect(request.getSession(false)).andReturn(session);
    expect(session.getAttribute(Globals.LOCALE_KEY)).andReturn(Locale.getDefault());
    expect(request.getAttribute(Globals.MODULE_KEY)).andReturn(moduleConfig);
    expect(moduleConfig.findMessageResourcesConfigs()).andReturn(new MessageResourcesConfig[]
    {
      new MessageResourcesConfig()
    });
    expect(servlet.getServletContext()).andReturn(context);
    expect(request.getAttribute(Globals.MODULE_KEY)).andReturn(moduleConfig);
    expect(moduleConfig.getPrefix()).andReturn("");
    expect(context.getAttribute(Globals.MESSAGES_KEY)).andReturn(messageResources);

    expect(mapping.getPath()).andReturn("appPath");

    replay(actionBean);
    replay(mapping);
View Full Code Here

    ActionWithContext action = new ActionWithContext();

    c.readAnnotations(action.getClass());
    Map<String, InjectionWrapper> inputs = c.getInjectionMap();

    ServletContext context = createMock(ServletContext.class);

    replay(context);

    InjectionWrapper inputWrapper = inputs.get("context");
View Full Code Here

    c.readAnnotations(action.getClass());
    Map<String, InjectionWrapper> inputs = c.getInjectionMap();

    HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
    HttpSession session = EasyMock.createMock(HttpSession.class);
    ServletContext context = EasyMock.createMock(ServletContext.class);

    expect(request.getParameter("integerInput")).andReturn(null);
    expect(request.getAttribute("integer.Input")).andReturn(null);

    expect(request.getSession()).andReturn(session);
    expect(session.getAttribute("integer.Input")).andReturn(null);
    expect(context.getAttribute("integer.Input")).andReturn(new Integer(1));

    replay(request);
    replay(session);

    InjectionWrapper inputWrapper = inputs.get("integerInput");
View Full Code Here

    RequestSessionAction action = new RequestSessionAction();

    c.readAnnotations(action.getClass());
    Map<String, InjectionWrapper> inputs = c.getInjectionMap();

    ServletContext context = EasyMock.createMock(ServletContext.class);

    expect(context.getAttribute("contextAttribute")).andReturn(new Integer(1));

    replay(context);

    InjectionWrapper inputWrapper = inputs.get("contextAttribute");
View Full Code Here

TOP

Related Classes of javax.servlet.ServletContext

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.