use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementServiceImplIT method testUserMarkAnnouncementAsReadFailed.
@Test(expected = EntityExistsException.class)
@WithMockUser(username = "user", roles = "USER")
public void testUserMarkAnnouncementAsReadFailed() {
final Announcement a = announcementService.read(1L);
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
final User user = userService.getUserByUsername(auth.getName());
announcementService.markAnnouncementAsReadByUser(a, user);
}
use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementServiceImplIT method testGetUnreadAnnouncementsForUser.
@Test
@WithMockUser(username = "user3", roles = "USER")
public void testGetUnreadAnnouncementsForUser() {
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
final User user = userService.getUserByUsername(auth.getName());
List<Announcement> announcementList = announcementService.getUnreadAnnouncementsForUser(user);
assertEquals("Number of unread announcements doesn't match expected value", 6, announcementList.size());
Announcement ann = announcementService.read(6L);
announcementService.markAnnouncementAsReadByUser(ann, user);
announcementList = announcementService.getUnreadAnnouncementsForUser(user);
assertEquals("Number of unread announcements doesn't match expected value", 5, announcementList.size());
}
use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementServiceImpl method countReadsForAllAnnouncements.
/**
* {@inheritDoc}
*/
@Override
@PreAuthorize("hasRole('ROLE_ADMIN')")
public Map<Announcement, Long> countReadsForAllAnnouncements() {
Map<Announcement, Long> counts = new HashMap<>();
List<Announcement> announcements = getAllAnnouncements();
for (Announcement a : announcements) {
counts.put(a, countReadsForOneAnnouncement(a));
}
return counts;
}
use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementServiceImplIT method testGetSingleAnnouncementById.
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testGetSingleAnnouncementById() {
Announcement a = announcementService.read(3L);
Long idExpected = 3L;
String messageExpected = "You cannot have your cake and eat it too.";
assertEquals("IDs for announcement doesn't match", idExpected, a.getId());
assertEquals("Announcement message content doesn't match expected", messageExpected, a.getMessage());
}
use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementServiceImplIT method testCreateAnnouncementAsAdmin.
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testCreateAnnouncementAsAdmin() {
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
final User user = userService.getUserByUsername(auth.getName());
Announcement an = new Announcement("This is a message", user);
try {
announcementService.create(an);
} catch (AccessDeniedException e) {
fail("Admin should be able to create a new announcement.");
} catch (Exception e) {
fail("Failed for unknown reason, stack trace follows: ");
e.printStackTrace();
}
}
Aggregations