| 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.tctest.spring.bean.ISingleton; 10 import com.tctest.spring.integrationtests.framework.AbstractTwoServerDeploymentTest; 11 import com.tctest.spring.integrationtests.framework.DeploymentBuilder; 12 import com.tctest.spring.integrationtests.framework.ProxyBuilder; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import junit.extensions.TestSetup; 18 import junit.framework.Test; 19 20 21 24 public class SingletonV3Test extends AbstractTwoServerDeploymentTest { 25 26 private static final String REMOTE_SERVICE_NAME = "singletonservice"; 27 private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory.xml"; 28 private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/singleton-tc-config.xml"; 29 30 31 private static ISingleton singleton1; 32 private static ISingleton singleton2; 33 34 public void testSharedField() throws Exception { 35 36 logger.debug("testing shared fields"); 37 38 assertEquals(singleton1.getCounter(), singleton2.getCounter()); 39 singleton1.incrementCounter(); 40 assertEquals(singleton1.getCounter(), singleton2.getCounter()); 41 singleton2.incrementCounter(); 42 assertEquals(singleton2.getCounter(), singleton1.getCounter()); 43 44 logger.debug("!!!! Asserts passed !!!"); 45 } 46 47 public void testTransientField() throws Exception { 48 49 logger.debug("Testing transient fields"); 50 assertEquals("aaa", singleton1.getTransientValue()); 51 assertEquals("aaa", singleton2.getTransientValue()); 52 singleton1.setTransientValue("s1"); 53 assertEquals("aaa", singleton2.getTransientValue()); 54 singleton2.setTransientValue("s2"); 55 assertEquals("s1", singleton1.getTransientValue()); 56 assertEquals("s2", singleton2.getTransientValue()); 57 logger.debug("done testing transient fields"); 58 } 59 60 public void testSharedBooleanField() throws Exception { 61 assertTrue(singleton1.toggleBoolean()); 62 assertFalse(singleton2.toggleBoolean()); 63 assertTrue(singleton1.toggleBoolean()); 64 } 65 66 private static class SingletonTestSetup extends TwoSvrSetup { 67 private static final String APP_NAME = "test-singleton"; 68 69 private SingletonTestSetup() { 70 super(SingletonV3Test.class, CONFIG_FILE_FOR_TEST, APP_NAME); 71 } 72 73 protected void setUp() throws Exception { 74 try { 75 super.setUp(); 76 77 Map initCtx = new HashMap (); 78 initCtx.put(ProxyBuilder.EXPORTER_TYPE_KEY, HttpInvokerServiceExporter.class); 79 singleton1 = (ISingleton) server1.getProxy(ISingleton.class, APP_NAME + "/http/" + REMOTE_SERVICE_NAME, initCtx); 80 singleton2 = (ISingleton) server2.getProxy(ISingleton.class, APP_NAME + "/http/" + REMOTE_SERVICE_NAME, initCtx); 81 } catch(Exception ex) { 82 ex.printStackTrace(); throw ex; 83 } 84 } 85 86 protected void configureWar(DeploymentBuilder builder) { 87 builder.addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST); 88 builder.addRemoteService(HttpInvokerServiceExporter.class,REMOTE_SERVICE_NAME, "singleton", ISingleton.class); 89 builder.setDispatcherServlet("httpinvoker", "/http/*", DispatcherServlet.class, null, true); 90 } 91 92 } 93 94 97 public static Test suite() { 98 TestSetup setup = new SingletonTestSetup(); 99 return setup; 100 } 101 102 } 103 | Popular Tags |