Skip to content

Commit

Permalink
Write test for factory to ensure it supports the config split feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus von Rüden committed Jul 29, 2014
1 parent 3abd0e8 commit 25eb1bc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Expand Up @@ -302,14 +302,16 @@ public JmxCollection getJmxCollection(String collectionName) {
if (collection != null) {
// we clone the collection by marshal/unmarshalling the object :)
try {
// TODO mvr we cannot do it this way, this does not consider import
StringWriter out = new StringWriter();
Marshaller.marshal(collection, out);
StringReader in = new StringReader(out.toString());
return (JmxCollection) Unmarshaller.unmarshal(JmxCollection.class, in);
} catch (XMLException e) {
LOG.error("Could not marshal/unmarshal JMX config for collection '{}'.", collectionName);
return null;
}
} else {
LOG.warn("No JMX Config for collection '{}' found", collectionName);
}
return null;
}
Expand Down
@@ -0,0 +1,27 @@
package org.opennms.netmgt.config;

import org.junit.Assert;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class JMXDataCollectionConfigFactoryTest {

@Test
// Tests that the JmxDataCollectionConfigFactory also supports/implements the split config feature.
public void shouldSupportSplitConfig() throws FileNotFoundException {
File jmxCollectionConfig = new File("src/test/resources/etc/jmx-datacollection-split.xml");
Assert.assertTrue("JMX configuration file is not readable", jmxCollectionConfig.canRead());
FileInputStream configFileStream = new FileInputStream(jmxCollectionConfig);

JMXDataCollectionConfigFactory factory = new JMXDataCollectionConfigFactory(configFileStream);

Assert.assertNotNull(factory.getJmxCollection("jboss"));
Assert.assertNotNull(factory.getJmxCollection("jsr160"));
Assert.assertEquals(8, factory.getJmxCollection("jboss").getMbeans().getMbeanCount());
Assert.assertEquals(4, factory.getJmxCollection("jsr160").getMbeans().getMbeanCount());

}
}

0 comments on commit 25eb1bc

Please sign in to comment.