KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > test > DefaultLongTxnHandlerTest


1 /*
2  * Copyright (c) 2003-2004, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.controller.test;
8
9
10 import com.inversoft.junit.WebTestCase;
11 import com.inversoft.verge.mvc.MVCException;
12 import com.inversoft.verge.mvc.controller.DefaultLongTxnHandler;
13 import com.inversoft.verge.mvc.controller.GenericResult;
14
15
16 /**
17  * <p>
18  * This class tests the default long txn handler.
19  * </p>
20  *
21  * @author Brian Pontarelli
22  */

23 public class DefaultLongTxnHandlerTest extends WebTestCase {
24
25     /**
26      * Constructs a new <code>DefaultLongTxnHandlerTest</code>.
27      */

28     public DefaultLongTxnHandlerTest(String JavaDoc name) {
29         super(name);
30         setLocal(true);
31     }
32
33
34     /**
35      * Tests that the start long txn method with a URL works.
36      */

37     public void testStartURL() {
38         DefaultLongTxnHandler h = new DefaultLongTxnHandler();
39         try {
40             h.handleStartLongTxn(request, response, "/testURL");
41             assertEquals("/testURL", getRequest().getRequestDispatcher().getURL());
42             assertFalse(getRequest().getRequestDispatcher().isForwarded());
43             assertTrue(getRequest().getRequestDispatcher().isIncluded());
44         } catch (MVCException mvce) {
45             fail(mvce.toString());
46         }
47     }
48
49     /**
50      * Test that the start long txn with no URL is a no-op
51      */

52     public void testStartNoURL() {
53         DefaultLongTxnHandler h = new DefaultLongTxnHandler();
54         try {
55             h.handleStartLongTxn(request, response, null);
56             assertNull(getRequest().getRequestDispatcher());
57         } catch (MVCException mvce) {
58             fail(mvce.toString());
59         }
60     }
61
62     /**
63      * Tests that the end long txn method with a URL works.
64      */

65     public void testEndURL() {
66         DefaultLongTxnHandler h = new DefaultLongTxnHandler();
67         GenericResult r = new GenericResult("/testDoneURL", null, true);
68         try {
69             h.handleEndLongTxn(request, response, "/testURL", r);
70             assertEquals("/testURL", getRequest().getRequestDispatcher().getURL());
71             assertFalse(getRequest().getRequestDispatcher().isForwarded());
72             assertTrue(getRequest().getRequestDispatcher().isIncluded());
73             assertSame(r, request.getAttribute(DefaultLongTxnHandler.RESULT_PARAMETER));
74         } catch (MVCException mvce) {
75             fail(mvce.toString());
76         }
77     }
78
79     /**
80      * Test that the end long txn with no URL outputs the meta-refresh correctly.
81      */

82     public void testEndNoURL() {
83         DefaultLongTxnHandler h = new DefaultLongTxnHandler();
84         GenericResult r = new GenericResult("/testDoneURL", null, true);
85         try {
86             h.handleEndLongTxn(request, response, null, r);
87             assertNull(getRequest().getRequestDispatcher());
88             assertEquals("<head><meta http-equiv='REFRESH' content='0;url=/testDoneURL'/></head></html>",
89                 getResponse().getText());
90         } catch (MVCException mvce) {
91             fail(mvce.toString());
92         }
93     }
94
95     /**
96      * Test that the end long txn with no URL outputs the and encodes the URL
97      * correctly.
98      */

99     public void testEndNoURLEncode() {
100         getResponse().setEncode(true);
101
102         DefaultLongTxnHandler h = new DefaultLongTxnHandler();
103         GenericResult r = new GenericResult("/testDoneURL", null, true);
104         try {
105             h.handleEndLongTxn(request, response, null, r);
106             assertNull(getRequest().getRequestDispatcher());
107             assertEquals("<head><meta http-equiv='REFRESH' content='0;url=/testDoneURL#encodeRedirect'/></head></html>",
108                 getResponse().getText());
109         } catch (MVCException mvce) {
110             fail(mvce.toString());
111         }
112     }
113 }
Popular Tags