use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class PageSequenceMonitorIT method testDsNamePerPage.
@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testDsNamePerPage() throws Exception {
m_params.put("page-sequence", "" + "<?xml version=\"1.0\"?>" + "<page-sequence>\n" + " <page path=\"/opennms/\" ds-name=\"test1\" port=\"10342\" virtual-host=\"localhost\" successMatch=\"<title>(.*?)</title>\" />\n" + " <page path=\"/opennms/j_spring_security_check\" ds-name=\"test2\" port=\"10342\" virtual-host=\"localhost\" successMatch=\"<title>(.*?)</title>\" />\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 three DSes", (3 == status.getProperties().size()));
assertTrue("Expected a DS called 'test1' but did not find one", status.getProperties().containsKey("test1"));
assertTrue("Expected a DS called 'test2' but did not find one", status.getProperties().containsKey("test2"));
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 FasterFilesystemForeignSourceRepositoryTest method testImportHttpSource.
@Test
@JUnitHttpServer(port = 9162)
public void testImportHttpSource() throws Exception {
FileSystemBuilder bldr = new FileSystemBuilder("target", "testGetForeignSource");
File fsDir = bldr.dir("foreignSource").file("test.xml", fs("test")).file("noreq.xml", fs("noreq")).pop();
File reqDir = bldr.dir("requisitions").file("test.xml", req("test")).file("pending.xml", req("pending")).pop();
FasterFilesystemForeignSourceRepository repo = repo(fsDir, reqDir);
Resource resource = new UrlResource("http://localhost:9162/requisition-test.xml");
Requisition req = repo.importResourceRequisition(resource);
assertNotNull(req);
System.err.println(JaxbUtils.marshal(req));
assertNotNull(req.getNode("4243"));
assertNotNull(req.getNode("4244"));
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class RancidProvisioningAdapterIT method testAdd.
/**
* TODO: This test needs to be updated so that it properly connects to the JUnitHttpServer
* for simulated RANCID REST operations.
*/
@Test
@Transactional
@JUnitHttpServer(port = 7081, basicAuth = true)
@Ignore
public void testAdd() throws Exception {
OnmsNode n = m_nodeDao.findByForeignId("rancid", "1");
m_adapter.addNode(n.getId());
m_adapter.processPendingOperationForNode(m_addOperation);
Thread.sleep(3000);
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class HttpCollectorIT method testPersistApacheStats.
@Test
@JUnitHttpServer(port = 10342, vhosts = { "127.0.0.1" })
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/http-datacollection-persist-apache-stats.xml", datacollectionType = "http", anticipateRrds = { "1/TotalAccesses", "1/TotalkBytes", "1/CPULoad", "1/Uptime", "1/ReqPerSec", "1/BytesPerSec", "1/BytesPerReq", "1/BusyWorkers", "1/IdleWorkers" })
public final void testPersistApacheStats() throws Exception {
File snmpRrdDirectory = (File) m_context.getAttribute("rrdDirectory");
FileAnticipator anticipator = (FileAnticipator) m_context.getAttribute("fileAnticipator");
int numUpdates = 2;
int stepSizeInSecs = 1;
int stepSizeInMillis = stepSizeInSecs * 1000;
final int rangeSizeInMillis = stepSizeInMillis + 20000;
CollectorTestUtils.collectNTimes(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, m_collectionAgent, numUpdates);
// node level collection
File nodeDir = CollectorTestUtils.anticipatePath(anticipator, snmpRrdDirectory, "1");
File documentCountRrdFile = new File(nodeDir, CollectorTestUtils.rrd(m_rrdStrategy, "TotalAccesses"));
File someNumberRrdFile = new File(nodeDir, CollectorTestUtils.rrd(m_rrdStrategy, "IdleWorkers"));
File cpuLoadRrdFile = new File(nodeDir, CollectorTestUtils.rrd(m_rrdStrategy, "CPULoad"));
// Total Accesses: 175483
assertEquals("TotalAccesses", Double.valueOf(175483.0), m_rrdStrategy.fetchLastValueInRange(documentCountRrdFile.getAbsolutePath(), "TotalAccesses", stepSizeInMillis, rangeSizeInMillis));
// IdleWorkers: 12
assertEquals("IdleWorkers", Double.valueOf(12.0), m_rrdStrategy.fetchLastValueInRange(someNumberRrdFile.getAbsolutePath(), "IdleWorkers", stepSizeInMillis, rangeSizeInMillis));
// CPU Load: .497069
assertEquals("CPULoad", Double.valueOf(0.497069), m_rrdStrategy.fetchLastValueInRange(cpuLoadRrdFile.getAbsolutePath(), "CPULoad", stepSizeInMillis, rangeSizeInMillis));
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class HttpNotificationStrategyIT method testSend.
/*
* Test method for 'org.opennms.netmgt.notifd.HttpNotificationStrategy.send(List)'
*/
@Test
@JUnitHttpServer(webapps = { @Webapp(context = "/cgi-bin/noauth", path = "src/test/resources/HttpNotificationStrategyTest") })
public void testSend() {
final int port = JUnitHttpServerExecutionListener.getPort();
assertTrue(port > 0);
try {
final String message = "text message for unit testing";
final NotificationStrategy ns = new HttpNotificationStrategy();
final List<Argument> arguments = new ArrayList<>();
arguments.add(new Argument("url", null, "http://localhost:" + port + "/cgi-bin/noauth/nmsgw.pl", false));
arguments.add(new Argument("post-NodeID", null, "1", false));
arguments.add(new Argument("result-match", null, "(?s).*OK\\s+([0-9]+).*", false));
arguments.add(new Argument("post-message", null, "-tm", false));
arguments.add(new Argument("-tm", null, message, false));
arguments.add(new Argument("sql", null, "UPDATE alarms SET tticketID=${1} WHERE lastEventID = 1", false));
final int statusCode = ns.send(arguments);
assertEquals(200, statusCode);
final Map<String, String> parameters = HttpNotificationStrategyTestServlet.getRequestParameters();
assertNotNull(parameters);
assertEquals(2, parameters.size());
assertEquals("1", parameters.get("NodeID"));
assertEquals(message, parameters.get("message"));
} catch (Throwable e) {
e.printStackTrace();
fail("Caught Exception: " + e.getMessage());
}
}
Aggregations