Search in sources :

Example 1 with DefaultNameProvider

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"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CompMember(org.opennms.netmgt.config.collectd.jmx.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)

Example 2 with DefaultNameProvider

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"));
}
Also used : Mbean(org.opennms.netmgt.config.collectd.jmx.Mbean) ArrayList(java.util.ArrayList) DefaultNameProvider(org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.DefaultNameProvider) Test(org.junit.Test)

Example 3 with DefaultNameProvider

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"));
}
Also used : DefaultNameProvider(org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.DefaultNameProvider) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 DefaultNameProvider (org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.DefaultNameProvider)3 ArrayList (java.util.ArrayList)2 Field (com.vaadin.ui.Field)1 TextField (com.vaadin.ui.TextField)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NameProvider (org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.NameProvider)1 CompMember (org.opennms.netmgt.config.collectd.jmx.CompMember)1 Mbean (org.opennms.netmgt.config.collectd.jmx.Mbean)1