001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004:
005: package com.tctest.spring.integrationtests.tests;
006:
007: import com.tc.test.server.appserver.deployment.AbstractTwoServerDeploymentTest;
008: import com.tc.test.server.appserver.deployment.Deployment;
009: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
010: import com.tc.test.server.appserver.deployment.WebApplicationServer;
011: import com.tctest.spring.bean.AppCtxDefBean;
012: import com.tctest.spring.integrationtests.SpringServerTestSetup;
013:
014: import junit.framework.Test;
015: import junit.framework.TestSuite;
016:
017: /**
018: * Test ApplicationContext definition
019: *
020: * LKC-1762: Test: ApplicationContext/Bean definition test
021: * https://jira.terracotta.lan/jira/browse/LKC-1762
022: *
023: * Single definition file
024: * Multiple bean definition files
025: * Include test for circular dependencies between files
026: * Tests verify that AppCtx/BeanFactory ends up being distributed/non-distributed
027: */
028: public class AppCtxDefTest extends AbstractTwoServerDeploymentTest {
029:
030: public static Test suite() {
031: return new AppContextDefinitionTestSetup();
032: }
033:
034: public void testAppCtxDef1local() throws Exception {
035: verifyClustered("appCtxDef1local_beanA", 22);
036: }
037:
038: public void testAppCtxDef1shared() throws Exception {
039: verifyClustered("appCtxDef1shared_beanA", 23);
040: }
041:
042: public void testAppCtxDef2local() throws Exception {
043: verifyClustered("appCtxDef2local_beanB", 32);
044: verifyClustered("appCtxDef2local_beanC", 33);
045: }
046:
047: public void testAppCtxDef2shared() throws Exception {
048: verifyClustered("appCtxDef2shared_beanB", 35);
049: verifyClustered("appCtxDef2shared_beanC", 36);
050: }
051:
052: private void verifyClustered(String service, int n)
053: throws Exception {
054: boolean isLocal = service.indexOf("local") > -1;
055:
056: AppCtxDefBean bean1 = (AppCtxDefBean) server0.getProxy(
057: AppCtxDefBean.class, service);
058: AppCtxDefBean bean2 = (AppCtxDefBean) server1.getProxy(
059: AppCtxDefBean.class, service);
060:
061: bean1.setValue(n);
062: assertTrue("Expected " + (isLocal ? "local " : "shared ")
063: + service, n == bean2.getValue() ? !isLocal : isLocal);
064:
065: bean2.setValue(n + 11);
066: assertTrue("Expected " + (isLocal ? "local " : "shared ")
067: + service, (n + 11) == bean1.getValue() ? !isLocal
068: : isLocal);
069: }
070:
071: private static class AppContextDefinitionTestSetup extends
072: SpringServerTestSetup {
073:
074: private AppContextDefinitionTestSetup() {
075: super (AppCtxDefTest.class);
076: }
077:
078: protected void setUp() throws Exception {
079: super .setUp();
080:
081: if (shouldDisable())
082: return;
083:
084: WebApplicationServer server0 = createServer();
085: WebApplicationServer server1 = createServer();
086:
087: TestSuite suite = (TestSuite) getTest();
088: for (int i = 0; i < suite.testCount(); i++) {
089: AbstractTwoServerDeploymentTest test = (AbstractTwoServerDeploymentTest) suite
090: .testAt(i);
091: test.setServer0(server0);
092: test.setServer1(server1);
093: }
094: }
095:
096: private WebApplicationServer createServer() throws Exception {
097: WebApplicationServer server = getServerManager()
098: .makeWebApplicationServer(
099: "/tc-config-files/appctxdef-tc-config.xml");
100:
101: server.addWarDeployment(
102: createAppCtxDef1war("appCtxDef1local"),
103: "appCtxDef1local");
104: server.addWarDeployment(
105: createAppCtxDef1war("appCtxDef1shared"),
106: "appCtxDef1shared");
107: server.addWarDeployment(
108: createAppCtxDef2war("appCtxDef2local"),
109: "appCtxDef2local");
110: server.addWarDeployment(
111: createAppCtxDef2war("appCtxDef2shared"),
112: "appCtxDef2shared");
113: server.start();
114:
115: return server;
116: }
117:
118: private Deployment createAppCtxDef1war(String warName)
119: throws Exception {
120: return createWarTemplate(warName).addBeanDefinitionFile(
121: "classpath:/com/tctest/spring/appCtxDef1.xml")
122: .addRemoteService(warName + "_beanA", "bean1",
123: AppCtxDefBean.class).makeDeployment();
124: }
125:
126: private Deployment createAppCtxDef2war(String warName)
127: throws Exception {
128: return createWarTemplate(warName)
129: .addBeanDefinitionFile(
130: "classpath:/com/tctest/spring/appCtxDef2a.xml")
131: .addBeanDefinitionFile(
132: "classpath:/com/tctest/spring/appCtxDef2.xml")
133: .addRemoteService(warName + "_beanB", "bean1",
134: AppCtxDefBean.class).addRemoteService(
135: warName + "_beanC", "bean2",
136: AppCtxDefBean.class).makeDeployment();
137: }
138:
139: private DeploymentBuilder createWarTemplate(String warName) {
140: return makeDeploymentBuilder(warName + ".war")
141: .addDirectoryOrJARContainingClass(
142: AppContextDefinitionTestSetup.class)
143: .addDirectoryContainingResource(
144: "/tc-config-files/appctxdef-tc-config.xml");
145: }
146:
147: }
148:
149: }
|