use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class RegistrationServiceTest method testActivateUser.
@Test
public void testActivateUser() {
when(tokenStoreService.findAndVerifyToken("TOKEN1234")).thenReturn(ImmutableTokenStoreRestData.builder().from(defaultTokenStoreData).user(new UserEntity().setEnabled(false)).expiryDate(Date.from(defaultTokenStoreData.getExpiryDate().toInstant().minus(Period.ofDays(1)))).build());
registrationService.activateUser("TOKEN1234");
verify(tokenStoreService).findAndVerifyToken("TOKEN1234");
when(tokenStoreService.findAndVerifyToken("TOKEN1235")).thenReturn(ImmutableTokenStoreRestData.builder().from(defaultTokenStoreData).user(new UserEntity().setEnabled(true)).build());
assertThatThrownBy(() -> registrationService.activateUser("TOKEN1235")).hasMessage("Your Account is already activated").isInstanceOf(RegistrationException.class);
verify(tokenStoreService).findAndVerifyToken("TOKEN1235");
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class RoleServiceTest method testAddRoleToUser.
@Test
public void testAddRoleToUser() {
RoleEntity role = new RoleEntity().setId(UUID.randomUUID().toString()).setCode("role").setPrivileges(new HashSet<>());
role.getPrivileges();
UserEntity user = new UserEntity().setId(UUID.randomUUID().toString()).setUsername("user");
UserRoleEntity result = new UserRoleEntity(user, role);
result.setId(UUID.randomUUID().toString());
when(roleRepository.findByCode("role")).thenReturn(Optional.of(role));
when(userRepository.findByUsername("user")).thenReturn(Optional.of(user));
when(userRoleRepository.save(any(UserRoleEntity.class))).thenReturn(result);
assertThat(roleService.addRoleToUser("user", "role")).isEqualTo(user);
verify(roleRepository).findByCode("role");
verify(userRepository).findByUsername("user");
verify(userRoleRepository).save(any(UserRoleEntity.class));
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class UserFollowerServiceTest method testFindUserFollowers.
@Test
public void testFindUserFollowers() {
when(userFollowerRepository.findByUserId(eq("123"), any())).thenReturn(new PageImpl<>(userFollowerEntities));
Page<UserEntity> users = userFollowerService.findUserFollowers("123", new PageRequest(0, 10));
assertThat(users.getTotalElements()).isEqualTo(10);
assertThat(users.getContent()).first().hasFieldOrPropertyWithValue("id", "80123");
verify(userFollowerRepository).findByUserId(eq("123"), any());
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class UserFollowerServiceTest method testFindUserFollowings.
@Test
public void testFindUserFollowings() {
when(userFollowerRepository.findByFollowerId(eq("123"), any())).thenReturn(new PageImpl<>(userFollowerEntities));
Page<UserEntity> users = userFollowerService.findUserFollowings("123", new PageRequest(0, 10));
assertThat(users.getTotalElements()).isEqualTo(10);
assertThat(users.getContent()).first().hasFieldOrPropertyWithValue("id", "0123");
verify(userFollowerRepository).findByFollowerId(eq("123"), any());
}
use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.
the class UserFollowerServiceTest method init.
@Before
public void init() throws Exception {
MockitoAnnotations.initMocks(this);
userFollowerService = new UserFollowerServiceImpl(userFollowerRepository);
userFollowerEntities = new ArrayList<>();
for (int i = 0; i < 10; i++) {
userFollowerEntities.add(new UserFollowerEntity().setUser(new UserEntity().setId(i + "123")).setFollower(new UserEntity().setId((i + 80) + "123")));
}
}
Aggregations