001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004:
005: package com.tctest.spring.integrationtests.tests;
006:
007: import com.meterware.httpunit.WebConversation;
008: import com.meterware.httpunit.WebResponse;
009: import com.tc.test.TestConfigObject;
010: import com.tc.test.server.appserver.deployment.AbstractTwoServerDeploymentTest;
011: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
012: import com.tc.test.server.appserver.deployment.WebApplicationServer;
013: import com.tctest.spring.integrationtests.SpringTwoServerTestSetup;
014:
015: import junit.framework.Test;
016:
017: /**
018: * Test ApplicationContext definition
019: *
020: * LKC-804: Test: Session scoped Spring Beans
021: * https://jira.terracotta.lan/jira//browse/LKC-804
022: *
023: * Test sharing of state
024: * Test scope is really session scope
025: * More??
026: *
027: * Use Tomcat and WLS DSO session clustering.
028: *
029: * <b>This is for Spring 2.0 only!</b>
030: */
031: public class ScopedBeanTest extends AbstractTwoServerDeploymentTest {
032:
033: public static Test suite() {
034: return new SessionScopedBeanTestSetup();
035: }
036:
037: public ScopedBeanTest() {
038: disableVariant(TestConfigObject.SPRING_VARIANT, "128");
039: }
040:
041: public void testSessionScopedBean() throws Exception {
042: WebConversation webConversation1 = new WebConversation();
043: verifyValue(server0, webConversation1, "Jonas");
044: updateValue(server0, webConversation1, "Tim");
045: verifyValue(server0, webConversation1, "Tim");
046: verifyValue(server1, webConversation1, "Tim");
047:
048: WebConversation webConversation2 = new WebConversation();
049: verifyValue(server1, webConversation2, "Jonas");
050: updateValue(server1, webConversation2, "Steve");
051: verifyValue(server1, webConversation2, "Steve");
052: verifyValue(server0, webConversation2, "Steve");
053:
054: verifyValue(server1, webConversation1, "Tim");
055: verifyValue(server1, webConversation1, "Tim");
056: }
057:
058: private void verifyValue(WebApplicationServer server,
059: WebConversation conversation, String expectedText)
060: throws Exception {
061: WebResponse response = server.ping("/scopedBeans/get.html",
062: conversation);
063: String responseText = response.getText().trim();
064: assertEquals("Incorrect value from session "
065: + conversation.getCookieValue("JSESSIONID"),
066: expectedText, responseText);
067: }
068:
069: private void updateValue(WebApplicationServer server,
070: WebConversation conversation, String newText)
071: throws Exception {
072: WebResponse response = server.ping(
073: "/scopedBeans/set.html?value=" + newText, conversation);
074: String responseText = response.getText().trim();
075: assertEquals("Incorrect value from session "
076: + conversation.getCookieValue("JSESSIONID"), newText,
077: responseText);
078: }
079:
080: private static class SessionScopedBeanTestSetup extends
081: SpringTwoServerTestSetup {
082:
083: public SessionScopedBeanTestSetup() {
084: super (ScopedBeanTest.class,
085: "/tc-config-files/scopedbeans-tc-config.xml",
086: "scopedBeans");
087: }
088:
089: protected void configureWar(DeploymentBuilder builder) {
090: builder
091: // .addDirectoryOrJARContainingClass(SessionScopedBeanTestSetup.class)
092: .addDirectoryOrJARContainingClass(
093: org.apache.taglibs.standard.Version.class)
094: // standard-1.0.6.jar
095: .addDirectoryOrJARContainingClass(
096: javax.servlet.jsp.jstl.core.Config.class)
097: // jstl-1.0.jar
098:
099: .addResource("/web-resources", "scopedBeans.jsp",
100: "WEB-INF")
101: .addResource("/web-resources", "weblogic.xml",
102: "WEB-INF")
103:
104: .addResource("/com/tctest/spring",
105: "scopedBeans-servlet.xml", "WEB-INF")
106:
107: .addServlet(
108: "scopedBeans",
109: "*.html",
110: org.springframework.web.servlet.DispatcherServlet.class,
111: null, true);
112:
113: }
114:
115: }
116:
117: }
|