KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > servletunit > struts > tests > TestTilesForward


1 // StrutsTestCase - a JUnit extension for testing Struts actions
2
// within the context of the ActionServlet.
3
// Copyright (C) 2002 Deryl Seale
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the Apache Software License as
7
// published by the Apache Software Foundation; either version 1.1
8
// of the License, or (at your option) any later version.
9
//
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// Apache Software Foundation Licens for more details.
14
//
15
// You may view the full text here: http://www.apache.org/LICENSE.txt
16

17 package servletunit.struts.tests;
18
19 import servletunit.struts.MockStrutsTestCase;
20 import junit.framework.AssertionFailedError;
21
22 public class TestTilesForward extends MockStrutsTestCase {
23
24     public TestTilesForward(String JavaDoc testName) {
25         super(testName);
26     }
27
28     public void setUp() throws Exception JavaDoc {
29         super.setUp();
30         setConfigFile("tiles","/WEB-INF/struts-config-tiles.xml");
31         setServletConfigFile("/WEB-INF/web.xml");
32         setConfigFile("/WEB-INF/struts-config.xml");
33     }
34
35
36     public void testTilesForward() {
37         addRequestParameter("username","deryl");
38         addRequestParameter("password","radar");
39         setRequestPathInfo("tiles","/tilesForward.do");
40         actionPerform();
41         verifyForward("success");
42         verifyForwardPath("/layouts/pageLayout.jsp");
43         verifyTilesForward("success","page.library");
44     }
45
46     public void testTilesInputForward() {
47         setRequestPathInfo("tiles","/tilesInputForward.do");
48         actionPerform();
49         verifyInputForward();
50         verifyInputTilesForward("page.library");
51     }
52
53     public void testTileForwardFail() {
54         addRequestParameter("username","deryl");
55         addRequestParameter("password","radar");
56         setRequestPathInfo("tiles","/tilesForward.do");
57         actionPerform();
58         verifyForward("success");
59         verifyForwardPath("/layouts/pageLayout.jsp");
60         try {
61         verifyTilesForward("success","foo.fail");
62         } catch (AssertionFailedError afe) {
63             return;
64         }
65         fail("Should have failed.");
66     }
67
68 // todo: this test is failing because tiles verify doesn't work properly
69
// public void testTileForwardFailDefinitionExists() {
70
// addRequestParameter("username","deryl");
71
// addRequestParameter("password","radar");
72
// setRequestPathInfo("tiles","/tilesForward.do");
73
// actionPerform();
74
// verifyForward("success");
75
// verifyForwardPath("/layouts/pageLayout.jsp");
76
// try {
77
// verifyTilesForward("failure","another.page");
78
// } catch (AssertionFailedError afe) {
79
// return;
80
// }
81
// fail("Should have failed.");
82
// }
83

84
85 }
86
Popular Tags