KickJava   Java API By Example, From Geeks To Geeks.

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


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.ISingleton;
7 import com.tctest.spring.integrationtests.framework.AbstractTwoServerDeploymentTest;
8 import com.tctest.spring.integrationtests.framework.DeploymentBuilder;
9
10 import junit.extensions.TestSetup;
11 import junit.framework.Test;
12
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 AbstractTwoServerDeploymentTest {
19
20   private static final String JavaDoc REMOTE_SERVICE_NAME = "Singleton";
21   private static final String JavaDoc CONFIG_FILE_FOR_TEST = "/tc-config-files/singleton-tc-config.xml";
22
23   private static ISingleton singleton1;
24   private static ISingleton singleton2;
25
26   public void testSharedField() throws Exception JavaDoc {
27
28     logger.debug("testing shared fields");
29
30     assertEquals(singleton1.getCounter(), singleton2.getCounter());
31     singleton1.incrementCounter();
32     assertEquals(singleton1.getCounter(), singleton2.getCounter());
33     singleton2.incrementCounter();
34     assertEquals(singleton2.getCounter(), singleton1.getCounter());
35
36     logger.debug("!!!! Asserts passed !!!");
37   }
38
39   public void testTransientField() throws Exception JavaDoc {
40
41     logger.debug("Testing transient fields");
42     assertEquals("aaa", singleton1.getTransientValue());
43     assertEquals("aaa", singleton2.getTransientValue());
44     singleton1.setTransientValue("s1");
45     assertEquals("aaa", singleton2.getTransientValue());
46     singleton2.setTransientValue("s2");
47     assertEquals("s1", singleton1.getTransientValue());
48     assertEquals("s2", singleton2.getTransientValue());
49     logger.debug("done testing transient fields");
50   }
51   
52   public void testSharedBooleanField() throws Exception JavaDoc {
53     assertTrue(singleton1.toggleBoolean());
54     assertFalse(singleton2.toggleBoolean());
55     assertTrue(singleton1.toggleBoolean());
56   }
57
58   private static class SingletonTestSetup extends TwoSvrSetup {
59     private SingletonTestSetup() {
60       super(HierarchicalAppCtxTest.class, CONFIG_FILE_FOR_TEST, "test-singleton");
61     }
62
63     protected void setUp() throws Exception JavaDoc {
64       super.setUp();
65
66       singleton1 = (ISingleton) server1.getProxy(ISingleton.class, REMOTE_SERVICE_NAME);
67       singleton2 = (ISingleton) server2.getProxy(ISingleton.class, REMOTE_SERVICE_NAME);
68     }
69
70     protected void configureWar(DeploymentBuilder builder) {
71       builder.setParentApplicationContextRef("/com/tctest/spring/hierarchicalAppCtxTest/beanfactoryRef.xml", "spring.xml");
72       builder.addBeanDefinitionFile("classpath:/com/tctest/spring/hierarchicalAppCtxTest/child-beanfactory.xml");
73       builder.addRemoteService(REMOTE_SERVICE_NAME, "singleton", ISingleton.class);
74     }
75
76   }
77
78   /**
79    * JUnit test loader entry point
80    */

81   public static Test suite() {
82     TestSetup setup = new SingletonTestSetup();
83     return setup;
84   }
85 }
86
Popular Tags