001: package com.sun.portal.samples.asc.tests;
002:
003: import java.net.HttpURLConnection;
004: import java.util.HashMap;
005: import java.util.Map;
006:
007: /**
008: * U3: Client requests processing of channel's edit action
009: * URL: provider=AJAXEditContainer&action=process&targetProvider=channelName&containerName=AJAXTableContainer
010: * Request: XMLHttpRequest
011: * success/failure: JSON message
012: * @author gregz
013: *
014: */
015: public class TestUseCase3 extends AJAXTestCase {
016:
017: public void testU3Success() {
018: try {
019: int response;
020: String expected;
021:
022: // add a bookmark
023: response = processBookmarkAdd("Google",
024: "http%3A%2F%2Fgoogle.com");
025: // funky stuff to handle POST redirect
026: assertEquals(302, response);
027: expected = Configuration.editChannel + "-editRedirect.html";
028: compareExpected(expected);
029: // verify bookmark was added in updated edit content
030: getSession().followRedirect(
031: getSession().getConnection().getHeaderField(
032: "Location"));
033: assertEquals(200, getSession().getConnection()
034: .getResponseCode());
035: expected = Configuration.editChannel
036: + "-editBookmarkAdded.html";
037: compareExpected(expected);
038:
039: // remove it
040: response = processBookmarkDelete();
041: // funky stuff to handle POST redirect
042: assertEquals(302, response);
043: expected = Configuration.editChannel
044: + "-processRedirect.html";
045: compareExpected(expected);
046: // verify bookmark was deleted and success JSON msg sent back
047: getSession().followRedirect(
048: getSession().getConnection().getHeaderField(
049: "Location"));
050: assertEquals(200, getSession().getConnection()
051: .getResponseCode());
052: expected = "Success.js";
053: compareExpected(expected);
054:
055: } catch (Exception e) {
056: TestUtils.fail(this , e);
057: }
058: }
059:
060: public void testU3GeneralFailure() {
061: try {
062: int response = processChannelEdit("UnknownChannel");
063: assertEquals(200, response);
064: String expected = "DesktopError.js";
065: compareExpected(expected);
066: } catch (Exception e) {
067: TestUtils.fail(this , e);
068: }
069: }
070:
071: public void testU3FormFailure() {
072: try {
073: int response;
074: String expected;
075:
076: // try to add a bookmark with non-ascii characters
077: response = processBookmarkAdd(
078: "Bummer",
079: "ÉÃÂÃÂ�óÃÂúÚñ¡ú¿ÃÂ'Üüñ");
080: // funky stuff to handle POST redirect
081: assertEquals(302, response);
082: expected = Configuration.editChannel
083: + "-errorRedirect.html";
084: compareExpected(expected);
085: // verify bookmark was added in updated edit content
086: getSession().followRedirect(
087: getSession().getConnection().getHeaderField(
088: "Location"));
089: assertEquals(200, getSession().getConnection()
090: .getResponseCode());
091: expected = Configuration.editChannel
092: + "-editFormError.html";
093: compareExpected(expected);
094:
095: } catch (Exception e) {
096: TestUtils.fail(this , e);
097: }
098: }
099:
100: private int processBookmarkAdd(String resourceName,
101: String resourceURL) throws Exception {
102:
103: String provider = Configuration.editContainer;
104: String containerName = Configuration.defaultContainer;
105: String channel = Configuration.editChannel;
106:
107: Map p = new HashMap();
108: p.put("provider", provider);
109: p.put("action", "process");
110: p.put("targetprovider", channel);
111: p.put("containerName", containerName);
112: p.put("editArgs",
113: "%3Faction%3Dedit%26dojo.transport=xmlhttp%26provider%3D"
114: + provider + "%26targetprovider%3D" + channel
115: + "%26containerName%3D" + containerName);
116: p.put("resourceCount", "3");
117: p.put("add_more", "true");
118: p.put("resourceName", resourceName);
119: p.put("resourceURL", resourceURL);
120: p.put("Add+Resource", "Add+Resource");
121: p.put("name0", "Sun+home+page");
122: p.put("url0", "http%3A%2F%2Fwww.sun.com");
123: p.put("name1", "CNN+home+page");
124: p.put("url1", "http%3A%2F%2Fwww.cnn.com");
125: p.put("name2", "Yahoo+home+page");
126: p.put("url2", "http%3A%2F%2Fwww.yahoo.com");
127: p.put("windowPref", "all_new");
128:
129: return asyncPost(p);
130:
131: }
132:
133: private int processBookmarkDelete() throws Exception {
134:
135: String provider = Configuration.editContainer;
136: String containerName = Configuration.defaultContainer;
137: String channel = Configuration.editChannel;
138:
139: Map p = new HashMap();
140: p.put("provider", provider);
141: p.put("action", "process");
142: p.put("targetprovider", channel);
143: p.put("containerName", containerName);
144: p.put("editArgs",
145: "%3Faction%3Dedit%26dojo.transport=xmlhttp%26provider%3D"
146: + provider + "%26targetprovider%3D" + channel
147: + "%26containerName%3D" + containerName);
148: p.put("resourceCount", "4");
149: p.put("add_more", "");
150: p.put("resourceName", "");
151: p.put("resourceURL", "");
152: p.put("name0", "Sun+home+page");
153: p.put("url0", "http%3A%2F%2Fwww.sun.com");
154: p.put("name1", "CNN+home+page");
155: p.put("url1", "http%3A%2F%2Fwww.cnn.com");
156: p.put("name2", "Yahoo+home+page");
157: p.put("url2", "http%3A%2F%2Fwww.yahoo.com");
158: p.put("remove3", "1");
159: p.put("name3", "Google");
160: p.put("url3", "http%3A%2F%2Fgoogle.com");
161: p.put("windowPref", "all_new");
162: p.put("Submit", "Finished");
163:
164: return asyncPost(p);
165:
166: }
167:
168: private int processChannelEdit(String channelName) throws Exception {
169:
170: Map p = new HashMap();
171: p.put("provider", Configuration.editContainer);
172: p.put("action", "process");
173: p.put("targetprovider", channelName);
174: p.put("containerName", Configuration.defaultContainer);
175:
176: return asyncPost(p);
177:
178: }
179:
180: }
|