Search in sources :

Example 36 with JUnitHttpServer

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

the class PageSequenceMonitorIT method testDsNamePerPage.

@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testDsNamePerPage() throws Exception {
    m_params.put("page-sequence", "" + "<?xml version=\"1.0\"?>" + "<page-sequence>\n" + "  <page path=\"/opennms/\" ds-name=\"test1\" port=\"10342\" virtual-host=\"localhost\" successMatch=\"&lt;title&gt;(.*?)&lt;/title&gt;\" />\n" + "  <page path=\"/opennms/j_spring_security_check\" ds-name=\"test2\" port=\"10342\" virtual-host=\"localhost\" successMatch=\"&lt;title&gt;(.*?)&lt;/title&gt;\" />\n" + "</page-sequence>\n");
    PollStatus status = m_monitor.poll(getHttpService("localhost"), m_params);
    assertTrue("Expected available but was " + status + ": reason = " + status.getReason(), status.isAvailable());
    assertTrue("Expected three DSes", (3 == status.getProperties().size()));
    assertTrue("Expected a DS called 'test1' but did not find one", status.getProperties().containsKey("test1"));
    assertTrue("Expected a DS called 'test2' but did not find one", status.getProperties().containsKey("test2"));
    assertTrue("Expected a DS called 'response-time' but did not find one", status.getProperties().containsKey(PollStatus.PROPERTY_RESPONSE_TIME));
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 37 with JUnitHttpServer

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

the class FasterFilesystemForeignSourceRepositoryTest method testImportHttpSource.

@Test
@JUnitHttpServer(port = 9162)
public void testImportHttpSource() throws Exception {
    FileSystemBuilder bldr = new FileSystemBuilder("target", "testGetForeignSource");
    File fsDir = bldr.dir("foreignSource").file("test.xml", fs("test")).file("noreq.xml", fs("noreq")).pop();
    File reqDir = bldr.dir("requisitions").file("test.xml", req("test")).file("pending.xml", req("pending")).pop();
    FasterFilesystemForeignSourceRepository repo = repo(fsDir, reqDir);
    Resource resource = new UrlResource("http://localhost:9162/requisition-test.xml");
    Requisition req = repo.importResourceRequisition(resource);
    assertNotNull(req);
    System.err.println(JaxbUtils.marshal(req));
    assertNotNull(req.getNode("4243"));
    assertNotNull(req.getNode("4244"));
}
Also used : UrlResource(org.springframework.core.io.UrlResource) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) File(java.io.File) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 38 with JUnitHttpServer

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

the class RancidProvisioningAdapterIT method testAdd.

/**
 * 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 testAdd() throws Exception {
    OnmsNode n = m_nodeDao.findByForeignId("rancid", "1");
    m_adapter.addNode(n.getId());
    m_adapter.processPendingOperationForNode(m_addOperation);
    Thread.sleep(3000);
}
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 39 with JUnitHttpServer

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

the class HttpCollectorIT method testPersistApacheStats.

@Test
@JUnitHttpServer(port = 10342, vhosts = { "127.0.0.1" })
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/http-datacollection-persist-apache-stats.xml", datacollectionType = "http", anticipateRrds = { "1/TotalAccesses", "1/TotalkBytes", "1/CPULoad", "1/Uptime", "1/ReqPerSec", "1/BytesPerSec", "1/BytesPerReq", "1/BusyWorkers", "1/IdleWorkers" })
public final void testPersistApacheStats() throws Exception {
    File snmpRrdDirectory = (File) m_context.getAttribute("rrdDirectory");
    FileAnticipator anticipator = (FileAnticipator) m_context.getAttribute("fileAnticipator");
    int numUpdates = 2;
    int stepSizeInSecs = 1;
    int stepSizeInMillis = stepSizeInSecs * 1000;
    final int rangeSizeInMillis = stepSizeInMillis + 20000;
    CollectorTestUtils.collectNTimes(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, m_collectionAgent, numUpdates);
    // node level collection
    File nodeDir = CollectorTestUtils.anticipatePath(anticipator, snmpRrdDirectory, "1");
    File documentCountRrdFile = new File(nodeDir, CollectorTestUtils.rrd(m_rrdStrategy, "TotalAccesses"));
    File someNumberRrdFile = new File(nodeDir, CollectorTestUtils.rrd(m_rrdStrategy, "IdleWorkers"));
    File cpuLoadRrdFile = new File(nodeDir, CollectorTestUtils.rrd(m_rrdStrategy, "CPULoad"));
    // Total Accesses: 175483
    assertEquals("TotalAccesses", Double.valueOf(175483.0), m_rrdStrategy.fetchLastValueInRange(documentCountRrdFile.getAbsolutePath(), "TotalAccesses", stepSizeInMillis, rangeSizeInMillis));
    // IdleWorkers: 12
    assertEquals("IdleWorkers", Double.valueOf(12.0), m_rrdStrategy.fetchLastValueInRange(someNumberRrdFile.getAbsolutePath(), "IdleWorkers", stepSizeInMillis, rangeSizeInMillis));
    // CPU Load: .497069
    assertEquals("CPULoad", Double.valueOf(0.497069), m_rrdStrategy.fetchLastValueInRange(cpuLoadRrdFile.getAbsolutePath(), "CPULoad", stepSizeInMillis, rangeSizeInMillis));
}
Also used : File(java.io.File) FileAnticipator(org.opennms.test.FileAnticipator) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 40 with JUnitHttpServer

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

the class HttpNotificationStrategyIT method testSend.

/*
     * Test method for 'org.opennms.netmgt.notifd.HttpNotificationStrategy.send(List)'
     */
@Test
@JUnitHttpServer(webapps = { @Webapp(context = "/cgi-bin/noauth", path = "src/test/resources/HttpNotificationStrategyTest") })
public void testSend() {
    final int port = JUnitHttpServerExecutionListener.getPort();
    assertTrue(port > 0);
    try {
        final String message = "text message for unit testing";
        final NotificationStrategy ns = new HttpNotificationStrategy();
        final List<Argument> arguments = new ArrayList<>();
        arguments.add(new Argument("url", null, "http://localhost:" + port + "/cgi-bin/noauth/nmsgw.pl", false));
        arguments.add(new Argument("post-NodeID", null, "1", false));
        arguments.add(new Argument("result-match", null, "(?s).*OK\\s+([0-9]+).*", false));
        arguments.add(new Argument("post-message", null, "-tm", false));
        arguments.add(new Argument("-tm", null, message, false));
        arguments.add(new Argument("sql", null, "UPDATE alarms SET tticketID=${1} WHERE lastEventID = 1", false));
        final int statusCode = ns.send(arguments);
        assertEquals(200, statusCode);
        final Map<String, String> parameters = HttpNotificationStrategyTestServlet.getRequestParameters();
        assertNotNull(parameters);
        assertEquals(2, parameters.size());
        assertEquals("1", parameters.get("NodeID"));
        assertEquals(message, parameters.get("message"));
    } catch (Throwable e) {
        e.printStackTrace();
        fail("Caught Exception: " + e.getMessage());
    }
}
Also used : Argument(org.opennms.netmgt.model.notifd.Argument) ArrayList(java.util.ArrayList) NotificationStrategy(org.opennms.netmgt.model.notifd.NotificationStrategy) 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