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  
18  package org.apache.shale.usecases.systest;
19  
20  import com.gargoylesoftware.htmlunit.html.HtmlElement;
21  import com.gargoylesoftware.htmlunit.html.HtmlForm;
22  import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
23  import java.util.ArrayList;
24  import java.util.List;
25  import java.util.Locale;
26  
27  import junit.framework.Test;
28  import junit.framework.TestSuite;
29  import org.apache.shale.test.cargo.CargoTestSetup;
30  
31  /***
32   * <p>Test case for view controller lifecycle callbacks testing.</p>
33   */
34  public class ViewControllerTestCase extends AbstractTestCase {
35  
36  
37      // ------------------------------------------------------------ Constructors
38  
39  
40      // Construct a new instance of this test case.
41      public ViewControllerTestCase(String name) {
42          super(name);
43      }
44  
45  
46      // ---------------------------------------------------- Overall Test Methods
47  
48  
49      // Set up instance variables required by this test case.
50      protected void setUp() throws Exception {
51  
52          super.setUp();
53          page("/view/test.faces");
54  
55      }
56  
57      // Return the tests included in this test case.
58      public static Test suite() {
59  
60          return new CargoTestSetup(new TestSuite(ViewControllerTestCase.class));
61  
62      }
63  
64  
65      // Tear down instance variables required by this test case.
66      protected void tearDown() throws Exception {
67  
68          super.tearDown();
69  
70      }
71  
72  
73      // ------------------------------------------------------------ Test Methods
74  
75  
76      /***
77       * <p>Validate pristine instance of the test page.</p>
78       */
79      public void testPristine() throws Exception {
80  
81          HtmlForm form = null;
82          HtmlElement text = null;
83          HtmlSubmitInput submit = null;
84  
85          // setUp() should have put us on the page
86          assertEquals("View Controller Test", title());
87          form = (HtmlForm) element("form");
88          assertNotNull(form);
89          text = element("form:text");
90          assertNotNull(text);
91          submit = (HtmlSubmitInput) element("form:submit");
92          assertNotNull(submit);
93  
94          // Check the expected contents of the "text" element on
95          // an initial request for this page.  Note that we cannot
96          // check for the destroy event, because it has not yet occurred
97          // when the value binding expression in our test page is evaluated
98          assertEquals("init/false/prerender/false/", text.asText());
99  
100     }
101 
102 
103     /***
104      * <p>Submit the page and validate the results.</p>
105      */
106     public void testSubmit() throws Exception {
107 
108         // setUp() should have put us on the page
109         assertEquals("View Controller Test", title());
110 
111         // Submit the form
112         HtmlSubmitInput submit = (HtmlSubmitInput) element("form:submit");
113         submit(submit);
114 
115         // Validate the redispayed content
116         assertEquals("View Controller Test", title());
117         HtmlElement text = element("form:text");
118         assertNotNull(text);
119         assertEquals("init/true/preprocess/true/submit/true/prerender/true/", text.asText());
120 
121     }
122 
123 
124 }