Search in sources :

Example 1 with NameProvider

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"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CompMember(org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember) Field(com.vaadin.ui.Field) TextField(com.vaadin.ui.TextField) DefaultNameProvider(org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.DefaultNameProvider) NameProvider(org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.NameProvider) TextField(com.vaadin.ui.TextField) DefaultNameProvider(org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.DefaultNameProvider) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Field (com.vaadin.ui.Field)1 TextField (com.vaadin.ui.TextField)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 DefaultNameProvider (org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.DefaultNameProvider)1 NameProvider (org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.NameProvider)1 CompMember (org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember)1