Search in sources :

Example 1 with HttpCollectionConfigFactory

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);
}
Also used : HttpCollectionConfigFactory(org.opennms.netmgt.config.HttpCollectionConfigFactory) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) DatabaseSchemaConfigFactory(org.opennms.netmgt.config.DatabaseSchemaConfigFactory) FileAnticipator(org.opennms.test.FileAnticipator) DefaultDataCollectionConfigDao(org.opennms.netmgt.config.DefaultDataCollectionConfigDao)

Aggregations

InputStream (java.io.InputStream)1 DatabaseSchemaConfigFactory (org.opennms.netmgt.config.DatabaseSchemaConfigFactory)1 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)1 HttpCollectionConfigFactory (org.opennms.netmgt.config.HttpCollectionConfigFactory)1 FileAnticipator (org.opennms.test.FileAnticipator)1 Resource (org.springframework.core.io.Resource)1