use of org.opennms.netmgt.config.HttpCollectionConfigFactory in project opennms by OpenNMS.
the class JUnitCollectorExecutionListener method beforeTestMethod.
@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
m_fileAnticipator = new FileAnticipator();
JUnitCollector config = findCollectorAnnotation(testContext);
if (config == null) {
return;
}
// make a fake database schema with hibernate
InputStream is = ConfigurationTestUtils.getInputStreamForResource(testContext.getTestInstance(), config.schemaConfig());
DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(is));
is.close();
// set up temporary directories for RRD files
m_snmpRrdDirectory = m_fileAnticipator.tempDir("snmp");
m_snmpRrdDirectory.mkdirs();
testContext.setAttribute("fileAnticipator", m_fileAnticipator);
testContext.setAttribute("rrdDirectory", m_snmpRrdDirectory);
// set up the collection configuration factory
if ("http".equalsIgnoreCase(config.datacollectionType()) || "https".equalsIgnoreCase(config.datacollectionType())) {
is = ConfigurationTestUtils.getInputStreamForResourceWithReplacements(testContext.getTestInstance(), config.datacollectionConfig(), new String[] { "%rrdRepository%", m_snmpRrdDirectory.getAbsolutePath() });
HttpCollectionConfigFactory factory = new HttpCollectionConfigFactory(is);
HttpCollectionConfigFactory.setInstance(factory);
HttpCollectionConfigFactory.init();
} else if ("snmp".equalsIgnoreCase(config.datacollectionType())) {
Resource r = ConfigurationTestUtils.getSpringResourceForResourceWithReplacements(testContext.getTestInstance(), config.datacollectionConfig(), new String[] { "%rrdRepository%", m_snmpRrdDirectory.getAbsolutePath() });
DefaultDataCollectionConfigDao dataCollectionDao = new DefaultDataCollectionConfigDao();
dataCollectionDao.setConfigResource(r);
dataCollectionDao.afterPropertiesSet();
DataCollectionConfigFactory.setInstance(dataCollectionDao);
} else {
throw new UnsupportedOperationException("data collection type '" + config.datacollectionType() + "' not supported");
}
IOUtils.closeQuietly(is);
}
Aggregations