use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class RoleServiceTest method testFindRolesByUserUsername.
@Test
public void testFindRolesByUserUsername() {
Set<UserRoleEntity> dbResult = new HashSet<>(Collections.singletonList(new UserRoleEntity().setRole(new RoleEntity().setCode("role")).setUser(new UserEntity())));
when(userRoleRepository.findByUserUsername("user")).thenReturn(dbResult);
Set<RoleEntity> result = roleService.findRolesByUserUsername("user");
assertThat(result.size()).isEqualTo(1);
assertThat(result.iterator().next()).isEqualTo(dbResult.iterator().next().getRole());
verify(userRoleRepository).findByUserUsername("user");
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class TokenStoreServiceTest method testSendEmailActivation.
@Test
public void testSendEmailActivation() {
UserEntity user = new UserEntity().setId(UUID.randomUUID().toString()).setUsername("user").setPassword(passwordEncoder.encode("user")).setEmail("user@codenergic.org");
user.setLastModifiedDate(new Date());
TokenStoreRestData activationTokenData = tokenStoreService.sendTokenNotification(TokenStoreType.USER_ACTIVATION, user);
TokenStoreRestData changePasswordTokenData = tokenStoreService.sendTokenNotification(TokenStoreType.CHANGE_PASSWORD, user);
assertThat(activationTokenData.getSignedToken()).isNotBlank();
assertThat(changePasswordTokenData.getSignedToken()).isNotBlank();
assertThat(!activationTokenData.isExpired() && !changePasswordTokenData.isExpired()).isTrue();
assertThat(greenMail.waitForIncomingEmail(1000, 2)).isTrue();
MimeMessage messageActivation = greenMail.getReceivedMessages()[0];
assertThat(GreenMailUtil.getBody(messageActivation)).contains("activate?at=");
MimeMessage messageChangePassword = greenMail.getReceivedMessages()[1];
assertThat(GreenMailUtil.getBody(messageChangePassword)).contains("update?rt=");
when(userRepository.findById(user.getId())).thenReturn(Optional.of(user));
TokenStoreRestData verifiedData = tokenStoreService.findAndVerifyToken(changePasswordTokenData.getSignedToken());
assertThat(verifiedData.getUuid()).isEqualTo(changePasswordTokenData.getUuid());
verify(userRepository).findById(user.getId());
user.setEmail("@codenergic.org");
assertThatThrownBy(() -> tokenStoreService.sendTokenNotification(TokenStoreType.USER_ACTIVATION, user)).isInstanceOf(RegistrationException.class);
assertThatThrownBy(() -> tokenStoreService.sendTokenNotification(TokenStoreType.CHANGE_PASSWORD, user)).isInstanceOf(RegistrationException.class);
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class PostReactionServiceTest method testFindUserByPostReaction.
@Test
public void testFindUserByPostReaction() throws Exception {
List<PostReactionEntity> reactions = Collections.singletonList(new PostReactionEntity().setUser(new UserEntity().setId(USER_ID)));
when(postReactionRepository.findByPostIdAndReactionType(eq(POST_ID), eq(DISLIKE), any())).thenReturn(new PageImpl<>(reactions));
Page<UserEntity> users = postReactionService.findUserByPostReaction(POST_ID, DISLIKE, null);
assertThat(users).hasSize(1);
assertThat(users).first().hasFieldOrPropertyWithValue("id", USER_ID);
verify(postReactionRepository).findByPostIdAndReactionType(eq(POST_ID), eq(DISLIKE), any());
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class RegistrationRestControllerTest method testRegister.
@Test
public void testRegister() throws Exception {
final RegistrationForm form = new RegistrationForm().setUsername("test123").setPassword("12345678").setEmail("test@email.com");
final UserEntity user = new UserEntity().setId("123");
when(registrationService.registerUser(any())).thenReturn(user);
MockHttpServletRequestBuilder request = post("/api/register").content("{\"username\": \"test123\", \"password\": \"12345678\", " + "\"email\": \"test@email.com\"}").contentType(MediaType.APPLICATION_JSON);
MockHttpServletResponse response = mockMvc.perform(request).andExpect(status().isOk()).andDo(document("registration")).andReturn().getResponse();
assertThat(response.getContentAsString()).isEqualTo(objectMapper.writeValueAsString(form));
verify(registrationService).registerUser(any());
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class UserRoleRestControllerTest method testRemoveRoleFromUser.
@Test
public void testRemoveRoleFromUser() throws Exception {
final UserEntity user = new UserEntity().setId("user123");
when(roleService.removeRoleFromUser("user123", "role123")).thenReturn(user);
ResultActions resultActions = mockMvc.perform(delete("/api/users/user123/roles").content("{\"role\": \"role123\"}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(document("user-role-delete"));
MockHttpServletResponse response = resultActions.andReturn().getResponse();
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(userMapper.toUserData(user)));
verify(roleService).removeRoleFromUser("user123", "role123");
}
Aggregations