use of com.serotonin.m2m2.rt.event.type.MockEventType in project ma-core-public by infiniteautomation.
the class EventInstanceServiceTest method newVO.
@Override
EventInstanceVO newVO(User owner) {
EventInstanceVO vo = new EventInstanceVO();
vo.setAlarmLevel(AlarmLevels.URGENT);
vo.setEventType(new MockEventType(readRole));
vo.setActiveTimestamp(System.currentTimeMillis());
vo.setRtnApplicable(false);
vo.setMessage(new TranslatableMessage("common.noMessage"));
return vo;
}
use of com.serotonin.m2m2.rt.event.type.MockEventType in project ma-core-public by infiniteautomation.
the class EmailEventHandlerDaoTest method testHandlerMappings.
@Test
public void testHandlerMappings() {
EmailEventHandlerVO handler = newVO();
dao.insert(handler);
EmailEventHandlerVO fromDB = (EmailEventHandlerVO) dao.get(handler.getId());
assertEquals(1, fromDB.getEventTypes().size());
// Update
dao.saveEventHandlerMapping(fromDB.getId(), new MockEventType(readRole));
fromDB = (EmailEventHandlerVO) dao.get(handler.getId());
assertEquals(1, fromDB.getEventTypes().size());
// Delete by type and handlerId
dao.deleteEventHandlerMapping(fromDB.getId(), new MockEventType(readRole));
fromDB = (EmailEventHandlerVO) dao.get(handler.getId());
assertEquals(0, fromDB.getEventTypes().size());
// Insert
dao.saveEventHandlerMapping(fromDB.getId(), new MockEventType(readRole));
fromDB = (EmailEventHandlerVO) dao.get(handler.getId());
assertEquals(1, fromDB.getEventTypes().size());
// Delete by type
dao.deleteEventHandlerMappings(new MockEventType(readRole));
fromDB = (EmailEventHandlerVO) dao.get(handler.getId());
assertEquals(0, fromDB.getEventTypes().size());
}
use of com.serotonin.m2m2.rt.event.type.MockEventType in project ma-core-public by infiniteautomation.
the class EventInstanceDaoTest method newVO.
@Override
EventInstanceVO newVO() {
EventInstanceVO vo = new EventInstanceVO();
vo.setAlarmLevel(AlarmLevels.URGENT);
vo.setEventType(new MockEventType(readRole));
vo.setActiveTimestamp(System.currentTimeMillis());
vo.setRtnApplicable(false);
vo.setMessage(new TranslatableMessage("common.noMessage"));
return vo;
}
use of com.serotonin.m2m2.rt.event.type.MockEventType in project ma-core-public by infiniteautomation.
the class UserEventsTest method testRaiseEvents.
@Test
public void testRaiseEvents() throws InterruptedException {
// Create some users
List<User> users = createUsers(userCount, PermissionHolder.SUPERADMIN_ROLE);
List<MockUserEventListener> listeners = new ArrayList<>();
for (User u : users) {
MockUserEventListener l = new MockUserEventListener(u, MockEventType.class);
listeners.add(l);
Common.eventManager.addUserEventListener(l);
}
// Raise some events
List<MockEventTypeTime> raised = new ArrayList<>();
for (int i = 0; i < eventCount; i++) {
MockEventType event = new MockEventType(DuplicateHandling.ALLOW, null, i, dataPointId, null);
raised.add(new MockEventTypeTime(event, this.timer.currentTimeMillis()));
Common.eventManager.raiseEvent(event, this.timer.currentTimeMillis(), true, AlarmLevels.URGENT, new TranslatableMessage("common.default", "Mock Event"), null);
timer.fastForwardTo(timer.currentTimeMillis() + 1);
}
assertEvents(listeners, EventAction.RAISED, raised);
// Acknowledge
List<MockEventTypeTime> acknowledged = new ArrayList<>();
List<EventInstance> instances = EventDao.getInstance().getActiveEvents();
for (EventInstance event : instances) {
MockEventTypeTime rtn = new MockEventTypeTime((MockEventType) event.getEventType(), this.timer.currentTimeMillis());
acknowledged.add(rtn);
Common.eventManager.acknowledgeEventById(event.getId(), timer.currentTimeMillis(), users.get(0), null);
timer.fastForwardTo(timer.currentTimeMillis() + 1);
}
assertEvents(listeners, EventAction.ACKNOWLEDGED, acknowledged);
// Return to normal
List<MockEventTypeTime> returned = new ArrayList<>();
for (MockEventTypeTime event : raised) {
MockEventTypeTime rtn = new MockEventTypeTime(event.type, this.timer.currentTimeMillis());
returned.add(rtn);
Common.eventManager.returnToNormal(rtn.type, rtn.time);
timer.fastForwardTo(timer.currentTimeMillis() + 1);
}
assertEvents(listeners, EventAction.RETURNED, returned);
}
use of com.serotonin.m2m2.rt.event.type.MockEventType in project ma-core-public by MangoAutomation.
the class EmailEventHandlerServiceTest method newVO.
@Override
EmailEventHandlerVO newVO(User user) {
EmailEventHandlerVO vo = (EmailEventHandlerVO) ModuleRegistry.getEventHandlerDefinition(EmailEventHandlerDefinition.TYPE_NAME).baseCreateEventHandlerVO();
vo.setXid(UUID.randomUUID().toString());
vo.setName(UUID.randomUUID().toString());
ScriptPermissions permissions = new ScriptPermissions(Collections.singleton(readRole));
vo.setScriptRoles(permissions);
List<EventTypeMatcher> eventTypes = Collections.singletonList(new EventTypeMatcher(new MockEventType(readRole)));
vo.setEventTypes(eventTypes);
return vo;
}
Aggregations