KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > spring > integrationtests > tests > AppCtxDefTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 /**
18  * Test ApplicationContext definition
19  *
20  * LKC-1762: Test: ApplicationContext/Bean definition test
21  * https://jira.terracotta.lan/jira/browse/LKC-1762
22  *
23  * Single definition file
24  * Multiple bean definition files
25  * Include test for circular dependencies between files
26  * Tests verify that AppCtx/BeanFactory ends up being distributed/non-distributed
27  */

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 JavaDoc {
36     verifyClustered("appCtxDef1local_beanA", 22);
37   }
38   
39   public void testAppCtxDef1shared() throws Exception JavaDoc {
40     verifyClustered("appCtxDef1shared_beanA", 23);
41   }
42   
43   public void testAppCtxDef2local() throws Exception JavaDoc {
44     verifyClustered("appCtxDef2local_beanB", 32);
45     verifyClustered("appCtxDef2local_beanC", 33);
46   }
47
48   public void testAppCtxDef2shared() throws Exception JavaDoc {
49     verifyClustered("appCtxDef2shared_beanB", 35);
50     verifyClustered("appCtxDef2shared_beanC", 36);
51   }
52   
53   
54   private void verifyClustered(String JavaDoc service, int n) throws Exception JavaDoc {
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 JavaDoc {
75       super.setUp();
76
77       server1 = createServer();
78       server2 = createServer();
79     }
80
81     private WebApplicationServer createServer() throws Exception JavaDoc {
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 JavaDoc warName) throws Exception JavaDoc {
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 JavaDoc warName) throws Exception JavaDoc {
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 JavaDoc 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