Search in sources :

Example 11 with UserEntity

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

the class ProfileServiceTest method testUpdateProfile.

@Test
public void testUpdateProfile() {
    when(userRepository.findByUsername(anyString())).thenReturn(new UserEntity());
    profileService.updateProfile("username", new UserEntity());
    verify(userRepository).findByUsername("username");
}
Also used : UserEntity(org.codenergic.theskeleton.user.UserEntity) Test(org.junit.Test)

Example 12 with UserEntity

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

the class ProfileServiceTest method testUpdateProfilePicture.

@Test
public void testUpdateProfilePicture() throws Exception {
    final InputStream inputStream = ClassLoader.getSystemResourceAsStream("static/logo.png");
    when(userRepository.findByUsername("user")).thenReturn(new UserEntity());
    profileService.updateProfilePicture("user", inputStream, "image/png");
    verify(userRepository).findByUsername("user");
    verify(minioClient).putObject(anyString(), anyString(), any(InputStream.class), eq("image/png"));
    verify(minioClient).getObjectUrl(anyString(), anyString());
    inputStream.close();
}
Also used : InputStream(java.io.InputStream) UserEntity(org.codenergic.theskeleton.user.UserEntity) Test(org.junit.Test)

Example 13 with UserEntity

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

the class ProfileServiceTest method testUpdateProfilePassword.

@Test
public void testUpdateProfilePassword() {
    final String rawPassword = "p@$$w0rd!";
    when(userRepository.findByUsername("user")).thenReturn(new UserEntity());
    final UserEntity result = profileService.updateProfilePassword("user", rawPassword);
    assertThat(passwordEncoder.matches(rawPassword, result.getPassword())).isTrue();
    verify(userRepository).findByUsername("user");
}
Also used : UserEntity(org.codenergic.theskeleton.user.UserEntity) Test(org.junit.Test)

Example 14 with UserEntity

use of org.codenergic.theskeleton.user.UserEntity 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)

Example 15 with UserEntity

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

the class UserPostRestControllerTest method init.

@Before
public void init() {
    mockMvc = MockMvcBuilders.standaloneSetup(new UserPostRestController(postService)).setCustomArgumentResolvers(new UserArgumentResolver(username -> new UserEntity().setUsername(username)), new AuthenticationPrincipalArgumentResolver(), new PageableHandlerMethodArgumentResolver()).apply(documentationConfiguration(restDocumentation)).build();
    Authentication authentication = new TestingAuthenticationToken(new UserEntity().setId(USER_ID).setUsername(USERNAME), "1234");
    SecurityContextHolder.getContext().setAuthentication(authentication);
}
Also used : PageableHandlerMethodArgumentResolver(org.springframework.data.web.PageableHandlerMethodArgumentResolver) Authentication(org.springframework.security.core.Authentication) UserArgumentResolver(org.codenergic.theskeleton.core.web.UserArgumentResolver) AuthenticationPrincipalArgumentResolver(org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) 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