Search in sources :

Example 31 with JUnitHttpServer

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

the class SSLCertMonitorIT method testExpiredDateForCertificate.

@Test
@JUnitHttpServer(port = 10342, https = true)
public void testExpiredDateForCertificate() throws UnknownHostException {
    SSLCertMonitor monitor = new SSLCertMonitor() {

        @Override
        protected Calendar getCalendarInstance() {
            final Calendar cal = GregorianCalendar.getInstance();
            cal.setTimeInMillis(EXPIRE_DATE - 86400000 * -1);
            return cal;
        }
    };
    Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
    parameters.put("port", "10342");
    parameters.put("retry", "0");
    parameters.put("timeout", "500");
    parameters.put("verbose", "true");
    parameters.put("days", "5");
    MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", false), "SSLCert");
    PollStatus status = monitor.poll(svc, parameters);
    assertTrue(status.isUnavailable());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) PollStatus(org.opennms.netmgt.poller.PollStatus) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 32 with JUnitHttpServer

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

the class SSLCertMonitorIT method testHostNameVerificationFails.

@Test
@JUnitHttpServer(port = 10342, https = true)
public void testHostNameVerificationFails() throws UnknownHostException {
    SSLCertMonitor monitor = new SSLCertMonitor() {

        @Override
        protected Calendar getCalendarInstance() {
            final Calendar cal = GregorianCalendar.getInstance();
            cal.setTimeInMillis(EXPIRE_DATE - 86400000 * 5);
            return cal;
        }
    };
    Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
    parameters.put("port", "10342");
    parameters.put("retry", "0");
    parameters.put("timeout", "500");
    parameters.put("verbose", "true");
    parameters.put("days", "5");
    parameters.put("server-name", "klatschmohnwiese");
    MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", false), "SSLCert");
    PollStatus status = monitor.poll(svc, parameters);
    assertTrue(status.isUnavailable());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) PollStatus(org.opennms.netmgt.poller.PollStatus) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 33 with JUnitHttpServer

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

the class HttpMonitorIT method testNMS2702.

@Test
@JUnitHttpServer()
public void testNMS2702() throws UnknownHostException {
    HttpMonitor monitor = new HttpMonitor();
    Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
    final int port = JUnitHttpServerExecutionListener.getPort();
    if (port > 0) {
        parameters.put("port", String.valueOf(port));
    } else {
        throw new IllegalStateException("Unable to determine what port the HTTP server started on!");
    }
    parameters.put("url", "/test-NMS2702.html");
    parameters.put("retry", "1");
    parameters.put("timeout", "500");
    parameters.put("verbose", "true");
    // Match a string included on Initial Server Response
    parameters.put("response-text", "~.*OK.*");
    MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", false), "HTTP");
    PollStatus status = monitor.poll(svc, parameters);
    assertTrue(status.isAvailable());
    // Match a string included on Header
    parameters.put("response-text", "~.*Jetty.*");
    svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", false), "HTTP");
    status = monitor.poll(svc, parameters);
    assertTrue(status.isAvailable());
}
Also used : ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) PollStatus(org.opennms.netmgt.poller.PollStatus) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) MonitoredService(org.opennms.netmgt.poller.MonitoredService) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 34 with JUnitHttpServer

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

the class PageSequenceMonitorIT method testLoginDynamicCredentials.

@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testLoginDynamicCredentials() 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\">\n" + "    <parameter key=\"j_username\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + "    <parameter key=\"j_password\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + "  </page>\n" + "  <page virtual-host=\"localhost\" path=\"/opennms/events.html\" port=\"10342\" successMatch=\"Event Queries\" />\n" + "  <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_logout\" port=\"10342\" successMatch=\"Login with Username and Password\" />\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 35 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)

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