use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class UserRoleRestControllerTest method testAddRoleToUser.
@Test
public void testAddRoleToUser() throws Exception {
final UserEntity user = new UserEntity().setId("123").setUsername("user123").setPassword("123456");
when(roleService.addRoleToUser("user123", "role123")).thenReturn(user);
ResultActions resultActions = mockMvc.perform(put("/api/users/user123/roles").content("{\"role\": \"role123\"}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(document("user-role-create"));
MockHttpServletResponse response = resultActions.andReturn().getResponse();
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(userMapper.toUserData(user)));
verify(roleService).addRoleToUser("user123", "role123");
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class PostRestControllerTest method init.
@Before
public void init() {
when(userDetailsService.loadUserByUsername(USERNAME)).thenReturn(new UserEntity().setId(USER_ID).setUsername(USERNAME));
mockMvc = MockMvcBuilders.standaloneSetup(new PostRestController(postService, postReactionService)).setCustomArgumentResolvers(new UserArgumentResolver(userDetailsService), new AuthenticationPrincipalArgumentResolver(), new PageableHandlerMethodArgumentResolver()).apply(documentationConfiguration(restDocumentation)).build();
Authentication authentication = new UsernamePasswordAuthenticationToken(new UserEntity().setId(USER_ID).setUsername(USERNAME), "1234");
SecurityContextHolder.getContext().setAuthentication(authentication);
PostServiceTest.DUMMY_POST.setCreatedDate(new Date());
PostServiceTest.DUMMY_POST.setLastModifiedDate(new Date());
PostServiceTest.DUMMY_POST2.setCreatedDate(new Date());
PostServiceTest.DUMMY_POST2.setLastModifiedDate(new Date());
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class UserFollowerRestControllerTest method testFindUserFollowings.
@Test
public void testFindUserFollowings() throws Exception {
when(userFollowerService.findUserFollowings(eq(USER_ID), any())).thenReturn(new PageImpl<>(Collections.singletonList(new UserEntity().setId(USERNAME).setUsername(USER_ID).setPictureUrl(USERNAME))));
MockHttpServletResponse response = mockMvc.perform(get("/api/users/" + USERNAME + "/followings").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn().getResponse();
assertThat(response.getStatus()).isEqualTo(200);
Page<UserFollowerRestData> result = new PageImpl<>(Collections.singletonList(UserFollowerRestData.builder().followingUsername(USER_ID).followingPictureUrl(USERNAME).build()));
assertThat(response.getContentAsString()).isEqualTo(objectMapper.writeValueAsString(result));
verify(userFollowerService).findUserFollowings(eq(USER_ID), any());
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class UserFollowerRestControllerTest method testFindUserFollowers.
@Test
public void testFindUserFollowers() throws Exception {
when(userFollowerService.findUserFollowers(eq(USER_ID), any())).thenReturn(new PageImpl<>(Collections.singletonList(new UserEntity().setId(USERNAME).setUsername(USER_ID).setPictureUrl(USERNAME))));
MockHttpServletResponse response = mockMvc.perform(get("/api/users/" + USERNAME + "/followers").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn().getResponse();
assertThat(response.getStatus()).isEqualTo(200);
Page<UserFollowerRestData> result = new PageImpl<>(Collections.singletonList(UserFollowerRestData.builder().followerUsername(USER_ID).followerPictureUrl(USERNAME).build()));
assertThat(response.getContentAsString()).isEqualTo(objectMapper.writeValueAsString(result));
verify(userFollowerService).findUserFollowers(eq(USER_ID), any());
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class UserFollowerRestControllerTest method testFollowUser.
@Test
public void testFollowUser() throws Exception {
when(userFollowerService.followUser(USER_ID, USER_ID)).thenReturn(new UserFollowerEntity().setUser(new UserEntity().setUsername(USER_ID).setPictureUrl(USERNAME)).setFollower(new UserEntity().setUsername(USERNAME).setPictureUrl(USER_ID)));
MockHttpServletResponse response = mockMvc.perform(put("/api/users/" + USERNAME + "/followers").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn().getResponse();
assertThat(response.getStatus()).isEqualTo(200);
UserFollowerRestData result = UserFollowerRestData.builder().followingUsername(USER_ID).followingPictureUrl(USERNAME).followerUsername(USERNAME).followerPictureUrl(USER_ID).build();
assertThat(response.getContentAsString()).isEqualTo(objectMapper.writeValueAsString(result));
verify(userFollowerService).followUser(USER_ID, USER_ID);
}
Aggregations