1 4 package com.tctest.spring.integrationtests.tests; 5 6 import com.tctest.spring.bean.ISingleton; 7 import com.tctest.spring.integrationtests.framework.AbstractTwoServerDeploymentTest; 8 import com.tctest.spring.integrationtests.framework.DeploymentBuilder; 9 10 import junit.extensions.TestSetup; 11 import junit.framework.Test; 12 13 18 21 public class SingletonV2Test extends AbstractTwoServerDeploymentTest { 22 23 private static final String REMOTE_SERVICE_NAME = "Singleton"; 24 private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory.xml"; 25 private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/singleton-tc-config.xml"; 26 27 private static ISingleton singleton1; 28 private static ISingleton singleton2; 29 30 public void testSharedField() throws Exception { 31 32 logger.debug("testing shared fields"); 33 34 assertEquals(singleton1.getCounter(), singleton2.getCounter()); 35 singleton1.incrementCounter(); 36 assertEquals(singleton1.getCounter(), singleton2.getCounter()); 37 singleton2.incrementCounter(); 38 assertEquals(singleton2.getCounter(), singleton1.getCounter()); 39 40 logger.debug("!!!! Asserts passed !!!"); 41 } 42 43 public void testTransientField() throws Exception { 44 45 logger.debug("Testing transient fields"); 46 assertEquals("aaa", singleton1.getTransientValue()); 47 assertEquals("aaa", singleton2.getTransientValue()); 48 singleton1.setTransientValue("s1"); 49 assertEquals("aaa", singleton2.getTransientValue()); 50 singleton2.setTransientValue("s2"); 51 assertEquals("s1", singleton1.getTransientValue()); 52 assertEquals("s2", singleton2.getTransientValue()); 53 logger.debug("done testing transient fields"); 54 } 55 56 public void testSharedBooleanField() throws Exception { 57 assertTrue(singleton1.toggleBoolean()); 58 assertFalse(singleton2.toggleBoolean()); 59 assertTrue(singleton1.toggleBoolean()); 60 } 61 62 private static class SingletonTestSetup extends TwoSvrSetup { 63 private SingletonTestSetup() { 64 super(SingletonV2Test.class, CONFIG_FILE_FOR_TEST, "test-singleton"); 65 } 66 67 protected void setUp() throws Exception { 68 try { 69 super.setUp(); 70 71 singleton1 = (ISingleton) server1.getProxy(ISingleton.class, REMOTE_SERVICE_NAME); 72 singleton2 = (ISingleton) server2.getProxy(ISingleton.class, REMOTE_SERVICE_NAME); 73 } catch (Exception e) { 74 e.printStackTrace(); 75 throw e; 76 } 77 } 78 79 protected void configureWar(DeploymentBuilder builder) { 80 builder.addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST); 81 builder.addRemoteService(REMOTE_SERVICE_NAME, "singleton", ISingleton.class); 82 } 83 84 } 85 86 89 public static Test suite() { 90 TestSetup setup = new SingletonTestSetup(); 91 return setup; 92 } 93 94 } 95 | Popular Tags |