提交 10648942 编写于 作者: C Chris Beams

Update AbstractMBeanServerTests hierarchy to JUnit 4

This commit lays the groundwork for introducing TestGroup#JMXMP and
related assumptions in select JMX-related tests in a subsequent commit;
JUnit assumptions require JUnit 4+ to function properly, so the entire
AbstractMBeanServerTests hierarchy must be moved over to JUnit 4+ style.

Issue: SPR-8089
上级 cbe03093
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -20,13 +20,15 @@ import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.util.MBeanTestUtils;
import static org.junit.Assert.*;
/**
* <strong>Note:</strong> the JMX test suite requires the presence of the
* {@code jmxremote_optional.jar} in your classpath. Thus, if you
......@@ -40,12 +42,13 @@ import org.springframework.util.MBeanTestUtils;
* @author Rob Harrop
* @author Juergen Hoeller
* @author Sam Brannen
* @author Chris Beams
*/
public abstract class AbstractMBeanServerTests extends TestCase {
public abstract class AbstractMBeanServerTests {
protected MBeanServer server;
@Override
@Before
public final void setUp() throws Exception {
this.server = MBeanServerFactory.createMBeanServer();
try {
......@@ -64,8 +67,8 @@ public abstract class AbstractMBeanServerTests extends TestCase {
return ctx;
}
@Override
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
releaseServer();
onTearDown();
}
......
......@@ -29,6 +29,7 @@ import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import org.junit.Test;
import org.springframework.jmx.AbstractMBeanServerTests;
import org.springframework.jmx.IJmxTestBean;
import org.springframework.jmx.JmxException;
......@@ -40,6 +41,7 @@ import org.springframework.jmx.export.assembler.AbstractReflectiveMBeanInfoAssem
* @author Rob Harrop
* @author Juergen Hoeller
* @author Sam Brannen
* @author Chris Beams
*/
public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
......@@ -77,6 +79,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
return (IJmxTestBean) factory.getObject();
}
@Test
public void testProxyClassIsDifferent() throws Exception {
if (!runTests)
return;
......@@ -84,6 +87,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
assertTrue("The proxy class should be different than the base class", (proxy.getClass() != IJmxTestBean.class));
}
@Test
public void testDifferentProxiesSameClass() throws Exception {
if (!runTests)
return;
......@@ -94,6 +98,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
assertSame("The proxy classes should be the same", proxy1.getClass(), proxy2.getClass());
}
@Test
public void testGetAttributeValue() throws Exception {
if (!runTests)
return;
......@@ -102,6 +107,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
assertEquals("The age should be 100", 100, age);
}
@Test
public void testSetAttributeValue() throws Exception {
if (!runTests)
return;
......@@ -110,6 +116,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
assertEquals("The name of the bean should have been updated", "Rob Harrop", target.getName());
}
@Test
public void testSetAttributeValueWithRuntimeException() throws Exception {
if (!runTests)
return;
......@@ -122,6 +129,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
}
}
@Test
public void testSetAttributeValueWithCheckedException() throws Exception {
if (!runTests)
return;
......@@ -134,6 +142,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
}
}
@Test
public void testSetAttributeValueWithIOException() throws Exception {
if (!runTests)
return;
......@@ -146,6 +155,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
}
}
@Test
public void testSetReadOnlyAttribute() throws Exception {
if (!runTests)
return;
......@@ -158,6 +168,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
}
}
@Test
public void testInvokeNoArgs() throws Exception {
if (!runTests)
return;
......@@ -166,6 +177,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
assertEquals("The operation should return 1", 1, result);
}
@Test
public void testInvokeArgs() throws Exception {
if (!runTests)
return;
......@@ -174,6 +186,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
assertEquals("The operation should return 3", 3, result);
}
@Test
public void testInvokeUnexposedMethodWithException() throws Exception {
if (!runTests)
return;
......@@ -186,6 +199,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
}
}
@Test
public void testTestLazyConnectionToRemote() throws Exception {
if (!runTests)
return;
......
......@@ -28,6 +28,7 @@ import javax.management.remote.JMXServiceURL;
/**
* @author Rob Harrop
* @author Chris Beams
*/
public class RemoteMBeanClientInterceptorTests extends MBeanClientInterceptorTests {
......
......@@ -22,8 +22,11 @@ import java.util.Date;
import javax.management.ObjectName;
import org.junit.Test;
import org.springframework.jmx.AbstractJmxTests;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
*/
......@@ -36,6 +39,7 @@ public class CustomEditorConfigurerTests extends AbstractJmxTests {
return "org/springframework/jmx/export/customConfigurer.xml";
}
@Test
public void testDatesInJmx() throws Exception {
// System.out.println(getServer().getClass().getName());
ObjectName oname = new ObjectName("bean:name=dateRange");
......@@ -47,6 +51,7 @@ public class CustomEditorConfigurerTests extends AbstractJmxTests {
assertEquals("endDate ", getEndDate(), endJmx);
}
@Test
public void testGetDates() throws Exception {
DateRange dr = (DateRange) getContext().getBean("dateRange");
......
......@@ -28,6 +28,8 @@ import org.springframework.jmx.JmxTestBean;
import org.springframework.jmx.export.naming.ObjectNamingStrategy;
import org.springframework.jmx.support.ObjectNameManager;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Juergen Hoeller
......
......@@ -33,6 +33,7 @@ import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.modelmbean.ModelMBeanInfo;
import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
......@@ -50,6 +51,8 @@ import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.tests.aop.interceptor.NopInterceptor;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
/**
* Integration tests for the {@link MBeanExporter} class.
*
......@@ -66,6 +69,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
private static final String OBJECT_NAME = "spring:test=jmxMBeanAdaptor";
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNonNotificationListenerType() throws Exception {
Map listeners = new HashMap();
// put a non-NotificationListener instance in as a value...
......@@ -80,6 +84,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNullNotificationListenerType() throws Exception {
Map listeners = new HashMap();
// put null in as a value...
......@@ -94,6 +99,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNotificationListenerForNonExistentMBean() throws Exception {
Map listeners = new HashMap();
NotificationListener dummyListener = new NotificationListener() {
......@@ -117,6 +123,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
@Test
public void testWithSuppliedMBeanServer() throws Exception {
MBeanExporter exporter = new MBeanExporter();
exporter.setBeans(getBeanMap());
......@@ -127,6 +134,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
/** Fails if JVM platform MBean server has been started already
@Test
public void testWithLocatedMBeanServer() throws Exception {
MBeanExporter adaptor = new MBeanExporter();
adaptor.setBeans(getBeanMap());
......@@ -136,6 +144,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
*/
@Test
public void testUserCreatedMBeanRegWithDynamicMBean() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("spring:name=dynBean", new TestDynamicMBean());
......@@ -153,6 +162,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertFalse("Assembler should not have been invoked", asm.invoked);
}
@Test
public void testAutodetectMBeans() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("autodetectMBeans.xml", getClass()));
......@@ -170,6 +180,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
@Test
public void testAutodetectWithExclude() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("autodetectMBeans.xml", getClass()));
......@@ -189,6 +200,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
@Test
public void testAutodetectLazyMBeans() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("autodetectLazyMBeans.xml", getClass()));
......@@ -210,6 +222,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
@Test
public void testAutodetectNoMBeans() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("autodetectNoMBeans.xml", getClass()));
......@@ -220,6 +233,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
@Test
public void testWithMBeanExporterListeners() throws Exception {
MockMBeanExporterListener listener1 = new MockMBeanExporterListener();
MockMBeanExporterListener listener2 = new MockMBeanExporterListener();
......@@ -235,6 +249,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertListener(listener2);
}
@Test
public void testExportJdkProxy() throws Exception {
JmxTestBean bean = new JmxTestBean();
bean.setName("Rob Harrop");
......@@ -260,6 +275,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertEquals("Rob Harrop", nameValue);
}
@Test
public void testSelfNaming() throws Exception {
ObjectName objectName = ObjectNameManager.getInstance(OBJECT_NAME);
SelfNamingTestBean testBean = new SelfNamingTestBean();
......@@ -278,6 +294,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertNotNull(instance);
}
@Test
public void testRegisterIgnoreExisting() throws Exception {
ObjectName objectName = ObjectNameManager.getInstance(OBJECT_NAME);
......@@ -311,6 +328,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertEquals("Rob Harrop", server.getAttribute(objectName, "Name"));
}
@Test
public void testRegisterReplaceExisting() throws Exception {
ObjectName objectName = ObjectNameManager.getInstance(OBJECT_NAME);
......@@ -339,6 +357,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertEquals("Sally Greenwood", server.getAttribute(objectName, "Name"));
}
@Test
public void testWithExposeClassLoader() throws Exception {
String name = "Rob Harrop";
String otherName = "Juergen Hoeller";
......@@ -368,6 +387,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertEquals("Incorrect updated name.", otherName, bean.getName());
}
@Test
public void testBonaFideMBeanIsNotExportedWhenAutodetectIsTotallyTurnedOff() throws Exception {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Person.class);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
......@@ -386,6 +406,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
exporter.afterPropertiesSet();
}
@Test
public void testOnlyBonaFideMBeanIsExportedWhenAutodetectIsMBeanOnly() throws Exception {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Person.class);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
......@@ -405,6 +426,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
ObjectNameManager.getInstance(exportedBeanName));
}
@Test
public void testBonaFideMBeanAndRegularBeanExporterWithAutodetectAll() throws Exception {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Person.class);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
......@@ -428,6 +450,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
ObjectNameManager.getInstance(notToBeExportedBeanName));
}
@Test
public void testBonaFideMBeanIsNotExportedWithAutodetectAssembler() throws Exception {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Person.class);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
......@@ -450,6 +473,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
/**
* Want to ensure that said MBean is not exported twice.
*/
@Test
public void testBonaFideMBeanExplicitlyExportedAndAutodetectionIsOn() throws Exception {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Person.class);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
......@@ -468,6 +492,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
ObjectNameManager.getInstance(OBJECT_NAME));
}
@Test
public void testSetAutodetectModeToOutOfRangeNegativeValue() throws Exception {
try {
MBeanExporter exporter = new MBeanExporter();
......@@ -478,6 +503,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
@Test
public void testSetAutodetectModeToOutOfRangePositiveValue() throws Exception {
try {
MBeanExporter exporter = new MBeanExporter();
......@@ -488,6 +514,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
@Test
public void testSetAutodetectModeNameToNull() throws Exception {
try {
MBeanExporter exporter = new MBeanExporter();
......@@ -498,6 +525,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
@Test
public void testSetAutodetectModeNameToAnEmptyString() throws Exception {
try {
MBeanExporter exporter = new MBeanExporter();
......@@ -508,6 +536,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
@Test
public void testSetAutodetectModeNameToAWhitespacedString() throws Exception {
try {
MBeanExporter exporter = new MBeanExporter();
......@@ -518,6 +547,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
@Test
public void testSetAutodetectModeNameToARubbishValue() throws Exception {
try {
MBeanExporter exporter = new MBeanExporter();
......@@ -528,6 +558,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
@Test
public void testNotRunningInBeanFactoryAndPassedBeanNameToExport() throws Exception {
try {
MBeanExporter exporter = new MBeanExporter();
......@@ -541,6 +572,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
@Test
public void testNotRunningInBeanFactoryAndAutodetectionIsOn() throws Exception {
try {
MBeanExporter exporter = new MBeanExporter();
......@@ -555,6 +587,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
/**
* SPR-2158
*/
@Test
public void testMBeanIsNotUnregisteredSpuriouslyIfSomeExternalProcessHasUnregisteredMBean() throws Exception {
MBeanExporter exporter = new MBeanExporter();
exporter.setBeans(getBeanMap());
......@@ -574,6 +607,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
/**
* SPR-3302
*/
@Test
public void testBeanNameCanBeUsedInNotificationListenersMap() throws Exception {
String beanName = "charlesDexterWard";
BeanDefinitionBuilder testBean = BeanDefinitionBuilder.rootBeanDefinition(JmxTestBean.class);
......@@ -595,6 +629,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
exporter.afterPropertiesSet();
}
@Test
public void testWildcardCanBeUsedInNotificationListenersMap() throws Exception {
String beanName = "charlesDexterWard";
BeanDefinitionBuilder testBean = BeanDefinitionBuilder.rootBeanDefinition(JmxTestBean.class);
......@@ -619,6 +654,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
/*
* SPR-3625
*/
@Test
public void testMBeanIsUnregisteredForRuntimeExceptionDuringInitialization() throws Exception {
BeanDefinitionBuilder builder1 = BeanDefinitionBuilder.rootBeanDefinition(Person.class);
BeanDefinitionBuilder builder2 = BeanDefinitionBuilder
......
......@@ -26,6 +26,7 @@ import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.jmx.AbstractMBeanServerTests;
import org.springframework.jmx.JmxTestBean;
......@@ -33,6 +34,8 @@ import org.springframework.jmx.access.NotificationListenerRegistrar;
import org.springframework.jmx.export.naming.SelfNaming;
import org.springframework.jmx.support.ObjectNameManager;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Mark Fisher
......@@ -41,6 +44,7 @@ import org.springframework.jmx.support.ObjectNameManager;
public class NotificationListenerTests extends AbstractMBeanServerTests {
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void testRegisterNotificationListenerForMBean() throws Exception {
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean();
......@@ -66,6 +70,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNotificationListenerWithWildcard() throws Exception {
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean();
......@@ -90,6 +95,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener not notified", 1, listener.getCount(attributeName));
}
@Test
public void testRegisterNotificationListenerWithHandback() throws Exception {
String objectName = "spring:name=Test";
JmxTestBean bean = new JmxTestBean();
......@@ -120,6 +126,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Handback object not transmitted correctly", handback, listener.getLastHandback(attributeName));
}
@Test
public void testRegisterNotificationListenerForAllMBeans() throws Exception {
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean();
......@@ -146,6 +153,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
}
@SuppressWarnings("serial")
@Test
public void testRegisterNotificationListenerWithFilter() throws Exception {
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean();
......@@ -186,6 +194,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener incorrectly notified for Age", 0, listener.getCount(ageAttribute));
}
@Test
public void testCreationWithNoNotificationListenerSet() {
try {
new NotificationListenerBean().afterPropertiesSet();
......@@ -195,6 +204,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNotificationListenerWithBeanNameAndBeanNameInBeansMap() throws Exception {
String beanName = "testBean";
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
......@@ -225,6 +235,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNotificationListenerWithBeanNameAndBeanInstanceInBeansMap() throws Exception {
String beanName = "testBean";
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
......@@ -255,6 +266,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNotificationListenerWithBeanNameBeforeObjectNameMappedToSameBeanInstance() throws Exception {
String beanName = "testBean";
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
......@@ -286,6 +298,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNotificationListenerWithObjectNameBeforeBeanNameMappedToSameBeanInstance() throws Exception {
String beanName = "testBean";
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
......@@ -317,6 +330,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRegisterNotificationListenerWithTwoBeanNamesMappedToDifferentBeanInstances() throws Exception {
String beanName1 = "testBean1";
String beanName2 = "testBean2";
......@@ -359,6 +373,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener not notified for testBean2", 2, listener.getCount("Age"));
}
@Test
public void testNotificationListenerRegistrar() throws Exception {
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean();
......@@ -391,6 +406,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener notified after destruction", 1, listener.getCount(attributeName));
}
@Test
public void testNotificationListenerRegistrarWithMultipleNames() throws Exception {
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
ObjectName objectName2 = ObjectName.getInstance("spring:name=Test2");
......
......@@ -32,12 +32,15 @@ import javax.management.NotificationBroadcasterSupport;
import javax.management.NotificationListener;
import javax.management.ReflectionException;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.jmx.AbstractMBeanServerTests;
import org.springframework.jmx.export.notification.NotificationPublisher;
import org.springframework.jmx.export.notification.NotificationPublisherAware;
import org.springframework.jmx.support.ObjectNameManager;
import static org.junit.Assert.*;
/**
* Integration tests for the Spring JMX {@link NotificationPublisher} functionality.
*
......@@ -48,6 +51,7 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
private CountingNotificationListener listener = new CountingNotificationListener();
@Test
public void testSimpleBean() throws Exception {
// start the MBeanExporter
ConfigurableApplicationContext ctx = loadContext("org/springframework/jmx/export/notificationPublisherTests.xml");
......@@ -60,6 +64,7 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
assertEquals("Notification not sent", 1, listener.count);
}
@Test
public void testSimpleBeanRegisteredManually() throws Exception {
// start the MBeanExporter
ConfigurableApplicationContext ctx = loadContext("org/springframework/jmx/export/notificationPublisherTests.xml");
......@@ -74,6 +79,7 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
assertEquals("Notification not sent", 1, listener.count);
}
@Test
public void testMBean() throws Exception {
// start the MBeanExporter
ConfigurableApplicationContext ctx = loadContext("org/springframework/jmx/export/notificationPublisherTests.xml");
......@@ -86,6 +92,7 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
}
/*
@Test
public void testStandardMBean() throws Exception {
// start the MBeanExporter
ApplicationContext ctx = new ClassPathXmlApplicationContext("org/springframework/jmx/export/notificationPublisherTests.xml");
......@@ -97,6 +104,7 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
}
*/
@Test
public void testLazyInit() throws Exception {
// start the MBeanExporter
ConfigurableApplicationContext ctx = loadContext("org/springframework/jmx/export/notificationPublisherLazyTests.xml");
......
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
......@@ -18,11 +18,15 @@ package org.springframework.jmx.export;
import javax.management.ObjectName;
import org.junit.Test;
import org.springframework.jmx.AbstractJmxTests;
import org.springframework.jmx.IJmxTestBean;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Chris Beams
*/
public class PropertyPlaceholderConfigurerTests extends AbstractJmxTests {
......@@ -31,6 +35,7 @@ public class PropertyPlaceholderConfigurerTests extends AbstractJmxTests {
return "org/springframework/jmx/export/propertyPlaceholderConfigurer.xml";
}
@Test
public void testPropertiesReplaced() {
IJmxTestBean bean = (IJmxTestBean) getContext().getBean("testBean");
......@@ -38,6 +43,7 @@ public class PropertyPlaceholderConfigurerTests extends AbstractJmxTests {
assertEquals("Age is incorrect", 100, bean.getAge());
}
@Test
public void testPropertiesCorrectInJmx() throws Exception {
ObjectName oname = new ObjectName("bean:name=proxyTestBean1");
Object name = getServer().getAttribute(oname, "Name");
......
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
......@@ -20,15 +20,22 @@ import javax.management.modelmbean.ModelMBeanInfo;
import javax.management.modelmbean.ModelMBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanOperationInfo;
import org.junit.Test;
import org.springframework.jmx.IJmxTestBean;
import org.springframework.jmx.export.assembler.AbstractMetadataAssemblerTests;
import org.springframework.jmx.export.metadata.JmxAttributeSource;
/** @author Rob Harrop */
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Chris Beams
*/
public class AnnotationMetadataAssemblerTests extends AbstractMetadataAssemblerTests {
private static final String OBJECT_NAME = "bean:name=testBean4";
@Test
public void testAttributeFromInterface() throws Exception {
ModelMBeanInfo inf = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = inf.getAttribute("Colour");
......@@ -36,12 +43,14 @@ public class AnnotationMetadataAssemblerTests extends AbstractMetadataAssemblerT
assertTrue("The name attribute should be readable", attr.isReadable());
}
@Test
public void testOperationFromInterface() throws Exception {
ModelMBeanInfo inf = getMBeanInfoFromAssembler();
ModelMBeanOperationInfo op = inf.getOperation("fromInterface");
assertNotNull(op);
}
@Test
public void testOperationOnGetter() throws Exception {
ModelMBeanInfo inf = getMBeanInfoFromAssembler();
ModelMBeanOperationInfo op = inf.getOperation("getExpensiveToCalculate");
......
......@@ -28,12 +28,16 @@ import javax.management.modelmbean.ModelMBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanInfo;
import javax.management.modelmbean.ModelMBeanOperationInfo;
import org.junit.Test;
import org.springframework.jmx.AbstractJmxTests;
import org.springframework.jmx.IJmxTestBean;
import org.springframework.jmx.support.ObjectNameManager;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Chris Beams
*/
public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
......@@ -43,12 +47,14 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
protected abstract String getObjectName();
@Test
public void testMBeanRegistration() throws Exception {
// beans are registered at this point - just grab them from the server
ObjectInstance instance = getObjectInstance();
assertNotNull("Bean should not be null", instance);
}
@Test
public void testRegisterOperations() throws Exception {
IJmxTestBean bean = getBean();
assertNotNull(bean);
......@@ -57,6 +63,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
getExpectedOperationCount(), inf.getOperations().length);
}
@Test
public void testRegisterAttributes() throws Exception {
IJmxTestBean bean = getBean();
assertNotNull(bean);
......@@ -65,11 +72,13 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
getExpectedAttributeCount(), inf.getAttributes().length);
}
@Test
public void testGetMBeanInfo() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
assertNotNull("MBeanInfo should not be null", info);
}
@Test
public void testGetMBeanAttributeInfo() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
MBeanAttributeInfo[] inf = info.getAttributes();
......@@ -84,6 +93,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
}
}
@Test
public void testGetMBeanOperationInfo() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
MBeanOperationInfo[] inf = info.getOperations();
......@@ -98,6 +108,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
}
}
@Test
public void testDescriptionNotNull() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
......@@ -105,6 +116,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
info.getDescription());
}
@Test
public void testSetAttribute() throws Exception {
ObjectName objectName = ObjectNameManager.getInstance(getObjectName());
getServer().setAttribute(objectName, new Attribute(NAME_ATTRIBUTE, "Rob Harrop"));
......@@ -112,6 +124,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
assertEquals("Rob Harrop", bean.getName());
}
@Test
public void testGetAttribute() throws Exception {
ObjectName objectName = ObjectNameManager.getInstance(getObjectName());
getBean().setName("John Smith");
......@@ -119,6 +132,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
assertEquals("Incorrect result", "John Smith", val);
}
@Test
public void testOperationInvocation() throws Exception{
ObjectName objectName = ObjectNameManager.getInstance(getObjectName());
Object result = getServer().invoke(objectName, "add",
......@@ -126,6 +140,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
assertEquals("Incorrect result", new Integer(50), result);
}
@Test
public void testAttributeInfoHasDescriptors() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
......@@ -141,6 +156,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
desc.getFieldValue("setMethod"));
}
@Test
public void testAttributeHasCorrespondingOperations() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
......@@ -159,6 +175,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
assertEquals("set operation should have role \"setter\"", "setter", set.getDescriptor().getFieldValue("role"));
}
@Test
public void testNotificationMetadata() throws Exception {
ModelMBeanInfo info = (ModelMBeanInfo) getMBeanInfo();
MBeanNotificationInfo[] notifications = info.getNotifications();
......
......@@ -26,6 +26,7 @@ import javax.management.modelmbean.ModelMBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanInfo;
import javax.management.modelmbean.ModelMBeanOperationInfo;
import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.jmx.IJmxTestBean;
import org.springframework.jmx.JmxTestBean;
......@@ -34,6 +35,8 @@ import org.springframework.jmx.export.metadata.JmxAttributeSource;
import org.springframework.jmx.support.ObjectNameManager;
import org.springframework.tests.aop.interceptor.NopInterceptor;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Chris Beams
......@@ -44,12 +47,14 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
protected static final String CACHE_ENTRIES_METRIC = "CacheEntries";
@Test
public void testDescription() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
assertEquals("The descriptions are not the same", "My Managed Bean",
info.getDescription());
}
@Test
public void testAttributeDescriptionOnSetter() throws Exception {
ModelMBeanInfo inf = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = inf.getAttribute(AGE_ATTRIBUTE);
......@@ -57,6 +62,7 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
"The Age Attribute", attr.getDescription());
}
@Test
public void testAttributeDescriptionOnGetter() throws Exception {
ModelMBeanInfo inf = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = inf.getAttribute(NAME_ATTRIBUTE);
......@@ -67,12 +73,14 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
/**
* Tests the situation where the attribute is only defined on the getter.
*/
@Test
public void testReadOnlyAttribute() throws Exception {
ModelMBeanInfo inf = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = inf.getAttribute(AGE_ATTRIBUTE);
assertFalse("The age attribute should not be writable", attr.isWritable());
}
@Test
public void testReadWriteAttribute() throws Exception {
ModelMBeanInfo inf = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = inf.getAttribute(NAME_ATTRIBUTE);
......@@ -83,6 +91,7 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
/**
* Tests the situation where the property only has a getter.
*/
@Test
public void testWithOnlySetter() throws Exception {
ModelMBeanInfo inf = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = inf.getAttribute("NickName");
......@@ -92,12 +101,14 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
/**
* Tests the situation where the property only has a setter.
*/
@Test
public void testWithOnlyGetter() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = info.getAttribute("Superman");
assertNotNull("Attribute should not be null", attr);
}
@Test
public void testManagedResourceDescriptor() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
Descriptor desc = info.getMBeanDescriptor();
......@@ -111,6 +122,7 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
assertEquals("Persist Name should be bar", "bar.jmx", desc.getFieldValue("persistName"));
}
@Test
public void testAttributeDescriptor() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
Descriptor desc = info.getAttribute(NAME_ATTRIBUTE).getDescriptor();
......@@ -121,6 +133,7 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
assertEquals("Persist Period should be 300", "300", desc.getFieldValue("persistPeriod"));
}
@Test
public void testOperationDescriptor() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
Descriptor desc = info.getOperation("myOperation").getDescriptor();
......@@ -129,6 +142,7 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
assertEquals("Role should be \"operation\"", "operation", desc.getFieldValue("role"));
}
@Test
public void testOperationParameterMetadata() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
ModelMBeanOperationInfo oper = info.getOperation("add");
......@@ -142,6 +156,7 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
assertEquals("Incorrect type for y param", int.class.getName(), params[1].getType());
}
@Test
public void testWithCglibProxy() throws Exception {
IJmxTestBean tb = createJmxTestBean();
ProxyFactory pf = new ProxyFactory();
......@@ -169,6 +184,7 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
assertTrue("Not included in autodetection", assembler.includeBean(proxy.getClass(), "some bean name"));
}
@Test
public void testMetricDescription() throws Exception {
ModelMBeanInfo inf = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo metric = inf.getAttribute(QUEUE_SIZE_METRIC);
......@@ -179,6 +195,7 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
"The QueueSize metric", operation.getDescription());
}
@Test
public void testMetricDescriptor() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
Descriptor desc = info.getAttribute(QUEUE_SIZE_METRIC).getDescriptor();
......@@ -191,6 +208,7 @@ public abstract class AbstractMetadataAssemblerTests extends AbstractJmxAssemble
assertEquals("Metric Category should be utilization", "utilization",desc.getFieldValue("metricCategory"));
}
@Test
public void testMetricDescriptorDefaults() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
Descriptor desc = info.getAttribute(CACHE_ENTRIES_METRIC).getDescriptor();
......
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
......@@ -19,8 +19,13 @@ package org.springframework.jmx.export.assembler;
import javax.management.modelmbean.ModelMBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanInfo;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Chris Beams
*/
public class InterfaceBasedMBeanInfoAssemblerCustomTests extends AbstractJmxAssemblerTests {
......@@ -48,6 +53,7 @@ public class InterfaceBasedMBeanInfoAssemblerCustomTests extends AbstractJmxAsse
return assembler;
}
@Test
public void testGetAgeIsReadOnly() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE);
......
......@@ -22,13 +22,19 @@ import javax.management.MBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanInfo;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Chris Beams
*/
public class InterfaceBasedMBeanInfoAssemblerMappedTests extends AbstractJmxAssemblerTests {
protected static final String OBJECT_NAME = "bean:name=testBean4";
@Test
public void testGetAgeIsReadOnly() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE);
......@@ -37,6 +43,7 @@ public class InterfaceBasedMBeanInfoAssemblerMappedTests extends AbstractJmxAsse
assertFalse("Age is not writable", attr.isWritable());
}
@Test
public void testWithUnknownClass() throws Exception {
try {
getWithMapping("com.foo.bar.Unknown");
......@@ -47,6 +54,7 @@ public class InterfaceBasedMBeanInfoAssemblerMappedTests extends AbstractJmxAsse
}
}
@Test
public void testWithNonInterface() throws Exception {
try {
getWithMapping("JmxTestBean");
......@@ -57,7 +65,8 @@ public class InterfaceBasedMBeanInfoAssemblerMappedTests extends AbstractJmxAsse
}
}
public void ignoreTestWithFallThrough() throws Exception {
@Test
public void testWithFallThrough() throws Exception {
InterfaceBasedMBeanInfoAssembler assembler =
getWithMapping("foobar", "org.springframework.jmx.export.assembler.ICustomJmxBean");
assembler.setManagedInterfaces(new Class<?>[] {IAdditionalTestMethods.class});
......@@ -68,6 +77,7 @@ public class InterfaceBasedMBeanInfoAssemblerMappedTests extends AbstractJmxAsse
assertNickName(attr);
}
@Test
public void testNickNameIsExposed() throws Exception {
ModelMBeanInfo inf = (ModelMBeanInfo) getMBeanInfo();
MBeanAttributeInfo attr = inf.getAttribute("NickName");
......
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -22,14 +22,20 @@ import javax.management.MBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanInfo;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Juergen Hoeller
* @author Rob Harrop
* @author Chris Beams
*/
public class MethodExclusionMBeanInfoAssemblerComboTests extends AbstractJmxAssemblerTests {
protected static final String OBJECT_NAME = "bean:name=testBean4";
@Test
public void testGetAgeIsReadOnly() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE);
......@@ -37,6 +43,7 @@ public class MethodExclusionMBeanInfoAssemblerComboTests extends AbstractJmxAsse
assertFalse("Age is not writable", attr.isWritable());
}
@Test
public void testNickNameIsExposed() throws Exception {
ModelMBeanInfo inf = (ModelMBeanInfo) getMBeanInfo();
MBeanAttributeInfo attr = inf.getAttribute("NickName");
......
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -22,13 +22,19 @@ import javax.management.MBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanInfo;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Chris Beams
*/
public class MethodExclusionMBeanInfoAssemblerMappedTests extends AbstractJmxAssemblerTests {
protected static final String OBJECT_NAME = "bean:name=testBean4";
@Test
public void testGetAgeIsReadOnly() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE);
......@@ -36,6 +42,7 @@ public class MethodExclusionMBeanInfoAssemblerMappedTests extends AbstractJmxAss
assertFalse("Age is not writable", attr.isWritable());
}
@Test
public void testNickNameIsExposed() throws Exception {
ModelMBeanInfo inf = (ModelMBeanInfo) getMBeanInfo();
MBeanAttributeInfo attr = inf.getAttribute("NickName");
......
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -22,14 +22,20 @@ import javax.management.MBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanInfo;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Juergen Hoeller
* @author Rob Harrop
* @author Chris Beams
*/
public class MethodExclusionMBeanInfoAssemblerNotMappedTests extends AbstractJmxAssemblerTests {
protected static final String OBJECT_NAME = "bean:name=testBean4";
@Test
public void testGetAgeIsReadOnly() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE);
......@@ -37,6 +43,7 @@ public class MethodExclusionMBeanInfoAssemblerNotMappedTests extends AbstractJmx
assertTrue("Age is not writable", attr.isWritable());
}
@Test
public void testNickNameIsExposed() throws Exception {
ModelMBeanInfo inf = (ModelMBeanInfo) getMBeanInfo();
MBeanAttributeInfo attr = inf.getAttribute("NickName");
......
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -22,11 +22,15 @@ import java.util.Properties;
import javax.management.modelmbean.ModelMBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanInfo;
import org.junit.Test;
import org.springframework.jmx.JmxTestBean;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Rick Evans
* @author Chris Beams
*/
public class MethodExclusionMBeanInfoAssemblerTests extends AbstractJmxAssemblerTests {
......@@ -60,6 +64,7 @@ public class MethodExclusionMBeanInfoAssemblerTests extends AbstractJmxAssembler
return assembler;
}
@Test
public void testSupermanIsReadOnly() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = info.getAttribute("Superman");
......@@ -71,6 +76,7 @@ public class MethodExclusionMBeanInfoAssemblerTests extends AbstractJmxAssembler
/*
* http://opensource.atlassian.com/projects/spring/browse/SPR-2754
*/
@Test
public void testIsNotIgnoredDoesntIgnoreUnspecifiedBeanMethods() throws Exception {
final String beanKey = "myTestBean";
MethodExclusionMBeanInfoAssembler assembler = new MethodExclusionMBeanInfoAssembler();
......
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
......@@ -16,18 +16,25 @@
package org.springframework.jmx.export.assembler;
import java.util.Properties;
import javax.management.MBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanInfo;
import java.util.Properties;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Chris Beams
*/
public class MethodNameBasedMBeanInfoAssemblerMappedTests extends AbstractJmxAssemblerTests {
protected static final String OBJECT_NAME = "bean:name=testBean4";
@Test
public void testGetAgeIsReadOnly() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE);
......@@ -36,6 +43,7 @@ public class MethodNameBasedMBeanInfoAssemblerMappedTests extends AbstractJmxAss
assertFalse("Age is not writable", attr.isWritable());
}
@Test
public void testWithFallThrough() throws Exception {
MethodNameBasedMBeanInfoAssembler assembler =
getWithMapping("foobar", "add,myOperation,getName,setName,getAge");
......@@ -47,6 +55,7 @@ public class MethodNameBasedMBeanInfoAssemblerMappedTests extends AbstractJmxAss
assertNickName(attr);
}
@Test
public void testNickNameIsExposed() throws Exception {
ModelMBeanInfo inf = (ModelMBeanInfo) getMBeanInfo();
MBeanAttributeInfo attr = inf.getAttribute("NickName");
......
......@@ -20,9 +20,14 @@ import javax.management.MBeanOperationInfo;
import javax.management.modelmbean.ModelMBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanInfo;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author David Boden
* @author Chris Beams
*/
public class MethodNameBasedMBeanInfoAssemblerTests extends AbstractJmxAssemblerTests {
......@@ -50,6 +55,7 @@ public class MethodNameBasedMBeanInfoAssemblerTests extends AbstractJmxAssembler
return assembler;
}
@Test
public void testGetAgeIsReadOnly() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
ModelMBeanAttributeInfo attr = info.getAttribute(AGE_ATTRIBUTE);
......@@ -58,6 +64,7 @@ public class MethodNameBasedMBeanInfoAssemblerTests extends AbstractJmxAssembler
assertFalse(attr.isWritable());
}
@Test
public void testSetNameParameterIsNamed() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
......
......@@ -28,15 +28,18 @@ import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import org.junit.Test;
import org.springframework.jmx.AbstractMBeanServerTests;
/**
* @author Rob Harrop
* @author Chris Beams
*/
public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
private static final String OBJECT_NAME = "spring:type=connector,name=test";
@Test
public void testStartupWithLocatedServer() throws Exception {
ConnectorServerFactoryBean bean = new ConnectorServerFactoryBean();
bean.afterPropertiesSet();
......@@ -48,6 +51,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
}
}
@Test
public void testStartupWithSuppliedServer() throws Exception {
//Added a brief snooze here - seems to fix occasional
//java.net.BindException: Address already in use errors
......@@ -64,6 +68,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
}
}
@Test
public void testRegisterWithMBeanServer() throws Exception {
//Added a brief snooze here - seems to fix occasional
//java.net.BindException: Address already in use errors
......@@ -81,6 +86,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
}
}
@Test
public void testNoRegisterWithMBeanServer() throws Exception {
ConnectorServerFactoryBean bean = new ConnectorServerFactoryBean();
bean.afterPropertiesSet();
......
......@@ -23,6 +23,7 @@ import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import org.junit.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.jmx.AbstractMBeanServerTests;
......@@ -42,6 +43,7 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
return JMXConnectorServerFactory.newJMXConnectorServer(getServiceUrl(), null, getServer());
}
@Test
public void testTestValidConnection() throws Exception {
JMXConnectorServer connectorServer = getConnectorServer();
connectorServer.start();
......@@ -65,6 +67,7 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
}
}
@Test
public void testWithNoServiceUrl() throws Exception {
MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean();
try {
......@@ -97,6 +100,7 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
}
}
@Test
public void testWithLazyConnectionAndNoAccess() throws Exception {
MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean();
bean.setServiceUrl(SERVICE_URL);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册