Search in sources :

Example 11 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class AlarmRestServiceIT method testAlarmClearAsRest.

@Test
@JUnitTemporaryDatabase
public void testAlarmClearAsRest() throws Exception {
    setUser("ranger", new String[] { "ROLE_REST" });
    final OnmsAlarm alarm = createAlarm(OnmsSeverity.MAJOR);
    sendRequest(PUT, "/alarms/" + alarm.getId(), parseParamData("clear=true"), 204);
    final String xml = sendRequest(GET, "/alarms/" + alarm.getId(), 200);
    final OnmsAlarm fromRest = JaxbUtils.unmarshal(OnmsAlarm.class, xml);
    assertEquals(fromRest.getSeverity(), OnmsSeverity.CLEARED);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 12 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class AlarmRestServiceIT method testAlarmClearAsMobile.

@Test
@JUnitTemporaryDatabase
public void testAlarmClearAsMobile() throws Exception {
    setUser("ranger", new String[] { "ROLE_MOBILE" });
    final OnmsAlarm alarm = createAlarm(OnmsSeverity.MAJOR);
    sendRequest(PUT, "/alarms/" + alarm.getId(), parseParamData("clear=true"), 204);
    final String xml = sendRequest(GET, "/alarms/" + alarm.getId(), 200);
    final OnmsAlarm fromRest = JaxbUtils.unmarshal(OnmsAlarm.class, xml);
    assertEquals(fromRest.getSeverity(), OnmsSeverity.CLEARED);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 13 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class AlarmRepositoryIT method testEscalateAlarms.

@Test
@JUnitTemporaryDatabase
public void testEscalateAlarms() {
    int[] alarmIds = { 1 };
    m_alarmRepo.escalateAlarms(alarmIds, "TestUser", new Date());
    OnmsAlarm[] alarms = m_alarmRepo.getMatchingAlarms(AlarmUtil.getOnmsCriteria(new AlarmCriteria(new AlarmIdFilter(1))));
    assertNotNull(alarms);
    assertEquals(OnmsSeverity.WARNING.getId(), alarms[0].getSeverity().getId());
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria) AlarmIdFilter(org.opennms.web.alarm.filter.AlarmIdFilter) Date(java.util.Date) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 14 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class AlarmRepositoryIT method testCountMatchingBySeverity.

@Test
@Transactional
@JUnitTemporaryDatabase
public void testCountMatchingBySeverity() {
    int[] matchingAlarmCount = m_alarmRepo.countMatchingAlarmsBySeverity(AlarmUtil.getOnmsCriteria(new AlarmCriteria(new SeverityFilter(OnmsSeverity.NORMAL))));
    assertEquals(8, matchingAlarmCount.length);
}
Also used : SeverityFilter(org.opennms.web.alarm.filter.SeverityFilter) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with JUnitTemporaryDatabase

use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.

the class AlarmRepositoryIT method testAcknowledgeUnacknowledge.

@Test
@JUnitTemporaryDatabase
public void testAcknowledgeUnacknowledge() {
    String user = "TestUser";
    m_alarmRepo.acknowledgeMatchingAlarms(user, new Date(), AlarmUtil.getOnmsCriteria(new AlarmCriteria(new AlarmIdFilter(1))));
    int matchingAlarmCount = m_alarmRepo.countMatchingAlarms(AlarmUtil.getOnmsCriteria(new AlarmCriteria(new AcknowledgedByFilter(user))));
    assertEquals(1, matchingAlarmCount);
    m_alarmRepo.unacknowledgeMatchingAlarms(AlarmUtil.getOnmsCriteria(new AlarmCriteria(new AlarmIdFilter(1))), user);
    matchingAlarmCount = m_alarmRepo.countMatchingAlarms(AlarmUtil.getOnmsCriteria(new AlarmCriteria(new AcknowledgedByFilter(user))));
    assertEquals(0, matchingAlarmCount);
}
Also used : AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria) AcknowledgedByFilter(org.opennms.web.alarm.filter.AcknowledgedByFilter) AlarmIdFilter(org.opennms.web.alarm.filter.AlarmIdFilter) Date(java.util.Date) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Aggregations

JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)109 Test (org.junit.Test)105 OnmsNode (org.opennms.netmgt.model.OnmsNode)21 Date (java.util.Date)20 JSONObject (org.json.JSONObject)18 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)18 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)17 Transactional (org.springframework.transaction.annotation.Transactional)14 FileInputStream (java.io.FileInputStream)10 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)10 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)9 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)8 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)7 AlarmIdFilter (org.opennms.web.alarm.filter.AlarmIdFilter)7 HashMap (java.util.HashMap)6 OutageCriteria (org.opennms.web.outage.filter.OutageCriteria)6 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 JSONArray (org.json.JSONArray)4 AcknowledgedByFilter (org.opennms.web.alarm.filter.AcknowledgedByFilter)4