Search in sources :

Example 76 with ResultActions

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

the class ProfileTypeControllerIntegrationTest method testRefreshUserProfileTypes.

@Test
public void testRefreshUserProfileTypes() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    ResultActions result = mockMvc.perform(post("/profileTypesStatus").content("{\"profileTypeCodes\":[\"AAA\",\"BBB\"]}").contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isNotFound());
    result.andExpect(jsonPath("$.errors", Matchers.hasSize(1)));
    result = mockMvc.perform(post("/profileTypesStatus").content("{\"profileTypeCodes\":[\"PFL\"]}").contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
    result.andExpect(jsonPath("$.payload.size()", is(2)));
    result.andExpect(jsonPath("$.payload.result", is("success")));
    result.andExpect(jsonPath("$.payload.profileTypeCodes.size()", is(1)));
    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 77 with ResultActions

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

the class ProfileTypeControllerIntegrationTest method testGetInvalidUserProfileType.

@Test
public void testGetInvalidUserProfileType() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    ResultActions result = mockMvc.perform(get("/profileTypes/{profileTypeCode}", new Object[] { "XXX" }).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isNotFound());
}
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 78 with ResultActions

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

the class ProfileTypeControllerIntegrationTest method testGetUserProfileAttributeType_2.

@Test
public void testGetUserProfileAttributeType_2() 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[] { "WrongTypeCode" }).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isNotFound());
    result.andExpect(jsonPath("$.payload", Matchers.hasSize(0)));
    result.andExpect(jsonPath("$.errors", Matchers.hasSize(1)));
    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 79 with ResultActions

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

the class ProfileTypeControllerIntegrationTest method testAddGetUserProfileType_1.

@Test
public void testAddGetUserProfileType_1() throws Exception {
    try {
        Assert.assertNull(this.userProfileManager.getEntityPrototype("TST"));
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        this.executeProfileTypePost("2_POST_valid.json", accessToken, status().isOk());
        UserProfile addedType = (UserProfile) this.userProfileManager.getEntityPrototype("TST");
        Assert.assertNotNull(addedType);
        Assert.assertEquals("Profile Type TST", addedType.getTypeDescription());
        Assert.assertEquals(3, addedType.getAttributeList().size());
        ResultActions result = mockMvc.perform(get("/profileTypes/{profileTypeCode}", new Object[] { "TST" }).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        result.andExpect(jsonPath("$.payload.code", is("TST")));
        result.andExpect(jsonPath("$.payload.attributes.size()", is(3)));
        result.andExpect(jsonPath("$.errors", Matchers.hasSize(0)));
    } finally {
        if (null != this.userProfileManager.getEntityPrototype("TST")) {
            ((IEntityTypesConfigurer) this.userProfileManager).removeEntityPrototype("TST");
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) UserProfile(org.entando.entando.aps.system.services.userprofile.model.UserProfile) ResultActions(org.springframework.test.web.servlet.ResultActions) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 80 with ResultActions

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

the class ProfileTypeControllerIntegrationTest method testGetUserProfileTypesWithAdminPermission.

@Test
public void testGetUserProfileTypesWithAdminPermission() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    ResultActions result = mockMvc.perform(get("/profileTypes").header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
}
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)

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