Search in sources :

Example 16 with Announcement

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);
}
Also used : WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(ca.corefacility.bioinformatics.irida.model.user.User) Announcement(ca.corefacility.bioinformatics.irida.model.announcements.Announcement) Authentication(org.springframework.security.core.Authentication) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 17 with Announcement

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);
}
Also used : WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(ca.corefacility.bioinformatics.irida.model.user.User) Announcement(ca.corefacility.bioinformatics.irida.model.announcements.Announcement) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 18 with Announcement

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);
}
Also used : Announcement(ca.corefacility.bioinformatics.irida.model.announcements.Announcement) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 19 with Announcement

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());
    }
}
Also used : WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(ca.corefacility.bioinformatics.irida.model.user.User) Announcement(ca.corefacility.bioinformatics.irida.model.announcements.Announcement) Authentication(org.springframework.security.core.Authentication) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 20 with Announcement

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());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Announcement(ca.corefacility.bioinformatics.irida.model.announcements.Announcement) Sort(org.springframework.data.domain.Sort) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Aggregations

Announcement (ca.corefacility.bioinformatics.irida.model.announcements.Announcement)29 Test (org.junit.Test)20 WithMockUser (org.springframework.security.test.context.support.WithMockUser)17 User (ca.corefacility.bioinformatics.irida.model.user.User)15 Authentication (org.springframework.security.core.Authentication)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 PageRequest (org.springframework.data.domain.PageRequest)5 DTAnnouncementUser (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTAnnouncementUser)4 IOException (java.io.IOException)3 Sort (org.springframework.data.domain.Sort)3 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)3 EntityExistsException (ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException)2 AnnouncementUserJoin (ca.corefacility.bioinformatics.irida.model.announcements.AnnouncementUserJoin)2 DataTablesResponse (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)2 DataTablesResponseModel (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel)2 AnnouncementService (ca.corefacility.bioinformatics.irida.service.AnnouncementService)2 UserService (ca.corefacility.bioinformatics.irida.service.user.UserService)2 Principal (java.security.Principal)2 AccessDeniedException (org.springframework.security.access.AccessDeniedException)2