KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > spring > integrationtests > tests > ScopedBeanTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 /**
18  * Test ApplicationContext definition
19  *
20  * LKC-804: Test: Session scoped Spring Beans
21  * https://jira.terracotta.lan/jira//browse/LKC-804
22  *
23  * Test sharing of state
24  * Test scope is really session scope
25  * More??
26  *
27  * Use Tomcat and WLS DSO session clustering.
28  *
29  * <b>This is for Spring 2.0 only!</b>
30  */

31 public class ScopedBeanTest extends AbstractTwoServerDeploymentTest {
32
33   public static Test suite() {
34     return new SessionScopedBeanTestSetup();
35   }
36
37   
38   public ScopedBeanTest() {
39     // XXX timebombed till 2006-09-15
40
disableAllUntil("2007-09-15");
41   }
42   
43   public void testSessionScopedBean() throws Exception JavaDoc {
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 JavaDoc expectedText) throws Exception JavaDoc {
61     WebResponse response = server.ping("/scopedBeans/get.html", conversation);
62     String JavaDoc 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 JavaDoc newText) throws Exception JavaDoc {
67     WebResponse response = server.ping("/scopedBeans/set.html?value="+newText, conversation);
68     String JavaDoc 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 JavaDoc {
80       super.setUp();
81
82       Deployment deployment = makeDeploymentBuilder("scopedBeans.war")
83           .addDirectoryOrJARContainingClass(SessionScopedBeanTestSetup.class)
84           .addDirectoryOrJARContainingClass(org.apache.taglibs.standard.Version.class) // standard-1.0.6.jar
85
.addDirectoryOrJARContainingClass(javax.servlet.jsp.jstl.core.Config.class) // jstl-1.0.jar
86

87           .addDirectoryContainingResource("/tc-config-files/scopedbeans-tc-config.xml")
88
89 // .addResource("/web-resources", "c.tld", "WEB-INF")
90
// .addResource("/web-resources", "fmt.tld", "WEB-INF")
91
.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 // .addTaglib("http://java.sun.com/jsp/jstl/core", "/WEB-INF/c.tld")
99
// .addTaglib("http://java.sun.com/jsp/jstl/fmt", "/WEB-INF/fmt.tld")
100

101           .makeDeployment();
102
103       server1 = createServer(deployment);
104       server2 = createServer(deployment);
105     }
106
107     private WebApplicationServer createServer(Deployment deployment) throws Exception JavaDoc {
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