1 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 ; 11 import javax.management.ObjectName ; 12 13 import junit.extensions.TestSetup; 14 import junit.framework.Test; 15 16 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 REMOTE_SERVICE_NAME = "Singleton"; 29 private static final String BEAN_DEFINITION_FILE_FOR_TEST = "classpath:/com/tctest/spring/beanfactory-jmx.xml"; 30 private static final String 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 mbeanServerConn1; 35 private static MBeanServerConnection mbeanServerConn2; 36 37 public void testJMXSupport() throws Exception { 38 39 logger.debug("testing JMX Support"); 40 singleton1.incrementCounter(); 41 singleton2.incrementCounter(); 42 43 Integer counter1 = (Integer )mbeanServerConn1.getAttribute( 44 new ObjectName ("bean:name=singleton"), "Counter"); 45 Integer counter2 = (Integer )mbeanServerConn2.getAttribute( 46 new ObjectName ("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 { 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 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 84 public static Test suite() { 85 TestSetup setup = new JMXSupportTestSetup(); 86 return setup; 87 } 88 89 } 90 | Popular Tags |