AlertsJmxConfiguration implements DynamicMBean { @Override public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { Assert.notNull(attribute, "attribute must not be null"); String attrName = attribute.getName(); String value = (String) attribute.getValue(); AlertInfo alert = getAlert(attrName); if (StringUtils.endsWith(attrName, ENABLE_SUFFIX)) { alert.setEnabled(BooleanUtils.toBoolean(value)); } else if (StringUtils.endsWith(attrName, LIMIT_SUFFIX)) { alert.setLimit(Long.valueOf(value)); } else { throw new IllegalStateException("unsupported attribute name '" + attrName + "'"); } } @Autowired  AlertsJmxConfiguration(AbstractAlertsConfiguration configuration); @Override MBeanInfo getMBeanInfo(); @Override Object getAttribute(String attrName); @Override void setAttribute(Attribute attribute); @Override AttributeList getAttributes(String[] strings); @Override AttributeList setAttributes(AttributeList objects); @Override Object invoke(String s, Object[] objects, String[] strings);  }
@Test public void testSetAttribute() throws Exception { Attribute attribute = new Attribute("ID.enabled", "false"); jmx.setAttribute(attribute); assertThat(jmx.getAttribute("ID.enabled").toString(), is("false")); attribute = new Attribute("ID.limit", "8"); jmx.setAttribute(attribute); assertThat(jmx.getAttribute("ID.limit").toString(), is("8")); try { attribute = new Attribute("something", "enable"); jmx.setAttribute(attribute); fail("there is no attribute with specified key"); } catch (AttributeNotFoundException ex) { } }