KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.tctest.spring.integrationtests.tests;
5
6 import com.tctest.spring.bean.IMasterBean;
7 import com.tctest.spring.bean.ISingleton;
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
13 import junit.framework.Test;
14
15 /**
16  * Test application context loaded from multiple bean configs.
17  *
18  * @author Eugene Kuleshov
19  */

20 public class MultifileContextTest extends AbstractTwoServerDeploymentTest {
21
22   private static final String JavaDoc REMOTE_SERVICE_NAME = "MasterService";
23   
24   
25   public void testBeanFromMultipleContexts() throws Exception JavaDoc {
26     server1.start();
27     server2.start();
28
29     try {
30       
31     IMasterBean masterBean1 = (IMasterBean) server1.getProxy(IMasterBean.class, REMOTE_SERVICE_NAME);
32     IMasterBean masterBean2 = (IMasterBean) server2.getProxy(IMasterBean.class, REMOTE_SERVICE_NAME);
33
34     ISingleton singleton1 = masterBean1.getSingleton();
35     ISingleton singleton2 = masterBean2.getSingleton();
36     
37     assertNotNull(singleton1);
38     assertNotNull(singleton2);
39     
40     } finally {
41       server1.stop();
42       server2.stop();
43     }
44   }
45
46
47   private static class MultipleBeanDefsTestSetup extends ServerTestSetup {
48
49     private MultipleBeanDefsTestSetup() {
50       super(MultifileContextTest.class);
51     }
52
53     protected void setUp() throws Exception JavaDoc {
54       super.setUp();
55       
56       String JavaDoc tcConfigFile = "/tc-config-files/multifile-context-tc-config.xml";
57       String JavaDoc context = "test-multifile-context";
58
59       DeploymentBuilder builder = super.makeDeploymentBuilder(context+".war");
60       
61       builder.addDirectoryOrJARContainingClass(MultifileContextTest.class);
62       builder.addDirectoryContainingResource(tcConfigFile);
63       
64       builder.addBeanDefinitionFile("/WEB-INF/multifile-context-factory*.xml");
65       
66       builder.addResource("/com/tctest/spring", "multifile-context-factory1.xml", "/WEB-INF/");
67       builder.addResource("/com/tctest/spring", "multifile-context-factory2.xml", "/WEB-INF/");
68       
69       builder.addRemoteService(REMOTE_SERVICE_NAME, "distributedMasterBean", IMasterBean.class);
70       
71       Deployment warPath = builder.makeDeployment();
72
73       server1 = sm.makeWebApplicationServer(tcConfigFile);
74       server1.addWarDeployment(warPath, context);
75       
76       server2 = sm.makeWebApplicationServer(tcConfigFile);
77       server2.addWarDeployment(warPath, context);
78     }
79
80   }
81
82   
83   public static Test suite() {
84     return new MultipleBeanDefsTestSetup();
85   }
86
87 }
88
Popular Tags