Search in sources :

Example 6 with Announcement

use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.

the class AnnouncementServiceImplIT method testUpdateAnnouncementAsAdminSuccess.

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testUpdateAnnouncementAsAdminSuccess() {
    Announcement announcement = announcementService.read(1L);
    final String newMessage = "A new message";
    announcement.setMessage(newMessage);
    announcement = announcementService.update(announcement);
    assertEquals("Message content doesn't match", newMessage, announcement.getMessage());
}
Also used : Announcement(ca.corefacility.bioinformatics.irida.model.announcements.Announcement) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 7 with Announcement

use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.

the class AnnouncementServiceImplIT method testSearchReturnsExistingAnnouncement.

@Test
@WithMockUser(username = "user", roles = "USER")
public void testSearchReturnsExistingAnnouncement() {
    String searchString = "Downtime";
    Page<Announcement> searchAnnouncement = announcementService.search(AnnouncementSpecification.searchAnnouncement(searchString), new PageRequest(0, 10, new Sort(Sort.Direction.ASC, "id")));
    assertEquals("Unexpected number of announcements returned", 2, searchAnnouncement.getContent().size());
    for (Announcement a : searchAnnouncement) {
        assertTrue(a.getMessage().contains(searchString));
    }
}
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)

Example 8 with Announcement

use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.

the class AnnouncementServiceImplIT method testUserMarkAnnouncementAsReadSuccess.

@Test
@WithMockUser(username = "user3", roles = "USER")
public void testUserMarkAnnouncementAsReadSuccess() {
    final Announcement a = announcementService.read(2L);
    final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    final User user = userService.getUserByUsername(auth.getName());
    try {
        announcementService.markAnnouncementAsReadByUser(a, user);
    } catch (AccessDeniedException e) {
        fail("User should be able able to mark announcement as read.");
    } catch (EntityExistsException e) {
        fail("Failed for unknown reason, stack trace follows:");
        e.printStackTrace();
    }
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) 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) EntityExistsException(ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 9 with Announcement

use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.

the class AnnouncementServiceImplIT method testSearchNullSearchString.

@Test
@WithMockUser(username = "user", roles = "USER")
public void testSearchNullSearchString() {
    Page<Announcement> searchAnnouncement = announcementService.search(AnnouncementSpecification.searchAnnouncement(null), new PageRequest(0, 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)

Example 10 with Announcement

use of ca.corefacility.bioinformatics.irida.model.announcements.Announcement in project irida by phac-nml.

the class AnnouncementServiceImplIT method testCreateAnnouncementNotAdmin.

@Test(expected = AccessDeniedException.class)
@WithMockUser(username = "user", roles = "USER")
public void testCreateAnnouncementNotAdmin() {
    final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    final User user = userService.getUserByUsername(auth.getName());
    announcementService.create(new Announcement("This is a message", user));
}
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)

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