Search in sources :

Example 16 with UserEntity

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");
}
Also used : UserEntity(org.codenergic.theskeleton.user.UserEntity) Test(org.junit.Test)

Example 17 with UserEntity

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));
}
Also used : UserEntity(org.codenergic.theskeleton.user.UserEntity) Test(org.junit.Test)

Example 18 with UserEntity

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());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) UserEntity(org.codenergic.theskeleton.user.UserEntity) Test(org.junit.Test)

Example 19 with UserEntity

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());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) UserEntity(org.codenergic.theskeleton.user.UserEntity) Test(org.junit.Test)

Example 20 with UserEntity

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")));
    }
}
Also used : UserEntity(org.codenergic.theskeleton.user.UserEntity) Before(org.junit.Before)

Aggregations

UserEntity (org.codenergic.theskeleton.user.UserEntity)48 Test (org.junit.Test)30 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)14 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)10 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)8 Transactional (org.springframework.transaction.annotation.Transactional)7 WithMockUser (org.springframework.security.test.context.support.WithMockUser)6 Before (org.junit.Before)5 Authentication (org.springframework.security.core.Authentication)5 PageableHandlerMethodArgumentResolver (org.springframework.data.web.PageableHandlerMethodArgumentResolver)4 AuthenticationPrincipalArgumentResolver (org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver)4 InputStream (java.io.InputStream)3 Date (java.util.Date)3 UserArgumentResolver (org.codenergic.theskeleton.core.web.UserArgumentResolver)3 PageImpl (org.springframework.data.domain.PageImpl)3 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)3 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)2 OAuth2ClientEntity (org.codenergic.theskeleton.client.OAuth2ClientEntity)2 EmailServiceTest (org.codenergic.theskeleton.core.mail.EmailServiceTest)2 RegistrationException (org.codenergic.theskeleton.registration.RegistrationException)2