Search in sources :

Example 46 with JUnitHttpServer

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

the class PageSequenceMonitorIT method testRedirectLocationMatch.

@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testRedirectLocationMatch() throws Exception {
    m_params.put("page-sequence", "" + "<?xml version=\"1.0\"?>" + "<page-sequence>\n" + "  <page path=\"/opennms/\" port=\"10342\" virtual-host=\"localhost\" successMatch=\"(?s)&lt;hea(.)&gt;&lt;titl(.)&gt;.*&lt;/for(.)&gt;&lt;/b(.)dy&gt;\">\n" + "    <session-variable name=\"ltr1\" match-group=\"1\" />\n" + "    <session-variable name=\"ltr2\" match-group=\"2\" />\n" + "    <session-variable name=\"ltr3\" match-group=\"3\" />\n" + "    <session-variable name=\"ltr4\" match-group=\"4\" />\n" + "  </page>\n" + "  <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_check\" port=\"10342\" method=\"POST\" response-range=\"300-399\" locationMatch=\"/opennms/\">\n" + "    <parameter key=\"j_username\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + "    <parameter key=\"j_password\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + "  </page>\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 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 47 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 48 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)

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