use of org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.NameProvider 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"));
}
Aggregations