use of org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember in project opennms by OpenNMS.
the class UniqueAttributeNameValidatorTest method testOverriddenByField.
/**
* We test that the values in the fieldMap are considered while validating the uniqueness of aliases.
*/
@Test
public void testOverriddenByField() {
// simulate a user input in a text field bound to the MBeans only CompAttrib's CompMember (see method before/setUp)
Field<String> dummyField = new TextField();
dummyField.setValue("attrib1");
CompMember compMember = selectionManager.getSelectedCompositeMembers(null).iterator().next();
final Map<Object, Field<String>> fieldMap = new HashMap<>();
fieldMap.put(compMember, dummyField);
// Verify nameProvider
NameProvider nameProvider = new DefaultNameProvider(selectionManager);
List<String> names = new ArrayList<>(nameProvider.getNamesMap().values());
Assert.assertNotNull(names);
Collections.sort(names);
Assert.assertTrue(Arrays.equals(new String[] { "attrib1", "compMem1", "compMem2" }, names.toArray(new String[names.size()])));
// Verify validator
UniqueAttributeNameValidator validator = new UniqueAttributeNameValidator(nameProvider, new UniqueAttributeNameValidator.FieldProvider() {
@Override
public Map<Object, Field<String>> getObjectFieldMap() {
return fieldMap;
}
});
names = validator.getNames();
Assert.assertNotNull(names);
Collections.sort(names);
Assert.assertTrue(Arrays.equals(new String[] { "attrib1", "attrib1", "compMem2" }, names.toArray(new String[names.size()])));
Assert.assertEquals(false, validator.isValid("attrib1"));
Assert.assertEquals(true, validator.isValid("compMem2"));
}
use of org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember in project opennms by OpenNMS.
the class AttributeValidatorTest method testCompositeMemberValidator.
@Test
public void testCompositeMemberValidator() {
// simple test first
CompMember compMember = new CompMember();
compMember.setName("ulf");
compMember.setAlias("ulf");
validationManager.validate(compMember, result);
Assert.assertEquals(Boolean.TRUE, result.isValid());
// lets have a length issue
compMember.setAlias(Strings.repeat("X", Config.ATTRIBUTES_ALIAS_MAX_LENGTH + 1));
validationManager.validate(compMember, result);
verifyResult(result, compMember, 1, MaximumLengthValidator.ERROR_MESSAGE);
// lets also have a name issue
compMember.setAlias("Ülf");
validationManager.validate(compMember, result);
verifyResult(result, compMember, 2, MaximumLengthValidator.ERROR_MESSAGE, AttributeNameValidator.ERROR_MESSAGE);
}
use of org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember in project opennms by OpenNMS.
the class TestHelper method createCompMember.
public static CompMember createCompMember(String name, String alias) {
CompMember compMember = new CompMember();
compMember.setName(name);
compMember.setAlias(alias);
return compMember;
}
use of org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember in project opennms by OpenNMS.
the class TestHelper method createCompAttrib.
public static CompAttrib createCompAttrib(String name, CompMember... compMember) {
CompAttrib compAttrib = new CompAttrib();
compAttrib.setName(name);
for (CompMember eachMember : compMember) {
compAttrib.getCompMember().add(eachMember);
}
return compAttrib;
}
use of org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember in project opennms by OpenNMS.
the class MBeansView method createJmxDataCollectionAccordingToSelection.
/**
* The whole point was to select/deselect
* Mbeans/Attribs/CompMembers/CompAttribs. In this method we simply create a
* JmxDatacollectionConfig considering the choices we made in the gui. To do
* this, we clone the original <code>JmxDatacollectionConfig</code>
* loaded at the beginning. After that we remove all
* MBeans/Attribs/CompMembers/CompAttribs and add all selected
* MBeans/Attribs/CompMembers/CompAttribs afterwards.
*
* @return
*/
private static JmxDatacollectionConfig createJmxDataCollectionAccordingToSelection(final UiModel uiModel, final SelectionManager selectionManager) {
/*
* At First we clone the original collection. This is done, because if
* we make any modifications (e.g. deleting not selected elements) the
* data isn't available in the GUI, too. To avoid reloading the data
* from server, we just clone it.
*/
JmxDatacollectionConfig clone = JmxCollectionCloner.clone(uiModel.getRawModel());
/*
* At second we remove all MBeans from original data and get only
* selected once.
*/
List<Mbean> exportBeans = clone.getJmxCollection().get(0).getMbeans().getMbean();
exportBeans.clear();
Iterable<Mbean> selectedMbeans = selectionManager.getSelectedMbeans();
for (Mbean mbean : selectedMbeans) {
/*
* We remove all Attributes from Mbean, because we only want
* selected ones.
*/
Mbean exportBean = JmxCollectionCloner.clone(mbean);
// we only want selected ones :)
exportBean.getAttrib().clear();
for (Attrib att : selectionManager.getSelectedAttributes(mbean)) {
exportBean.getAttrib().add(JmxCollectionCloner.clone(att));
}
// we do not add the parent
if (!exportBean.getAttrib().isEmpty()) {
exportBeans.add(exportBean);
}
/*
* We remove all CompAttribs and CompMembers from MBean,
* because we only want selected ones.
*/
exportBean.getCompAttrib().clear();
for (CompAttrib compAtt : selectionManager.getSelectedCompositeAttributes(mbean)) {
CompAttrib cloneCompAtt = JmxCollectionCloner.clone(compAtt);
cloneCompAtt.getCompMember().clear();
for (CompMember compMember : selectionManager.getSelectedCompositeMembers(compAtt)) {
cloneCompAtt.getCompMember().add(JmxCollectionCloner.clone(compMember));
}
// we do not add the child
if (!cloneCompAtt.getCompMember().isEmpty()) {
exportBean.getCompAttrib().add(cloneCompAtt);
}
}
}
// we sort the order, so the result is deterministic
sort(exportBeans);
// Last but not least, we need to update the service name
clone.getJmxCollection().get(0).setName(uiModel.getServiceName());
return clone;
}
Aggregations