Search in sources :

Example 1 with CompMember

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"));
}
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)

Example 2 with CompMember

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);
}
Also used : CompMember(org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember) Test(org.junit.Test)

Example 3 with CompMember

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;
}
Also used : CompMember(org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember)

Example 4 with 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;
}
Also used : CompAttrib(org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib) CompMember(org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember)

Example 5 with CompMember

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;
}
Also used : Mbean(org.opennms.xmlns.xsd.config.jmx_datacollection.Mbean) JmxDatacollectionConfig(org.opennms.xmlns.xsd.config.jmx_datacollection.JmxDatacollectionConfig) CompAttrib(org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib) CompAttrib(org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib) Attrib(org.opennms.xmlns.xsd.config.jmx_datacollection.Attrib) CompMember(org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember)

Aggregations

CompMember (org.opennms.xmlns.xsd.config.jmx_datacollection.CompMember)11 CompAttrib (org.opennms.xmlns.xsd.config.jmx_datacollection.CompAttrib)7 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)2 Attrib (org.opennms.xmlns.xsd.config.jmx_datacollection.Attrib)2 Mbean (org.opennms.xmlns.xsd.config.jmx_datacollection.Mbean)2 Field (com.vaadin.ui.Field)1 TextField (com.vaadin.ui.TextField)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CompositeData (javax.management.openmbean.CompositeData)1 DefaultNameProvider (org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.DefaultNameProvider)1 NameProvider (org.opennms.features.vaadin.jmxconfiggenerator.ui.mbeans.NameProvider)1 JmxDatacollectionConfig (org.opennms.xmlns.xsd.config.jmx_datacollection.JmxDatacollectionConfig)1