1 56 57 58 package org.hamletsoft.enhydra.cactus.business.sample; 59 60 import org.hamletsoft.enhydra.cactus.business.EnhydraAppTestCase; 61 import org.hamletsoft.enhydra.cactus.presentation.sample.SamplePO; 62 import junit.framework.Test; 63 import junit.framework.TestSuite; 64 import org.apache.cactus.WebResponse; 65 import java.io.IOException ; 66 import org.apache.cactus.WebRequest; 67 import java.util.Map ; 68 import org.apache.cactus.client.authentication.BasicAuthentication; 69 import com.lutris.http.BasicAuth; 70 import com.lutris.http.BasicAuthResult; 71 import org.apache.log4j.PropertyConfigurator; 72 73 74 84 public class SampleEnhydraAppTestCase extends EnhydraAppTestCase { 85 static { 86 PropertyConfigurator.configure("log_client.properties"); 88 } 89 90 public SampleEnhydraAppTestCase (String name) { 91 super(name); 92 } 93 94 99 public static void main (String [] theArgs) { 100 junit.awtui.TestRunner.main(new String [] { 101 SampleEnhydraAppTestCase.class.getName() 102 }); 103 } 104 105 111 115 public static Test suite () { 116 return new TestSuite(SampleEnhydraAppTestCase.class); 118 } 119 120 123 public void testReadOutputStream () throws Exception { 124 SamplePO samplePO = new SamplePO(); 125 samplePO.run(comms); 126 } 127 128 133 public void endReadOutputStream (WebResponse theResponse) throws IOException { 134 String expected = SamplePO.Answer1; 135 String result = theResponse.getText(); 137 assertEquals(expected, result); 138 } 139 140 146 public void beginPostMethod (WebRequest theRequest) { 147 theRequest.addParameter("param1", "value1", WebRequest.POST_METHOD); 148 } 149 150 155 public void testPostMethod () throws Exception { 156 SamplePO samplePO = new SamplePO(); 157 samplePO.run(comms); 158 assertEquals("POST", samplePO.checkMethod()); 159 } 160 161 168 public void beginGetMethod (WebRequest theRequest) {} 169 170 173 public void testGetMethod () throws Exception { 174 SamplePO samplePO = new SamplePO(); 175 samplePO.run(comms); 176 assertEquals("GET", samplePO.checkMethod()); 177 } 178 179 185 public void beginSendParams (WebRequest theRequest) { 186 theRequest.addParameter("param1", "value1"); 187 theRequest.addParameter("param2", "value2"); 188 } 189 190 193 public void testSendParams () throws Exception { 194 SamplePO samplePO = new SamplePO(); 195 samplePO.run(comms); 196 Map params = samplePO.getRequestParameters(); 197 assertTrue(params.get("param1") != null); 198 assertTrue(params.get("param2") != null); 199 assertEquals("value1", params.get("param1")); 200 assertEquals("value2", params.get("param2")); 201 } 202 203 209 public void beginSendHeader (WebRequest theRequest) { 210 theRequest.addHeader("testheader", "this is a header test"); 211 } 212 213 216 public void testSendHeader () throws Exception { 217 SamplePO samplePO = new SamplePO(); 218 samplePO.run(comms); 219 String headerValue = samplePO.getRequestHeader("testheader"); 220 assertEquals("this is a header test", headerValue); 221 } 222 223 230 public void beginSendCookie (WebRequest theRequest) { 231 theRequest.addCookie("testcookie", "thisisacookie"); 236 } 237 238 241 public void testSendCookie () throws Exception { 242 SamplePO samplePO = new SamplePO(); 243 samplePO.run(comms); 244 Map cookies = samplePO.getRequestCookies(); 245 assertTrue("Cannot find [testcookie] cookie in request", cookies.get("testcookie") 246 != null); 247 assertEquals("thisisacookie", cookies.get("testcookie")); 248 } 249 250 253 public void beginBasicAuthentication (WebRequest theRequest) { 254 theRequest.setAuthentication(new BasicAuthentication("testuser", "testpwd")); 255 } 256 257 260 public void testBasicAuthentication () throws Exception { 261 BasicAuthResult authResult = BasicAuth.getAuthentication(comms.request); 262 assertEquals("testuser", authResult.username); 263 assertEquals("testpwd", authResult.password); 264 } 265 } 267 268 269 | Popular Tags |