Search in sources :

Example 21 with SimpleServer

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

the class TcpDetectorTest method testSuccessServer.

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

        @Override
        public void onInit() {
            setBanner("Hello");
        }
    };
    m_server.init();
    m_server.startServer();
    m_detector.setPort(m_server.getLocalPort());
    DetectFuture future = m_detector.isServiceDetected(m_server.getInetAddress());
    future.addListener(new DetectFutureListener<DetectFuture>() {

        @Override
        public void operationComplete(DetectFuture future) {
            TcpDetector detector = m_detector;
            m_detector = null;
            detector.dispose();
        }
    });
    assertNotNull(future);
    future.awaitForUninterruptibly();
    assertTrue(future.isServiceDetected());
}
Also used : TcpDetector(org.opennms.netmgt.provision.detector.simple.TcpDetector) SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) DetectFuture(org.opennms.netmgt.provision.DetectFuture) Test(org.junit.Test)

Example 22 with SimpleServer

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

the class WebDetectorTest method createServer.

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

        @Override
        public void init() throws Exception {
            super.init();
            setServerSocket(new ServerSocket(0, 0, InetAddress.getLocalHost()));
            addResponseHandler(contains("GET"), shutdownServer(httpResponse));
        }
    };
    server.init();
    server.startServer();
    return server;
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) ServerSocket(java.net.ServerSocket)

Example 23 with SimpleServer

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

the class NsclientDetectorTest method setUp.

@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    m_detector = m_detectorFactory.createDetector();
    // Initialize Mock NSClient Server
    m_server = new SimpleServer() {

        @Override
        public void onInit() {
            addResponseHandler(startsWith("None&1"), new RequestHandler() {

                @Override
                public void doRequest(OutputStream out) throws IOException {
                    out.write(String.format("%s\r\n", "NSClient++ 0.3.8.75 2010-05-27").getBytes());
                }
            });
        }
    };
    m_server.init();
    m_server.startServer();
    // make sure the server is really started
    Thread.sleep(100);
    // Initialize Detector
    m_detector.setServiceName("NSclient++");
    m_detector.setPort(m_server.getLocalPort());
    m_detector.setTimeout(2000);
    m_detector.setRetries(3);
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) RequestHandler(org.opennms.netmgt.provision.server.exchange.RequestHandler) OutputStream(java.io.OutputStream) Before(org.junit.Before)

Example 24 with SimpleServer

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

the class AbstractNsclientTest method startServer.

public void startServer(final String command, final String response) throws Exception {
    m_server = new SimpleServer() {

        @Override
        public void onInit() {
            addResponseHandler(startsWith(command), new RequestHandler() {

                @Override
                public void doRequest(OutputStream out) throws IOException {
                    out.write(response.getBytes());
                }
            });
        }
    };
    m_server.init();
    m_server.startServer();
    // make sure the server is really started
    Thread.sleep(100);
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) RequestHandler(org.opennms.netmgt.provision.server.exchange.RequestHandler) OutputStream(java.io.OutputStream)

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