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 public class BeanWithSuperclassTest extends AbstractTwoServerDeploymentTest { 19 20 private static final String REMOTE_SERVICE_NAME = "Singleton"; 21 private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory-subclass.xml"; 22 private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/singleton-tc-config.xml"; 23 24 private static ISingleton singleton1; 25 private static ISingleton singleton2; 26 27 public void testSharedField() throws Exception { 28 29 logger.debug("testing shared fields"); 30 31 assertEquals(singleton1.getCounter(), singleton2.getCounter()); 32 singleton1.incrementCounter(); 33 assertEquals(singleton1.getCounter(), singleton2.getCounter()); 34 singleton2.incrementCounter(); 35 assertEquals(singleton2.getCounter(), singleton1.getCounter()); 36 37 logger.debug("!!!! Asserts passed !!!"); 38 } 39 40 public void testTransientField() throws Exception { 41 42 logger.debug("Testing transient fields"); 43 assertEquals("aaa", singleton1.getTransientValue()); 44 assertEquals("aaa", singleton2.getTransientValue()); 45 singleton1.setTransientValue("s1"); 46 assertEquals("aaa", singleton2.getTransientValue()); 47 singleton2.setTransientValue("s2"); 48 assertEquals("s1", singleton1.getTransientValue()); 49 assertEquals("s2", singleton2.getTransientValue()); 50 logger.debug("done testing transient fields"); 51 } 52 53 public void testSharedBooleanField() throws Exception { 54 assertTrue(singleton1.toggleBoolean()); 55 assertFalse(singleton2.toggleBoolean()); 56 assertTrue(singleton1.toggleBoolean()); 57 } 58 59 private static class SingletonTestSetup extends TwoSvrSetup { 60 private SingletonTestSetup() { 61 super(BeanWithSuperclassTest.class, CONFIG_FILE_FOR_TEST, "test-singleton"); 62 } 63 64 protected void setUp() throws Exception { 65 super.setUp(); 66 67 singleton1 = (ISingleton) server1.getProxy(ISingleton.class, REMOTE_SERVICE_NAME); 68 singleton2 = (ISingleton) server2.getProxy(ISingleton.class, REMOTE_SERVICE_NAME); 69 } 70 71 protected void configureWar(DeploymentBuilder builder) { 72 builder.addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST); 73 builder.addRemoteService(REMOTE_SERVICE_NAME, "singleton", ISingleton.class); 74 } 75 76 } 77 78 81 public static Test suite() { 82 TestSetup setup = new SingletonTestSetup(); 83 return setup; 84 } 85 86 } 87 | Popular Tags |