use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class MattermostNotificationStrategyIT method testSendValidJustArgs.
/*
* Test method for 'org.opennms.netmgt.notifd.MattermostNotificationStrategy.send(List)'
*/
@Test
@JUnitHttpServer(webapps = { @Webapp(context = "/hooks", path = "src/test/resources/MattermostNotificationStrategyTest") })
public void testSendValidJustArgs() {
final int port = JUnitHttpServerExecutionListener.getPort();
assertTrue(port > 0);
try {
final NotificationStrategy ns = new MattermostNotificationStrategy();
final List<Argument> arguments = new ArrayList<>();
// Set these properties. We will override them with Args on the first run.
System.setProperty("org.opennms.netmgt.notifd.mattermost.webhookURL", "http://localhost:" + port + "/hooks/abunchofstuffthatidentifiesawebhook");
System.setProperty("org.opennms.netmgt.notifd.mattermost.channel", "integrationtestsXX");
System.setProperty("org.opennms.netmgt.notifd.mattermost.iconURL", "http://opennms.org/logo.pngXX");
System.setProperty("org.opennms.netmgt.notifd.mattermost.iconEmoji", ":shipitXX:");
System.setProperty("org.opennms.netmgt.notifd.mattermost.username", "opennmsXX");
arguments.add(new Argument("url", null, "http://localhost:" + port + "/hooks/abunchofstuffthatidentifiesawebhook", false));
arguments.add(new Argument("channel", null, "integrationtests", false));
arguments.add(new Argument("username", null, "opennms", false));
arguments.add(new Argument("iconurl", null, "http://opennms.org/logo.png", false));
arguments.add(new Argument("iconemoji", null, ":shipit:", false));
arguments.add(new Argument("-subject", null, "Test", false));
arguments.add(new Argument("-tm", null, "This is only a test", false));
int statusCode = ns.send(arguments);
assertEquals(0, statusCode);
JSONObject inputJson = MattermostNotificationStrategyTestServlet.getInputJson();
assertNotNull(inputJson);
assertEquals("opennms", inputJson.get("username"));
assertEquals("**Test**\nThis is only a test", inputJson.get("text"));
assertEquals("integrationtests", inputJson.get("channel"));
assertEquals("http://opennms.org/logo.png", inputJson.get("icon_url"));
assertEquals(":shipit:", inputJson.get("icon_emoji"));
assertEquals(5, inputJson.size());
// Now do it again, without the Args, and verify that the property values come out
arguments.clear();
arguments.add(new Argument("-subject", null, "Test again", false));
arguments.add(new Argument("-tm", null, "This is only a second test", false));
statusCode = ns.send(arguments);
assertEquals(0, statusCode);
inputJson = MattermostNotificationStrategyTestServlet.getInputJson();
assertNotNull(inputJson);
assertEquals("opennmsXX", inputJson.get("username"));
assertEquals("**Test again**\nThis is only a second test", inputJson.get("text"));
assertEquals("integrationtestsXX", inputJson.get("channel"));
assertEquals("http://opennms.org/logo.pngXX", inputJson.get("icon_url"));
assertEquals(":shipitXX:", inputJson.get("icon_emoji"));
assertEquals(5, inputJson.size());
} catch (Throwable e) {
e.printStackTrace();
fail("Caught Exception: " + e.getMessage());
}
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class SlackNotificationStrategyIT method testSendValidMessage.
/*
* Test method for 'org.opennms.netmgt.notifd.MattermostNotificationStrategy.send(List)'
*/
@Test
@JUnitHttpServer(webapps = { @Webapp(context = "/hooks", path = "src/test/resources/MattermostNotificationStrategyTest") })
public void testSendValidMessage() {
final int port = JUnitHttpServerExecutionListener.getPort();
assertTrue(port > 0);
try {
final NotificationStrategy ns = new SlackNotificationStrategy();
final List<Argument> arguments = new ArrayList<>();
// Set these properties. We will override them with Args on the first run.
System.setProperty("org.opennms.netmgt.notifd.slack.webhookURL", "http://localhost:" + port + "/hooks/abunchofstuffthatidentifiesawebhook");
System.setProperty("org.opennms.netmgt.notifd.slack.channel", "integrationtestsXX");
System.setProperty("org.opennms.netmgt.notifd.slack.iconURL", "http://opennms.org/logo.pngXX");
System.setProperty("org.opennms.netmgt.notifd.slack.iconEmoji", ":shipitXX:");
System.setProperty("org.opennms.netmgt.notifd.slack.username", "opennmsXX");
arguments.add(new Argument("url", null, "http://localhost:" + port + "/hooks/abunchofstuffthatidentifiesawebhook", false));
arguments.add(new Argument("channel", null, "integrationtests", false));
arguments.add(new Argument("username", null, "opennms", false));
arguments.add(new Argument("iconurl", null, "http://opennms.org/logo.png", false));
arguments.add(new Argument("iconemoji", null, ":shipit:", false));
arguments.add(new Argument("-subject", null, "Test", false));
arguments.add(new Argument("-tm", null, "This is only a test", false));
int statusCode = ns.send(arguments);
assertEquals(0, statusCode);
JSONObject inputJson = MattermostNotificationStrategyTestServlet.getInputJson();
assertNotNull(inputJson);
assertEquals("opennms", inputJson.get("username"));
assertEquals("*Test*\nThis is only a test", inputJson.get("text"));
assertEquals("integrationtests", inputJson.get("channel"));
assertEquals("http://opennms.org/logo.png", inputJson.get("icon_url"));
assertEquals(":shipit:", inputJson.get("icon_emoji"));
assertEquals(5, inputJson.size());
// Now do it again, without the Args, and verify that the property values come out
arguments.clear();
arguments.add(new Argument("-subject", null, "Test again", false));
arguments.add(new Argument("-tm", null, "This is only a second test", false));
statusCode = ns.send(arguments);
assertEquals(0, statusCode);
inputJson = MattermostNotificationStrategyTestServlet.getInputJson();
assertNotNull(inputJson);
assertEquals("opennmsXX", inputJson.get("username"));
assertEquals("*Test again*\nThis is only a second test", inputJson.get("text"));
assertEquals("integrationtestsXX", inputJson.get("channel"));
assertEquals("http://opennms.org/logo.pngXX", inputJson.get("icon_url"));
assertEquals(":shipitXX:", inputJson.get("icon_emoji"));
assertEquals(5, inputJson.size());
} catch (Throwable e) {
e.printStackTrace();
fail("Caught Exception: " + e.getMessage());
}
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class HttpUrlConnectionIT method testServlet.
/**
* Test the Servlet with a simple POST Request based on XML Data.
*
* @throws Exception the exception
*/
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testServlet() throws Exception {
String xml = "<person><firstName>Alejandro</firstName></person>";
final HttpClientWrapper clientWrapper = HttpClientWrapper.create();
try {
StringEntity entity = new StringEntity(xml, ContentType.APPLICATION_XML);
HttpPost method = new HttpPost("http://localhost:10342/junit/test/sample");
method.setEntity(entity);
CloseableHttpResponse response = clientWrapper.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
Assert.assertEquals("OK!", EntityUtils.toString(response.getEntity()));
} finally {
IOUtils.closeQuietly(clientWrapper);
}
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class HttpDataCollectionIT method testJsonHttpCollection.
/**
* Test HTTP Data Collection with JSON
*
* @throws Exception the exception
*/
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testJsonHttpCollection() throws Exception {
File configFile = new File("src/test/resources/solaris-zones-datacollection-config.xml");
XmlDataCollectionConfig config = JaxbUtils.unmarshal(XmlDataCollectionConfig.class, configFile);
XmlDataCollection collection = config.getDataCollectionByName("Solaris");
RrdRepository repository = createRrdRepository(collection.getXmlRrd());
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("collection", "Solaris");
DefaultJsonCollectionHandler collector = new DefaultJsonCollectionHandler();
collector.setRrdRepository(repository);
collector.setServiceName("HTTP");
CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_nodeDao, collector, m_collectionAgent, collection, parameters);
Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
System.err.println(CollectionSetUtils.flatten(collectionSet));
ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, repository, false, false);
collectionSet.visit(persister);
RrdDb jrb = new RrdDb(new File(getSnmpRoot(), "1/solarisZoneStats/global/solaris-zone-stats.jrb"));
Assert.assertNotNull(jrb);
Assert.assertEquals(6, jrb.getDsCount());
Datasource ds = jrb.getDatasource("nproc");
Assert.assertNotNull(ds);
Assert.assertEquals(new Double(245.0), Double.valueOf(ds.getLastValue()));
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class HttpDataCollectionIT method testHttpCollection.
/**
* Test HTTP Data Collection with XPath
*
* @throws Exception the exception
*/
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testHttpCollection() throws Exception {
File configFile = new File("src/test/resources/http-datacollection-config.xml");
XmlDataCollectionConfig config = JaxbUtils.unmarshal(XmlDataCollectionConfig.class, configFile);
XmlDataCollection collection = config.getDataCollectionByName("Http-Count");
RrdRepository repository = createRrdRepository(collection.getXmlRrd());
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("collection", "Http-Count");
DefaultXmlCollectionHandler collector = new DefaultXmlCollectionHandler();
collector.setRrdRepository(repository);
collector.setServiceName("HTTP");
CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_nodeDao, collector, m_collectionAgent, collection, parameters);
Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, repository, false, false);
collectionSet.visit(persister);
RrdDb jrb = new RrdDb(new File(getSnmpRoot(), "1/count-stats.jrb"));
Assert.assertNotNull(jrb);
Assert.assertEquals(1, jrb.getDsCount());
Datasource ds = jrb.getDatasource("count");
Assert.assertNotNull(ds);
Assert.assertEquals(new Double(5), Double.valueOf(ds.getLastValue()));
}
Aggregations