@Test public void withLocateExistingAndFallbackToPlatformServer() { MBeanServerFactoryBean bean = new MBeanServerFactoryBean(); bean.setLocateExistingServerIfPossible(true); bean.afterPropertiesSet(); try { assertSame(ManagementFactory.getPlatformMBeanServer(), bean.getObject()); } finally { bean.destroy(); } }
@Test public void withEmptyAgentIdAndFallbackToPlatformServer() { MBeanServerFactoryBean bean = new MBeanServerFactoryBean(); bean.setAgentId(""); bean.afterPropertiesSet(); try { assertSame(ManagementFactory.getPlatformMBeanServer(), bean.getObject()); } finally { bean.destroy(); } }
@Test public void getObject() throws Exception { MBeanServerFactoryBean bean = new MBeanServerFactoryBean(); bean.afterPropertiesSet(); try { MBeanServer server = bean.getObject(); assertNotNull("The MBeanServer should not be null", server); } finally { bean.destroy(); } }
private void testCreation(boolean referenceShouldExist, String failMsg) throws Exception { MBeanServerFactoryBean bean = new MBeanServerFactoryBean(); bean.setRegisterWithFactory(referenceShouldExist); bean.afterPropertiesSet(); try { MBeanServer server = bean.getObject(); List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null); boolean found = false; for (MBeanServer candidate : servers) { if (candidate == server) { found = true; break; } } if (!(found == referenceShouldExist)) { fail(failMsg); } } finally { bean.destroy(); } }
@Test public void defaultDomain() throws Exception { MBeanServerFactoryBean bean = new MBeanServerFactoryBean(); bean.setDefaultDomain("foo"); bean.afterPropertiesSet(); try { MBeanServer server = bean.getObject(); assertEquals("The default domain should be foo", "foo", server.getDefaultDomain()); } finally { bean.destroy(); } }
@Before public void start() throws Exception { MBeanServerFactoryBean factory = new MBeanServerFactoryBean(); factory.setLocateExistingServerIfPossible(true); factory.afterPropertiesSet(); server = factory.getObject(); }
@Test public void withLocateExistingAndExistingServer() { MBeanServer server = MBeanServerFactory.createMBeanServer(); try { MBeanServerFactoryBean bean = new MBeanServerFactoryBean(); bean.setLocateExistingServerIfPossible(true); bean.afterPropertiesSet(); try { MBeanServer otherServer = bean.getObject(); assertSame("Existing MBeanServer not located", server, otherServer); } finally { bean.destroy(); } } finally { MBeanServerFactory.releaseMBeanServer(server); } }
@BeforeClass public static void setupClass() { serverFactoryBean = new MBeanServerFactoryBean(); serverFactoryBean.afterPropertiesSet(); }
@BeforeClass public static void setupClass() { factoryBean = new MBeanServerFactoryBean(); factoryBean.afterPropertiesSet(); server = factoryBean.getObject(); }
@BeforeClass public static void setup() { factoryBean = new MBeanServerFactoryBean(); factoryBean.setLocateExistingServerIfPossible(true); factoryBean.afterPropertiesSet(); server = factoryBean.getObject(); }
@Test public void basicPolling() throws Exception { MBeanServerFactoryBean factoryBean = new MBeanServerFactoryBean(); factoryBean.afterPropertiesSet(); MBeanServer server = factoryBean.getObject(); TestCounter counter = new TestCounter(); server.registerMBean(counter, ObjectNameManager.getInstance("test:name=counter")); AttributePollingMessageSource source = new AttributePollingMessageSource(); source.setAttributeName("Count"); source.setObjectName("test:name=counter"); source.setServer(server); Message<?> message1 = source.receive(); assertNotNull(message1); assertEquals(0, message1.getPayload()); counter.increment(); Message<?> message2 = source.receive(); assertNotNull(message2); assertEquals(1, message2.getPayload()); factoryBean.destroy(); }