Search in sources :

Example 1 with HttpCollectionHandler

use of org.opennms.protocols.http.collector.HttpCollectionHandler in project opennms by OpenNMS.

the class HttpDataCollectionIT method testCssSelectorHttpCollection.

/**
     * Test HTTP Data Collection with CSS Selector
     *
     * @throws Exception the exception
     */
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testCssSelectorHttpCollection() throws Exception {
    File configFile = new File("src/test/resources/http-datacollection-config.xml");
    XmlDataCollectionConfig config = JaxbUtils.unmarshal(XmlDataCollectionConfig.class, configFile);
    XmlDataCollection collection = config.getDataCollectionByName("Http-Market");
    RrdRepository repository = createRrdRepository(collection.getXmlRrd());
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("collection", "Http-Market");
    HttpCollectionHandler collector = new HttpCollectionHandler();
    collector.setRrdRepository(repository);
    collector.setServiceName("HTTP");
    CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_nodeDao, collector, m_collectionAgent, collection, parameters);
    Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
    CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, repository, false, false);
    collectionSet.visit(persister);
    RrdDb jrb = new RrdDb(new File(getSnmpRoot(), "1/market.jrb"));
    Assert.assertNotNull(jrb);
    Assert.assertEquals(2, jrb.getDsCount());
    Datasource ds = jrb.getDatasource("nasdaq");
    Assert.assertNotNull(ds);
    Assert.assertEquals(new Double(3578.30), Double.valueOf(ds.getLastValue()));
}
Also used : Datasource(org.jrobin.core.Datasource) XmlDataCollectionConfig(org.opennms.protocols.xml.config.XmlDataCollectionConfig) HashMap(java.util.HashMap) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) HttpCollectionHandler(org.opennms.protocols.http.collector.HttpCollectionHandler) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) XmlDataCollection(org.opennms.protocols.xml.config.XmlDataCollection) RrdDb(org.jrobin.core.RrdDb) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) File(java.io.File) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Aggregations

File (java.io.File)1 HashMap (java.util.HashMap)1 Datasource (org.jrobin.core.Datasource)1 RrdDb (org.jrobin.core.RrdDb)1 Test (org.junit.Test)1 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)1 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)1 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)1 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)1 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)1 HttpCollectionHandler (org.opennms.protocols.http.collector.HttpCollectionHandler)1 XmlDataCollection (org.opennms.protocols.xml.config.XmlDataCollection)1 XmlDataCollectionConfig (org.opennms.protocols.xml.config.XmlDataCollectionConfig)1