use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class JUnitHttpServerTest method testWebappWithServlet.
@Test
@JUnitHttpServer(port = 9162, webapps = { @Webapp(context = "/testContext", path = "src/test/resources/test-webapp") })
public void testWebappWithServlet() throws Exception {
HttpUriRequest method = new HttpGet("http://localhost:9162/testContext/monkey");
final CloseableHttpResponse response = m_clientWrapper.execute(method);
String responseString = EntityUtils.toString(response.getEntity());
LOG.debug("got response:\n{}", responseString);
assertEquals(200, response.getStatusLine().getStatusCode());
assertTrue(responseString.contains("You are reading this from a servlet!"));
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class JUnitHttpServerTest method testBasicAuthFailure.
@Test
@JUnitHttpServer(port = 9162, basicAuth = true, webapps = { @Webapp(context = "/testContext", path = "src/test/resources/test-webapp") })
public void testBasicAuthFailure() throws Exception {
final HttpUriRequest method = new HttpGet("http://localhost:9162/testContext/monkey");
m_clientWrapper.addBasicCredentials("admin", "sucks");
final HttpResponse response = m_clientWrapper.execute(method);
assertEquals(401, response.getStatusLine().getStatusCode());
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class SimpleBackEndTest method testBackendWithBasicAuthInDifferentThread.
@Test
@JUnitHttpServer(port = 9162, basicAuth = true, webapps = @Webapp(context = "/", path = "src/test/resources/simple-test-webapp"))
public void testBackendWithBasicAuthInDifferentThread() throws Exception {
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("testuser", "testpassword"));
assertNotNull(m_authBackEnd);
final AtomicInteger first = new AtomicInteger(-1);
final AtomicInteger second = new AtomicInteger(-1);
Thread t = new Thread() {
@Override
public void run() {
first.set(m_authBackEnd.getCount());
second.set(m_authBackEnd.getCount());
}
};
t.start();
t.join();
assertEquals("first get should be 0", 0, first.get());
assertEquals("second should be 1", 1, second.get());
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class PageSequenceMonitorIT method testLogin.
@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testLogin() throws Exception {
m_params.put("page-sequence", "" + "<?xml version=\"1.0\"?>" + "<page-sequence>\n" + " <page virtual-host=\"localhost\" path=\"/opennms/\" port=\"10342\" successMatch=\"Password\" />\n" + " <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_check\" port=\"10342\" method=\"POST\" response-range=\"300-399\">\n" + " <parameter key=\"j_username\" value=\"demo\"/>\n" + " <parameter key=\"j_password\" value=\"demo\"/>\n" + " </page>\n" + " <page virtual-host=\"localhost\" path=\"/opennms/events.html\" port=\"10342\" successMatch=\"Event Queries\" />\n" + " <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_logout\" port=\"10342\" successMatch=\"Login with Username and Password\" />\n" + "</page-sequence>\n");
PollStatus status = m_monitor.poll(getHttpService("localhost"), m_params);
assertTrue("Expected available but was " + status + ": reason = " + status.getReason(), status.isAvailable());
assertTrue("Expected a DS called 'response-time' but did not find one", status.getProperties().containsKey(PollStatus.PROPERTY_RESPONSE_TIME));
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class PageSequenceMonitorIT method testLoginDynamicCredentialsRedirectPost.
@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testLoginDynamicCredentialsRedirectPost() throws Exception {
m_params.put("page-sequence", "" + "<?xml version=\"1.0\"?>" + "<page-sequence>\n" + " <page path=\"/opennms/\" port=\"10342\" virtual-host=\"localhost\" successMatch=\"(?s)<hea(.)><titl(.)>.*</for(.)></b(.)dy>\">\n" + " <session-variable name=\"ltr1\" match-group=\"1\" />\n" + " <session-variable name=\"ltr2\" match-group=\"2\" />\n" + " <session-variable name=\"ltr3\" match-group=\"3\" />\n" + " <session-variable name=\"ltr4\" match-group=\"4\" />\n" + " </page>\n" + " <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_check\" port=\"10342\" method=\"POST\" failureMatch=\"(?s)Your login attempt was not successful.*Reason: ([^<]*)\" failureMessage=\"Login in Failed: ${1}\">\n" + " <parameter key=\"j_username\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + " <parameter key=\"j_password\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + " </page>\n" + " <page virtual-host=\"localhost\" path=\"/opennms/events.html\" port=\"10342\" successMatch=\"Event Queries\" />\n" + " <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_logout\" port=\"10342\" successMatch=\"Login with Username and Password\" />\n" + "</page-sequence>\n");
Map<String, Object> params = new HashMap<String, Object>();
for (Entry<String, Object> entry : m_params.entrySet()) {
params.put(entry.getKey(), entry.getValue());
}
try {
PollStatus status = m_monitor.poll(getHttpService("localhost"), params);
assertTrue("Expected available but was " + status + ": reason = " + status.getReason(), status.isAvailable());
assertTrue("Expected a DS called 'response-time' but did not find one", status.getProperties().containsKey(PollStatus.PROPERTY_RESPONSE_TIME));
} finally {
// Print some debug output if necessary
}
}
Aggregations