| 1 4 5 package com.tctest.spring.integrationtests.tests; 6 7 import com.meterware.httpunit.WebConversation; 8 import com.meterware.httpunit.WebResponse; 9 import com.tctest.spring.integrationtests.framework.AbstractTwoServerDeploymentTest; 10 import com.tctest.spring.integrationtests.framework.Deployment; 11 import com.tctest.spring.integrationtests.framework.ServerTestSetup; 12 import com.tctest.spring.integrationtests.framework.WebApplicationServer; 13 14 import junit.framework.Test; 15 16 17 31 public class ScopedBeanTest extends AbstractTwoServerDeploymentTest { 32 33 public static Test suite() { 34 return new SessionScopedBeanTestSetup(); 35 } 36 37 38 public ScopedBeanTest() { 39 disableAllUntil("2007-09-15"); 41 } 42 43 public void testSessionScopedBean() throws Exception { 44 WebConversation webConversation1 = new WebConversation(); 45 verifyValue(server1, webConversation1, "Jonas"); 46 updateValue(server1, webConversation1, "Tim"); 47 verifyValue(server1, webConversation1, "Tim"); 48 49 WebConversation webConversation2 = new WebConversation(); 50 verifyValue(server2, webConversation2, "Jonas"); 51 updateValue(server2, webConversation2, "Steve"); 52 verifyValue(server2, webConversation2, "Steve"); 53 verifyValue(server1, webConversation2, "Steve"); 54 55 verifyValue(server2, webConversation1, "Tim"); 56 verifyValue(server2, webConversation1, "Tim"); 57 } 58 59 60 private void verifyValue(WebApplicationServer server, WebConversation conversation, String expectedText) throws Exception { 61 WebResponse response = server.ping("/scopedBeans/get.html", conversation); 62 String responseText = response.getText().trim(); 63 assertEquals("Incorrect value from session "+conversation.getCookieValue("JSESSIONID"), expectedText, responseText); 64 } 65 66 private void updateValue(WebApplicationServer server, WebConversation conversation, String newText) throws Exception { 67 WebResponse response = server.ping("/scopedBeans/set.html?value="+newText, conversation); 68 String responseText = response.getText().trim(); 69 assertEquals("Incorrect value from session "+conversation.getCookieValue("JSESSIONID"), newText, responseText); 70 } 71 72 73 private static class SessionScopedBeanTestSetup extends ServerTestSetup { 74 75 public SessionScopedBeanTestSetup() { 76 super(ScopedBeanTest.class); 77 } 78 79 protected void setUp() throws Exception { 80 super.setUp(); 81 82 Deployment deployment = makeDeploymentBuilder("scopedBeans.war") 83 .addDirectoryOrJARContainingClass(SessionScopedBeanTestSetup.class) 84 .addDirectoryOrJARContainingClass(org.apache.taglibs.standard.Version.class) .addDirectoryOrJARContainingClass(javax.servlet.jsp.jstl.core.Config.class) 87 .addDirectoryContainingResource("/tc-config-files/scopedbeans-tc-config.xml") 88 89 .addResource("/web-resources", "scopedBeans.jsp", "WEB-INF") 92 .addResource("/web-resources", "weblogic.xml", "WEB-INF") 93 94 .addResource("/com/tctest/spring", "scopedBeans-servlet.xml", "WEB-INF") 95 96 .addServlet("scopedBeans", "*.html", org.springframework.web.servlet.DispatcherServlet.class, null, true) 97 98 101 .makeDeployment(); 102 103 server1 = createServer(deployment); 104 server2 = createServer(deployment); 105 } 106 107 private WebApplicationServer createServer(Deployment deployment) throws Exception { 108 WebApplicationServer server = sm.makeWebApplicationServer("/tc-config-files/scopedbeans-tc-config.xml"); 109 110 server.addWarDeployment(deployment, "scopedBeans"); 111 server.start(); 112 113 return server; 114 } 115 116 } 117 118 } 119 120 | Popular Tags |