Search in sources :

Example 11 with SimpleServer

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

the class Pop3DetectorTest method setUp.

@Before
public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    m_server = new SimpleServer() {

        @Override
        public void onInit() {
            setBanner("+OK");
            addResponseHandler(startsWith("QUIT"), shutdownServer("+OK"));
        // setExpectedClose("QUIT", "+OK");
        }
    };
    m_server.init();
    m_server.startServer();
    m_detector = createDetector(m_server.getLocalPort());
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) Before(org.junit.Before)

Example 12 with SimpleServer

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

the class TcpDetectorTest method testServerCloses.

/**
 * I think that this test is redundant with {@link #testFailureClosedPort()} since neither
 * server is actually started. The detector just times out on both connections.
 */
@Test(timeout = 20000)
public void testServerCloses() throws Exception {
    initializeDefaultDetector();
    m_server = new SimpleServer() {

        @Override
        public void onInit() {
            shutdownServer("Closing");
        }
    };
    m_server.init();
    // m_server.startServer();
    m_detector.setPort(m_server.getLocalPort());
    // assertFalse("Test should fail because the server closes before detection takes place", m_detector.isServiceDetected(m_server.getInetAddress()));
    DetectFuture future = m_detector.isServiceDetected(m_server.getInetAddress());
    assertNotNull(future);
    future.awaitForUninterruptibly();
    assertFalse(future.isServiceDetected());
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) DetectFuture(org.opennms.netmgt.provision.DetectFuture) Test(org.junit.Test)

Example 13 with SimpleServer

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

the class AsyncDetectorFileDescriptorLeakTest method setUpServer.

private void setUpServer(final String banner, final int bannerDelay) throws Exception {
    m_server = new SimpleServer() {

        @Override
        public void onInit() {
            if (banner != null) {
                setBanner(banner);
                setBannerDelay(bannerDelay);
            }
        }
    };
    // No timeout
    m_server.setTimeout(0);
    // m_server.setThreadSleepLength(0);
    m_server.init();
    m_server.startServer();
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer)

Example 14 with SimpleServer

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

the class ImapDetectorTest method testDetectorFailUnexpectedLogoutResponse.

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

        @Override
        public void onInit() {
            setBanner("* NOT OK THIS IS A BANNER FOR IMAP");
            addResponseHandler(contains("LOGOUT"), singleLineRequest("* NOT OK"));
        }
    };
    m_server.init();
    m_server.startServer();
    try {
        m_detector.setPort(m_server.getLocalPort());
        // assertFalse(m_detector.isServiceDetected(m_server.getInetAddress()));
        DetectFuture future = m_detector.isServiceDetected(m_server.getInetAddress());
        assertNotNull(future);
        future.awaitForUninterruptibly();
        assertFalse(future.isServiceDetected());
    } finally {
        m_server.stopServer();
    }
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) DetectFuture(org.opennms.netmgt.provision.DetectFuture) Test(org.junit.Test)

Example 15 with SimpleServer

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

the class ImapDetectorTest method testDetectorFailUnexpectedBanner.

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

        @Override
        public void onInit() {
            setBanner("* NOT OK THIS IS A BANNER FOR IMAP");
        }
    };
    m_server.init();
    m_server.startServer();
    try {
        m_detector.setPort(m_server.getLocalPort());
        // assertFalse(m_detector.isServiceDetected(m_server.getInetAddress()));
        DetectFuture future = m_detector.isServiceDetected(m_server.getInetAddress());
        assertNotNull(future);
        future.awaitForUninterruptibly();
        assertFalse(future.isServiceDetected());
    } finally {
        m_server.stopServer();
    }
}
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