1 4 5 package com.tctest.spring.integrationtests.tests; 6 7 import com.tctest.spring.bean.AppCtxDefBean; 8 import com.tctest.spring.integrationtests.framework.AbstractTwoServerDeploymentTest; 9 import com.tctest.spring.integrationtests.framework.Deployment; 10 import com.tctest.spring.integrationtests.framework.DeploymentBuilder; 11 import com.tctest.spring.integrationtests.framework.ServerTestSetup; 12 import com.tctest.spring.integrationtests.framework.WebApplicationServer; 13 14 import junit.framework.Test; 15 16 17 28 public class AppCtxDefTest extends AbstractTwoServerDeploymentTest { 29 30 public static Test suite() { 31 return new AppContextDefinitionTestSetup(); 32 } 33 34 35 public void testAppCtxDef1local() throws Exception { 36 verifyClustered("appCtxDef1local_beanA", 22); 37 } 38 39 public void testAppCtxDef1shared() throws Exception { 40 verifyClustered("appCtxDef1shared_beanA", 23); 41 } 42 43 public void testAppCtxDef2local() throws Exception { 44 verifyClustered("appCtxDef2local_beanB", 32); 45 verifyClustered("appCtxDef2local_beanC", 33); 46 } 47 48 public void testAppCtxDef2shared() throws Exception { 49 verifyClustered("appCtxDef2shared_beanB", 35); 50 verifyClustered("appCtxDef2shared_beanC", 36); 51 } 52 53 54 private void verifyClustered(String service, int n) throws Exception { 55 boolean isLocal = service.indexOf("local")>-1; 56 57 AppCtxDefBean bean1 = (AppCtxDefBean) server1.getProxy(AppCtxDefBean.class, service); 58 AppCtxDefBean bean2 = (AppCtxDefBean) server2.getProxy(AppCtxDefBean.class, service); 59 60 bean1.setValue(n); 61 assertTrue("Expected "+(isLocal ? "local " : "shared ")+service, n==bean2.getValue() ? !isLocal : isLocal); 62 63 bean2.setValue(n+11); 64 assertTrue("Expected "+(isLocal ? "local " : "shared ")+service, (n+11)==bean1.getValue() ? !isLocal : isLocal); 65 } 66 67 68 private static class AppContextDefinitionTestSetup extends ServerTestSetup { 69 70 private AppContextDefinitionTestSetup() { 71 super(AppCtxDefTest.class); 72 } 73 74 protected void setUp() throws Exception { 75 super.setUp(); 76 77 server1 = createServer(); 78 server2 = createServer(); 79 } 80 81 private WebApplicationServer createServer() throws Exception { 82 WebApplicationServer server = sm.makeWebApplicationServer("/tc-config-files/appctxdef-tc-config.xml"); 83 84 server.addWarDeployment(createAppCtxDef1war("appCtxDef1local"), "appCtxDef1local"); 85 server.addWarDeployment(createAppCtxDef1war("appCtxDef1shared"), "appCtxDef1shared"); 86 server.addWarDeployment(createAppCtxDef2war("appCtxDef2local"), "appCtxDef2local"); 87 server.addWarDeployment(createAppCtxDef2war("appCtxDef2shared"), "appCtxDef2shared"); 88 server.start(); 89 90 return server; 91 } 92 93 private Deployment createAppCtxDef1war(String warName) throws Exception { 94 return createWarTemplate(warName) 95 .addBeanDefinitionFile("classpath:/com/tctest/spring/appCtxDef1.xml") 96 .addRemoteService(warName+"_beanA", "bean1", AppCtxDefBean.class) 97 .makeDeployment(); 98 } 99 100 private Deployment createAppCtxDef2war(String warName) throws Exception { 101 return createWarTemplate(warName) 102 .addBeanDefinitionFile("classpath:/com/tctest/spring/appCtxDef2a.xml") 103 .addBeanDefinitionFile("classpath:/com/tctest/spring/appCtxDef2.xml") 104 .addRemoteService(warName+"_beanB", "bean1", AppCtxDefBean.class) 105 .addRemoteService(warName+"_beanC", "bean2", AppCtxDefBean.class) 106 .makeDeployment(); 107 } 108 109 private DeploymentBuilder createWarTemplate(String warName) { 110 return makeDeploymentBuilder(warName+".war") 111 .addDirectoryOrJARContainingClass(AppContextDefinitionTestSetup.class) 112 .addDirectoryContainingResource("/tc-config-files/appctxdef-tc-config.xml"); 113 } 114 115 } 116 117 } 118 119 | Popular Tags |