Search in sources :

Example 31 with Transactional

use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.

the class DefaultSurveillanceServiceIntegrationIT method testCreateSurveillanceServiceTableUsingViewName.

@Test
@Transactional
public void testCreateSurveillanceServiceTableUsingViewName() {
    String viewName = "default";
    SimpleWebTable table = m_surveillanceService.createSurveillanceTable(viewName, new ProgressMonitor() {

        @Override
        public void beginNextPhase(String string) {
            System.err.println("PHASE: " + string);
        }

        @Override
        public void setPhaseCount(int i) {
        }
    });
    assertEquals("default", table.getTitle());
}
Also used : ProgressMonitor(org.opennms.web.svclayer.model.ProgressMonitor) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 32 with Transactional

use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.

the class AlarmRestServiceIT method testAlarmUpdates.

@Test
@Transactional
@JUnitTemporaryDatabase
public void testAlarmUpdates() throws Exception {
    createAlarm(OnmsSeverity.MAJOR);
    OnmsAlarm alarm = getLastAlarm();
    alarm.setAlarmAckTime(null);
    alarm.setAlarmAckUser(null);
    getAlarmDao().saveOrUpdate(alarm);
    final Integer alarmId = alarm.getId();
    sendPut("/alarms", "ack=true&alarmId=" + alarmId, 204);
    String xml = sendRequest(GET, "/alarms/" + alarmId, 200);
    assertTrue(xml.contains("ackUser>admin<"));
    sendPut("/alarms/" + alarmId, "clear=true", 204);
    xml = sendRequest(GET, "/alarms/" + alarmId, 200);
    assertTrue(xml.contains("severity=\"CLEARED\""));
    sendPut("/alarms/" + alarmId, "escalate=true", 204);
    xml = sendRequest(GET, "/alarms/" + alarmId, 200);
    assertTrue(xml.contains("severity=\"NORMAL\""));
    sendPut("/alarms/" + alarmId, "ticketId=12345", 204);
    xml = sendRequest(GET, "/alarms/" + alarmId, 200);
    assertTrue(xml.contains("<troubleTicket>12345</troubleTicket>"));
    sendPut("/alarms/" + alarmId, "ticketState=UPDATE_PENDING", 204);
    xml = sendRequest(GET, "/alarms/" + alarmId, 200);
    sendPut("/alarms/" + alarmId, "ticketState=UPDATE_PENDING", 204);
    alarm = getLastAlarm();
    alarm.setSeverity(OnmsSeverity.MAJOR);
    alarm.setAlarmAckTime(null);
    alarm.setAlarmAckUser(null);
    getAlarmDao().saveOrUpdate(alarm);
    // Log in as a normal REST user and attempt to resolve an alarm as a different user.
    // This should fail with a 403 forbidden.
    setUser("foo", new String[] { "ROLE_REST" });
    sendPut("/alarms/" + alarmId, "ack=true&ackUser=bar", 403);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with Transactional

use of org.springframework.transaction.annotation.Transactional 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 34 with Transactional

use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.

the class AlarmRepositoryFilterIT method testBeforeFirstEventTimeFilter.

@Test
@Transactional
@JUnitTemporaryDatabase
public void testBeforeFirstEventTimeFilter() {
    OnmsAlarm[] alarms = m_daoAlarmRepo.getMatchingAlarms(AlarmUtil.getOnmsCriteria(new AlarmCriteria(new BeforeFirstEventTimeFilter(new Date()))));
    assertEquals(1, alarms.length);
    alarms = m_daoAlarmRepo.getMatchingAlarms(AlarmUtil.getOnmsCriteria(new AlarmCriteria(new BeforeLastEventTimeFilter(new Date()))));
    assertEquals(1, alarms.length);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Date(java.util.Date) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with Transactional

use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.

the class AlarmRepositoryIT method testSortAndSearchBySameProperty.

@Test
@Transactional
@JUnitTemporaryDatabase
public void testSortAndSearchBySameProperty() {
    Filter[] filters = new Filter[] { new NodeNameLikeFilter("node") };
    AlarmCriteria sorted = new AlarmCriteria(filters, SortStyle.NODE, AcknowledgeType.UNACKNOWLEDGED, 100, 0);
    OnmsAlarm[] alarms = m_alarmRepo.getMatchingAlarms(AlarmUtil.getOnmsCriteria(sorted));
    assertTrue("Failed to sort with style " + SortStyle.NODE, alarms.length > 0);
}
Also used : NodeNameLikeFilter(org.opennms.web.alarm.filter.NodeNameLikeFilter) SeverityFilter(org.opennms.web.alarm.filter.SeverityFilter) Filter(org.opennms.web.filter.Filter) AlarmIdFilter(org.opennms.web.alarm.filter.AlarmIdFilter) NodeNameLikeFilter(org.opennms.web.alarm.filter.NodeNameLikeFilter) AcknowledgedByFilter(org.opennms.web.alarm.filter.AcknowledgedByFilter) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) 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)

Aggregations

Transactional (org.springframework.transaction.annotation.Transactional)4561 Test (org.junit.Test)1387 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)724 DAOException (com.tomasio.projects.trainning.exception.DAOException)385 CoreException (com.tomasio.projects.trainning.exeption.CoreException)372 ArrayList (java.util.ArrayList)324 Date (java.util.Date)252 Query (javax.persistence.Query)218 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)213 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)211 WithMockUser (org.springframework.security.test.context.support.WithMockUser)204 HashMap (java.util.HashMap)187 List (java.util.List)163 User (io.github.jhipster.sample.domain.User)150 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)135 HashSet (java.util.HashSet)135 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)132 UUID (java.util.UUID)131 Rollback (org.springframework.test.annotation.Rollback)109 ParseException (java.text.ParseException)108