Search in sources :

Example 71 with ResultActions

use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.

the class UserControllerIntegrationTest method testUpdateUser.

@Test
public void testUpdateUser() throws Exception {
    String validUsername = "test_test";
    String validPassword = "password";
    try {
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        String mockJson = "{\"username\": \"" + validUsername + "\",\"status\": \"active\",\"password\": \"" + validPassword + "\"}";
        this.executeUserPost(mockJson, accessToken, status().isOk());
        String invalidBody1 = "{\"username\": \"" + validUsername + "\",\"status\": \"active\",\"password\": \"$invalid%%\"}";
        ResultActions resultInvalid1 = this.executeUserPut(invalidBody1, validUsername, accessToken, status().isBadRequest());
        System.out.println(resultInvalid1.andReturn().getResponse().getContentAsString());
        resultInvalid1.andExpect(jsonPath("$.payload", Matchers.hasSize(0)));
        resultInvalid1.andExpect(jsonPath("$.errors", Matchers.hasSize(1)));
        resultInvalid1.andExpect(jsonPath("$.errors[0].code", is("3")));
        resultInvalid1.andExpect(jsonPath("$.metaData.size()", is(0)));
        String invalidBody2 = "{\"username\": \"" + validUsername + "\",\"status\": \"active\",\"password\": \"upasswordvelylong_.veryverylong\"}";
        ResultActions resultInvalid2 = this.executeUserPut(invalidBody2, validUsername, accessToken, status().isBadRequest());
        resultInvalid2.andExpect(jsonPath("$.errors[0].code", is("3")));
        String invalidBody3 = "{\"username\": \"" + validUsername + "\",\"status\": \"active\",\"password\": \"" + validPassword + "\"}";
        ResultActions resultInvalid3 = this.executeUserPut(invalidBody3, "invalidUsername", accessToken, status().isConflict());
        resultInvalid3.andExpect(jsonPath("$.errors[0].code", is("2")));
        String valid1 = "{\"username\": \"" + validUsername + "\",\"status\": \"active\",\"reset\": true}";
        ResultActions resultValid1 = this.executeUserPut(valid1, validUsername, accessToken, status().isOk());
        String responseValid1 = resultValid1.andReturn().getResponse().getContentAsString();
        System.out.println("resp:" + responseValid1);
        resultValid1.andExpect(jsonPath("$.payload.username", is(validUsername)));
        UserDetails authUser = this.authenticationProviderManager.getUser(validUsername, validPassword);
        Assert.assertNotNull(authUser);
        String valid2 = "{\"username\": \"" + validUsername + "\",\"status\": \"active\",\"password\": \"12345678\",\"reset\": true}";
        ResultActions resultValid2 = this.executeUserPut(valid2, validUsername, accessToken, status().isOk());
        String responseValid2 = resultValid2.andReturn().getResponse().getContentAsString();
        System.out.println("resp:" + responseValid2);
        resultValid2.andExpect(jsonPath("$.payload.username", is(validUsername)));
        authUser = this.authenticationProviderManager.getUser(validUsername, validPassword);
        Assert.assertNull(authUser);
        authUser = this.authenticationProviderManager.getUser(validUsername, "12345678");
        Assert.assertNotNull(authUser);
    } catch (Throwable e) {
        throw e;
    } finally {
        this.userManager.removeUser(validUsername);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 72 with ResultActions

use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.

the class UserProfileControllerTest method testAddProfile.

@Test
public void testAddProfile() throws Exception {
    when(this.userProfileService.addUserProfile(any(EntityDto.class), any(BindingResult.class))).thenReturn(Mockito.mock(EntityDto.class));
    String mockJson = "{\n" + "    \"id\": \"user\",\n" + "    \"typeCode\": \"" + SystemConstants.DEFAULT_PROFILE_TYPE_CODE + "\",\n" + "    \"attributes\": [\n" + "         {\"code\": \"fullname\", \"value\": \"User\"},\n" + "         {\"code\": \"email\", \"value\": \"test@example.com\"}\n" + "    ]}";
    ResultActions result = performPostUserProfiles(mockJson);
    result.andExpect(status().isOk());
}
Also used : EntityDto(org.entando.entando.aps.system.services.entity.model.EntityDto) BindingResult(org.springframework.validation.BindingResult) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 73 with ResultActions

use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.

the class UserProfileControllerTest method shouldGetNewlyCreatedProfile.

@Test
public void shouldGetNewlyCreatedProfile() throws Exception {
    when(this.userManager.getUser("user_without_profile")).thenReturn(Mockito.mock(UserDetails.class));
    when(this.userProfileManager.getDefaultProfileType()).thenReturn(Mockito.mock(IUserProfile.class));
    ResultActions result = performGetUserProfiles("user_without_profile");
    result.andExpect(status().isOk());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 74 with ResultActions

use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.

the class UserProfileControllerTest method testUnexistingProfile.

@Test
public void testUnexistingProfile() throws Exception {
    ResultActions result = performGetUserProfiles("user_without_profile");
    result.andExpect(status().isNotFound());
}
Also used : ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 75 with ResultActions

use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.

the class ProfileTypeControllerIntegrationTest method executeProfileAttributeDelete.

private ResultActions executeProfileAttributeDelete(String typeCode, String attributeCode, String accessToken, ResultMatcher expected) throws Exception {
    ResultActions result = mockMvc.perform(delete("/profileTypes/{profileTypeCode}/attribute/{attributeCode}", new Object[] { typeCode, attributeCode }).header("Authorization", "Bearer " + accessToken));
    result.andExpect(expected);
    return result;
}
Also used : ResultActions(org.springframework.test.web.servlet.ResultActions)

Aggregations

ResultActions (org.springframework.test.web.servlet.ResultActions)624 Test (org.junit.Test)547 UserDetails (com.agiletec.aps.system.services.user.UserDetails)297 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)221 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)101 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)65 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)61 MvcResult (org.springframework.test.web.servlet.MvcResult)43 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)39 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)32 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)26 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)23 UUID (java.util.UUID)22 InputStream (java.io.InputStream)21 Map (java.util.Map)19 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)17 HashMap (java.util.HashMap)17 Test (org.junit.jupiter.api.Test)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 WebIntegrationBaseTest (org.nextprot.api.web.dbunit.base.mvc.WebIntegrationBaseTest)14