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: package com.tctest.spring.integrationtests.tests;
005:
006: import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
007: import org.springframework.web.servlet.DispatcherServlet;
008:
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.ProxyBuilder;
013: import com.tctest.spring.bean.ISimpleBean;
014: import com.tctest.spring.integrationtests.SpringTwoServerTestSetup;
015:
016: import java.util.HashMap;
017: import java.util.Map;
018:
019: import junit.framework.Test;
020:
021: /**
022: * Test clustering session scoped bean.
023: */
024: public class SessionScopedBeanTest extends
025: AbstractTwoServerDeploymentTest {
026: private static final String APP_NAME = "test-sessionscope";
027: private static final String SERVICE_FOR_SHARED_SESSION_SCOPED_BEAN = "SimpleBeanSvc";
028: // private static final String SERVICE_FOR_LOCAL_SESSION_SCOPED_BEAN = "LocalSimpleBeanSvc";
029: private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory-sessionscope.xml";
030: private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/sessionscoped-tc-config.xml";
031:
032: private ISimpleBean beanN1S1; // node1 session1
033: private ISimpleBean beanN1S2; // node1 session2
034:
035: private ISimpleBean beanN2S1; // node2 session1
036: private ISimpleBean beanN2S2; // node2 session2
037:
038: // private static ISimpleBean beanN1S1Local; // node1 session1
039: // private static ISimpleBean beanN2S1Local; // node2 session1
040:
041: public SessionScopedBeanTest() {
042: // this.disableAllUntil("2007-05-14");
043: this .disableVariant(TestConfigObject.SPRING_VARIANT, "128");
044: }
045:
046: protected void setUp() throws Exception {
047: try {
048: super .setUp();
049:
050: Map initCtx = new HashMap();
051: initCtx.put(ProxyBuilder.EXPORTER_TYPE_KEY,
052: HttpInvokerServiceExporter.class);
053:
054: String name = APP_NAME + "/http/"
055: + SERVICE_FOR_SHARED_SESSION_SCOPED_BEAN;
056: beanN1S1 = (ISimpleBean) server0.getProxy(
057: ISimpleBean.class, name, initCtx);
058: // beanN1S1Local = (ISimpleBean) server1.getProxy(ISimpleBean.class, name);
059: beanN2S1 = (ISimpleBean) server1.getProxy(
060: ISimpleBean.class, name, initCtx);
061: // beanN2S1Local = (ISimpleBean) server2.getProxy(ISimpleBean.class, name);
062:
063: initCtx.remove(ProxyBuilder.HTTP_CLIENT_KEY); // this resets the internal client
064:
065: beanN1S2 = (ISimpleBean) server0.getProxy(
066: ISimpleBean.class, name, initCtx);
067: beanN2S2 = (ISimpleBean) server1.getProxy(
068: ISimpleBean.class, name, initCtx);
069: } catch (Exception e) {
070: e.printStackTrace();
071: throw e;
072: }
073: }
074:
075: // public void testLocalSessionScopedBeans() throws Exception {
076: // logger.debug("testing local beans");
077: //
078: // beanN1S1Local.setField("newLocalVal1");
079: //
080: // Thread.sleep(4000);
081: //
082: // assertEquals("Unexcpected value: ", "newLocalVal1", beanN1S1Local.getField());
083: // assertEquals("Unexcpected sharing: ", "local-v1", beanN2S1Local.getField());
084: //
085: // logger.debug("!!!! Asserts passed !!!");
086: // }
087:
088: public void testSharedFields() throws Exception {
089: beanN1S1.setField("newVal1");
090: beanN2S2.setField("newVal2");
091:
092: Thread.sleep(4000);
093:
094: assertEquals("Failed to shared: ", "newVal1", beanN2S1
095: .getField());
096: assertEquals("Failed to shared: ", "newVal2", beanN1S2
097: .getField());
098: }
099:
100: public void testTransparentFields() throws Exception {
101: assertEquals(
102: "Failed to initialize/virtualize the transient field.",
103: "transient-val", beanN1S1.getTransientField());
104: assertEquals(
105: "Failed to initialize/virtualize the transient field.",
106: "transient-val", beanN1S2.getTransientField());
107: assertEquals(
108: "Failed to initialize/virtualize the transient field.",
109: "transient-val", beanN2S1.getTransientField());
110: assertEquals(
111: "Failed to initialize/virtualize the transient field.",
112: "transient-val", beanN2S2.getTransientField());
113:
114: beanN1S1.setTransientField("newVal11");
115: beanN1S2.setTransientField("newVal12");
116: beanN2S1.setTransientField("newVal21");
117: beanN2S2.setTransientField("newVal22");
118:
119: assertEquals("Unexpected sharing: ", "newVal11", beanN1S1
120: .getTransientField());
121: assertEquals("Unexpected sharing: ", "newVal12", beanN1S2
122: .getTransientField());
123: assertEquals("Unexpected sharing: ", "newVal21", beanN2S1
124: .getTransientField());
125: assertEquals("Unexpected sharing: ", "newVal22", beanN2S2
126: .getTransientField());
127: }
128:
129: private static class InnerTestSetup extends
130: SpringTwoServerTestSetup {
131:
132: private InnerTestSetup() {
133: super (SessionScopedBeanTest.class, CONFIG_FILE_FOR_TEST,
134: APP_NAME);
135: }
136:
137: protected void configureWar(DeploymentBuilder builder) {
138: builder
139: .addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST);
140: builder.addRemoteService(HttpInvokerServiceExporter.class,
141: SERVICE_FOR_SHARED_SESSION_SCOPED_BEAN,
142: "simplebean", ISimpleBean.class);
143: // builder.addRemoteService(HttpInvokerServiceExporter.class,SERVICE_FOR_LOCAL_SESSION_SCOPED_BEAN, "localsimplebean", ISimpleBean.class);
144: builder.setDispatcherServlet("httpinvoker", "/http/*",
145: DispatcherServlet.class, null, true);
146: builder
147: .addDirectoryOrJARContainingClass(net.sf.cglib.core.Constants.class);
148: }
149:
150: }
151:
152: public static Test suite() {
153: return new InnerTestSetup();
154: }
155:
156: }
|