KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.management.MBeanServerConnection JavaDoc;
11 import javax.management.ObjectName JavaDoc;
12
13 import junit.extensions.TestSetup;
14 import junit.framework.Test;
15
16 /**
17  * Test TC-Spring working with Spring JMX support.
18  *
19  */

20 public class JMXSupportTest extends AbstractTwoServerDeploymentTest {
21
22   public JMXSupportTest() {
23     this.disableForJavaVersion("1.4.2_13");
24     this.disableForJavaVersion("1.4.2_12");
25     this.disableForJavaVersion("1.4.2_11");
26   }
27
28   private static final String JavaDoc REMOTE_SERVICE_NAME = "Singleton";
29   private static final String JavaDoc BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory-jmx.xml";
30   private static final String JavaDoc CONFIG_FILE_FOR_TEST = "/tc-config-files/singleton-tc-config.xml";
31
32   private static ISingleton singleton1;
33   private static ISingleton singleton2;
34   private static MBeanServerConnection JavaDoc mbeanServerConn1;
35   private static MBeanServerConnection JavaDoc mbeanServerConn2;
36
37   public void testJMXSupport() throws Exception JavaDoc {
38
39     logger.debug("testing JMX Support");
40     singleton1.incrementCounter();
41     singleton2.incrementCounter();
42     
43     Integer JavaDoc counter1 = (Integer JavaDoc)mbeanServerConn1.getAttribute(
44         new ObjectName JavaDoc("bean:name=singleton"), "Counter");
45     Integer JavaDoc counter2 = (Integer JavaDoc)mbeanServerConn2.getAttribute(
46         new ObjectName JavaDoc("bean:name=singleton"), "Counter");
47     
48     assertEquals("Expecting multiple increments in singleton", 2, singleton1.getCounter());
49     assertEquals("Expecting multiple increments in singleton", 2, singleton2.getCounter());
50     assertEquals("Expecting multiple increments in mbean", 2, counter1.intValue());
51     assertEquals("Expecting multiple increments in mbean", 2, counter2.intValue());
52
53     logger.debug("!!!! Asserts passed !!!");
54   }
55
56   private static class JMXSupportTestSetup extends TwoSvrSetup {
57     private JMXSupportTestSetup() {
58       super(JMXSupportTest.class, CONFIG_FILE_FOR_TEST, "test-singleton");
59     }
60
61     protected void setUp() throws Exception JavaDoc {
62       try {
63         super.setUp();
64         if (this.shouldContinue) {
65           singleton1 = (ISingleton) server1.getProxy(ISingleton.class, REMOTE_SERVICE_NAME);
66           singleton2 = (ISingleton) server2.getProxy(ISingleton.class, REMOTE_SERVICE_NAME);
67           mbeanServerConn1 = server1.getMBeanServerConnection();
68           mbeanServerConn2 = server2.getMBeanServerConnection();
69         }
70       } catch (Exception JavaDoc e) {
71         e.printStackTrace(); throw e;
72       }
73     }
74
75     protected void configureWar(DeploymentBuilder builder) {
76       builder.addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST);
77       builder.addRemoteService(REMOTE_SERVICE_NAME, "singleton", ISingleton.class);
78     }
79   }
80
81   /**
82    * JUnit test loader entry point
83    */

84   public static Test suite() {
85     TestSetup setup = new JMXSupportTestSetup();
86     return setup;
87   }
88
89 }
90
Popular Tags