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();
}
}
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;
}
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())));
}
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())));
}
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());
}
Aggregations