org.springframework.jmx.IJmxTestBean Java Examples

The following examples show how to use org.springframework.jmx.IJmxTestBean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MBeanExporterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testExportJdkProxy() throws Exception {
	JmxTestBean bean = new JmxTestBean();
	bean.setName("Rob Harrop");

	ProxyFactory factory = new ProxyFactory();
	factory.setTarget(bean);
	factory.addAdvice(new NopInterceptor());
	factory.setInterfaces(IJmxTestBean.class);

	IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
	String name = "bean:mmm=whatever";

	Map<String, Object> beans = new HashMap<>();
	beans.put(name, proxy);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.registerBeans();

	ObjectName oname = ObjectName.getInstance(name);
	Object nameValue = server.getAttribute(oname, "Name");
	assertEquals("Rob Harrop", nameValue);
}
 
Example #2
Source File: MBeanExporterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testExportJdkProxy() throws Exception {
	JmxTestBean bean = new JmxTestBean();
	bean.setName("Rob Harrop");

	ProxyFactory factory = new ProxyFactory();
	factory.setTarget(bean);
	factory.addAdvice(new NopInterceptor());
	factory.setInterfaces(IJmxTestBean.class);

	IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
	String name = "bean:mmm=whatever";

	Map<String, Object> beans = new HashMap<>();
	beans.put(name, proxy);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.registerBeans();

	ObjectName oname = ObjectName.getInstance(name);
	Object nameValue = server.getAttribute(oname, "Name");
	assertEquals("Rob Harrop", nameValue);
}
 
Example #3
Source File: MBeanExporterTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testExportJdkProxy() throws Exception {
	JmxTestBean bean = new JmxTestBean();
	bean.setName("Rob Harrop");

	ProxyFactory factory = new ProxyFactory();
	factory.setTarget(bean);
	factory.addAdvice(new NopInterceptor());
	factory.setInterfaces(IJmxTestBean.class);

	IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
	String name = "bean:mmm=whatever";

	Map<String, Object> beans = new HashMap<String, Object>();
	beans.put(name, proxy);

	MBeanExporter exporter = new MBeanExporter();
	exporter.setServer(server);
	exporter.setBeans(beans);
	exporter.registerBeans();

	ObjectName oname = ObjectName.getInstance(name);
	Object nameValue = server.getAttribute(oname, "Name");
	assertEquals("Rob Harrop", nameValue);
}
 
Example #4
Source File: MBeanClientInterceptorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testInvokeArgs() throws Exception {
	assumeTrue(runTests);
	IJmxTestBean proxy = getProxy();
	int result = proxy.add(1, 2);
	assertEquals("The operation should return 3", 3, result);
}
 
Example #5
Source File: MBeanClientInterceptorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testInvokeNoArgs() throws Exception {
	assumeTrue(runTests);
	IJmxTestBean proxy = getProxy();
	long result = proxy.myOperation();
	assertEquals("The operation should return 1", 1, result);
}
 
Example #6
Source File: AbstractJmxAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetAttribute() throws Exception {
	ObjectName objectName = ObjectNameManager.getInstance(getObjectName());
	getServer().setAttribute(objectName, new Attribute(NAME_ATTRIBUTE, "Rob Harrop"));
	IJmxTestBean bean = (IJmxTestBean) getContext().getBean("testBean");
	assertEquals("Rob Harrop", bean.getName());
}
 
Example #7
Source File: AbstractMetadataAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithCglibProxy() throws Exception {
	IJmxTestBean tb = createJmxTestBean();
	ProxyFactory pf = new ProxyFactory();
	pf.setTarget(tb);
	pf.addAdvice(new NopInterceptor());
	Object proxy = pf.getProxy();

	MetadataMBeanInfoAssembler assembler = (MetadataMBeanInfoAssembler) getAssembler();

	MBeanExporter exporter = new MBeanExporter();
	exporter.setBeanFactory(getContext());
	exporter.setAssembler(assembler);

	String objectName = "spring:bean=test,proxy=true";

	Map<String, Object> beans = new HashMap<String, Object>();
	beans.put(objectName, proxy);
	exporter.setBeans(beans);
	start(exporter);

	MBeanInfo inf = getServer().getMBeanInfo(ObjectNameManager.getInstance(objectName));
	assertEquals("Incorrect number of operations", getExpectedOperationCount(), inf.getOperations().length);
	assertEquals("Incorrect number of attributes", getExpectedAttributeCount(), inf.getAttributes().length);

	assertTrue("Not included in autodetection", assembler.includeBean(proxy.getClass(), "some bean name"));
}
 
Example #8
Source File: AbstractMetadataAssemblerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testWithCglibProxy() throws Exception {
	IJmxTestBean tb = createJmxTestBean();
	ProxyFactory pf = new ProxyFactory();
	pf.setTarget(tb);
	pf.addAdvice(new NopInterceptor());
	Object proxy = pf.getProxy();

	MetadataMBeanInfoAssembler assembler = (MetadataMBeanInfoAssembler) getAssembler();

	MBeanExporter exporter = new MBeanExporter();
	exporter.setBeanFactory(getContext());
	exporter.setAssembler(assembler);

	String objectName = "spring:bean=test,proxy=true";

	Map<String, Object> beans = new HashMap<>();
	beans.put(objectName, proxy);
	exporter.setBeans(beans);
	start(exporter);

	MBeanInfo inf = getServer().getMBeanInfo(ObjectNameManager.getInstance(objectName));
	assertEquals("Incorrect number of operations", getExpectedOperationCount(), inf.getOperations().length);
	assertEquals("Incorrect number of attributes", getExpectedAttributeCount(), inf.getAttributes().length);

	assertTrue("Not included in autodetection", assembler.includeBean(proxy.getClass(), "some bean name"));
}
 
Example #9
Source File: MBeanClientInterceptorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvokeNoArgs() throws Exception {
	assumeTrue(runTests);
	IJmxTestBean proxy = getProxy();
	long result = proxy.myOperation();
	assertEquals("The operation should return 1", 1, result);
}
 
Example #10
Source File: AbstractJmxAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisterAttributes() throws Exception {
	IJmxTestBean bean = getBean();
	assertNotNull(bean);
	MBeanInfo inf = getMBeanInfo();
	assertEquals("Incorrect number of attributes registered",
			getExpectedAttributeCount(), inf.getAttributes().length);
}
 
Example #11
Source File: PropertyPlaceholderConfigurerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testPropertiesReplaced() {
	IJmxTestBean bean = (IJmxTestBean) getContext().getBean("testBean");

	assertEquals("Name is incorrect", "Rob Harrop", bean.getName());
	assertEquals("Age is incorrect", 100, bean.getAge());
}
 
Example #12
Source File: MBeanClientInterceptorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testDifferentProxiesSameClass() throws Exception {
	assumeTrue(runTests);
	IJmxTestBean proxy1 = getProxy();
	IJmxTestBean proxy2 = getProxy();

	assertNotSame("The proxies should NOT be the same", proxy1, proxy2);
	assertSame("The proxy classes should be the same", proxy1.getClass(), proxy2.getClass());
}
 
Example #13
Source File: MBeanClientInterceptorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testGetAttributeValue() throws Exception {
	assumeTrue(runTests);
	IJmxTestBean proxy1 = getProxy();
	int age = proxy1.getAge();
	assertEquals("The age should be 100", 100, age);
}
 
Example #14
Source File: MBeanClientInterceptorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testSetAttributeValue() throws Exception {
	assumeTrue(runTests);
	IJmxTestBean proxy = getProxy();
	proxy.setName("Rob Harrop");
	assertEquals("The name of the bean should have been updated", "Rob Harrop", target.getName());
}
 
Example #15
Source File: MBeanClientInterceptorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testSetAttributeValue() throws Exception {
	assumeTrue(runTests);
	IJmxTestBean proxy = getProxy();
	proxy.setName("Rob Harrop");
	assertEquals("The name of the bean should have been updated", "Rob Harrop", target.getName());
}
 
Example #16
Source File: MBeanClientInterceptorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvokeArgs() throws Exception {
	assumeTrue(runTests);
	IJmxTestBean proxy = getProxy();
	int result = proxy.add(1, 2);
	assertEquals("The operation should return 3", 3, result);
}
 
Example #17
Source File: AbstractJmxAssemblerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisterOperations() throws Exception {
	IJmxTestBean bean = getBean();
	assertNotNull(bean);
	MBeanInfo inf = getMBeanInfo();
	assertEquals("Incorrect number of operations registered",
			getExpectedOperationCount(), inf.getOperations().length);
}
 
Example #18
Source File: MBeanClientInterceptorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected IJmxTestBean getProxy() throws Exception {
	MBeanProxyFactoryBean factory = new MBeanProxyFactoryBean();
	factory.setServer(getServerConnection());
	factory.setProxyInterface(IJmxTestBean.class);
	factory.setObjectName(OBJECT_NAME);
	factory.afterPropertiesSet();
	return (IJmxTestBean) factory.getObject();
}
 
Example #19
Source File: MBeanClientInterceptorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testInvokeNoArgs() throws Exception {
	assumeTrue(runTests);
	IJmxTestBean proxy = getProxy();
	long result = proxy.myOperation();
	assertEquals("The operation should return 1", 1, result);
}
 
Example #20
Source File: MBeanClientInterceptorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testInvokeArgs() throws Exception {
	assumeTrue(runTests);
	IJmxTestBean proxy = getProxy();
	int result = proxy.add(1, 2);
	assertEquals("The operation should return 3", 3, result);
}
 
Example #21
Source File: MBeanClientInterceptorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected IJmxTestBean getProxy() throws Exception {
	MBeanProxyFactoryBean factory = new MBeanProxyFactoryBean();
	factory.setServer(getServerConnection());
	factory.setProxyInterface(IJmxTestBean.class);
	factory.setObjectName(OBJECT_NAME);
	factory.afterPropertiesSet();
	return (IJmxTestBean) factory.getObject();
}
 
Example #22
Source File: MBeanClientInterceptorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetAttributeValue() throws Exception {
	assumeTrue(runTests);
	IJmxTestBean proxy = getProxy();
	proxy.setName("Rob Harrop");
	assertEquals("The name of the bean should have been updated", "Rob Harrop", target.getName());
}
 
Example #23
Source File: MBeanClientInterceptorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAttributeValue() throws Exception {
	assumeTrue(runTests);
	IJmxTestBean proxy1 = getProxy();
	int age = proxy1.getAge();
	assertEquals("The age should be 100", 100, age);
}
 
Example #24
Source File: AbstractMetadataAssemblerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testWithCglibProxy() throws Exception {
	IJmxTestBean tb = createJmxTestBean();
	ProxyFactory pf = new ProxyFactory();
	pf.setTarget(tb);
	pf.addAdvice(new NopInterceptor());
	Object proxy = pf.getProxy();

	MetadataMBeanInfoAssembler assembler = (MetadataMBeanInfoAssembler) getAssembler();

	MBeanExporter exporter = new MBeanExporter();
	exporter.setBeanFactory(getContext());
	exporter.setAssembler(assembler);

	String objectName = "spring:bean=test,proxy=true";

	Map<String, Object> beans = new HashMap<>();
	beans.put(objectName, proxy);
	exporter.setBeans(beans);
	start(exporter);

	MBeanInfo inf = getServer().getMBeanInfo(ObjectNameManager.getInstance(objectName));
	assertEquals("Incorrect number of operations", getExpectedOperationCount(), inf.getOperations().length);
	assertEquals("Incorrect number of attributes", getExpectedAttributeCount(), inf.getAttributes().length);

	assertTrue("Not included in autodetection", assembler.includeBean(proxy.getClass(), "some bean name"));
}
 
Example #25
Source File: MBeanClientInterceptorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testDifferentProxiesSameClass() throws Exception {
	assumeTrue(runTests);
	IJmxTestBean proxy1 = getProxy();
	IJmxTestBean proxy2 = getProxy();

	assertNotSame("The proxies should NOT be the same", proxy1, proxy2);
	assertSame("The proxy classes should be the same", proxy1.getClass(), proxy2.getClass());
}
 
Example #26
Source File: AbstractJmxAssemblerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testRegisterOperations() throws Exception {
	IJmxTestBean bean = getBean();
	assertNotNull(bean);
	MBeanInfo inf = getMBeanInfo();
	assertEquals("Incorrect number of operations registered",
			getExpectedOperationCount(), inf.getOperations().length);
}
 
Example #27
Source File: AbstractJmxAssemblerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testRegisterAttributes() throws Exception {
	IJmxTestBean bean = getBean();
	assertNotNull(bean);
	MBeanInfo inf = getMBeanInfo();
	assertEquals("Incorrect number of attributes registered",
			getExpectedAttributeCount(), inf.getAttributes().length);
}
 
Example #28
Source File: AbstractJmxAssemblerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testSetAttribute() throws Exception {
	ObjectName objectName = ObjectNameManager.getInstance(getObjectName());
	getServer().setAttribute(objectName, new Attribute(NAME_ATTRIBUTE, "Rob Harrop"));
	IJmxTestBean bean = (IJmxTestBean) getContext().getBean("testBean");
	assertEquals("Rob Harrop", bean.getName());
}
 
Example #29
Source File: MBeanClientInterceptorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected IJmxTestBean getProxy() throws Exception {
	MBeanProxyFactoryBean factory = new MBeanProxyFactoryBean();
	factory.setServer(getServerConnection());
	factory.setProxyInterface(IJmxTestBean.class);
	factory.setObjectName(OBJECT_NAME);
	factory.afterPropertiesSet();
	return (IJmxTestBean) factory.getObject();
}
 
Example #30
Source File: PropertyPlaceholderConfigurerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testPropertiesReplaced() {
	IJmxTestBean bean = (IJmxTestBean) getContext().getBean("testBean");

	assertEquals("Name is incorrect", "Rob Harrop", bean.getName());
	assertEquals("Age is incorrect", 100, bean.getAge());
}