01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: TestEngineDwr.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.engine;
09:
10: import com.meterware.httpunit.GetMethodWebRequest;
11: import com.meterware.httpunit.WebConversation;
12: import com.meterware.httpunit.WebRequest;
13: import com.meterware.httpunit.WebResponse;
14: import com.uwyn.rife.TestCaseServerside;
15:
16: public class TestEngineDwr extends TestCaseServerside {
17: public TestEngineDwr(int siteType, String name) {
18: super (siteType, name);
19: }
20:
21: public void testDwrHello() throws Throwable {
22: setupSite("site/dwr.xml");
23:
24: WebConversation conversation = new WebConversation();
25: WebRequest request = new GetMethodWebRequest(
26: "http://localhost:8181/hello");
27: WebResponse response = null;
28:
29: response = conversation.getResponse(request);
30: assertTrue(response
31: .getText()
32: .indexOf(
33: "src=\"http://localhost:8181/dwr/hello/interface/Hello.js\"") != -1);
34: assertTrue(response.getText().indexOf(
35: "src=\"http://localhost:8181/dwr/hello/engine.js\"") != -1);
36: assertTrue(response.getText().indexOf(
37: "src=\"http://localhost:8181/dwr/hello/util.js\"") != -1);
38:
39: // assert that the correct remote function has been generated
40: request = new GetMethodWebRequest(
41: "http://localhost:8181/dwr/hello/interface/Hello.js");
42: response = conversation.getResponse(request);
43: String interface_text = response.getText();
44: assertTrue(interface_text
45: .indexOf("Hello.echo = function(p0, callback)") != -1);
46:
47: // assert that the remoting works properly
48: GetMethodWebRequest remoting_request = new GetMethodWebRequest(
49: "http://localhost:8181/dwr/hello/call/plaincall/Hello.echo.dwr");
50: remoting_request.setParameter("callCount", "1");
51: remoting_request.setParameter("page", "/hello");
52: remoting_request.setParameter("httpSessionId", "");
53: remoting_request.setParameter("scriptSessionId", "");
54: remoting_request.setParameter("c0-scriptName", "Hello");
55: remoting_request.setParameter("c0-methodName", "echo");
56: remoting_request.setParameter("c0-id", "0");
57: remoting_request.setParameter("c0-param0",
58: "string:honorable visitor");
59: remoting_request.setParameter("batchId", "1");
60: response = conversation.getResponse(remoting_request);
61: String remoting_text = response.getText();
62:
63: assertEquals(
64: remoting_text,
65: "//#DWR-INSERT\n"
66: + "//#DWR-REPLY\n"
67: + "dwr.engine._remoteHandleCallback('1','0',\"I got: honorable visitor\");\n");
68: }
69: }
|