Search in sources :

Example 1 with SimpleServer

use of org.opennms.netmgt.provision.server.SimpleServer in project opennms by OpenNMS.

the class MemcachedDetectorTest method testServerSuccess.

@Test(timeout = 20000)
public void testServerSuccess() throws Exception {
    m_server = new SimpleServer() {

        @Override
        public void onInit() {
            addResponseHandler(contains("version"), new RequestHandler() {

                @Override
                public void doRequest(OutputStream out) throws IOException {
                    out.write(String.format("%s\r\n", "VERSION 1.2.3").getBytes());
                }
            });
        }
    };
    m_server.init();
    m_server.startServer();
    // make sure the server is really started
    Thread.sleep(100);
    try {
        m_detector.setPort(m_server.getLocalPort());
        m_detector.setIdleTime(1000);
        DetectFuture future = m_detector.isServiceDetected(m_server.getInetAddress());
        assertNotNull(future);
        future.awaitForUninterruptibly();
        assertTrue(future.isServiceDetected());
    } finally {
        m_server.stopServer();
    }
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) RequestHandler(org.opennms.netmgt.provision.server.exchange.RequestHandler) DetectFuture(org.opennms.netmgt.provision.DetectFuture) OutputStream(java.io.OutputStream) Test(org.junit.Test)

Example 2 with SimpleServer

use of org.opennms.netmgt.provision.server.SimpleServer in project opennms by OpenNMS.

the class HttpDetectorTest method createServer.

private SimpleServer createServer(final String httpResponse) throws Exception {
    SimpleServer server = new SimpleServer() {

        @Override
        public void onInit() {
            addResponseHandler(contains("GET"), shutdownServer(httpResponse));
        }
    };
    server.init();
    server.startServer();
    return server;
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer)

Example 3 with SimpleServer

use of org.opennms.netmgt.provision.server.SimpleServer in project opennms by OpenNMS.

the class SmtpDetectorTest method testDetectorFailWrongCodeExpectedMultilineRequest.

@Test(timeout = 20000)
public void testDetectorFailWrongCodeExpectedMultilineRequest() throws Exception {
    SimpleServer tempServer = new SimpleServer() {

        @Override
        public void onInit() {
            String[] multiLine = { "600 First line" };
            setBanner("220 ewhserver279.edgewebhosting.net");
            addResponseHandler(matches("HELO LOCALHOST"), multilineLineRequest(multiLine));
            addResponseHandler(matches("QUIT"), shutdownServer("221 Service closing transmission channel"));
        }
    };
    tempServer.init();
    tempServer.startServer();
    m_detector.setPort(tempServer.getLocalPort());
    assertFalse(doCheck(m_detector.isServiceDetected(tempServer.getInetAddress())));
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) Test(org.junit.Test)

Example 4 with SimpleServer

use of org.opennms.netmgt.provision.server.SimpleServer in project opennms by OpenNMS.

the class SmtpDetectorTest method testDetectorFailIncompleteMultilineResponseFromServer.

@Test(timeout = 20000)
public void testDetectorFailIncompleteMultilineResponseFromServer() throws Exception {
    SimpleServer tempServer = new SimpleServer() {

        @Override
        public void onInit() {
            String[] multiLine = { "250-First line", "400-Bogus second line" };
            setBanner("220 ewhserver279.edgewebhosting.net");
            addResponseHandler(matches("HELO LOCALHOST"), multilineLineRequest(multiLine));
            addResponseHandler(matches("QUIT"), shutdownServer("221 Service closing transmission channel"));
        }
    };
    tempServer.init();
    tempServer.startServer();
    m_detector.setPort(tempServer.getLocalPort());
    assertFalse(doCheck(m_detector.isServiceDetected(tempServer.getInetAddress())));
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) Test(org.junit.Test)

Example 5 with SimpleServer

use of org.opennms.netmgt.provision.server.SimpleServer in project opennms by OpenNMS.

the class TcpDetectorTest method testFailureConnectionTimesOutWhenExpectingABanner.

@Test(timeout = 20000)
public void testFailureConnectionTimesOutWhenExpectingABanner() throws Exception {
    initializeDefaultDetector();
    m_server = new SimpleServer() {

        @Override
        public void onInit() {
            setTimeout(500);
        }
    };
    m_server.init();
    m_server.startServer();
    m_detector.setPort(m_server.getLocalPort());
    DetectFuture future = m_detector.isServiceDetected(m_server.getInetAddress());
    assertNotNull(future);
    future.awaitForUninterruptibly();
    assertFalse("Test should fail because no banner was sent when expecting a banner to be sent", future.isServiceDetected());
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) DetectFuture(org.opennms.netmgt.provision.DetectFuture) Test(org.junit.Test)

Aggregations

SimpleServer (org.opennms.netmgt.provision.server.SimpleServer)24 Test (org.junit.Test)15 DetectFuture (org.opennms.netmgt.provision.DetectFuture)12 OutputStream (java.io.OutputStream)4 Before (org.junit.Before)4 RequestHandler (org.opennms.netmgt.provision.server.exchange.RequestHandler)4 ServerSocket (java.net.ServerSocket)1 Ignore (org.junit.Ignore)1 TcpDetector (org.opennms.netmgt.provision.detector.simple.TcpDetector)1