01: package com.sun.portal.samples.asc.tests;
02:
03: import java.util.Map;
04:
05: import junit.framework.TestCase;
06:
07: public class AJAXTestCase extends TestCase {
08:
09: static final String BASEDIR = "src/com/sun/portal/samples/asc/tests/responses/";
10:
11: private ClientSession session = null;
12:
13: protected void setUp() throws Exception {
14:
15: // get a session from Firefox
16: // TODO what headers for async request?
17: Device device = new Firefox1dot5();
18: session = new ClientSession(device);
19: getSession().getDesktop();
20:
21: }
22:
23: protected void tearDown() throws Exception {
24: getSession().logout();
25: }
26:
27: protected ClientSession getSession() throws Exception {
28: if (session == null) {
29: throw new Exception("Session has not been established.");
30: }
31:
32: return session;
33: }
34:
35: protected int asyncGet(Map dtParams) throws Exception {
36: // TODO are there any other request parameters from dojo?
37: dtParams.put("dojo.transport", "xmlhttp");
38:
39: return httpGet(dtParams);
40: }
41:
42: protected int asyncPost(Map dtParams) throws Exception {
43: // TODO are there any other request parameters from dojo?
44: dtParams.put("dojo.transport", "xmlhttp");
45:
46: return httpPost(dtParams);
47: }
48:
49: protected int httpGet(Map dtParams) throws Exception {
50: getSession().doGet(Configuration.dtUrl, dtParams);
51: System.out.println("client get="
52: + getSession().getConnection().toString());
53: return getSession().getConnection().getResponseCode();
54: }
55:
56: protected int httpPost(Map dtParams) throws Exception {
57: getSession().doPost(Configuration.dtUrl, dtParams);
58: System.out.println("client post="
59: + getSession().getConnection().toString());
60: System.out.println("client post data=" + dtParams);
61: return getSession().getConnection().getResponseCode();
62: }
63:
64: protected int getDesktop() throws Exception {
65: getSession().getDesktop();
66: System.out.println("client post="
67: + getSession().getConnection().toString());
68: return getSession().getConnection().getResponseCode();
69: }
70:
71: protected void compareExpected(String expected) throws Exception {
72: // check the result against reference files
73: String result = TestUtils.getString(getSession()
74: .getConnection().getInputStream());
75: Compare comp = new Compare(this );
76: comp.expected(result, BASEDIR + expected);
77: }
78:
79: protected void compareUnexpected(String unexpected)
80: throws Exception {
81: // check the result against reference files
82: String result = TestUtils.getString(getSession()
83: .getConnection().getInputStream());
84: Compare comp = new Compare(this);
85: comp.unexpected(result, BASEDIR + unexpected);
86: }
87:
88: }
|