1 4 package com.tctest.spring.integrationtests.tests; 5 6 import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter; 7 import org.springframework.web.servlet.DispatcherServlet; 8 9 import com.tc.test.TestConfigObject; 10 import com.tctest.spring.bean.ISimpleBean; 11 import com.tctest.spring.integrationtests.framework.AbstractTwoServerDeploymentTest; 12 import com.tctest.spring.integrationtests.framework.DeploymentBuilder; 13 import com.tctest.spring.integrationtests.framework.ProxyBuilder; 14 15 import java.util.HashMap ; 16 import java.util.Map ; 17 18 import junit.extensions.TestSetup; 19 import junit.framework.Test; 20 21 22 25 public class SessionScopedBeanTest extends AbstractTwoServerDeploymentTest { 26 27 private static final String SERVICE_FOR_SHARED_SESSION_SCOPED_BEAN = "SimpleBeanSvc"; 28 private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory-sessionscope.xml"; 30 private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/sessionscoped-tc-config.xml"; 31 32 33 private static ISimpleBean beanN1S1; private static ISimpleBean beanN1S2; 36 private static ISimpleBean beanN2S1; private static ISimpleBean beanN2S2; 39 42 public SessionScopedBeanTest() { 43 this.disableVariant(TestConfigObject.SPRING_VARIANT, "128"); 44 } 45 46 59 public void testSharedFields() throws Exception { 60 beanN1S1.setField("newVal1"); 61 beanN2S2.setField("newVal2"); 62 63 Thread.sleep(4000); 64 65 assertEquals("Failed to shared: ", "newVal1", beanN2S1.getField()); 66 assertEquals("Failed to shared: ", "newVal2", beanN1S2.getField()); 67 } 68 69 public void testTransparentFields() throws Exception { 70 assertEquals("Failed to initialize/virtualize the transient field.", "transient-val", beanN1S1.getTransientField()); 71 assertEquals("Failed to initialize/virtualize the transient field.", "transient-val", beanN1S2.getTransientField()); 72 assertEquals("Failed to initialize/virtualize the transient field.", "transient-val", beanN2S1.getTransientField()); 73 assertEquals("Failed to initialize/virtualize the transient field.", "transient-val", beanN2S2.getTransientField()); 74 75 beanN1S1.setTransientField("newVal11"); 76 beanN1S2.setTransientField("newVal12"); 77 beanN2S1.setTransientField("newVal21"); 78 beanN2S2.setTransientField("newVal22"); 79 80 assertEquals("Unexpected sharing: ", "newVal11", beanN1S1.getTransientField()); 81 assertEquals("Unexpected sharing: ", "newVal12", beanN1S2.getTransientField()); 82 assertEquals("Unexpected sharing: ", "newVal21", beanN2S1.getTransientField()); 83 assertEquals("Unexpected sharing: ", "newVal22", beanN2S2.getTransientField()); 84 } 85 86 private static class InnerTestSetup extends TwoSvrSetup { 87 private static final String APP_NAME = "test-sessionscope"; 88 89 private InnerTestSetup() { 90 super(SessionScopedBeanTest.class, CONFIG_FILE_FOR_TEST, APP_NAME); 91 } 92 93 protected void setUp() throws Exception { 94 try { 95 super.setUp(); 96 97 Map initCtx = new HashMap (); 98 initCtx.put(ProxyBuilder.EXPORTER_TYPE_KEY, HttpInvokerServiceExporter.class); 99 100 beanN1S1 = (ISimpleBean) server1.getProxy(ISimpleBean.class, APP_NAME + "/http/" + SERVICE_FOR_SHARED_SESSION_SCOPED_BEAN, initCtx); 101 beanN2S1 = (ISimpleBean) server2.getProxy(ISimpleBean.class, APP_NAME + "/http/" + SERVICE_FOR_SHARED_SESSION_SCOPED_BEAN, initCtx); 103 105 initCtx.remove(ProxyBuilder.HTTP_CLIENT_KEY); 107 beanN1S2 = (ISimpleBean) server1.getProxy(ISimpleBean.class, APP_NAME + "/http/" + SERVICE_FOR_SHARED_SESSION_SCOPED_BEAN, initCtx); 108 beanN2S2 = (ISimpleBean) server2.getProxy(ISimpleBean.class, APP_NAME + "/http/" + SERVICE_FOR_SHARED_SESSION_SCOPED_BEAN, initCtx); 109 } catch (Exception e) { 110 e.printStackTrace(); throw e; 111 } 112 } 113 114 protected void configureWar(DeploymentBuilder builder) { 115 builder.addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST); 116 builder.addRemoteService(HttpInvokerServiceExporter.class,SERVICE_FOR_SHARED_SESSION_SCOPED_BEAN, "simplebean", ISimpleBean.class); 117 builder.setDispatcherServlet("httpinvoker", "/http/*", DispatcherServlet.class, null, true); 119 builder.addDirectoryOrJARContainingClass(net.sf.cglib.core.Constants.class); 120 } 121 122 } 123 124 127 public static Test suite() { 128 TestSetup setup = new InnerTestSetup(); 129 return setup; 130 } 131 132 } 133 | Popular Tags |