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: * Runs a couple of tests within the same JVM
16: *
17: * @author cer
18: */
19: public class BeanWithSuperclassTest extends
20: AbstractTwoServerDeploymentTest {
21:
22: private static final String REMOTE_SERVICE_NAME = "Singleton";
23: private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory-subclass.xml";
24: private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/singleton-tc-config.xml";
25:
26: private ISingleton singleton1;
27: private ISingleton singleton2;
28:
29: protected void setUp() throws Exception {
30: super .setUp();
31:
32: singleton1 = (ISingleton) server0.getProxy(ISingleton.class,
33: REMOTE_SERVICE_NAME);
34: singleton2 = (ISingleton) server1.getProxy(ISingleton.class,
35: REMOTE_SERVICE_NAME);
36: }
37:
38: public void testSharedField() throws Exception {
39: logger.debug("testing shared fields");
40:
41: assertEquals(singleton1.getCounter(), singleton2.getCounter());
42: singleton1.incrementCounter();
43: assertEquals(singleton1.getCounter(), singleton2.getCounter());
44: singleton2.incrementCounter();
45: assertEquals(singleton2.getCounter(), singleton1.getCounter());
46:
47: logger.debug("!!!! Asserts passed !!!");
48: }
49:
50: public void testTransientField() throws Exception {
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 (BeanWithSuperclassTest.class, CONFIG_FILE_FOR_TEST,
72: "test-singleton");
73: }
74:
75: protected void configureWar(DeploymentBuilder builder) {
76: builder
77: .addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST);
78: builder.addRemoteService(REMOTE_SERVICE_NAME, "singleton",
79: ISingleton.class);
80: }
81:
82: }
83:
84: /**
85: * JUnit test loader entry point
86: */
87: public static Test suite() {
88: TestSetup setup = new SingletonTestSetup();
89: return setup;
90: }
91:
92: }
|