1 4 package com.tctest.spring.integrationtests.tests; 5 6 import com.tctest.spring.bean.ISimpleBean; 7 import com.tctest.spring.integrationtests.framework.AbstractTwoServerDeploymentTest; 8 import com.tctest.spring.integrationtests.framework.DeploymentBuilder; 9 10 import java.util.HashSet ; 11 import java.util.Set ; 12 13 import junit.extensions.TestSetup; 14 import junit.framework.Test; 15 16 25 public class ReferenceAndReplicationTest extends AbstractTwoServerDeploymentTest { 26 27 private static final String SHAREDPARENT_SERVICE_NAME = "ShareParent"; 28 private static final String LOCALCHILD1_SERVICE_NAME = "LocalChild1"; 29 private static final String LOCALCHILD2_SERVICE_NAME = "LocalChild2"; 30 private static final String LOCALCHILD3_SERVICE_NAME = "LocalChild3"; 31 private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory-referenceandreplication.xml"; 32 private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/referenceandreplication-tc-config.xml"; 33 34 private static ISimpleBean sharedParentN1; 36 private static ISimpleBean localChild1N1; 37 private static ISimpleBean localChild2N1; 38 private static ISimpleBean localChild3N1; 39 40 private static ISimpleBean sharedParentN2; 42 private static ISimpleBean localChild1N2; 43 private static ISimpleBean localChild2N2; 44 private static ISimpleBean localChild3N2; 45 46 public void testReplication() throws Exception { 47 logger.debug("testing replication of shared spring bean"); 48 long id2 = sharedParentN2.getId(); 50 long id1 = sharedParentN1.getId(); 51 52 assertFalse("Pre-condition check failed" , id1 == id2); 53 54 long timeStamp1 = sharedParentN1.getTimeStamp(); 55 long timeStamp2 = sharedParentN2.getTimeStamp(); 56 long timeStampMin = timeStamp1 < timeStamp2 ? timeStamp1 : timeStamp2; 57 58 59 assertEquals("Shared field replication failed: " + sharedParentN1.getSharedId(), timeStampMin, sharedParentN1.getSharedId()); 63 assertEquals("Shared field replication failed: " + sharedParentN2.getSharedId(), timeStampMin, sharedParentN2.getSharedId()); 64 65 assertNull("", sharedParentN2.getField()); 67 sharedParentN1.setField("" + id1); 68 assertEquals("Shared field replication failed: " + sharedParentN2.getField(), "" + id1, sharedParentN2.getField()); 69 70 assertNull("Pre-condition check failed", sharedParentN1.getTransientField()); 72 assertNull("Pre-condition check failed", sharedParentN2.getTransientField()); 73 sharedParentN1.setTransientField("" + id1); 74 sharedParentN2.setTransientField("" + id2); 75 assertEquals("Unexpected field replication: " + sharedParentN1.getTransientField(), "" + id1, sharedParentN1.getTransientField()); 76 assertEquals("Unexpected field replication: " + sharedParentN2.getTransientField(), "" + id2, sharedParentN2.getTransientField()); 77 78 assertNull("Pre-condition check failed", sharedParentN1.getDsoTransientField()); 80 assertNull("Pre-condition check failed", sharedParentN2.getDsoTransientField()); 81 sharedParentN1.setDsoTransientField("" + id1); 82 sharedParentN2.setDsoTransientField("" + id2); 83 assertEquals("Unexpected field replication: " + sharedParentN1.getDsoTransientField(), "" + id1, sharedParentN1.getDsoTransientField()); 84 assertEquals("Unexpected field replication: " + sharedParentN2.getDsoTransientField(), "" + id2, sharedParentN2.getDsoTransientField()); 85 86 assertNull("Pre-condition check failed", sharedParentN1.getStaticField()); 88 assertNull("Pre-condition check failed", sharedParentN2.getStaticField()); 89 sharedParentN1.setStaticField("" + id1); 90 sharedParentN2.setStaticField("" + id2); 91 assertEquals("Unexpected field replication: " + sharedParentN1.getStaticField(), "" + id1, sharedParentN1.getStaticField()); 92 assertEquals("Unexpected field replication: " + sharedParentN2.getStaticField(), "" + id2, sharedParentN2.getStaticField()); 93 94 logger.debug("!!!! Asserts passed !!!"); 95 } 96 97 public void testBeanReference() throws Exception { 98 logger.debug("testing shared bean reference other beans"); 99 100 long id2 = sharedParentN2.getId(); 102 long id1 = sharedParentN1.getId(); 103 104 assertFalse("Pre-condition check failed" , id1 == id2); 105 106 Set idSet = new HashSet (); 107 108 long id11 = localChild1N1.getId(); idSet.add(new Long (id11)); 109 long id21 = localChild2N1.getId(); idSet.add(new Long (id21)); 110 long id31 = localChild3N1.getId(); idSet.add(new Long (id31)); 111 long id12 = localChild1N2.getId(); idSet.add(new Long (id12)); 112 long id22 = localChild2N2.getId(); idSet.add(new Long (id22)); 113 long id32 = localChild3N2.getId(); idSet.add(new Long (id32)); 114 115 assertEquals("Pre-condition check failed: " + idSet, 6, idSet.size()); 116 117 126 localChild2N1.setField("localChild2N1"); 128 localChild2N2.setField("localChild2N2"); 129 assertEquals("Unexcpected field replication: " + localChild2N1.getField(), "localChild2N1", localChild2N1.getField()); 130 assertEquals("Unexcpected field replication: " + localChild2N2.getField(), "localChild2N2", localChild2N2.getField()); 131 132 localChild3N1.setField("localChild3N1"); 134 localChild3N2.setField("localChild3N2"); 135 assertEquals("Unexcpected field replication: " + localChild3N1.getField(), "localChild3N1", localChild3N1.getField()); 136 assertEquals("Unexcpected field replication: " + localChild3N2.getField(), "localChild3N2", localChild3N2.getField()); 137 138 logger.debug("!!!! Asserts passed !!!"); 139 } 140 141 private static class InnerTestSetup extends TwoSvrSetup { 142 private InnerTestSetup() { 143 super(ReferenceAndReplicationTest.class, CONFIG_FILE_FOR_TEST, "test-referenceandreplication"); 144 } 145 146 protected void setUp() throws Exception { 147 super.setUp(); 148 localChild1N1 = (ISimpleBean) server1.getProxy(ISimpleBean.class, LOCALCHILD1_SERVICE_NAME); 150 localChild2N1 = (ISimpleBean) server1.getProxy(ISimpleBean.class, LOCALCHILD2_SERVICE_NAME); 151 localChild3N1 = (ISimpleBean) server1.getProxy(ISimpleBean.class, LOCALCHILD3_SERVICE_NAME); 152 sharedParentN1 = (ISimpleBean) server1.getProxy(ISimpleBean.class, SHAREDPARENT_SERVICE_NAME); 153 localChild1N2 = (ISimpleBean) server2.getProxy(ISimpleBean.class, LOCALCHILD1_SERVICE_NAME); 155 localChild2N2 = (ISimpleBean) server2.getProxy(ISimpleBean.class, LOCALCHILD2_SERVICE_NAME); 156 localChild3N2 = (ISimpleBean) server2.getProxy(ISimpleBean.class, LOCALCHILD3_SERVICE_NAME); 157 sharedParentN2 = (ISimpleBean) server2.getProxy(ISimpleBean.class, SHAREDPARENT_SERVICE_NAME); 158 } 159 160 protected void configureWar(DeploymentBuilder builder) { 161 builder.addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST); 162 builder.addRemoteService(SHAREDPARENT_SERVICE_NAME, "sharedParent", ISimpleBean.class); 163 builder.addRemoteService(LOCALCHILD1_SERVICE_NAME, "localChild1", ISimpleBean.class); 164 builder.addRemoteService(LOCALCHILD2_SERVICE_NAME, "localChild2", ISimpleBean.class); 165 builder.addRemoteService(LOCALCHILD3_SERVICE_NAME, "localChild3", ISimpleBean.class); 166 } 167 } 168 169 172 public static Test suite() { 173 TestSetup setup = new InnerTestSetup(); 174 return setup; 175 } 176 } 177 | Popular Tags |