示例#1
0
  public void testTest1ResultController_test2Action() throws Throwable {
    WebApplicationContextTester.run(
        "/controller/test2",
        new WebApplicationTester() {

          public void prepareContext(Map<String, String> parameters) {
            parameters.put(
                ContextLoader.CONTEXT_CLASS, MockAnnotationWebApplicationContext.class.getName());

            parameters.put(MockAnnotationWebApplicationContext.IGNORE_RESOURCES, "true");
          }

          public void prepareSession(Map<String, String> parameters) {}

          public void prepareRequest(Map<String, String> parameters) {}

          public void checkResult(
              HttpServletRequest request,
              HttpServletResponse response,
              ServletContext context,
              ConfigurableWebApplicationContext applicationContext) {

            Assert.assertEquals(true, request.getAttribute("resultAction"));
            Assert.assertNull(request.getAttribute("result"));
          }

          public void checkException(Throwable e) throws Throwable {
            throw e;
          }
        },
        new Class[] {Test1ResultController.class});
  }
示例#2
0
  public void testTest1FailRestrictionController() throws Throwable {
    WebApplicationContextTester.run(
        "",
        new WebApplicationTester() {

          public void prepareContext(Map<String, String> parameters) {
            parameters.put(
                ContextLoader.CONTEXT_CLASS, MockAnnotationWebApplicationContext.class.getName());

            parameters.put(MockAnnotationWebApplicationContext.IGNORE_RESOURCES, "true");
          }

          public void prepareSession(Map<String, String> parameters) {}

          public void prepareRequest(Map<String, String> parameters) {}

          public void checkResult(
              HttpServletRequest request,
              HttpServletResponse response,
              ServletContext context,
              ConfigurableWebApplicationContext applicationContext) {

            Assert.fail("expected: the action not return any value: test1Action}");
          }

          public void checkException(Throwable e) throws Throwable {
            Assert.assertNotNull(e);
            Throwable ex = e;
            do {
              if (ex.getMessage().equals("the action not return any value: test1Action")) return;
            } while ((ex = ex.getCause()) != null);

            Assert.fail("expected: {the action not return any value: test1Action}");
          }
        },
        new Class[] {Test1FailResultController.class});
  }