KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hamletsoft > enhydra > cactus > business > sample > SampleEnhydraRedirectionTestCase


1 /*
2  * put your module comment here
3  * formatted with JxBeauty (c) johann.langhofer@nextra.at
4  */

5
6
7 package org.hamletsoft.enhydra.cactus.business.sample;
8
9 import org.hamletsoft.enhydra.cactus.business.EnhydraAppTestCase;
10 import org.hamletsoft.enhydra.cactus.presentation.RedirectPresentation;
11 import junit.framework.Test;
12 import junit.framework.TestSuite;
13 import java.io.IOException JavaDoc;
14 import org.apache.cactus.WebRequest;
15 import java.util.Map JavaDoc;
16 import com.meterware.httpunit.WebResponse;
17 import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
18 import java.util.Hashtable JavaDoc;
19 import javax.servlet.http.HttpUtils JavaDoc;
20 import org.apache.log4j.PropertyConfigurator;
21
22
23 /**
24  * SampleEnhydraRedirectionTestCase.java
25  *
26  *
27  * Created: Wed Feb 13 17:53:50 2002
28  *
29  * @author <a HREF="mailto:hattori@hitachizosen.co.jp">Ryuji Hattori</a>
30  * @version
31  */

32 public class SampleEnhydraRedirectionTestCase extends EnhydraAppTestCase {
33   static {
34     // instructs PropertyConfigurator to parse a configuration file and set up logging accordingly
35
PropertyConfigurator.configure("log_client.properties");
36   }
37
38   public SampleEnhydraRedirectionTestCase (String JavaDoc name) {
39     super(name);
40   }
41
42   /**
43    * Start the tests.
44    *
45    * @param theArgs the arguments. Not used
46    */

47   public static void main (String JavaDoc[] theArgs) {
48     junit.awtui.TestRunner.main(new String JavaDoc[] {
49       SampleEnhydraRedirectionTestCase.class.getName()
50     });
51   }
52
53   /**
54    * @return a test suite (<code>TestSuite</code>) that includes all methods
55    * starting with "test"
56    */

57   public static Test suite () {
58     // All methods starting with "test" will be executed in the test suite.
59
return new TestSuite(SampleEnhydraRedirectionTestCase.class);
60   }
61   String JavaDoc answer1 = "http://localhost:9000/WelcomePresentation.po";
62
63   /**
64    * Verify that we can assert the client side redirection.
65    */

66   public void testRedirection1 () throws Exception JavaDoc {
67     RedirectPresentation samplePO = new RedirectPresentation();
68     samplePO.run(comms);
69   }
70
71   /**
72    * Verify that we can assert the client side redirection.
73    *
74    * @param theResponse the response from the server side.
75    */

76   public void endRedirection1 (WebResponse theResponse) throws IOException JavaDoc {
77     assertEquals(theResponse.getHeaderField("Location"), answer1);
78   }
79
80   /**
81    * Verify that we can assert the client side redirection.
82    */

83   public void testRedirection2 () throws Exception JavaDoc {
84     RedirectPresentation samplePO = new RedirectPresentation();
85     try {
86       samplePO.run(comms);
87     } catch (ClientPageRedirectException cpre) {
88       cpre.addArgument("test1", "TEST1");
89       cpre.addArgument("test2", "TEST2");
90       cpre.addArgument("test3", "TEST3");
91       throw cpre;
92     }
93   }
94
95   /**
96    * Hook method on Server Side for client page redirection.
97    *
98    * @param url URL of Page Redirection.
99    * @param ht HTTP parameter table for the URL of Page Redirection.()
100    */

101   protected void hookForClientPageRedirect (String JavaDoc url, Hashtable JavaDoc ht) {
102     if (ht == null)
103       return; //for Test1
104
assertEquals("TEST3", ((String JavaDoc[])ht.get("test3"))[0]);
105     assertEquals("TEST2", ((String JavaDoc[])ht.get("test2"))[0]);
106     assertEquals("TEST1", ((String JavaDoc[])ht.get("test1"))[0]);
107   }
108
109   /**
110    * Verify that we can assert the client side redirection.
111    *
112    * @param theResponse the response from the server side.
113    */

114   public void endRedirection2 (WebResponse theResponse) throws IOException JavaDoc {
115     String JavaDoc str = theResponse.getHeaderField("Location");
116     Hashtable JavaDoc ht = getRedirectParameters(str);
117     assertEquals("TEST3", ((String JavaDoc[])ht.get("test3"))[0]);
118     assertEquals("TEST2", ((String JavaDoc[])ht.get("test2"))[0]);
119     assertEquals("TEST1", ((String JavaDoc[])ht.get("test1"))[0]);
120   }
121 } // SampleEnhydraRedirectionTestCase
122

123
124
125
Popular Tags