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.HtmlHiddenInput;
23  import com.gargoylesoftware.htmlunit.html.HtmlPage;
24  import com.gargoylesoftware.htmlunit.html.HtmlSpan;
25  import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
26  import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
27  import java.util.ArrayList;
28  import java.util.List;
29  import java.util.Locale;
30  
31  import junit.framework.Test;
32  import junit.framework.TestSuite;
33  import org.apache.shale.test.cargo.CargoTestSetup;
34  
35  /***
36   * <p>Test case for the exception handling use case.</p>
37   */
38  public class ExceptionTestCase extends AbstractTestCase {
39  
40  
41      // ------------------------------------------------------------ Constructors
42  
43  
44      // Construct a new instance of this test case.
45      public ExceptionTestCase(String name) {
46          super(name);
47      }
48  
49  
50      // ---------------------------------------------------- Overall Test Methods
51  
52  
53      // Set up instance variables required by this test case.
54      protected void setUp() throws Exception {
55  
56          super.setUp();
57          page("/exception/test.faces");
58  
59      }
60  
61      // Return the tests included in this test case.
62      public static Test suite() {
63  
64          return new CargoTestSetup(new TestSuite(ExceptionTestCase.class));
65  
66      }
67  
68  
69      // Tear down instance variables required by this test case.
70      protected void tearDown() throws Exception {
71  
72          super.tearDown();
73  
74      }
75  
76  
77      // ------------------------------------------------------------ Test Methods
78  
79  
80      /***
81       * <p>Test the "normal" flow of submitting a correctly entered form.</p>
82       */
83      public void testNormal() throws Exception {
84  
85          HtmlElement element = null;
86  
87          // setUp() should have put us on the page
88          assertEquals("Exception Handling Test", title());
89  
90          // Submit the form
91          HtmlSubmitInput submit = (HtmlSubmitInput) element("form:submit");
92          submit(submit);
93  
94          // Validate that we have transferred to the exception handling page
95          assertEquals("Exception Handling - Correct Result", title());
96  
97          // Validate the contents of selected fields
98          element = element("form:status_code");
99          assertNotNull(element);
100         assertEquals("200", element.asText());
101         element = element("form:exception_type");
102         assertNotNull(element);
103         assertEquals("org.apache.shale.view.ApplicationException", element.asText());
104 
105     }
106 
107 
108     /***
109      * <p>Validate pristine instance of the "Token" test page.</p>
110      */
111     public void testPristine() throws Exception {
112 
113         HtmlForm form = null;
114         HtmlElement messages = null;
115         HtmlSubmitInput submit = null;
116 
117         // setUp() should have put us on the page
118         assertEquals("Exception Handling Test", title());
119         form = (HtmlForm) element("form");
120         assertNotNull(form);
121         messages = element("form:messages");
122         // MyFaces 1.1 and the JSF RI 1.1 are inconsistent about whether the
123         // "messages" element is actually created when there are no messages
124 //        assertNull(messages);
125         submit = (HtmlSubmitInput) element("form:submit");
126         assertNotNull(submit);
127 
128     }
129 
130 
131 }