1 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 ; 14 import org.apache.cactus.WebRequest; 15 import java.util.Map ; 16 import com.meterware.httpunit.WebResponse; 17 import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException; 18 import java.util.Hashtable ; 19 import javax.servlet.http.HttpUtils ; 20 import org.apache.log4j.PropertyConfigurator; 21 22 23 32 public class SampleEnhydraRedirectionTestCase extends EnhydraAppTestCase { 33 static { 34 PropertyConfigurator.configure("log_client.properties"); 36 } 37 38 public SampleEnhydraRedirectionTestCase (String name) { 39 super(name); 40 } 41 42 47 public static void main (String [] theArgs) { 48 junit.awtui.TestRunner.main(new String [] { 49 SampleEnhydraRedirectionTestCase.class.getName() 50 }); 51 } 52 53 57 public static Test suite () { 58 return new TestSuite(SampleEnhydraRedirectionTestCase.class); 60 } 61 String answer1 = "http://localhost:9000/WelcomePresentation.po"; 62 63 66 public void testRedirection1 () throws Exception { 67 RedirectPresentation samplePO = new RedirectPresentation(); 68 samplePO.run(comms); 69 } 70 71 76 public void endRedirection1 (WebResponse theResponse) throws IOException { 77 assertEquals(theResponse.getHeaderField("Location"), answer1); 78 } 79 80 83 public void testRedirection2 () throws Exception { 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 101 protected void hookForClientPageRedirect (String url, Hashtable ht) { 102 if (ht == null) 103 return; assertEquals("TEST3", ((String [])ht.get("test3"))[0]); 105 assertEquals("TEST2", ((String [])ht.get("test2"))[0]); 106 assertEquals("TEST1", ((String [])ht.get("test1"))[0]); 107 } 108 109 114 public void endRedirection2 (WebResponse theResponse) throws IOException { 115 String str = theResponse.getHeaderField("Location"); 116 Hashtable ht = getRedirectParameters(str); 117 assertEquals("TEST3", ((String [])ht.get("test3"))[0]); 118 assertEquals("TEST2", ((String [])ht.get("test2"))[0]); 119 assertEquals("TEST1", ((String [])ht.get("test1"))[0]); 120 } 121 } 123 124 125 | Popular Tags |