KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
7 import org.springframework.web.servlet.DispatcherServlet;
8
9 import com.tctest.spring.bean.ISingleton;
10 import com.tctest.spring.integrationtests.framework.AbstractTwoServerDeploymentTest;
11 import com.tctest.spring.integrationtests.framework.DeploymentBuilder;
12 import com.tctest.spring.integrationtests.framework.ProxyBuilder;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import junit.extensions.TestSetup;
18 import junit.framework.Test;
19
20
21 /**
22  * Serve as an example for using the HttpInvoker framework.
23  */

24 public class SingletonV3Test extends AbstractTwoServerDeploymentTest {
25
26   private static final String JavaDoc REMOTE_SERVICE_NAME = "singletonservice";
27   private static final String JavaDoc BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory.xml";
28   private static final String JavaDoc CONFIG_FILE_FOR_TEST = "/tc-config-files/singleton-tc-config.xml";
29
30
31   private static ISingleton singleton1;
32   private static ISingleton singleton2;
33
34   public void testSharedField() throws Exception JavaDoc {
35
36     logger.debug("testing shared fields");
37
38     assertEquals(singleton1.getCounter(), singleton2.getCounter());
39     singleton1.incrementCounter();
40     assertEquals(singleton1.getCounter(), singleton2.getCounter());
41     singleton2.incrementCounter();
42     assertEquals(singleton2.getCounter(), singleton1.getCounter());
43
44     logger.debug("!!!! Asserts passed !!!");
45   }
46
47   public void testTransientField() throws Exception JavaDoc {
48
49     logger.debug("Testing transient fields");
50     assertEquals("aaa", singleton1.getTransientValue());
51     assertEquals("aaa", singleton2.getTransientValue());
52     singleton1.setTransientValue("s1");
53     assertEquals("aaa", singleton2.getTransientValue());
54     singleton2.setTransientValue("s2");
55     assertEquals("s1", singleton1.getTransientValue());
56     assertEquals("s2", singleton2.getTransientValue());
57     logger.debug("done testing transient fields");
58   }
59
60   public void testSharedBooleanField() throws Exception JavaDoc {
61     assertTrue(singleton1.toggleBoolean());
62     assertFalse(singleton2.toggleBoolean());
63     assertTrue(singleton1.toggleBoolean());
64   }
65
66   private static class SingletonTestSetup extends TwoSvrSetup {
67     private static final String JavaDoc APP_NAME = "test-singleton";
68
69     private SingletonTestSetup() {
70       super(SingletonV3Test.class, CONFIG_FILE_FOR_TEST, APP_NAME);
71     }
72
73     protected void setUp() throws Exception JavaDoc {
74       try {
75         super.setUp();
76         
77         Map JavaDoc initCtx = new HashMap JavaDoc();
78         initCtx.put(ProxyBuilder.EXPORTER_TYPE_KEY, HttpInvokerServiceExporter.class);
79         singleton1 = (ISingleton) server1.getProxy(ISingleton.class, APP_NAME + "/http/" + REMOTE_SERVICE_NAME, initCtx);
80         singleton2 = (ISingleton) server2.getProxy(ISingleton.class, APP_NAME + "/http/" + REMOTE_SERVICE_NAME, initCtx);
81       } catch(Exception JavaDoc ex) {
82         ex.printStackTrace(); throw ex;
83       }
84     }
85
86     protected void configureWar(DeploymentBuilder builder) {
87       builder.addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST);
88       builder.addRemoteService(HttpInvokerServiceExporter.class,REMOTE_SERVICE_NAME, "singleton", ISingleton.class);
89       builder.setDispatcherServlet("httpinvoker", "/http/*", DispatcherServlet.class, null, true);
90     }
91
92   }
93
94   /**
95    * JUnit test loader entry point
96    */

97   public static Test suite() {
98     TestSetup setup = new SingletonTestSetup();
99     return setup;
100   }
101
102 }
103
Popular Tags