use of com.serotonin.m2m2.rt.event.type.MockEventType in project ma-core-public by MangoAutomation.
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 MangoAutomation.
the class UserEventMulticasterTest method testMulticastEventsForUsersWithPermissions.
@Test
public void testMulticastEventsForUsersWithPermissions() {
PermissionService service = Common.getBean(PermissionService.class);
int dataPointId = 1;
int eventCount = 100;
int userCount = 5 * 6;
// Add them out of order so the tree is jumbled with permissions hither and yon
List<User> users = new ArrayList<>();
int added = 0;
for (int i = 0; i < (userCount / 6); i++) {
users.add(createUser("User" + added, "user" + added, "password", "user" + added + "@yourMangoDomain.com", PermissionHolder.SUPERADMIN_ROLE));
added++;
}
for (int i = 0; i < (userCount / 6); i++) {
users.add(createUser("User" + added, "user" + added, "password", "user" + added + "@yourMangoDomain.com", mockRole.getRole()));
added++;
}
for (int i = 0; i < (userCount / 6); i++) {
users.add(createUser("User" + added, "user" + added, "password", "user" + added + "@yourMangoDomain.com"));
added++;
}
for (int i = 0; i < (userCount / 6); i++) {
users.add(createUser("User" + added, "user" + added, "password", "user" + added + "@yourMangoDomain.com", PermissionHolder.SUPERADMIN_ROLE));
added++;
}
for (int i = 0; i < (userCount / 6); i++) {
users.add(createUser("User" + added, "user" + added, "password", "user" + added + "@yourMangoDomain.com", mockRole.getRole()));
added++;
}
for (int i = 0; i < (userCount / 6); i++) {
users.add(createUser("User" + added, "user" + added, "password", "user" + added + "@yourMangoDomain.com"));
added++;
}
List<Integer> idsToNotify = new ArrayList<>();
List<MockUserEventListener> listeners = new ArrayList<>();
UserEventListener multicaster = null;
MockEventType mockEventType = new MockEventType(DuplicateHandling.ALLOW, null, 0, dataPointId, this.mockRole.getRole());
for (User u : users) {
MockUserEventListener l = new MockUserEventListener(u);
if (// This work is normally done by the event manager handling the raiseEvent calls
mockEventType.hasPermission(u, service))
// through an EventNotifyWorkItem
idsToNotify.add(u.getId());
listeners.add(l);
multicaster = UserEventMulticaster.add(multicaster, l);
}
List<EventInstance> events = new ArrayList<>();
long time = 0;
for (int i = 0; i < eventCount; i++) {
EventInstance event = createMockEventInstance(i, dataPointId, time);
events.add(event);
event.setIdsToNotify(idsToNotify);
multicaster.raised(event);
time += 1;
}
// Ack
for (EventInstance e : events) multicaster.acknowledged(e);
// Rtn
for (EventInstance e : events) multicaster.returnToNormal(e);
// Confirm those with correct permissions permissions saw all raised
for (MockUserEventListener l : listeners) {
if (!(service.hasPermission(l.getUser(), MangoPermission.requireAnyRole(mockRole.getRole())) || service.hasAdminRole(l.getUser()))) {
assertEquals(0, l.getRaised().size());
} else {
assertEquals(eventCount, l.getRaised().size());
}
}
// Confirm those with permissions saw all acked
for (MockUserEventListener l : listeners) {
if (!(service.hasPermission(l.getUser(), MangoPermission.requireAnyRole(mockRole.getRole())) || service.hasAdminRole(l.getUser()))) {
assertEquals(0, l.getAcknowledged().size());
} else {
assertEquals(eventCount, l.getAcknowledged().size());
}
}
// Confirm those with permissions saw all rtned
for (MockUserEventListener l : listeners) {
if (!(service.hasPermission(l.getUser(), MangoPermission.requireAnyRole(mockRole.getRole())) || service.hasAdminRole(l.getUser()))) {
assertEquals(0, l.getReturned().size());
} else {
assertEquals(eventCount, l.getReturned().size());
}
}
}
use of com.serotonin.m2m2.rt.event.type.MockEventType in project ma-core-public by MangoAutomation.
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);
}
Aggregations