Search in sources :

Example 61 with ResultActions

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

the class UserControllerUnitTest method shouldAddUserAuthorities.

@Test
public void shouldAddUserAuthorities() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    String mockJson = "[{\"group\":\"group1\", \"role\":\"role1\"},{\"group\":\"group2\", \"role\":\"role2\"}]";
    List<UserAuthorityDto> authorities = (List<UserAuthorityDto>) this.createMetadata(mockJson, List.class);
    when(this.controller.getUserValidator().getGroupManager().getGroup(any(String.class))).thenReturn(mockedGroup());
    when(this.controller.getUserValidator().getRoleManager().getRole(any(String.class))).thenReturn(mockedRole());
    when(this.controller.getUserService().addUserAuthorities(any(String.class), any(UserAuthoritiesRequest.class))).thenReturn(authorities);
    ResultActions result = mockMvc.perform(put("/users/{target}/authorities", "mockuser").sessionAttr("user", user).content(mockJson).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) UserAuthoritiesRequest(org.entando.entando.web.user.model.UserAuthoritiesRequest) UserAuthorityDto(org.entando.entando.aps.system.services.user.model.UserAuthorityDto) List(java.util.List) ArrayList(java.util.ArrayList) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 62 with ResultActions

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

the class ProfileTypeControllerIntegrationTest method testGetUserProfileAttributeTypes_2.

@Test
public void testGetUserProfileAttributeTypes_2() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    ResultActions result = mockMvc.perform(get("/profileTypeAttributes").param("pageSize", "5").param("sort", "code").param("direction", "DESC").header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
    result.andExpect(jsonPath("$.payload", Matchers.hasSize(5)));
    result.andExpect(jsonPath("$.metaData.pageSize", is(5)));
    result.andExpect(jsonPath("$.metaData.lastPage", is(3)));
    result.andExpect(jsonPath("$.metaData.totalItems", is(15)));
    result.andExpect(jsonPath("$.payload[0]", is("Timestamp")));
}
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 63 with ResultActions

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

the class ProfileTypeControllerIntegrationTest method testGetUserProfileAttributeType_1.

@Test
public void testGetUserProfileAttributeType_1() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    ResultActions result = mockMvc.perform(get("/profileTypeAttributes/{attributeTypeCode}", new Object[] { "Monotext" }).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
    result.andExpect(jsonPath("$.payload.code", is("Monotext")));
    result.andExpect(jsonPath("$.payload.simple", is(true)));
    result.andExpect(jsonPath("$.errors", Matchers.hasSize(0)));
    result.andExpect(jsonPath("$.metaData.size()", is(0)));
}
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 64 with ResultActions

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

the class ProfileTypeControllerIntegrationTest method testGetUserProfileTypesWithoutPermission.

@Test
public void testGetUserProfileTypesWithoutPermission() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("normal_user", "0x24").build();
    String accessToken = mockOAuthInterceptor(user);
    ResultActions result = mockMvc.perform(get("/profileTypes").header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isForbidden());
}
Also used : OAuth2TestUtils(org.entando.entando.web.utils.OAuth2TestUtils) 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 65 with ResultActions

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

the class ProfileTypeControllerIntegrationTest method executeProfileAttributePut.

private ResultActions executeProfileAttributePut(String fileName, String typeCode, String attributeCode, String accessToken, ResultMatcher expected) throws Exception {
    InputStream isJsonPutValid = this.getClass().getResourceAsStream(fileName);
    String jsonPutValid = FileTextReader.getText(isJsonPutValid);
    ResultActions result = mockMvc.perform(put("/profileTypes/{profileTypeCode}/attribute/{attributeCode}", new Object[] { typeCode, attributeCode }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
    result.andExpect(expected);
    return result;
}
Also used : InputStream(java.io.InputStream) 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