use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementServiceImplIT method testUpdateAnnouncementNotExists.
@Test(expected = InvalidDataAccessApiUsageException.class)
@WithMockUser(username = "admin", roles = "ADMIN")
public void testUpdateAnnouncementNotExists() {
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
final User user = userService.getUserByUsername(auth.getName());
final Announcement a = new Announcement("Doesn't exist", user);
announcementService.update(a);
}
use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementServiceImplIT method testMarkAnnouncementAsUnreadForOtherUser.
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testMarkAnnouncementAsUnreadForOtherUser() {
final Announcement a1 = announcementService.read(1L);
final Announcement a2 = announcementService.read(2L);
final User user = userService.getUserByUsername("user");
// for checking whether announcements or users have been incorrectly deleted from the database
final int numUsersBefore = Lists.newArrayList(userService.findAll()).size();
final int numAnnsBefore = announcementService.getAllAnnouncements().size();
announcementService.markAnnouncementAsUnreadByUser(a1, user);
announcementService.markAnnouncementAsUnreadByUser(a2, user);
final int numUsersAfter = Lists.newArrayList(userService.findAll()).size();
final int numAnnsAfter = announcementService.getAllAnnouncements().size();
assertEquals("User was incorrectly modified/deleted", numUsersBefore, numUsersAfter);
assertEquals("Announcement was incorrectly modified/deleted", numAnnsBefore, numAnnsAfter);
}
use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementServiceImplIT method testUpdateAnnouncementAsUserFail.
@Test(expected = AccessDeniedException.class)
@WithMockUser(username = "user", roles = "USER")
public void testUpdateAnnouncementAsUserFail() {
final Announcement a = announcementService.read(1L);
announcementService.update(a);
}
use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementServiceImplIT method testGetAnnouncementsCreatedByAdmin.
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testGetAnnouncementsCreatedByAdmin() {
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
final User user = userService.getUserByUsername(auth.getName());
List<Announcement> announcements = announcementService.getAnnouncementsCreatedByUser(user);
for (Announcement a : announcements) {
assertEquals("Announcement was not created by the selected user", user, a.getUser());
}
int beforeSize = announcements.size();
announcementService.create(new Announcement("The newest announcement", user));
announcementService.create(new Announcement("No, this is the newest one!", user));
assertEquals("Number of announcements doesn't match", beforeSize + 2, announcementService.getAnnouncementsCreatedByUser(user).size());
announcementService.delete(1L);
assertEquals("Number of announcements doesn't match", beforeSize + 1, announcementService.getAnnouncementsCreatedByUser(user).size());
announcementService.create(new Announcement("Someone else made me do it!", userService.getUserByUsername("admin2")));
announcements = announcementService.getAnnouncementsCreatedByUser(user);
for (Announcement a : announcements) {
assertEquals("Announcement was not created by the selected user", user, a.getUser());
}
}
use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.
the class AnnouncementServiceImplIT method testSearchReturnsNoResults.
@Test
@WithMockUser(username = "user", roles = "USER")
public void testSearchReturnsNoResults() {
String searchString = "ThisShouldn'tMatchAnything!!";
Page<Announcement> searchAnnouncement = announcementService.search(AnnouncementSpecification.searchAnnouncement(searchString), new PageRequest(1, 10, new Sort(Sort.Direction.ASC, "id")));
assertEquals("Unexpected number of announcements returned", 0, searchAnnouncement.getContent().size());
}
Aggregations