Search in sources :

Example 1 with UserRestData

use of org.codenergic.theskeleton.user.UserRestData in project theskeleton by codenergic.

the class PostRestControllerTest method testFindPostReactions.

@Test
public void testFindPostReactions() throws Exception {
    when(postReactionService.findUserByPostReaction(eq("1234"), eq(PostReactionType.LIKE), any())).thenReturn(new PageImpl<>(Collections.singletonList(new UserEntity().setUsername("user").setPictureUrl("1234"))));
    MockHttpServletResponse response = mockMvc.perform(get("/api/posts/1234/reactions/likes").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(document("post-reactions-read")).andReturn().getResponse();
    assertThat(response.getStatus()).isEqualTo(200);
    Page<UserRestData> expectedResponse = new PageImpl<>(Collections.singletonList(ImmutableUserRestData.builder().username("user").pictureUrl("1234").isNonLocked(false).build()));
    assertThat(response.getContentAsString()).isEqualTo(objectMapper.writeValueAsString(expectedResponse));
    verify(postReactionService).findUserByPostReaction(eq("1234"), eq(PostReactionType.LIKE), any());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) UserRestData(org.codenergic.theskeleton.user.UserRestData) ImmutableUserRestData(org.codenergic.theskeleton.user.ImmutableUserRestData) UserEntity(org.codenergic.theskeleton.user.UserEntity) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

ImmutableUserRestData (org.codenergic.theskeleton.user.ImmutableUserRestData)1 UserEntity (org.codenergic.theskeleton.user.UserEntity)1 UserRestData (org.codenergic.theskeleton.user.UserRestData)1 Test (org.junit.Test)1 PageImpl (org.springframework.data.domain.PageImpl)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1