01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tctest.spring.integrationtests.tests;
05:
06: import com.tc.test.server.appserver.deployment.AbstractTwoServerDeploymentTest;
07: import com.tc.test.server.appserver.deployment.DeploymentBuilder;
08: import com.tctest.spring.bean.ISingleton;
09: import com.tctest.spring.integrationtests.SpringTwoServerTestSetup;
10:
11: import junit.framework.Test;
12:
13: /**
14: * Runs a couple of tests within the same JVM
15: */
16: public class AppCtxMatchingTest extends AbstractTwoServerDeploymentTest {
17: private static final String REMOTE_SERVICE_NAME = "Singleton";
18: private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/app-ctx-matching-tc-config.xml";
19:
20: ISingleton singleton1;
21: ISingleton singleton2;
22:
23: protected void setUp() throws Exception {
24: super .setUp();
25:
26: singleton1 = (ISingleton) server0.getProxy(ISingleton.class,
27: REMOTE_SERVICE_NAME);
28: singleton2 = (ISingleton) server1.getProxy(ISingleton.class,
29: REMOTE_SERVICE_NAME);
30: }
31:
32: public void testThatSingletonBeanIsNotDistributed()
33: throws Exception {
34: assertEquals(0, singleton1.getCounter());
35: assertEquals(0, singleton2.getCounter());
36:
37: singleton1.incrementCounter();
38: assertEquals(1, singleton1.getCounter());
39: assertEquals(1, singleton2.getCounter());
40:
41: singleton2.incrementCounter();
42: assertEquals(2, singleton1.getCounter());
43: assertEquals(2, singleton2.getCounter());
44: }
45:
46: private static class SingletonTestSetup extends
47: SpringTwoServerTestSetup {
48: SingletonTestSetup() {
49: super (AppCtxMatchingTest.class, CONFIG_FILE_FOR_TEST,
50: "test-singleton");
51: }
52:
53: protected void configureWar(DeploymentBuilder builder) {
54: builder
55: .addBeanDefinitionFile("classpath:/com/tctest/spring/beanfactory.xml");
56: // builder.addBeanDefinitionFile("classpath:/com/tctest/spring/beanfactory-proxiedbean.xml");
57: builder.addRemoteService(REMOTE_SERVICE_NAME, "singleton",
58: ISingleton.class);
59: }
60:
61: }
62:
63: public static Test suite() {
64: return new SingletonTestSetup();
65: }
66:
67: }
|