Search in sources :

Example 6 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 7 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)

Example 8 with SimpleServer

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

the class TcpDetectorTest method testFailureNoBannerSentWhenExpectingABanner.

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

        @Override
        public void onInit() {
        }
    };
    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)

Example 9 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 10 with SimpleServer

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

the class MSExchangeDetectorTest method setUp.

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

        @Override
        public void onInit() {
            setBanner(TEST_BANNER);
        }
    };
    m_pop3Server.init();
    m_pop3Server.startServer();
    m_imapServer = new SimpleServer() {

        @Override
        public void onInit() {
            setBanner(TEST_BANNER);
        }
    };
    m_imapServer.init();
    m_imapServer.startServer();
    m_detector = m_detectorFactory.createDetector();
    m_detector.setPop3Port(110);
    m_detector.setImapPort(143);
    m_detector.setTimeout(500);
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) Before(org.junit.Before)

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