use of org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.DefaultNameProvider 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.features.vaadin.jmxconfiggenerator.ui.mbeans.DefaultNameProvider in project opennms by OpenNMS.
the class UniqueAttributeNameValidatorTest method testNotEmpty.
@Test
public void testNotEmpty() {
Mbean mbean = selectionManager.getSelectedMbeans().iterator().next();
DefaultNameProvider nameProvider = new DefaultNameProvider(selectionManager);
List<String> names = new ArrayList<>(nameProvider.getNamesMap().values());
Assert.assertNotNull(names);
Assert.assertEquals(3, names.size());
Collections.sort(names);
Assert.assertTrue(Arrays.equals(new String[] { "attrib1", "compMem1", "compMem2" }, names.toArray(new String[names.size()])));
// alias clash
mbean.addAttrib(TestHelper.createAttrib("attribute2", "attrib1"));
names = new ArrayList<>(nameProvider.getNamesMap().values());
Assert.assertEquals(4, names.size());
UniqueAttributeNameValidator validator = new UniqueAttributeNameValidator(nameProvider);
Assert.assertEquals(Boolean.TRUE.booleanValue(), validator.isValid("yes"));
Assert.assertEquals(Boolean.TRUE.booleanValue(), validator.isValid("compMem1"));
Assert.assertEquals(Boolean.FALSE.booleanValue(), validator.isValid("attrib1"));
}
use of org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.DefaultNameProvider in project opennms by OpenNMS.
the class UniqueAttributeNameValidatorTest method testEmpty.
@Test
public void testEmpty() {
DefaultNameProvider defaultNameProvider = new DefaultNameProvider(SelectionManager.EMPTY);
Collection<String> names = new DefaultNameProvider(SelectionManager.EMPTY).getNamesMap().values();
Assert.assertNotNull(names);
Assert.assertEquals(Boolean.TRUE.booleanValue(), names.isEmpty());
UniqueAttributeNameValidator validator = new UniqueAttributeNameValidator(defaultNameProvider);
Assert.assertEquals(true, validator.isValid("not-existing"));
Assert.assertEquals(true, validator.isValid("compMem1"));
Assert.assertEquals(true, validator.isValid("attrib1"));
}
Aggregations