Search in sources :

Example 16 with JUnitHttpServer

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

the class TcpMonitorIT method testLocalhostIPv6Connection.

@Test
@JUnitHttpServer(port = 10342)
public void testLocalhostIPv6Connection() throws UnknownHostException {
    assumeTrue(!Boolean.getBoolean("skipIpv6Tests"));
    Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    Parameter p = new Parameter();
    ServiceMonitor monitor = new TcpMonitor();
    MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "::1", addr("::1"), "TCP");
    p.setKey("port");
    p.setValue("10342");
    m.put(p.getKey(), p.getValue());
    p.setKey("retry");
    p.setValue("1");
    m.put(p.getKey(), p.getValue());
    p.setKey("timeout");
    p.setValue("500");
    m.put(p.getKey(), p.getValue());
    PollStatus status = monitor.poll(svc, m);
    MockUtil.println("Reason: " + status.getReason());
    assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
    assertNull(status.getReason());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) PollStatus(org.opennms.netmgt.poller.PollStatus) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Parameter(org.opennms.netmgt.config.poller.Parameter) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 17 with JUnitHttpServer

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

the class HttpNorthBounderTest method testForwardAlarms.

/**
 * Test forward alarms.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
@JUnitHttpServer(port = 10342)
public void testForwardAlarms() throws InterruptedException {
    HttpNorthbounder nb = new HttpNorthbounder();
    HttpNorthbounderConfig config = new HttpNorthbounderConfig("localhost");
    config.setMethod(HttpMethod.POST);
    config.setPath("/jms/post");
    config.setPort(Integer.valueOf(10342));
    nb.setConfig(config);
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setId(1);
    alarm.setUei("uei.opennms.org/test/httpNorthBounder");
    NorthboundAlarm a = new NorthboundAlarm(alarm);
    nb.onAlarm(a);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 18 with JUnitHttpServer

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

the class RancidProvisioningAdapterIT method testDelete.

/**
 * TODO: This test needs to be updated so that it properly connects to the JUnitHttpServer
 * for simulated RANCID REST operations.
 * TODO: This test seems to pass even though it fails to connect with a mock RANCID server
 */
@Test
@Transactional
@JUnitHttpServer(port = 7081, basicAuth = true)
public void testDelete() throws Exception {
    OnmsNode n = m_nodeDao.findByForeignId("rancid", "1");
    m_adapter.deleteNode(n.getId());
    m_adapter.processPendingOperationForNode(m_deleteOperation);
    Thread.sleep(3000);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with JUnitHttpServer

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

the class RancidProvisioningAdapterIntegrationIT method testAddSameOperationTwice.

/**
 * TODO: This test needs to be updated so that it properly connects to the JUnitHttpServer
 * for simulated RANCID REST operations.
 */
@Test
@Transactional
@JUnitHttpServer(port = 7081, basicAuth = true)
@Ignore
public void testAddSameOperationTwice() throws InterruptedException {
    // AdapterOperationChecker verifyOperations = new AdapterOperationChecker(2);
    // m_adapter.getOperationQueue().addListener(verifyOperations);
    OnmsNode node = m_nodeDao.get(NODE_ID);
    assertNotNull(node);
    int firstNodeId = node.getId();
    m_adapter.addNode(firstNodeId);
    // should get deduplicated
    m_adapter.addNode(firstNodeId);
    m_adapter.updateNode(firstNodeId);
    // assertTrue(verifyOperations.enqueueLatch.await(4, TimeUnit.SECONDS));
    // assertTrue(verifyOperations.dequeueLatch.await(4, TimeUnit.SECONDS));
    // assertTrue(verifyOperations.executeLatch.await(4, TimeUnit.SECONDS));
    assertEquals(0, m_adapter.getOperationQueue().getOperationQueueForNode(firstNodeId).size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Ignore(org.junit.Ignore) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with JUnitHttpServer

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

the class HttpCollectorIT method testCollect.

/**
 * Test method for {@link org.opennms.netmgt.collectd.HttpCollector#collect(
 *   org.opennms.netmgt.collection.api.CollectionAgent, org.opennms.netmgt.model.events.EventProxy, Map)}.
 */
@Test
@JUnitHttpServer(port = 10342, vhosts = { "127.0.0.1" })
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/http-datacollection-config.xml", datacollectionType = "http", anticipateRrds = { "1/documentCount", "1/greatAnswer", "1/someNumber" }, anticipateFiles = { "1/strings.properties" })
public final void testCollect() throws Exception {
    CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
    assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
}
Also used : CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) 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