use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class IPhoneRestServiceIT method testEventsForNodeId.
@Test
@JUnitTemporaryDatabase
public void testEventsForNodeId() throws Exception {
OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation());
node.setId(1);
OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_distPollerDao.whoami());
event.setEventUei("uei.opennms.org/test");
event.setEventTime(new Date());
event.setEventSource("test");
event.setEventCreateTime(new Date());
event.setEventSeverity(OnmsSeverity.INDETERMINATE.getId());
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setNode(node);
m_eventDao.save(event);
m_eventDao.flush();
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("limit", "50");
parameters.put("node.id", "1");
String xml = sendRequest(GET, "/events", parameters, 200);
assertTrue(xml, xml.contains("totalCount=\"2\""));
assertTrue(xml, xml.contains("uei.opennms.org/test"));
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class EventRestServiceIT method testEvents.
@Test
@JUnitTemporaryDatabase
public void testEvents() throws Exception {
String url = "/events";
JSONObject object = new JSONObject(sendRequest(GET, url, 200));
Assert.assertEquals(6, object.getInt("totalCount"));
object = new JSONObject(sendRequest(GET, url, parseParamData("_s=node.label==server01"), 200));
Assert.assertEquals(3, object.getInt("totalCount"));
object = new JSONObject(sendRequest(GET, url, parseParamData("_s=event.uei==*somethingWentWrong"), 200));
Assert.assertEquals(2, object.getInt("totalCount"));
object = new JSONObject(sendRequest(GET, url, parseParamData("_s=category.name==Linux"), 200));
Assert.assertEquals(3, object.getInt("totalCount"));
object = new JSONObject(sendRequest(GET, url, parseParamData("_s=category.name==Linux;event.uei==*somethingWentWrong"), 200));
Assert.assertEquals(1, object.getInt("totalCount"));
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class NodeRestServiceIT method testAllEndPointsWithJSON.
@Test
@JUnitTemporaryDatabase
public void testAllEndPointsWithJSON() throws Exception {
JSONObject node = new JSONObject();
node.put("type", "A");
node.put("label", "TestMachine1");
node.put("foreignSource", "JUnit");
node.put("foreignId", "TestMachine1");
node.put("location", "Default");
node.put("labelSource", "H");
node.put("sysContact", "The Owner");
node.put("sysDescription", "Darwin TestMachine 9.4.0 Darwin Kernel Version 9.4.0: Mon Jun 9 19:30:53 PDT 2008; root:xnu-1228.5.20~1/RELEASE_I386 i386");
node.put("sysLocation", "Earth");
node.put("sysName", "TestMachine1");
node.put("sysObjectId", ".1.3.6.1.4.1.8072.3.2.255");
sendData(POST, MediaType.APPLICATION_JSON, "/nodes", node.toString(), 201);
LOG.warn(sendRequest(GET, "/nodes", 200));
// By ID
LOG.warn(sendRequest(GET, "/nodes/1", 200));
// By foreignSource/foreignId combination
LOG.warn(sendRequest(GET, "/nodes/JUnit:TestMachine1", 200));
JSONObject ipInterface = new JSONObject();
ipInterface.put("snmpPrimary", "P");
ipInterface.put("ipAddress", "10.10.10.10");
ipInterface.put("hostName", "TestMachine");
sendData(POST, MediaType.APPLICATION_JSON, "/nodes/1/ipinterfaces", ipInterface.toString(), 201);
LOG.warn(sendRequest(GET, "/nodes/1/ipinterfaces", 200));
// By IP Address
LOG.warn(sendRequest(GET, "/nodes/1/ipinterfaces/10.10.10.10", 200));
/*
* FIXME Doesn't work (the XML counterpart works without issues)
* Caused by: java.lang.IllegalArgumentException: Can not handle managed/back reference 'defaultReference':
* back reference type (java.util.Set) not compatible with managed type (org.opennms.netmgt.model.OnmsMonitoredService)
*/
/*
JSONObject serviceType = new JSONObject();
serviceType.put("name", "ICMP");
JSONObject service = new JSONObject();
service.put("status", "A");
service.put("serviceType", serviceType);
sendData(POST, MediaType.APPLICATION_JSON, "/nodes/1/ipinterfaces/10.10.10.10/services", service.toString(), 201);
LOG.warn(sendRequest(GET, "/nodes/1/ipinterfaces/10.10.10.10/services", 200));
LOG.warn(sendRequest(GET, "/nodes/1/ipinterfaces/10.10.10.10/services/ICMP", 200)); // By Name
*/
JSONObject snmpInterface = new JSONObject();
snmpInterface.put("ifIndex", 6);
snmpInterface.put("ifAdminStatus", 1);
snmpInterface.put("ifOperStatus", 1);
snmpInterface.put("ifDescr", "en1");
snmpInterface.put("ifName", "en1");
snmpInterface.put("ifSpeed", 10000000);
snmpInterface.put("ifType", 6);
snmpInterface.put("physAddr", "001e5271136d");
sendData(POST, MediaType.APPLICATION_JSON, "/nodes/1/snmpinterfaces", snmpInterface.toString(), 201);
LOG.warn(sendRequest(GET, "/nodes/1/snmpinterfaces", 200));
// By ifIndex
LOG.warn(sendRequest(GET, "/nodes/1/snmpinterfaces/6", 200));
JSONObject category = new JSONObject();
category.put("name", "Production");
sendData(POST, MediaType.APPLICATION_JSON, "/nodes/1/categories", category.toString(), 201);
LOG.warn(sendRequest(GET, "/nodes/1/categories", 200));
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class DaoWebOutageRepositoryIT method testGetMatchingOutagesByForeignSource.
/**
* @see http://issues.opennms.org/browse/NMS-8275
*/
@Test
// Relies on specific IDs so we need a fresh database
@JUnitTemporaryDatabase
public void testGetMatchingOutagesByForeignSource() {
Outage[] outages = m_daoOutageRepo.getMatchingOutages(new OutageCriteria(new ForeignSourceFilter("imported:")));
assertEquals(3, outages.length);
outages = m_daoOutageRepo.getMatchingOutages(new OutageCriteria(new ForeignSourceFilter("DOESNT_EXIST")));
assertEquals(0, outages.length);
outages = m_daoOutageRepo.getMatchingOutages(new OutageCriteria(new NegativeForeignSourceFilter("imported:")));
assertEquals(0, outages.length);
outages = m_daoOutageRepo.getMatchingOutages(new OutageCriteria(new NegativeForeignSourceFilter("DOESNT_EXIST")));
assertEquals(3, outages.length);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class AlarmRepositoryIT method testCountMatchingAlarmsBySeverity.
@Test
@Transactional
@JUnitTemporaryDatabase
public void testCountMatchingAlarmsBySeverity() {
AlarmCriteria criteria = new AlarmCriteria();
int[] matchingAlarms = m_alarmRepo.countMatchingAlarmsBySeverity(AlarmUtil.getOnmsCriteria(criteria));
assertEquals(8, matchingAlarms.length);
// Make sure that the count is correct per severity
assertEquals(0, matchingAlarms[OnmsSeverity.CLEARED.getId()]);
assertEquals(0, matchingAlarms[OnmsSeverity.CRITICAL.getId()]);
assertEquals(0, matchingAlarms[OnmsSeverity.INDETERMINATE.getId()]);
assertEquals(0, matchingAlarms[OnmsSeverity.MINOR.getId()]);
assertEquals(1, matchingAlarms[OnmsSeverity.NORMAL.getId()]);
assertEquals(0, matchingAlarms[OnmsSeverity.WARNING.getId()]);
assertEquals(0, matchingAlarms[OnmsSeverity.MAJOR.getId()]);
}
Aggregations