KickJava   Java API By Example, From Geeks To Geeks.

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


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.framework.Test;
11
12 /**
13  * Runs a couple of tests within the same JVM
14  */

15 public class AppCtxMatchingTest extends AbstractTwoServerDeploymentTest {
16   private static final String JavaDoc REMOTE_SERVICE_NAME = "Singleton";
17   private static final String JavaDoc CONFIG_FILE_FOR_TEST = "/tc-config-files/app-ctx-matching-tc-config.xml";
18
19   static ISingleton singleton1;
20   static ISingleton singleton2;
21
22   public void testThatSingletonBeanIsNotDistributed() throws Exception JavaDoc {
23     assertEquals(0, singleton1.getCounter());
24     assertEquals(0, singleton2.getCounter());
25     
26     singleton1.incrementCounter();
27     assertEquals(1, singleton1.getCounter());
28     assertEquals(1, singleton2.getCounter());
29     
30     singleton2.incrementCounter();
31     assertEquals(2, singleton1.getCounter());
32     assertEquals(2, singleton2.getCounter());
33   }
34
35   private static class SingletonTestSetup extends TwoSvrSetup {
36     SingletonTestSetup() {
37       super(AppCtxMatchingTest.class, CONFIG_FILE_FOR_TEST, "test-singleton");
38     }
39
40     protected void setUp() throws Exception JavaDoc {
41       super.setUp();
42
43       singleton1 = (ISingleton) server1.getProxy(ISingleton.class, REMOTE_SERVICE_NAME);
44       singleton2 = (ISingleton) server2.getProxy(ISingleton.class, REMOTE_SERVICE_NAME);
45     }
46
47     protected void configureWar(DeploymentBuilder builder) {
48       builder.addBeanDefinitionFile("classpath:/com/tctest/spring/beanfactory.xml");
49       // builder.addBeanDefinitionFile("classpath:/com/tctest/spring/beanfactory-proxiedbean.xml");
50
builder.addRemoteService(REMOTE_SERVICE_NAME, "singleton", ISingleton.class);
51     }
52
53   }
54
55   /**
56    * JUnit test loader entry point
57    */

58   public static Test suite() {
59     return new SingletonTestSetup();
60   }
61
62 }
63
Popular Tags