KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > CalcTestCase


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon;
17
18 /**
19  * Testcase to simulate the behavior of a user that opens a browser, starts
20  * the calculator example, and goes back in the processing several times.
21  *
22  * @version $Id: $
23  */

24 public class CalcTestCase
25     extends HtmlUnitTestCase
26 {
27     final String JavaDoc pageurl = "/samples/flow/jxcalc/";
28     final String JavaDoc submitXPath = "html/body//form/@action";
29     final String JavaDoc resultXPath = "html/body//form/p[contains(text(),'Result')]/strong";
30
31     public void testCalc()
32         throws Exception JavaDoc
33     {
34         loadHtmlPage(pageurl);
35         final String JavaDoc cont1 = evalXPath(submitXPath);
36         assertNotNull("cont1", cont1);
37
38         loadHtmlPage(pageurl+cont1+"?a=1");
39         final String JavaDoc cont2 = evalXPath(submitXPath);
40         assertNotNull("cont2", cont2);
41
42         loadHtmlPage(pageurl+cont2+"?b=2");
43         final String JavaDoc cont3 = evalXPath(submitXPath);
44         assertNotNull("cont3", cont3);
45
46         loadHtmlPage(pageurl+cont3+"?operator=plus");
47         final String JavaDoc result1 = evalXPath(resultXPath);
48         assertEquals("result1", "3.0", result1);
49
50         // Simulate going back in the browser
51

52         loadHtmlPage(pageurl+cont2+"?b=4");
53         final String JavaDoc cont4 = evalXPath(submitXPath);
54         assertNotNull("cont4", cont4);
55
56         loadHtmlPage(pageurl+cont4+"?operator=minus");
57         final String JavaDoc result2 = evalXPath(resultXPath);
58         assertEquals("result2", "-3.0", result2);
59
60         // Simulate going back again in the browser
61

62         loadHtmlPage(pageurl+cont4+"?operator=divide");
63         final String JavaDoc result3 = evalXPath(resultXPath);
64         assertEquals("result3", "0.25", result3);
65     }
66 }
67
Popular Tags