@Test(expected = ReflectionException.class) public void testSetThrows() throws Exception { AttributeThrows setThrow = new AttributeThrows(); JmxClient client = new JmxClient(DEFAULT_PORT); try { server.register(setThrow); client.setAttribute(DOMAIN_NAME, OBJECT_NAME, "throws", 1); } finally { server.unregister(setThrow); client.close(); } }
@Test(expected = AttributeNotFoundException.class) public void testUnknownSetter() throws Exception { TestObject testObj = new TestObject(); JmxClient client = new JmxClient(DEFAULT_PORT); try { server.register(testObj); client.setAttribute(DOMAIN_NAME, OBJECT_NAME, "unknown-attribute", 1); } finally { server.unregister(testObj); client.close(); } }
@Test public void testIsMethod() throws Exception { IsMethod isMethod = new IsMethod(); JmxClient client = new JmxClient(DEFAULT_PORT); try { server.register(isMethod); assertFalse((Boolean) client.getAttribute(DOMAIN_NAME, OBJECT_NAME, "flag")); client.setAttribute(DOMAIN_NAME, OBJECT_NAME, "flag", true); assertTrue((Boolean) client.getAttribute(DOMAIN_NAME, OBJECT_NAME, "flag")); } finally { server.unregister(isMethod); client.close(); } }
@Test public void testAttributeFieldSets() throws Exception { AttributeField attributeField = new AttributeField(); JmxClient client = new JmxClient(DEFAULT_PORT); try { server.register(attributeField); try { client.setAttribute(DOMAIN_NAME, OBJECT_NAME, "readOnly", 1); fail("Should have thrown"); } catch (AttributeNotFoundException e) { // expected } assertEquals(READ_WRITE_DEFAULT, client.getAttribute(DOMAIN_NAME, OBJECT_NAME, "readWrite")); int val = 530534543; client.setAttribute(DOMAIN_NAME, OBJECT_NAME, "readWrite", val); assertEquals(val, client.getAttribute(DOMAIN_NAME, OBJECT_NAME, "readWrite")); assertEquals(val, attributeField.readWrite); val = 342323423; client.setAttribute(DOMAIN_NAME, OBJECT_NAME, "writeOnly", val); assertEquals(val, attributeField.writeOnly); try { client.setAttribute(DOMAIN_NAME, OBJECT_NAME, "neither", 1); fail("Should have thrown"); } catch (AttributeNotFoundException e) { // expected } try { client.setAttribute(DOMAIN_NAME, OBJECT_NAME, "noAnnotation", 1); fail("Should have thrown"); } catch (AttributeNotFoundException e) { // expected } } finally { server.unregister(attributeField); client.close(); } }
@Test public void testRegister() throws Exception { TestObject obj = new TestObject(); JmxClient client; try { client = new JmxClient(DEFAULT_PORT); server.register(obj); try { client.getAttribute(DOMAIN_NAME, OBJECT_NAME, "unknown"); fail("Should have thrown"); } catch (Exception e) { // ignored } try { client.setAttribute(DOMAIN_NAME, OBJECT_NAME, "unknown", FOO_VALUE); fail("Should have thrown"); } catch (Exception e) { // ignored } try { client.invokeOperation(DOMAIN_NAME, OBJECT_NAME, "unknown"); fail("Should have thrown"); } catch (Exception e) { // ignored } try { client.invokeOperation(DOMAIN_NAME, OBJECT_NAME, "getFoo"); fail("Should have thrown"); } catch (Exception e) { // ignored } } finally { server.unregister(obj); } }