01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: package org.apache.cocoon;
18:
19: /**
20: * Testcase to simulate the behavior of a user that opens a browser, starts
21: * the calculator example, and goes back in the processing several times.
22: *
23: * @version $Id: $
24: */
25: public class CalcTestCase extends HtmlUnitTestCase {
26: final String pageurl = "/samples/flow/jxcalc/";
27: final String submitXPath = "html/body//form/@action";
28: final String resultXPath = "html/body//form/p[contains(text(),'Result')]/strong";
29:
30: public void testCalc() throws Exception {
31: loadHtmlPage(pageurl);
32: final String cont1 = evalXPath(submitXPath);
33: assertNotNull("cont1", cont1);
34:
35: loadHtmlPage(pageurl + cont1 + "?a=1");
36: final String cont2 = evalXPath(submitXPath);
37: assertNotNull("cont2", cont2);
38:
39: loadHtmlPage(pageurl + cont2 + "?b=2");
40: final String cont3 = evalXPath(submitXPath);
41: assertNotNull("cont3", cont3);
42:
43: loadHtmlPage(pageurl + cont3 + "?operator=plus");
44: final String result1 = evalXPath(resultXPath);
45: assertEquals("result1", "3.0", result1);
46:
47: // Simulate going back in the browser
48:
49: loadHtmlPage(pageurl + cont2 + "?b=4");
50: final String cont4 = evalXPath(submitXPath);
51: assertNotNull("cont4", cont4);
52:
53: loadHtmlPage(pageurl + cont4 + "?operator=minus");
54: final String result2 = evalXPath(resultXPath);
55: assertEquals("result2", "-3.0", result2);
56:
57: // Simulate going back again in the browser
58:
59: loadHtmlPage(pageurl + cont4 + "?operator=divide");
60: final String result3 = evalXPath(resultXPath);
61: assertEquals("result3", "0.25", result3);
62: }
63: }
|