@Test
  public void testGetSetMultiple() throws Exception {
    MultipleAttributes obj = new MultipleAttributes();
    JmxClient client = new JmxClient(DEFAULT_PORT);
    try {
      server.register(obj);
      int x = 2134;
      obj.x = x;
      int y = 242634;
      obj.y = y;

      List<Attribute> attributes =
          client.getAttributes(DOMAIN_NAME, OBJECT_NAME, new String[] {"x", "y"});
      assertEquals(2, attributes.size());
      assertEquals(x, attributes.get(0).getValue());
      assertEquals(y, attributes.get(1).getValue());

      int x2 = x + 1;
      int y2 = y + 1;
      attributes.clear();
      attributes.add(new Attribute("x", x2));
      attributes.add(new Attribute("y", y2));
      client.setAttributes(DOMAIN_NAME, OBJECT_NAME, attributes);

      attributes = client.getAttributes(DOMAIN_NAME, OBJECT_NAME, new String[] {"x", "y"});
      assertEquals(2, attributes.size());
      assertEquals("x", attributes.get(0).getName());
      assertEquals(x2, attributes.get(0).getValue());
      assertEquals("y", attributes.get(1).getName());
      assertEquals(y2, attributes.get(1).getValue());
    } finally {
      server.unregister(obj);
      client.close();
    }
  }
 @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 testMultiOperationSameName() throws Exception {
   MultiOperationSameName obj = new MultiOperationSameName();
   try {
     server.register(obj);
     JmxClient client = new JmxClient(DEFAULT_PORT);
     int x = 1002;
     assertEquals(x, client.invokeOperation(DOMAIN_NAME, OBJECT_NAME, "assignX", x));
     int y = 2934;
     assertEquals(y, client.invokeOperation(DOMAIN_NAME, OBJECT_NAME, "assignX", x, y));
   } finally {
     server.unregister(obj);
   }
 }
  @Test
  public void testGetAttributes() throws Exception {
    TestObject obj = new TestObject();
    JmxClient client;
    try {
      client = new JmxClient(DEFAULT_PORT);
      server.register(obj);

      MBeanAttributeInfo[] attributes = client.getAttributesInfo(DOMAIN_NAME, OBJECT_NAME);
      assertEquals(1, attributes.length);
      assertEquals("foo", attributes[0].getName());
      assertEquals(int.class.toString(), attributes[0].getType());

    } finally {
      server.unregister(obj);
    }
  }
  @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);
    }
  }
 @Test
 public void testAttributeFieldGets() throws Exception {
   AttributeField attributeField = new AttributeField();
   try {
     server.register(attributeField);
     JmxClient client = new JmxClient(DEFAULT_PORT);
     assertEquals(READ_ONLY_DEFAULT, client.getAttribute(DOMAIN_NAME, OBJECT_NAME, "readOnly"));
     assertEquals(READ_WRITE_DEFAULT, client.getAttribute(DOMAIN_NAME, OBJECT_NAME, "readWrite"));
     try {
       client.getAttribute(DOMAIN_NAME, OBJECT_NAME, "writeOnly");
       fail("Should have thrown");
     } catch (AttributeNotFoundException e) {
       // expected
     }
     try {
       client.getAttribute(DOMAIN_NAME, OBJECT_NAME, "neither");
       fail("Should have thrown");
     } catch (AttributeNotFoundException e) {
       // expected
     }
     try {
       client.getAttribute(DOMAIN_NAME, OBJECT_NAME, "noAnnotation");
       fail("Should have thrown");
     } catch (AttributeNotFoundException e) {
       // expected
     }
   } finally {
     server.unregister(attributeField);
   }
 }
 @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();
   }
 }