1 4 package com.tctest.spring.integrationtests.tests; 5 6 import com.tctest.spring.bean.ISimpleInitializingSingleton; 7 import com.tctest.spring.bean.SimpleInitializingSingleton; 8 import com.tctest.spring.integrationtests.framework.AbstractTwoServerDeploymentTest; 9 import com.tctest.spring.integrationtests.framework.DeploymentBuilder; 10 11 import junit.extensions.TestSetup; 12 import junit.framework.Test; 13 14 21 public class InitializingBean2Test 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-init2.xml"; 25 private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/init2-tc-config.xml"; 26 27 private static ISimpleInitializingSingleton singleton1; 28 private static ISimpleInitializingSingleton singleton2; 29 30 public void testInitialization() throws Exception { 31 32 logger.debug("testing initialization"); 33 34 assertEquals("Pre-condition check failed.", SimpleInitializingSingleton.ME, singleton1.getName()); assertEquals("Pre-condition check failed.", SimpleInitializingSingleton.ME, singleton1.getName()); 38 long id1 = singleton1.getId(); 39 long id2 = singleton2.getId(); 40 long innerId1 = singleton1.getInnerId(); 41 long innerId2 = singleton2.getInnerId(); 42 43 assertEquals(id1, innerId1); 45 assertTrue(singleton1.isTheSameInstance()); 46 47 assertEquals(id2, innerId2); 52 assertTrue(id1!=id2); 53 assertTrue("Failed to verify that afterPropertiesSet is invoked on the shared bean", singleton2.isTheSameInstance()); 55 56 logger.debug("!!!! Asserts passed !!!"); 57 } 58 59 private static class InitializingBean2Setup extends TwoSvrSetup { 60 private InitializingBean2Setup() { 61 super(InitializingBean2Test.class, CONFIG_FILE_FOR_TEST, "test-initializingbean2"); 62 } 63 64 protected void setUp() throws Exception { 65 super.setUp(); 66 67 singleton1 = (ISimpleInitializingSingleton) server1.getProxy(ISimpleInitializingSingleton.class, REMOTE_SERVICE_NAME); 68 singleton2 = (ISimpleInitializingSingleton) server2.getProxy(ISimpleInitializingSingleton.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, "distributedInitBeanProxy", ISimpleInitializingSingleton.class); 74 } 75 76 } 77 78 81 public static Test suite() { 82 TestSetup setup = new InitializingBean2Setup(); 83 return setup; 84 } 85 86 } 87 | Popular Tags |