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.extensions.TestSetup;
12: import junit.framework.Test;
13:
14: /**
15: * Test the scenario of WebApplication Context with a parent application context.
16: * The bean defined in the parent application context can be also shared.
17: */
18: public class HierarchicalAppCtxTest extends
19: AbstractTwoServerDeploymentTest {
20:
21: private static final String REMOTE_SERVICE_NAME = "Singleton";
22: private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/singleton-tc-config.xml";
23:
24: private ISingleton singleton1;
25: private ISingleton singleton2;
26:
27: protected void setUp() throws Exception {
28: super .setUp();
29:
30: singleton1 = (ISingleton) server0.getProxy(ISingleton.class,
31: REMOTE_SERVICE_NAME);
32: singleton2 = (ISingleton) server1.getProxy(ISingleton.class,
33: REMOTE_SERVICE_NAME);
34: }
35:
36: public void testSharedField() throws Exception {
37:
38: logger.debug("testing shared fields");
39:
40: assertEquals(singleton1.getCounter(), singleton2.getCounter());
41: singleton1.incrementCounter();
42: assertEquals(singleton1.getCounter(), singleton2.getCounter());
43: singleton2.incrementCounter();
44: assertEquals(singleton2.getCounter(), singleton1.getCounter());
45:
46: logger.debug("!!!! Asserts passed !!!");
47: }
48:
49: public void testTransientField() throws Exception {
50:
51: logger.debug("Testing transient fields");
52: assertEquals("aaa", singleton1.getTransientValue());
53: assertEquals("aaa", singleton2.getTransientValue());
54: singleton1.setTransientValue("s1");
55: assertEquals("aaa", singleton2.getTransientValue());
56: singleton2.setTransientValue("s2");
57: assertEquals("s1", singleton1.getTransientValue());
58: assertEquals("s2", singleton2.getTransientValue());
59: logger.debug("done testing transient fields");
60: }
61:
62: public void testSharedBooleanField() throws Exception {
63: assertTrue(singleton1.toggleBoolean());
64: assertFalse(singleton2.toggleBoolean());
65: assertTrue(singleton1.toggleBoolean());
66: }
67:
68: private static class SingletonTestSetup extends
69: SpringTwoServerTestSetup {
70: private SingletonTestSetup() {
71: super (HierarchicalAppCtxTest.class, CONFIG_FILE_FOR_TEST,
72: "test-singleton");
73: }
74:
75: protected void configureWar(DeploymentBuilder builder) {
76: builder
77: .setParentApplicationContextRef(
78: "/com/tctest/spring/hierarchicalAppCtxTest/beanfactoryRef.xml",
79: "spring.xml");
80: builder
81: .addBeanDefinitionFile("classpath:/com/tctest/spring/hierarchicalAppCtxTest/child-beanfactory.xml");
82: builder.addRemoteService(REMOTE_SERVICE_NAME, "singleton",
83: ISingleton.class);
84: }
85:
86: }
87:
88: /**
89: * JUnit test loader entry point
90: */
91: public static Test suite() {
92: TestSetup setup = new SingletonTestSetup();
93: return setup;
94: }
95: }
|