Search in sources :

Example 16 with MockMonitoredService

use of org.opennms.netmgt.poller.mock.MockMonitoredService in project opennms by OpenNMS.

the class DNSResolutionMonitorIT method testLookup.

@Test
public void testLookup() throws Exception {
    MockMonitoredService lookup = new MockMonitoredService(1, "no-such-name.example.com", InetAddress.getLocalHost(), "RESOLVE");
    DNSResolutionMonitor monitor = new DNSResolutionMonitor();
    Map<String, Object> parms = new HashMap<String, Object>();
    parms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_EITHER);
    parms.put(PARM_LOOKUP, "wipv6day.opennms.org");
    assertEquals(PollStatus.available(), monitor.poll(lookup, parms));
}
Also used : MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 17 with MockMonitoredService

use of org.opennms.netmgt.poller.mock.MockMonitoredService in project opennms by OpenNMS.

the class DNSResolutionMonitorIT method pollIPv4CNAME.

@Test
public void pollIPv4CNAME() throws Exception {
    MockMonitoredService cname = new MockMonitoredService(1, "www.opennms.org", InetAddress.getLocalHost(), "RESOLVE");
    DNSResolutionMonitor monitor = new DNSResolutionMonitor();
    Map<String, Object> params = new HashMap<>();
    params.put(PARM_RECORD_TYPES, PARM_RECORD_TYPE_CNAME);
    params.put(PARM_NAMESERVER, "[::1]:9153");
    assertEquals(PollStatus.available(), monitor.poll(cname, params));
}
Also used : MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 18 with MockMonitoredService

use of org.opennms.netmgt.poller.mock.MockMonitoredService in project opennms by OpenNMS.

the class DNSResolutionMonitorIT method pollIPv4andIPv6.

@Test
public void pollIPv4andIPv6() throws Exception {
    MockMonitoredService dual = new MockMonitoredService(1, "wipv6day.opennms.org", InetAddress.getLocalHost(), "RESOLVE");
    DNSResolutionMonitor monitor = new DNSResolutionMonitor();
    Map<String, Object> v4Parms = new HashMap<>();
    v4Parms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_V4);
    v4Parms.put(PARM_NAMESERVER, "[::1]:9153");
    Map<String, Object> v6Parms = new HashMap<>();
    v6Parms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_V6);
    v6Parms.put(PARM_NAMESERVER, "[::1]:9153");
    Map<String, Object> bothParms = new HashMap<>();
    bothParms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_BOTH);
    bothParms.put(PARM_NAMESERVER, "[::1]:9153");
    Map<String, Object> eitherParms = new HashMap<>();
    eitherParms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_EITHER);
    eitherParms.put(PARM_NAMESERVER, "[::1]:9153");
    assertEquals(PollStatus.available(), monitor.poll(dual, v4Parms));
    assertEquals(PollStatus.available(), monitor.poll(dual, v6Parms));
    assertEquals(PollStatus.available(), monitor.poll(dual, bothParms));
    assertEquals(PollStatus.available(), monitor.poll(dual, eitherParms));
}
Also used : MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 19 with MockMonitoredService

use of org.opennms.netmgt.poller.mock.MockMonitoredService in project opennms by OpenNMS.

the class DNSResolutionMonitorIT method pollIPv4Only.

@Test
public void pollIPv4Only() throws Exception {
    MockMonitoredService v4only = new MockMonitoredService(1, "choopa-ipv4.opennms.org", InetAddress.getLocalHost(), "RESOLVE");
    DNSResolutionMonitor monitor = new DNSResolutionMonitor();
    Map<String, Object> v4Parms = new HashMap<>();
    v4Parms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_V4);
    v4Parms.put(PARM_NAMESERVER, "[::1]:9153");
    Map<String, Object> v6Parms = new HashMap<>();
    v6Parms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_V6);
    v6Parms.put(PARM_NAMESERVER, "[::1]:9153");
    Map<String, Object> bothParms = new HashMap<>();
    bothParms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_BOTH);
    bothParms.put(PARM_NAMESERVER, "[::1]:9153");
    Map<String, Object> eitherParms = new HashMap<>();
    eitherParms.put(PARM_RESOLUTION_TYPE, PARM_RESOLUTION_TYPE_EITHER);
    eitherParms.put(PARM_NAMESERVER, "[::1]:9153");
    assertEquals(PollStatus.available(), monitor.poll(v4only, v4Parms));
    assertEquals(PollStatus.unavailable(), monitor.poll(v4only, v6Parms));
    assertEquals(PollStatus.unavailable(), monitor.poll(v4only, bothParms));
    assertEquals(PollStatus.available(), monitor.poll(v4only, eitherParms));
}
Also used : MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 20 with MockMonitoredService

use of org.opennms.netmgt.poller.mock.MockMonitoredService in project opennms by OpenNMS.

the class SeleniumMonitorTest method testPollStatusNotNull.

// Requires Firefox to be installed to run
@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/testWar"))
public void testPollStatusNotNull() throws UnknownHostException {
    MonitoredService monSvc = new MockMonitoredService(1, "papajohns", InetAddressUtils.addr("213.187.33.164"), "PapaJohnsSite");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("selenium-test", "SeleniumGroovyTest.groovy");
    params.put("base-url", "localhost");
    params.put("port", "10342");
    SeleniumMonitor ajaxPSM = new SeleniumMonitor();
    PollStatus pollStatus = ajaxPSM.poll(monSvc, params);
    assertNotNull("PollStatus must not be null", pollStatus);
    System.err.println("PollStatus message: " + pollStatus.getReason());
    assertEquals(PollStatus.available(), pollStatus);
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) SeleniumMonitor(org.opennms.netmgt.poller.monitors.SeleniumMonitor) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Aggregations

MockMonitoredService (org.opennms.netmgt.poller.mock.MockMonitoredService)35 HashMap (java.util.HashMap)27 Test (org.junit.Test)27 PollStatus (org.opennms.netmgt.poller.PollStatus)26 ServiceMonitor (org.opennms.netmgt.poller.ServiceMonitor)23 MonitoredService (org.opennms.netmgt.poller.MonitoredService)21 BufferedReader (java.io.BufferedReader)6 InputStreamReader (java.io.InputStreamReader)6 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)6 ServerSocket (java.net.ServerSocket)6 Socket (java.net.Socket)6 Package (org.opennms.netmgt.config.poller.Package)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1 Before (org.junit.Before)1 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)1 Parameter (org.opennms.netmgt.config.poller.Parameter)1