Package org.springframework.mock.web.portlet

Examples of org.springframework.mock.web.portlet.MockRenderRequest


      }
      public void validate(Object o, Errors e) {}
    };
    TestController tc = new TestController();
    tc.setValidator(v);
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    try {
      tc.handleRenderRequest(request, response);
      fail("Should have thrown IllegalArgumentException");
    }
View Full Code Here


      }
      public void validate(Object o, Errors e) {
        e.reject(errorCode, defaultMessage);
      }
    });
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    ModelAndView mav = tc.handleRenderRequest(request, response);
    BindException errors = (BindException)mav.getModel().get(ERRORS_KEY);
    assertEquals("There should be 1 error", 1, errors.getErrorCount());
    ObjectError error = errors.getGlobalError();
View Full Code Here

      }
      public void validate(Object o, Errors e) {
        ValidationUtils.rejectIfEmpty(e, "name", errorCode, defaultMessage);
      }
    });
    MockRenderRequest request = new MockRenderRequest();
    int age = 32;
    request.setParameter("age", "" + age);
    MockRenderResponse response = new MockRenderResponse();
    ModelAndView mav = tc.handleRenderRequest(request, response);
    TestBean command = (TestBean)mav.getModel().get(tc.getCommandName());
    assertNull("name should be null", command.getName());
    assertEquals(age, command.getAge());
View Full Code Here

      }
      public void validate(Object o, Errors e) {
        ValidationUtils.rejectIfEmptyOrWhitespace(e, "name", errorCode, defaultMessage);
      }
    });
    MockRenderRequest request = new MockRenderRequest();
    int age = 32;
    String whitespace = "  \t  ";
    request.setParameter("age", "" + age);
    request.setParameter("name", whitespace);
    MockRenderResponse response = new MockRenderResponse();
    ModelAndView mav = tc.handleRenderRequest(request, response);
    TestBean command = (TestBean)mav.getModel().get(tc.getCommandName());
    assertTrue(command.getName().equals(whitespace));
    assertEquals(age, command.getAge());
View Full Code Here

    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-default-1", view.getBeanName());
  }

  public void testCorrectLocaleInLocaleContextHolder() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    request.setParameter("myParam", "contextLocaleChecker");
    request.addPreferredLocale(Locale.CANADA);
    complexDispatcherPortlet.doDispatch(request, response);
    assertEquals("locale-ok", response.getContentAsString());
  }
View Full Code Here

    complexDispatcherPortlet.doDispatch(request, response);
    assertEquals("locale-ok", response.getContentAsString());
  }

  public void testIncorrectLocaleInLocalContextHolder() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    request.setParameter("myParam", "contextLocaleChecker");
    request.addPreferredLocale(Locale.ENGLISH);
    complexDispatcherPortlet.doDispatch(request, response);
    Map model = (Map) request.getAttribute(ViewRendererServlet.MODEL_ATTRIBUTE);
    Exception exception = (Exception) model.get("exception");
    assertTrue(exception.getClass().equals(PortletException.class));
    assertEquals("Incorrect Locale in LocaleContextHolder", exception.getMessage());
    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-default-1", view.getBeanName());
  }
View Full Code Here

    InternalResourceView view = (InternalResourceView) request.getAttribute(ViewRendererServlet.VIEW_ATTRIBUTE);
    assertEquals("failed-default-1", view.getBeanName());
  }

  public void testHandlerInterceptorNoAbort() throws Exception {
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    request.setPortletMode(PortletMode.VIEW);
    request.addUserRole("role1");
    request.addParameter("abort", "false");
    complexDispatcherPortlet.doDispatch(request, response);
    assertTrue(request.getAttribute("test1-remove-never") != null);
    assertTrue(request.getAttribute("test1-remove-post") == null);
    assertTrue(request.getAttribute("test1-remove-after") == null);
    assertTrue(request.getAttribute("test2-remove-never") != null);
    assertTrue(request.getAttribute("test2-remove-post") == null);
    assertTrue(request.getAttribute("test2-remove-after") == null);
  }
View Full Code Here

  public void testAuthorizedUser() throws Exception {
    UserRoleAuthorizationInterceptor interceptor = new UserRoleAuthorizationInterceptor();
    String validRole = "allowed";
    interceptor.setAuthorizedRoles(new String[] {validRole});
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    Object handler = new Object();
    request.addUserRole(validRole);
    assertTrue(request.isUserInRole(validRole));
    boolean shouldProceed = interceptor.preHandle(request, response, handler);
    assertTrue(shouldProceed);
  }
View Full Code Here

  public void testAuthorizedUserWithMultipleRoles() throws Exception {
    UserRoleAuthorizationInterceptor interceptor = new UserRoleAuthorizationInterceptor();
    String validRole1 = "allowed1";
    String validRole2 = "allowed2";
    interceptor.setAuthorizedRoles(new String[] {validRole1, validRole2});
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    Object handler = new Object();
    request.addUserRole(validRole2);
    request.addUserRole("someOtherRole");
    assertFalse(request.isUserInRole(validRole1));
    assertTrue(request.isUserInRole(validRole2));
    boolean shouldProceed = interceptor.preHandle(request, response, handler);
    assertTrue(shouldProceed);
  }
View Full Code Here

  public void testUnauthorizedUser() throws Exception {
    UserRoleAuthorizationInterceptor interceptor = new UserRoleAuthorizationInterceptor();
    String validRole = "allowed";
    interceptor.setAuthorizedRoles(new String[] {validRole});
    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    Object handler = new Object();
    request.addUserRole("someOtherRole");
    assertFalse(request.isUserInRole(validRole));
    try {
      interceptor.preHandle(request, response, handler);
      fail("should have thrown PortletSecurityException");
    }
    catch (PortletSecurityException ex) {
View Full Code Here

TOP

Related Classes of org.springframework.mock.web.portlet.MockRenderRequest

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.