2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   *
17   * $Id: IntegrationTestCase.java 472015 2006-11-07 07:35:41Z craigmcc $
18   */
19  
20  package org.apache.shale.examples.test.core.systest;
21  
22  import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
23  import com.gargoylesoftware.htmlunit.html.HtmlElement;
24  import com.gargoylesoftware.htmlunit.html.HtmlHiddenInput;
25  import com.gargoylesoftware.htmlunit.html.HtmlPage;
26  import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
27  import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
28  import junit.framework.Test;
29  import junit.framework.TestSuite;
30  import org.apache.shale.test.cargo.CargoTestSetup;
31  import org.apache.shale.test.htmlunit.AbstractHtmlUnitTestCase;
32  
33  /***
34   * <p>Integration tests for the Shale Core Library.</p>
35   */
36  public class IntegrationTestCase extends AbstractHtmlUnitTestCase {
37      
38  
39      // ------------------------------------------------------------ Constructors
40  
41  
42      /***
43       * <p>Construct a new instance of this test case.</p>
44       *
45       * @param name Name of the new test case
46       */
47      public IntegrationTestCase(String name) {
48  
49          super(name);
50  
51      }
52  
53  
54      // ------------------------------------------------------ Test Setup Methods
55  
56  
57      /***
58       * <p>Set up the instance variables required for this test case.</p>
59       */
60      protected void setUp() throws Exception {
61  
62          super.setUp();
63          page("/");
64  
65      }
66  
67  
68      /***
69       * <p>Return the set of tests included in this test suite.</p>
70       */
71      public static Test suite() {
72  
73          return new CargoTestSetup(new TestSuite(IntegrationTestCase.class));
74  
75      }
76  
77  
78      /***
79       * <p>Tear down instance variables required by this test case.</p>
80       */
81      protected void tearDown() throws Exception {
82  
83          super.tearDown();
84  
85      }
86  
87  
88  
89      // ------------------------------------------------- Individual Test Methods
90  
91  
92      // Test /menu.jsp
93      public void testMenu() throws Exception {
94  
95          assertEquals("Shale Test App (Core Library)", title());
96  
97      }
98  
99  
100     // Test /token1.jsp and /token2.jsp when invalid input
101     // on each page (submitted twice each to verify this capability)
102     // is ultimately followed by valid input on each page
103     public void testTokenInvalid() throws Exception {
104 
105         HtmlTextInput input;
106         HtmlSubmitInput submit;
107         page("/token1.faces");
108 
109         // /token1.jsp invalid input
110         assertEquals("Token Processor Test (Page 1)", title());
111         input = (HtmlTextInput) element("form:input");
112         assertNotNull(input);
113         // input.setValueAttribute("abc"); // NOTE - no value is set
114         submit = (HtmlSubmitInput) element("form:submit");
115         assertNotNull(submit);
116         submit(submit);
117 
118         // /token1.jsp invalid input (again)
119         assertEquals("Token Processor Test (Page 1)", title());
120         input = (HtmlTextInput) element("form:input");
121         assertNotNull(input);
122         // input.setValueAttribute("abc"); // NOTE - no value is set
123         submit = (HtmlSubmitInput) element("form:submit");
124         assertNotNull(submit);
125         submit(submit);
126 
127         // /token1.jsp valid input
128         assertEquals("Token Processor Test (Page 1)", title());
129         input = (HtmlTextInput) element("form:input");
130         assertNotNull(input);
131         input.setValueAttribute("abc"); // Now set a valid value
132         submit = (HtmlSubmitInput) element("form:submit");
133         assertNotNull(submit);
134         submit(submit);
135 
136         // /token2.jsp invalid input
137         assertEquals("Token Processor Test (Page 2)", title());
138         input = (HtmlTextInput) element("form:input");
139         assertNotNull(input);
140         input.setValueAttribute("abcdef"); // NOTE - invalid value is set
141         submit = (HtmlSubmitInput) element("form:submit");
142         assertNotNull(submit);
143         submit(submit);
144 
145         // /token2.jsp invalid input (again)
146         assertEquals("Token Processor Test (Page 2)", title());
147         input = (HtmlTextInput) element("form:input");
148         assertNotNull(input);
149         input.setValueAttribute("abcdef"); // NOTE - invalid value is set
150         submit = (HtmlSubmitInput) element("form:submit");
151         assertNotNull(submit);
152         submit(submit);
153 
154         // /token2.jsp valid input
155         assertEquals("Token Processor Test (Page 2)", title());
156         input = (HtmlTextInput) element("form:input");
157         assertNotNull(input);
158         input.setValueAttribute("abcd"); // NOTE - valid value is set
159         submit = (HtmlSubmitInput) element("form:submit");
160         assertNotNull(submit);
161         submit(submit);
162 
163         // Should have returned to the main menu
164         assertEquals("Shale Test App (Core Library)", title());
165 
166     }
167 
168 
169     // Test /token1.jsp and /token2.jsp when valid input is always entered
170     public void testTokenValid() throws Exception {
171 
172         HtmlTextInput input;
173         HtmlSubmitInput submit;
174         page("/token1.faces");
175 
176         // /token1.jsp valid input
177         assertEquals("Token Processor Test (Page 1)", title());
178         input = (HtmlTextInput) element("form:input");
179         assertNotNull(input);
180         input.setValueAttribute("abc");
181         submit = (HtmlSubmitInput) element("form:submit");
182         assertNotNull(submit);
183         submit(submit);
184 
185         // /token2.jsp valid input
186         assertEquals("Token Processor Test (Page 2)", title());
187         assertNotNull(input);
188         input.setValueAttribute("abc");
189         submit = (HtmlSubmitInput) element("form:submit");
190         assertNotNull(submit);
191         submit(submit);
192 
193         // Should have returned to the main menu
194         assertEquals("Shale Test App (Core Library)", title());
195 
196     }
197 
198 
199     // Test /token1.jsp simulating a resubmit of the same page
200     public void testTokenResubmit() throws Exception {
201 
202         HtmlHiddenInput hidden;
203         HtmlTextInput input;
204         HtmlSubmitInput submit;
205         page("/token1.faces");
206 
207         // /token1.jsp valid input
208         assertEquals("Token Processor Test (Page 1)", title());
209         input = (HtmlTextInput) element("form:input");
210         assertNotNull(input);
211         input.setValueAttribute("abc");
212         hidden = (HtmlHiddenInput) element("form:token");
213         assertNotNull(hidden);
214         submit = (HtmlSubmitInput) element("form:submit");
215         assertNotNull(submit);
216         HtmlPage page = page();
217         submit(submit);
218 
219         // Should have switched to /token2.jsp
220         assertEquals("Token Processor Test (Page 2)", title());
221 
222         // /token1.jsp valid input (resubmitted)
223         reset(page);
224         assertEquals("Token Processor Test (Page 1)", title());
225         hidden = (HtmlHiddenInput) element("form:token");
226         assertNotNull(hidden);
227         submit = (HtmlSubmitInput) element("form:submit");
228         assertNotNull(submit);
229         submit(submit);
230 
231         // Should still be on /token1.jsp
232         assertEquals("Token Processor Test (Page 1)", title());
233 
234     }
235 
236 
237 }