KickJava   Java API By Example, From Geeks To Geeks.

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


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.FooService;
7 import com.tctest.spring.bean.ISingleton;
8 import com.tctest.spring.integrationtests.framework.AbstractDeploymentTest;
9 import com.tctest.spring.integrationtests.framework.Deployment;
10 import com.tctest.spring.integrationtests.framework.DeploymentBuilder;
11 import com.tctest.spring.integrationtests.framework.Server;
12 import com.tctest.spring.integrationtests.framework.WebApplicationServer;
13
14 /**
15  * Verify various issues with deploying applications
16  */

17 public class DeploymentTest extends AbstractDeploymentTest {
18
19   private static final String JavaDoc FOO_SERVICE_NAME = "Foo";
20   private static final String JavaDoc SINGLETON_SERVICE_NAME = "Singleton";
21   private Deployment singletonWAR;
22   private Deployment fooServiceWAR;
23
24   protected void setUp() throws Exception JavaDoc {
25     super.setUp();
26     singletonWAR = makeSingletonWAR();
27     fooServiceWAR = makeFooServiceWAR();
28   }
29
30   protected void runTest() throws Throwable JavaDoc {
31     System.err.println("Running test method: " + this.getName());
32     super.runTest();
33   }
34
35   private Deployment makeSingletonWAR() throws Exception JavaDoc {
36     DeploymentBuilder builder = makeDeploymentBuilder("test-singleton.war");
37     builder.addBeanDefinitionFile("classpath:/com/tctest/spring/beanfactory.xml");
38     builder.addRemoteService(SINGLETON_SERVICE_NAME, "singleton", ISingleton.class);
39     builder.addDirectoryOrJARContainingClass(ISingleton.class);
40     builder.addDirectoryContainingResource("/tc-config-files/singleton-tc-config.xml");
41     return builder.makeDeployment();
42   }
43
44   private Deployment makeFooServiceWAR() throws Exception JavaDoc {
45     DeploymentBuilder builder = makeDeploymentBuilder("test-parent-child.war");
46     builder.addBeanDefinitionFile("classpath:/com/tctest/spring/beanfactory-parent-child.xml");
47     builder.addRemoteService(FOO_SERVICE_NAME, "service1", FooService.class);
48     builder.addDirectoryOrJARContainingClass(ISingleton.class);
49     builder.addDirectoryContainingResource("/tc-config-files/singleton-tc-config.xml");
50     return builder.makeDeployment();
51   }
52
53   public void testStartAndStopOneWebAppAndThenStartAnother() throws Exception JavaDoc {
54     startPingAndStop("test-singleton", singletonWAR, "/tc-config-files/singleton-tc-config.xml",
55                      new TestServerCallback() {
56                        public void test(Server server) throws Exception JavaDoc {
57                          ISingleton singleton1 = (ISingleton) server.getProxy(ISingleton.class, SINGLETON_SERVICE_NAME);
58                          singleton1.incrementCounter();
59
60                        }
61                      });
62
63     startPingAndStop("test-parent-child", fooServiceWAR, "/tc-config-files/parent-child-tc-config.xml",
64                      new TestServerCallback() {
65                        public void test(Server server) throws Exception JavaDoc {
66                          FooService foo = (FooService) server.getProxy(FooService.class, FOO_SERVICE_NAME);
67                          foo.serviceMethod();
68                        }
69                      });
70   }
71
72   private void startPingAndStop(String JavaDoc context, Deployment warFile, String JavaDoc tcConfigPath, TestServerCallback testCallback)
73       throws Exception JavaDoc {
74     WebApplicationServer server = makeWebApplicationServer(tcConfigPath);
75     server.addWarDeployment(warFile, context);
76     server.start();
77
78     testCallback.test(server);
79
80     server.stopIgnoringExceptions();
81   }
82
83   public void testDeployingTwoWARsOneDistributedOneNot() throws Exception JavaDoc {
84     Server server1 = makeServerWithTwoWARsOneDistributed();
85     Server server2 = makeServerWithTwoWARsOneDistributed();
86
87     server1.start();
88     server2.start();
89
90     SingletonStateUtil.assertSingletonShared(server1, server2, SINGLETON_SERVICE_NAME);
91
92     assertFooServiceTransient(server1, server2);
93   }
94
95   private void assertFooServiceTransient(Server server1, Server server2) throws Exception JavaDoc {
96     FooService foo1a = (FooService) server1.getProxy(FooService.class, FOO_SERVICE_NAME);
97     FooService foo2a = (FooService) server2.getProxy(FooService.class, FOO_SERVICE_NAME);
98     assertEquals("rawValue-0", foo1a.serviceMethod());
99     assertEquals("rawValue-0", foo2a.serviceMethod());
100   }
101
102   private Server makeServerWithTwoWARsOneDistributed() throws Exception JavaDoc {
103     return makeWebApplicationServer("/tc-config-files/singleton-tc-config.xml").addWarDeployment(singletonWAR,
104                                                                                                  "test-singleton")
105         .addWarDeployment(fooServiceWAR, "test-parent-child");
106   }
107
108   public void testDeployingTwoDistributedWARs() throws Exception JavaDoc {
109     Server server1 = makeServerWithTwoDistributedWARs();
110     Server server2 = makeServerWithTwoDistributedWARs();
111
112     server1.start();
113     server2.start();
114
115     SingletonStateUtil.assertSingletonShared(server1, server2, SINGLETON_SERVICE_NAME);
116
117     assertFooServiceShared(server1, server2);
118   }
119
120   private void assertFooServiceShared(Server server1, Server server2) throws Exception JavaDoc {
121     FooService foo1a = (FooService) server1.getProxy(FooService.class, FOO_SERVICE_NAME);
122     FooService foo2a = (FooService) server2.getProxy(FooService.class, FOO_SERVICE_NAME);
123     assertEquals("rawValue-0", foo1a.serviceMethod());
124     assertEquals("rawValue-1", foo2a.serviceMethod());
125   }
126
127   private Server makeServerWithTwoDistributedWARs() throws Exception JavaDoc {
128     return makeWebApplicationServer("/tc-config-files/singleton-parent-child-tc-config.xml")
129         .addWarDeployment(singletonWAR, "test-singleton").addWarDeployment(fooServiceWAR, "test-parent-child");
130   }
131
132 }
133
Popular Tags