001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestPagedNavigation.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.site;
009:
010: import com.meterware.httpunit.*;
011: import com.uwyn.rife.TestCaseServerside;
012:
013: public class TestPagedNavigation extends TestCaseServerside {
014: public TestPagedNavigation(int siteType, String name) {
015: super (siteType, name);
016: }
017:
018: public void testDefaults() throws Exception {
019: setupSite("site/pagednavigation.xml");
020:
021: WebConversation conversation = new WebConversation();
022: WebRequest request = new GetMethodWebRequest(
023: "http://localhost:8181/defaults");
024: WebResponse response = null;
025: WebLink link = null;
026:
027: response = conversation.getResponse(request);
028:
029: // check the 'next' link
030: String reponse0 = response.getText();
031: assertEquals(
032: response.getText(),
033: "0 : Pages: 8 ( first prev <a href=\"/defaults?offset=10\">next</a> <a href=\"/defaults?offset=70\">last</a> | 1 <a href=\"/defaults?offset=10\">2</a> <a href=\"/defaults?offset=20\">3</a> <a href=\"/defaults?offset=30\">4</a> ... )");
034: link = response.getLinkWith("next");
035: response = link.click();
036: String reponse10 = response.getText();
037: assertEquals(
038: response.getText(),
039: "10 : Pages: 8 ( <a href=\"/defaults?offset=0\">first</a> <a href=\"/defaults?offset=0\">prev</a> <a href=\"/defaults?offset=20\">next</a> <a href=\"/defaults?offset=70\">last</a> | <a href=\"/defaults?offset=0\">1</a> 2 <a href=\"/defaults?offset=20\">3</a> <a href=\"/defaults?offset=30\">4</a> <a href=\"/defaults?offset=40\">5</a> ... )");
040: link = response.getLinkWith("next");
041: response = link.click();
042: String reponse20 = response.getText();
043: assertEquals(
044: response.getText(),
045: "20 : Pages: 8 ( <a href=\"/defaults?offset=0\">first</a> <a href=\"/defaults?offset=10\">prev</a> <a href=\"/defaults?offset=30\">next</a> <a href=\"/defaults?offset=70\">last</a> | <a href=\"/defaults?offset=0\">1</a> <a href=\"/defaults?offset=10\">2</a> 3 <a href=\"/defaults?offset=30\">4</a> <a href=\"/defaults?offset=40\">5</a> <a href=\"/defaults?offset=50\">6</a> ... )");
046: link = response.getLinkWith("next");
047: response = link.click();
048: String reponse30 = response.getText();
049: assertEquals(
050: response.getText(),
051: "30 : Pages: 8 ( <a href=\"/defaults?offset=0\">first</a> <a href=\"/defaults?offset=20\">prev</a> <a href=\"/defaults?offset=40\">next</a> <a href=\"/defaults?offset=70\">last</a> | <a href=\"/defaults?offset=0\">1</a> <a href=\"/defaults?offset=10\">2</a> <a href=\"/defaults?offset=20\">3</a> 4 <a href=\"/defaults?offset=40\">5</a> <a href=\"/defaults?offset=50\">6</a> <a href=\"/defaults?offset=60\">7</a> ... )");
052: link = response.getLinkWith("next");
053: response = link.click();
054: String reponse40 = response.getText();
055: assertEquals(
056: response.getText(),
057: "40 : Pages: 8 ( <a href=\"/defaults?offset=0\">first</a> <a href=\"/defaults?offset=30\">prev</a> <a href=\"/defaults?offset=50\">next</a> <a href=\"/defaults?offset=70\">last</a> | ... <a href=\"/defaults?offset=10\">2</a> <a href=\"/defaults?offset=20\">3</a> <a href=\"/defaults?offset=30\">4</a> 5 <a href=\"/defaults?offset=50\">6</a> <a href=\"/defaults?offset=60\">7</a> <a href=\"/defaults?offset=70\">8</a> )");
058: link = response.getLinkWith("next");
059: response = link.click();
060: String reponse50 = response.getText();
061: assertEquals(
062: response.getText(),
063: "50 : Pages: 8 ( <a href=\"/defaults?offset=0\">first</a> <a href=\"/defaults?offset=40\">prev</a> <a href=\"/defaults?offset=60\">next</a> <a href=\"/defaults?offset=70\">last</a> | ... <a href=\"/defaults?offset=20\">3</a> <a href=\"/defaults?offset=30\">4</a> <a href=\"/defaults?offset=40\">5</a> 6 <a href=\"/defaults?offset=60\">7</a> <a href=\"/defaults?offset=70\">8</a> )");
064: link = response.getLinkWith("next");
065: response = link.click();
066: String reponse60 = response.getText();
067: assertEquals(
068: response.getText(),
069: "60 : Pages: 8 ( <a href=\"/defaults?offset=0\">first</a> <a href=\"/defaults?offset=50\">prev</a> <a href=\"/defaults?offset=70\">next</a> <a href=\"/defaults?offset=70\">last</a> | ... <a href=\"/defaults?offset=30\">4</a> <a href=\"/defaults?offset=40\">5</a> <a href=\"/defaults?offset=50\">6</a> 7 <a href=\"/defaults?offset=70\">8</a> )");
070: link = response.getLinkWith("next");
071: response = link.click();
072: String reponse70 = response.getText();
073: assertEquals(
074: response.getText(),
075: "70 : Pages: 8 ( <a href=\"/defaults?offset=0\">first</a> <a href=\"/defaults?offset=60\">prev</a> next last | ... <a href=\"/defaults?offset=40\">5</a> <a href=\"/defaults?offset=50\">6</a> <a href=\"/defaults?offset=60\">7</a> 8 )");
076: link = response.getLinkWith("next");
077: assertNull(link);
078:
079: // check the 'previous' link
080: link = response.getLinkWith("prev");
081: response = link.click();
082: assertEquals(response.getText(), reponse60);
083: link = response.getLinkWith("prev");
084: response = link.click();
085: assertEquals(response.getText(), reponse50);
086: link = response.getLinkWith("prev");
087: response = link.click();
088: assertEquals(response.getText(), reponse40);
089: link = response.getLinkWith("prev");
090: response = link.click();
091: assertEquals(response.getText(), reponse30);
092: link = response.getLinkWith("prev");
093: response = link.click();
094: assertEquals(response.getText(), reponse20);
095: link = response.getLinkWith("prev");
096: response = link.click();
097: assertEquals(response.getText(), reponse10);
098: link = response.getLinkWith("prev");
099: response = link.click();
100: assertEquals(response.getText(), reponse0);
101: link = response.getLinkWith("prev");
102: assertNull(link);
103:
104: // check the 'last' and 'first' links
105: assertEquals(response.getText(), reponse0);
106: link = response.getLinkWith("last");
107: assertEquals(link.click().getText(), reponse70);
108: link = response.getLinkWith("first");
109: assertNull(link);
110: response = response.getLinkWith("next").click();
111: assertEquals(response.getText(), reponse10);
112: link = response.getLinkWith("last");
113: assertEquals(link.click().getText(), reponse70);
114: link = response.getLinkWith("first");
115: assertEquals(link.click().getText(), reponse0);
116: response = response.getLinkWith("next").click();
117: assertEquals(response.getText(), reponse20);
118: link = response.getLinkWith("last");
119: assertEquals(link.click().getText(), reponse70);
120: link = response.getLinkWith("first");
121: assertEquals(link.click().getText(), reponse0);
122: response = response.getLinkWith("next").click();
123: assertEquals(response.getText(), reponse30);
124: link = response.getLinkWith("last");
125: assertEquals(link.click().getText(), reponse70);
126: link = response.getLinkWith("first");
127: assertEquals(link.click().getText(), reponse0);
128: response = response.getLinkWith("next").click();
129: assertEquals(response.getText(), reponse40);
130: link = response.getLinkWith("last");
131: assertEquals(link.click().getText(), reponse70);
132: link = response.getLinkWith("first");
133: assertEquals(link.click().getText(), reponse0);
134: response = response.getLinkWith("next").click();
135: assertEquals(response.getText(), reponse50);
136: link = response.getLinkWith("last");
137: assertEquals(link.click().getText(), reponse70);
138: link = response.getLinkWith("first");
139: assertEquals(link.click().getText(), reponse0);
140: response = response.getLinkWith("next").click();
141: assertEquals(response.getText(), reponse60);
142: link = response.getLinkWith("last");
143: assertEquals(link.click().getText(), reponse70);
144: link = response.getLinkWith("first");
145: assertEquals(link.click().getText(), reponse0);
146: response = response.getLinkWith("next").click();
147: assertEquals(response.getText(), reponse70);
148: link = response.getLinkWith("last");
149: assertNull(link);
150: link = response.getLinkWith("first");
151: assertEquals(link.click().getText(), reponse0);
152:
153: // check the absolute links
154: response = link.click();
155: assertEquals(response.getText(), reponse0);
156: link = response.getLinkWith("1");
157: assertNull(link);
158: link = response.getLinkWith("2");
159: assertEquals(link.click().getText(), reponse10);
160: link = response.getLinkWith("3");
161: assertEquals(link.click().getText(), reponse20);
162: link = response.getLinkWith("4");
163: assertEquals(link.click().getText(), reponse30);
164: link = response.getLinkWith("5");
165: assertNull(link);
166: link = response.getLinkWith("6");
167: assertNull(link);
168: link = response.getLinkWith("7");
169: assertNull(link);
170: link = response.getLinkWith("8");
171: assertNull(link);
172: response = response.getLinkWith("next").click();
173: assertEquals(response.getText(), reponse10);
174: link = response.getLinkWith("1");
175: assertEquals(link.click().getText(), reponse0);
176: link = response.getLinkWith("2");
177: assertNull(link);
178: link = response.getLinkWith("3");
179: assertEquals(link.click().getText(), reponse20);
180: link = response.getLinkWith("4");
181: assertEquals(link.click().getText(), reponse30);
182: link = response.getLinkWith("5");
183: assertEquals(link.click().getText(), reponse40);
184: link = response.getLinkWith("6");
185: assertNull(link);
186: link = response.getLinkWith("7");
187: assertNull(link);
188: link = response.getLinkWith("8");
189: assertNull(link);
190: response = response.getLinkWith("next").click();
191: assertEquals(response.getText(), reponse20);
192: link = response.getLinkWith("1");
193: assertEquals(link.click().getText(), reponse0);
194: link = response.getLinkWith("2");
195: assertEquals(link.click().getText(), reponse10);
196: link = response.getLinkWith("3");
197: assertNull(link);
198: link = response.getLinkWith("4");
199: assertEquals(link.click().getText(), reponse30);
200: link = response.getLinkWith("5");
201: assertEquals(link.click().getText(), reponse40);
202: link = response.getLinkWith("6");
203: assertEquals(link.click().getText(), reponse50);
204: link = response.getLinkWith("7");
205: assertNull(link);
206: link = response.getLinkWith("8");
207: assertNull(link);
208: response = response.getLinkWith("next").click();
209: assertEquals(response.getText(), reponse30);
210: link = response.getLinkWith("1");
211: assertEquals(link.click().getText(), reponse0);
212: link = response.getLinkWith("2");
213: assertEquals(link.click().getText(), reponse10);
214: link = response.getLinkWith("3");
215: assertEquals(link.click().getText(), reponse20);
216: link = response.getLinkWith("4");
217: assertNull(link);
218: link = response.getLinkWith("5");
219: assertEquals(link.click().getText(), reponse40);
220: link = response.getLinkWith("6");
221: assertEquals(link.click().getText(), reponse50);
222: link = response.getLinkWith("7");
223: assertEquals(link.click().getText(), reponse60);
224: link = response.getLinkWith("8");
225: assertNull(link);
226: response = response.getLinkWith("next").click();
227: assertEquals(response.getText(), reponse40);
228: link = response.getLinkWith("1");
229: assertNull(link);
230: link = response.getLinkWith("2");
231: assertEquals(link.click().getText(), reponse10);
232: link = response.getLinkWith("3");
233: assertEquals(link.click().getText(), reponse20);
234: link = response.getLinkWith("4");
235: assertEquals(link.click().getText(), reponse30);
236: link = response.getLinkWith("5");
237: assertNull(link);
238: link = response.getLinkWith("6");
239: assertEquals(link.click().getText(), reponse50);
240: link = response.getLinkWith("7");
241: assertEquals(link.click().getText(), reponse60);
242: link = response.getLinkWith("8");
243: assertEquals(link.click().getText(), reponse70);
244: response = response.getLinkWith("next").click();
245: assertEquals(response.getText(), reponse50);
246: link = response.getLinkWith("1");
247: assertNull(link);
248: link = response.getLinkWith("2");
249: assertNull(link);
250: link = response.getLinkWith("3");
251: assertEquals(link.click().getText(), reponse20);
252: link = response.getLinkWith("4");
253: assertEquals(link.click().getText(), reponse30);
254: link = response.getLinkWith("5");
255: assertEquals(link.click().getText(), reponse40);
256: link = response.getLinkWith("6");
257: assertNull(link);
258: link = response.getLinkWith("7");
259: assertEquals(link.click().getText(), reponse60);
260: link = response.getLinkWith("8");
261: assertEquals(link.click().getText(), reponse70);
262: response = response.getLinkWith("next").click();
263: assertEquals(response.getText(), reponse60);
264: link = response.getLinkWith("1");
265: assertNull(link);
266: link = response.getLinkWith("2");
267: assertNull(link);
268: link = response.getLinkWith("3");
269: assertNull(link);
270: link = response.getLinkWith("4");
271: assertEquals(link.click().getText(), reponse30);
272: link = response.getLinkWith("5");
273: assertEquals(link.click().getText(), reponse40);
274: link = response.getLinkWith("6");
275: assertEquals(link.click().getText(), reponse50);
276: link = response.getLinkWith("7");
277: assertNull(link);
278: link = response.getLinkWith("8");
279: assertEquals(link.click().getText(), reponse70);
280: response = response.getLinkWith("next").click();
281: assertEquals(response.getText(), reponse70);
282: link = response.getLinkWith("1");
283: assertNull(link);
284: link = response.getLinkWith("2");
285: assertNull(link);
286: link = response.getLinkWith("3");
287: assertNull(link);
288: link = response.getLinkWith("4");
289: assertNull(link);
290: link = response.getLinkWith("5");
291: assertEquals(link.click().getText(), reponse40);
292: link = response.getLinkWith("6");
293: assertEquals(link.click().getText(), reponse50);
294: link = response.getLinkWith("7");
295: assertEquals(link.click().getText(), reponse60);
296: link = response.getLinkWith("8");
297: assertNull(link);
298: }
299:
300: public void testCustom() throws Exception {
301: setupSite("site/pagednavigation.xml");
302:
303: WebConversation conversation = new WebConversation();
304: WebRequest request = new GetMethodWebRequest(
305: "http://localhost:8181/custom");
306: WebResponse response = null;
307: WebLink link = null;
308:
309: response = conversation.getResponse(request);
310:
311: // check the 'next' link
312: assertEquals(
313: response.getText(),
314: "0 : Pages: 4 ( first prev <a href=\"/custom?myoff=3\">next</a> <a href=\"/custom?myoff=9\">last</a> | 1 <a href=\"/custom?myoff=3\">2</a> <a href=\"/custom?myoff=6\">3</a> <a href=\"/custom?myoff=9\">4</a> )");
315: link = response.getLinkWith("next");
316: response = link.click();
317: assertEquals(
318: response.getText(),
319: "3 : Pages: 4 ( <a href=\"/custom?myoff=0\">first</a> <a href=\"/custom?myoff=0\">prev</a> <a href=\"/custom?myoff=6\">next</a> <a href=\"/custom?myoff=9\">last</a> | <a href=\"/custom?myoff=0\">1</a> 2 <a href=\"/custom?myoff=6\">3</a> <a href=\"/custom?myoff=9\">4</a> )");
320: link = response.getLinkWith("next");
321: response = link.click();
322: assertEquals(
323: response.getText(),
324: "6 : Pages: 4 ( <a href=\"/custom?myoff=0\">first</a> <a href=\"/custom?myoff=3\">prev</a> <a href=\"/custom?myoff=9\">next</a> <a href=\"/custom?myoff=9\">last</a> | <a href=\"/custom?myoff=0\">1</a> <a href=\"/custom?myoff=3\">2</a> 3 <a href=\"/custom?myoff=9\">4</a> )");
325: link = response.getLinkWith("next");
326: response = link.click();
327: assertEquals(
328: response.getText(),
329: "9 : Pages: 4 ( <a href=\"/custom?myoff=0\">first</a> <a href=\"/custom?myoff=6\">prev</a> next last | <a href=\"/custom?myoff=0\">1</a> <a href=\"/custom?myoff=3\">2</a> <a href=\"/custom?myoff=6\">3</a> 4 )");
330: }
331:
332: public void testNegativeOffset() throws Exception {
333: setupSite("site/pagednavigation.xml");
334:
335: WebConversation conversation = new WebConversation();
336: WebRequest request = new GetMethodWebRequest(
337: "http://localhost:8181/custom?myoff=-10");
338: WebResponse response = null;
339:
340: response = conversation.getResponse(request);
341: assertEquals(
342: response.getText(),
343: "-10 : Pages: 4 ( first prev <a href=\"/custom?myoff=3\">next</a> <a href=\"/custom?myoff=9\">last</a> | 1 <a href=\"/custom?myoff=3\">2</a> <a href=\"/custom?myoff=6\">3</a> <a href=\"/custom?myoff=9\">4</a> )");
344: }
345:
346: public void testOffsetEqualToCount() throws Exception {
347: setupSite("site/pagednavigation.xml");
348:
349: WebConversation conversation = new WebConversation();
350: WebRequest request = new GetMethodWebRequest(
351: "http://localhost:8181/defaults?offset=80");
352: WebResponse response = null;
353:
354: response = conversation.getResponse(request);
355: assertEquals(
356: response.getText(),
357: "80 : Pages: 8 ( <a href=\"/defaults?offset=0\">first</a> <a href=\"/defaults?offset=60\">prev</a> next last | ... <a href=\"/defaults?offset=40\">5</a> <a href=\"/defaults?offset=50\">6</a> <a href=\"/defaults?offset=60\">7</a> 8 )");
358: }
359:
360: public void testOffsetLargerThanCount() throws Exception {
361: setupSite("site/pagednavigation.xml");
362:
363: WebConversation conversation = new WebConversation();
364: WebRequest request = new GetMethodWebRequest(
365: "http://localhost:8181/defaults?offset=800");
366: WebResponse response = null;
367:
368: response = conversation.getResponse(request);
369: assertEquals(
370: response.getText(),
371: "800 : Pages: 8 ( <a href=\"/defaults?offset=0\">first</a> <a href=\"/defaults?offset=60\">prev</a> next last | ... <a href=\"/defaults?offset=40\">5</a> <a href=\"/defaults?offset=50\">6</a> <a href=\"/defaults?offset=60\">7</a> 8 )");
372: }
373:
374: public void testNegativeCount() throws Exception {
375: setupSite("site/pagednavigation.xml");
376:
377: WebConversation conversation = new WebConversation();
378: WebRequest request = new GetMethodWebRequest(
379: "http://localhost:8181/negativecount");
380: WebResponse response = null;
381:
382: response = conversation.getResponse(request);
383: assertEquals(response.getText(),
384: "0 : Pages: 0 ( first prev next last | )");
385: }
386:
387: public void testNoRangeCount() throws Exception {
388: setupSite("site/pagednavigation.xml");
389:
390: WebConversation conversation = new WebConversation();
391: WebRequest request = new GetMethodWebRequest(
392: "http://localhost:8181/norangecount");
393: WebResponse response = null;
394:
395: response = conversation.getResponse(request);
396: assertEquals(
397: response.getText(),
398: "0 : Pages: ( first prev <a href=\"/norangecount?offset=10\">next</a> <a href=\"/norangecount?offset=70\">last</a> | 1 <a href=\"/norangecount?offset=10\">2</a> <a href=\"/norangecount?offset=20\">3</a> <a href=\"/norangecount?offset=30\">4</a> ... )");
399: }
400:
401: public void testPathinfo() throws Exception {
402: setupSite("site/pagednavigation.xml");
403:
404: WebConversation conversation = new WebConversation();
405: WebRequest request = new GetMethodWebRequest(
406: "http://localhost:8181/pathinfo");
407: WebResponse response = null;
408:
409: response = conversation.getResponse(request);
410: assertEquals(
411: response.getText(),
412: "0 : Pages: 8 ( first prev <a href=\"/pathinfo/test/pathinfo?offset=10\">next</a> <a href=\"/pathinfo/test/pathinfo?offset=70\">last</a> | 1 <a href=\"/pathinfo/test/pathinfo?offset=10\">2</a> <a href=\"/pathinfo/test/pathinfo?offset=20\">3</a> <a href=\"/pathinfo/test/pathinfo?offset=30\">4</a> ... )");
413: }
414: }
|