Search in sources :

Example 21 with JUnitHttpServer

use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.

the class HttpUrlConnectionIT method testForm.

/**
 * Test POST Request based on Form Data.
 *
 * @throws Exception the exception
 */
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testForm() throws Exception {
    String json = "<form-fields><form-field name='firstName'>Alejandro</form-field><form-field name='lastName'>Galue</form-field></form-fields>";
    Request req = buildRequest("application/x-www-form-urlencoded", json);
    executeRequest(req);
}
Also used : Request(org.opennms.protocols.xml.config.Request) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 22 with JUnitHttpServer

use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.

the class HttpUrlConnectionIT method testJson.

/**
 * Test POST Request based on JSON Data.
 *
 * @throws Exception the exception
 */
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testJson() throws Exception {
    String json = "{ person: { firstName: 'Alejandro', lastName: 'Galue' } }";
    Request req = buildRequest("application/json", json);
    executeRequest(req);
}
Also used : Request(org.opennms.protocols.xml.config.Request) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 23 with JUnitHttpServer

use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.

the class HttpUrlConnectionIT method testXml.

/**
 * Test POST Request based on XML Data.
 *
 * @throws Exception the exception
 */
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testXml() throws Exception {
    String xml = "<person><firstName>Alejandro</firstName><lastName>Galue</lastName></person>";
    Request req = buildRequest("application/xml", xml);
    executeRequest(req);
}
Also used : Request(org.opennms.protocols.xml.config.Request) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 24 with JUnitHttpServer

use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.

the class NMS7963IT method testHttpCollection.

/**
 * Test HTTP Data Collection with XPath
 *
 * @throws Exception the exception
 */
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testHttpCollection() throws Exception {
    File configFile = new File("src/test/resources/http-datacollection-config.xml");
    XmlDataCollectionConfig config = JaxbUtils.unmarshal(XmlDataCollectionConfig.class, configFile);
    XmlDataCollection collection = config.getDataCollectionByName("NMS-7963");
    RrdRepository repository = createRrdRepository(collection.getXmlRrd());
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("collection", "NMS-7963");
    DefaultXmlCollectionHandler collector = new DefaultXmlCollectionHandler();
    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/xml-retrv-wipo-data.jrb"));
    Assert.assertNotNull(jrb);
    Assert.assertEquals(1, jrb.getDsCount());
    Datasource ds = jrb.getDatasource("xml-wipo-paco");
    Assert.assertNotNull(ds);
    Assert.assertEquals(new Double(903), 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) 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)

Example 25 with JUnitHttpServer

use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.

the class HypericAckProcessorIT method testStartAckd.

@Test
@JUnitHttpServer(port = 7081)
public void testStartAckd() throws Exception {
    AckdConfigurationDao realDao = createAckdConfigDao();
    AckdConfigurationDao mockDao = createMock(AckdConfigurationDao.class);
    expect(mockDao.getEnabledReaderCount()).andDelegateTo(realDao);
    expect(mockDao.isReaderEnabled("JavaMailReader")).andDelegateTo(realDao).times(2);
    expect(mockDao.isReaderEnabled("HypericReader")).andDelegateTo(realDao).times(2);
    expect(mockDao.getReaderSchedule("HypericReader")).andDelegateTo(realDao).times(2);
    replay(mockDao);
    m_daemon.setConfigDao(mockDao);
    m_daemon.start();
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
    }
    m_daemon.destroy();
    verify(mockDao);
}
Also used : DefaultAckdConfigurationDao(org.opennms.netmgt.dao.jaxb.DefaultAckdConfigurationDao) AckdConfigurationDao(org.opennms.netmgt.dao.api.AckdConfigurationDao) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Aggregations

JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)48 Test (org.junit.Test)46 PollStatus (org.opennms.netmgt.poller.PollStatus)18 MonitoredService (org.opennms.netmgt.poller.MonitoredService)9 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)8 File (java.io.File)7 HashMap (java.util.HashMap)7 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)6 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)6 Calendar (java.util.Calendar)5 GregorianCalendar (java.util.GregorianCalendar)5 HttpGet (org.apache.http.client.methods.HttpGet)5 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)5 Datasource (org.jrobin.core.Datasource)4 RrdDb (org.jrobin.core.RrdDb)4 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)4 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)4 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)4 XmlDataCollection (org.opennms.protocols.xml.config.XmlDataCollection)4 XmlDataCollectionConfig (org.opennms.protocols.xml.config.XmlDataCollectionConfig)4