Search in sources :

Example 1 with JUnitHttpServer

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

the class SimpleBackEndTest method testBackendWithBasicAuth.

@Test
@JUnitHttpServer(port = 9162, basicAuth = true, webapps = @Webapp(context = "/", path = "src/test/resources/simple-test-webapp"))
public void testBackendWithBasicAuth() throws Exception {
    SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("testuser", "testpassword"));
    assertNotNull(m_authBackEnd);
    assertEquals("first get should be 0", 0, m_authBackEnd.getCount());
    assertEquals("second should be 1", 1, m_authBackEnd.getCount());
}
Also used : UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 2 with JUnitHttpServer

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

the class TcpMonitorIT method testLocalhostConnection.

@Test
@JUnitHttpServer(port = 10342)
public void testLocalhostConnection() throws UnknownHostException {
    Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
    Parameter p = new Parameter();
    ServiceMonitor monitor = new TcpMonitor();
    MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost"), "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 3 with JUnitHttpServer

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

the class PageSequenceMonitorIT method testLoginDynamicCredentialsTwice.

@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testLoginDynamicCredentialsTwice() throws Exception {
    m_params.put("page-sequence", "" + "<?xml version=\"1.0\"?>" + "<page-sequence>\n" + "  <page path=\"/opennms/\" port=\"10342\" virtual-host=\"localhost\" successMatch=\"(?s)&gt;Login (.)(.)(.)(.) Username and Password&lt;\">\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" + "  <!-- Pick out the letters w-i-t-h to try and log in, this will fail -->\n" + "  <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_check\" response-range=\"300-399\" locationMatch=\"/opennms/spring_security_login\\?login_error\" port=\"10342\" method=\"POST\">\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/spring_security_login\" query=\"login_error\" port=\"10342\" failureMatch=\"(?s)Log out\" failureMessage=\"Login should have failed but did not\" successMatch=\"Your login attempt was not successful\"/>\n" + "  <!-- Pick out the letters d-e-m-o to try and log in, this will succeed -->\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\" response-range=\"300-399\" port=\"10342\" method=\"POST\">\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");
    try {
        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));
    } finally {
    // Print some debug output if necessary
    }
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 4 with JUnitHttpServer

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

the class PageSequenceMonitorIT method testRedirectLocationDoesNotMatch.

@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testRedirectLocationDoesNotMatch() 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=\"/opensadfnms/\">\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 down but was " + status + ": reason = " + status.getReason(), status.isDown());
    assertEquals("Failed to find '/opensadfnms/' in Location: header at http://127.0.0.1:10342/opennms/j_spring_security_check", status.getReason());
    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 5 with JUnitHttpServer

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

the class PageSequenceMonitorIT method testRequireIPv4.

@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testRequireIPv4() throws Exception {
    m_params.put("page-sequence", "" + "<?xml version=\"1.0\"?>" + "<page-sequence>\n" + "  <page host=\"localhost\" virtual-host=\"localhost\" path=\"/opennms/\" port=\"10342\" requireIPv4=\"true\"/>\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