Package test.javax.management.modelmbean.support

Examples of test.javax.management.modelmbean.support.ModelMBeanTarget


      String attrName1 = "MutableContent";

      ObjectName name = new ObjectName(":type=test");

      MutableInteger counter = new MutableInteger(0);
      ModelMBeanTarget bean = new ModelMBeanTarget(counter);

      String[] names1 = new String[]{"name", "descriptorType", "value", "iterable", "displayName", "setMethod", "getMethod", "currencyTimeLimit"};
      // changed to match the actual behaviour indicated in the specs about currencyTimeLimit
      // currencyTimeLimit is now -1
      Object[] values1 = new Object[]{attrName1, "attribute", null, "false", "", "set" + attrName1, "get" + attrName1, "-1"};
      DescriptorSupport attrDescr1 = new DescriptorSupport(names1, values1);

      ModelMBeanAttributeInfo attrInfo1 = new ModelMBeanAttributeInfo(attrName1, String.class.getName(), "", true, true, false, attrDescr1);
      ModelMBeanInfoSupport info = new ModelMBeanInfoSupport(ModelMBeanTarget.class.getName(), "", new ModelMBeanAttributeInfo[]{attrInfo1}, null, null, null);

      final MutableBoolean storeTester = new MutableBoolean(false);
      RequiredModelMBean rmmb = new StoreTesterRMMB(storeTester);
      rmmb.setModelMBeanInfo(info);
      rmmb.setManagedResource(bean, "ObjectReference");
      m_server.registerMBean(rmmb, name);

      // Adding a attribute change notification listener
      final MutableInteger listenerCount = new MutableInteger(0);
      rmmb.addAttributeChangeNotificationListener(new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            listenerCount.set(listenerCount.get() + 1);
         }
      }, attrName1, null);

      String value = "SET_FIRST_TIME";
      Attribute attribute = new Attribute(attrName1, value);
      m_server.setAttribute(name, attribute);

      // check that has really been set
      assertEquals(bean.getMutableContent(), value);
      // check through MBeanServer
      assertEquals(m_server.getAttribute(name, attrName1), value);
      // check that listener has been called
      assertEquals(listenerCount.get(), 1);
      // There is no persistence settings, check that store was not called
      assertFalse("Store should not have been called", storeTester.get());

      // Adding a attribute change notification listener with
      // null as attribute. test for bug #742389
      NotificationListener dummyListener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
         }
      };

      rmmb.addAttributeChangeNotificationListener(dummyListener, null, null);
      rmmb.removeAttributeChangeNotificationListener(dummyListener, null);

      // Change the persist policy - have to unregeister to call setModelMBeanInfo
      m_server.unregisterMBean(name);
      attrDescr1.setField("persistPolicy", "OnUpdate");
      info.setDescriptor(attrDescr1, "attribute");
      rmmb.setModelMBeanInfo(info);
      storeTester.set(false);
      m_server.registerMBean(rmmb, name);

      value = "SET_SECOND_TIME";
      attribute = new Attribute(attrName1, value);
      m_server.setAttribute(name, attribute);

      // check that listener has been called
      assertEquals(listenerCount.get(), 2);
      // There are persistence settings, check that store was called
      assertTrue("Store should have been called", storeTester.get());

      // Now remove setMethod - again we have to unregister
      m_server.unregisterMBean(name);
      names1 = new String[]{"name", "descriptorType", "value", "iterable", "displayName", "getMethod", "currencyTimeLimit"};
      // changed to match the actual behaviour indicated in the specs about currencyTimeLimit
      // currencyTimeLimit is now -1
      values1 = new Object[]{attrName1, "attribute", null, "false", "", "get" + attrName1, "-1"};
      attrDescr1 = new DescriptorSupport(names1, values1);
      attrDescr1.setField("persistPolicy", "OnUpdate");
      info.setDescriptor(attrDescr1, "attribute");
      rmmb.setModelMBeanInfo(info);
      storeTester.set(false);
      m_server.registerMBean(rmmb, name);

      value = "SET_THIRD_TIME";
      attribute = new Attribute(attrName1, value);
      m_server.setAttribute(name, attribute);

      // check that listener has been called
      assertEquals(listenerCount.get(), 3);
      // There are persistence settings, check that store was called
      assertTrue("Store should have been called", storeTester.get());
      // Check the attribute value
      if (bean.getMutableContent().equals(value))
      {
         fail("No setMethod, bean should not have been modified");
      }
      if (info.getAttribute(attrName1).getDescriptor().getFieldValue("value") != null)
      {
View Full Code Here


      String attrName2 = "MutableContent2";

      ObjectName name = new ObjectName(":type=test");

      MutableInteger counter = new MutableInteger(0);
      ModelMBeanTarget bean = new ModelMBeanTarget(counter);

      String[] names1 = new String[]{"name", "descriptorType", "value", "iterable", "displayName", "getMethod", "setMethod", "currencyTimeLimit"};
      // changed to match the actual behaviour indicated in the specs about currencyTimeLimit
      // currencyTimeLimit is now -1
      Object[] values1 = new Object[]{attrName1, "attribute", null, "false", "", "get" + attrName1, "set" + attrName1, "-1"};
      DescriptorSupport attrDescr1 = new DescriptorSupport(names1, values1);

      String[] names2 = new String[]{"name", "descriptorType", "value", "iterable", "displayName", "getMethod", "setMethod", "currencyTimeLimit"};
      // changed to match the actual behaviour indicated in the specs about currencyTimeLimit
      // currencyTimeLimit is now -1
      Object[] values2 = new Object[]{attrName2, "attribute", null, "false", "", "get" + attrName2, "set" + attrName2, "-1"};
      DescriptorSupport attrDescr2 = new DescriptorSupport(names2, values2);

      ModelMBeanAttributeInfo attrInfo1 = new ModelMBeanAttributeInfo(attrName1, String.class.getName(), "", true, true, false, attrDescr1);
      ModelMBeanAttributeInfo attrInfo2 = new ModelMBeanAttributeInfo(attrName2, "int", "", true, true, false, attrDescr2);
      ModelMBeanInfoSupport info = new ModelMBeanInfoSupport(ModelMBeanTarget.class.getName(), "", new ModelMBeanAttributeInfo[]{attrInfo1, attrInfo2}, null, null, null);

      RequiredModelMBean rmmb = new RequiredModelMBean();
      rmmb.setModelMBeanInfo(info);
      rmmb.setManagedResource(bean, "ObjectReference");
      m_server.registerMBean(rmmb, name);

      Attribute attr1 = new Attribute(attrName1, "FIRST");
      Attribute attr2 = new Attribute(attrName2, new Integer(5));
      AttributeList list = new AttributeList();
      list.add(attr1);
      list.add(attr2);
      AttributeList result = m_server.setAttributes(name, list);
      assertEquals("Wrong number of attributes were set", result.size(), 2);
      // Check that they're really the right ones
      Attribute attr = (Attribute)result.get(0);
      assertEquals(attr, attr1);
      attr = (Attribute)result.get(1);
      assertEquals(attr, attr2);
      // Check that they were really set
      assertEquals(bean.getMutableContent(), attr1.getValue());
      assertEquals(bean.getMutableContent2(), ((Integer)attr2.getValue()).intValue());

      // Test non-existing attribute
      attr = new Attribute("NonExisting", null);
      attr2 = new Attribute(attrName2, new Integer(7));
      list.clear();
      list.add(attr);
      list.add(attr2);
      result = m_server.setAttributes(name, list);
      assertEquals(result.size(), 1);
      // Check that they're really the right ones
      attr = (Attribute)result.get(0);
      assertEquals(attr, attr2);
      // Check that they were really set
      assertEquals(bean.getMutableContent2(), ((Integer)attr2.getValue()).intValue());

      attr = new Attribute("NonExisting", null);
      list.clear();
      list.add(attr);
      result = m_server.setAttributes(name, list);
View Full Code Here

      String operation = "operation1";

      ObjectName name = new ObjectName(":type=test");

      MutableInteger counter = new MutableInteger(0);
      ModelMBeanTarget bean = new ModelMBeanTarget(counter);

      String[] names1 = new String[]{"name", "descriptorType", "displayName", "role", "targetObject", "targetObjectType", "currencyTimeLimit"};
      // changed to match the actual behaviour indicated in the specs about currencyTimeLimit
      // currencyTimeLimit is now -1
      Object[] values1 = new Object[]{operation, "operation", "", "operation", null, null, "-1"};
View Full Code Here

      catch (Exception ignored)
      {
      }

      // Bug #940161 Required ModelMBean methods are not invoked
      m_server.invoke(name, "setManagedResource", new Object[]{new ModelMBeanTarget(new MutableInteger(0)), "ObjectReference"}, new String[]{Object.class.getName(), String.class.getName()});
      m_server.invoke(name, "store", new Object[0], new String[0]);
      m_server.invoke(name, "sendNotification", new Object[]{"generic"}, new String[]{String.class.getName()});

      // Now specify setManagedResource as an operation in the MMBI
      m_server.unregisterMBean(name);
      String operation = "setManagedResource";
      MBeanParameterInfo paramInfo1 = new MBeanParameterInfo("resource", Object.class.getName(), "");
      MBeanParameterInfo paramInfo2 = new MBeanParameterInfo("type", String.class.getName(), "");
      ModelMBeanOperationInfo operInfo = new ModelMBeanOperationInfo(operation, "", new MBeanParameterInfo[]{paramInfo1, paramInfo2}, null, ModelMBeanOperationInfo.ACTION, null);
      info = new ModelMBeanInfoSupport(ModelMBeanTarget.class.getName(), "", null, null, new ModelMBeanOperationInfo[]{operInfo}, null);
      mmb.setModelMBeanInfo(info);
      m_server.registerMBean(mmb, name);

      // Spec says I must be able to invoke it
      Object target = new ModelMBeanTarget(new MutableInteger(0));
      m_server.invoke(name, operation, new Object[]{target, "ObjectReference"}, new String[]{Object.class.getName(), String.class.getName()});
   }
View Full Code Here

      ModelMBeanAttributeInfo attributeInfo = new ModelMBeanAttributeInfo("MutableContent", String.class.getName(), "", true, true, false);
      ModelMBeanInfoSupport info = new ModelMBeanInfoSupport(ModelMBeanTarget.class.getName(), "", new ModelMBeanAttributeInfo[]{attributeInfo}, null, null, notification);

      RequiredModelMBean rmmb = new RequiredModelMBean();
      rmmb.setModelMBeanInfo(info);
      rmmb.setManagedResource(new ModelMBeanTarget(new MutableInteger(0)), "objectReference");
      m_server.registerMBean(rmmb, name);

      Object listenerHandback = new Object();

      TestNotificationListener listener = new TestNotificationListener();
View Full Code Here

   public void testGetAttributeDefault() throws Exception
   {
      ObjectName name = new ObjectName(":type=test");

      MutableInteger counter = new MutableInteger(0);
      ModelMBeanTarget bean = new ModelMBeanTarget(counter);

      String attrName = "FixedContent";

      String[] names = new String[]{"name", "descriptorType", "value", "iterable", "displayName", "default", "currencyTimeLimit"};
      // changed to match the actual behaviour indicated in the specs about currencyTimeLimit
View Full Code Here

   public void testGetAttributeAlwaysStale() throws Exception
   {
      ObjectName name = new ObjectName(":type=test");

      MutableInteger counter = new MutableInteger(0);
      ModelMBeanTarget bean = new ModelMBeanTarget(counter);

      String attrName = "FixedContent";

      String[] names = new String[]{"name", "descriptorType", "value", "iterable", "displayName", "default", "getMethod", "currencyTimeLimit"};
      // changed to match the actual behaviour indicated in the specs about currencyTimeLimit
      // if currencyTimeLimit is -1 then the value is always stale
      // fix for bug #794313
      Object[] values = new Object[]{attrName, "attribute", null, "false", "", "DEFAULT", "get" + attrName, "-1"};
      DescriptorSupport attrDescr = new DescriptorSupport(names, values);
      ModelMBeanAttributeInfo attrInfo = new ModelMBeanAttributeInfo(attrName, String.class.getName(), "", true, false, false, attrDescr);
      ModelMBeanInfoSupport info = new ModelMBeanInfoSupport(ModelMBeanTarget.class.getName(), "", new ModelMBeanAttributeInfo[]{attrInfo}, null, null, null);

      RequiredModelMBean rmmb = new RequiredModelMBean();
      rmmb.setModelMBeanInfo(info);
      rmmb.setManagedResource(bean, "ObjectReference");
      m_server.registerMBean(rmmb, name);

      // We set the staleness to 0 (-> always stale) so test if the bean method is always called
      String fixed = bean.getFixedContent();
      counter.set(0);
      int num = 5;
      for (int i = 0; i < num; ++i)
      {
         String value = (String)m_server.getAttribute(name, attrName);
View Full Code Here

   public void testGetAttributeNeverStale() throws Exception
   {
      ObjectName name = new ObjectName(":type=test");

      MutableInteger counter = new MutableInteger(0);
      ModelMBeanTarget bean = new ModelMBeanTarget(counter);

      String attrName = "FixedContent";

      String[] names = new String[]{"name", "descriptorType", "value", "iterable", "displayName", "default", "getMethod", "currencyTimeLimit", "value"};
      // changed to match the actual behaviour indicated in the specs about currencyTimeLimit
View Full Code Here

   public void testGetAttributeStale() throws Exception
   {
      ObjectName name = new ObjectName(":type=test");

      MutableInteger counter = new MutableInteger(0);
      ModelMBeanTarget bean = new ModelMBeanTarget(counter);

      String attrName = "MutableContent";

      String[] names = new String[]{"name", "descriptorType", "value", "iterable", "displayName", "default", "getMethod", "currencyTimeLimit"};
      Object[] values = new Object[]{attrName, "attribute", null, "false", "", "DEFAULT", "get" + attrName, "2"};
      DescriptorSupport attrDescr = new DescriptorSupport(names, values);
      ModelMBeanAttributeInfo attrInfo = new ModelMBeanAttributeInfo(attrName, "java.lang.String", "", true, false, false, attrDescr);
      ModelMBeanInfoSupport info = new ModelMBeanInfoSupport("test.javax.management.modelmbean.ModelMBeanTarget", "", new ModelMBeanAttributeInfo[]{attrInfo}, null, null, null);

      RequiredModelMBean rmmb = new RequiredModelMBean();
      rmmb.setModelMBeanInfo(info);
      rmmb.setManagedResource(bean, "ObjectReference");
      m_server.registerMBean(rmmb, name);

      // We set the staleness to 2 seconds

      // First time
      bean.setMutableContent("First");
      String attrValue = (String)m_server.getAttribute(name, attrName);
      assertEquals("getAttribute does not work", attrValue, "First");

      // Now value should be cached, check it
      bean.setMutableContent("Second");
      attrValue = (String)m_server.getAttribute(name, attrName);
      assertEquals("Attribute value caching does not work", attrValue, "First");

      // Now wait 2 seconds
      Thread.sleep(2000);
View Full Code Here

      String attrName2 = "MutableContent";

      ObjectName name = new ObjectName(":type=test");

      MutableInteger counter = new MutableInteger(0);
      ModelMBeanTarget bean = new ModelMBeanTarget(counter);

      String[] names1 = new String[]{"name", "descriptorType", "value", "iterable", "displayName", "getMethod", "currencyTimeLimit"};
      // changed to match the actual behaviour indicated in the specs about currencyTimeLimit
      // currencyTimeLimit is now -1
      Object[] values1 = new Object[]{attrName1, "attribute", null, "false", "", "get" + attrName1, "-1"};
View Full Code Here

TOP

Related Classes of test.javax.management.modelmbean.support.ModelMBeanTarget

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.