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 javax.management.MBeanServerConnection;
12: import javax.management.ObjectName;
13:
14: import junit.framework.Test;
15:
16: /**
17: * Test TC-Spring working with Spring JMX support.
18: */
19: public class JMXSupportTest extends AbstractTwoServerDeploymentTest {
20:
21: public JMXSupportTest() {
22: this .disableForJavaVersion("1.4.2_(\\d)+");
23: }
24:
25: private static final String REMOTE_SERVICE_NAME = "Singleton";
26: private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory-jmx.xml";
27: private static final String CONFIG_FILE_FOR_TEST = "/tc-config-files/singleton-tc-config.xml";
28:
29: private static ISingleton singleton1;
30: private static ISingleton singleton2;
31: private static MBeanServerConnection mbeanServerConn1;
32: private static MBeanServerConnection mbeanServerConn2;
33:
34: public void testJMXSupport() throws Exception {
35: logger.debug("testing JMX Support");
36: singleton1.incrementCounter();
37: singleton2.incrementCounter();
38:
39: Integer counter1 = (Integer) mbeanServerConn1.getAttribute(
40: new ObjectName("bean:name=singleton"), "Counter");
41: Integer counter2 = (Integer) mbeanServerConn2.getAttribute(
42: new ObjectName("bean:name=singleton"), "Counter");
43:
44: assertEquals("Expecting multiple increments in singleton", 2,
45: singleton1.getCounter());
46: assertEquals("Expecting multiple increments in singleton", 2,
47: singleton2.getCounter());
48: assertEquals("Expecting multiple increments in mbean", 2,
49: counter1.intValue());
50: assertEquals("Expecting multiple increments in mbean", 2,
51: counter2.intValue());
52:
53: logger.debug("!!!! Asserts passed !!!");
54: }
55:
56: private static class JMXSupportTestSetup extends
57: SpringTwoServerTestSetup {
58: private JMXSupportTestSetup() {
59: super (JMXSupportTest.class, CONFIG_FILE_FOR_TEST,
60: "test-singleton");
61: }
62:
63: protected void setUp() throws Exception {
64: super .setUp();
65:
66: if (shouldDisable())
67: return;
68:
69: try {
70: singleton1 = (ISingleton) server0.getProxy(
71: ISingleton.class, REMOTE_SERVICE_NAME);
72: singleton2 = (ISingleton) server1.getProxy(
73: ISingleton.class, REMOTE_SERVICE_NAME);
74: mbeanServerConn1 = server0.getMBeanServerConnection();
75: mbeanServerConn2 = server1.getMBeanServerConnection();
76: } catch (Exception e) {
77: e.printStackTrace();
78: throw e;
79: }
80: }
81:
82: protected void configureWar(DeploymentBuilder builder) {
83: builder
84: .addBeanDefinitionFile(BEAN_DEFINITION_FILE_FOR_TEST);
85: builder.addRemoteService(REMOTE_SERVICE_NAME, "singleton",
86: ISingleton.class);
87: }
88: }
89:
90: public static Test suite() {
91: return new JMXSupportTestSetup();
92: }
93:
94: }
|