Пример #1
0
  @Test(timeout = 90000)
  public void testServerSuccess() throws Exception {
    m_server =
        new SimpleServer() {

          @Override
          public void onInit() {
            setBanner("* OK THIS IS A BANNER FOR IMAP");
            addResponseHandler(contains("LOGOUT"), shutdownServer("* BYE\r\nONMSCAPSD OK"));
          }
        };

    m_server.init();
    m_server.startServer();

    Thread.sleep(100); // make sure the server is really started

    try {
      m_detector.setPort(m_server.getLocalPort());
      m_detector.setIdleTime(1000);

      // assertTrue(m_detector.isServiceDetected(m_server.getInetAddress()));
      DetectFuture future = m_detector.isServiceDetected(m_server.getInetAddress());
      assertNotNull(future);

      future.awaitForUninterruptibly();

      assertTrue(future.isServiceDetected());
    } finally {
      m_server.stopServer();
    }
  }
Пример #2
0
  @Test(timeout = 90000)
  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();
    }
  }