Search in sources :

Example 81 with ResultActions

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

the class ProfileTypeControllerIntegrationTest method executeProfileTypePost.

private ResultActions executeProfileTypePost(String fileName, String accessToken, ResultMatcher expected) throws Exception {
    InputStream isJsonPostValid = this.getClass().getResourceAsStream(fileName);
    String jsonPostValid = FileTextReader.getText(isJsonPostValid);
    ResultActions result = mockMvc.perform(post("/profileTypes").content(jsonPostValid).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)

Example 82 with ResultActions

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

the class ProfileTypeControllerIntegrationTest method testAddUpdateUserProfileType_1.

@Test
public void testAddUpdateUserProfileType_1() throws Exception {
    try {
        Assert.assertNull(this.userProfileManager.getEntityPrototype("AAA"));
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        this.executeProfileTypePost("1_POST_valid.json", accessToken, status().isOk());
        UserProfile addedType = (UserProfile) this.userProfileManager.getEntityPrototype("AAA");
        Assert.assertNotNull(addedType);
        Assert.assertEquals("Profile Type AAA", addedType.getTypeDescription());
        Assert.assertEquals(1, addedType.getAttributeList().size());
        this.executeProfileTypePut("1_PUT_invalid.json", "AAA", accessToken, status().isBadRequest());
        this.executeProfileTypePut("1_PUT_valid.json", "AAA", accessToken, status().isOk());
        addedType = (UserProfile) this.userProfileManager.getEntityPrototype("AAA");
        Assert.assertEquals("Profile Type AAA Modified", addedType.getTypeDescription());
        Assert.assertEquals(2, addedType.getAttributeList().size());
        ResultActions result4 = mockMvc.perform(delete("/profileTypes/{profileTypeCode}", new Object[] { "AAA" }).header("Authorization", "Bearer " + accessToken));
        result4.andExpect(status().isOk());
        Assert.assertNull(this.userProfileManager.getEntityPrototype("AAA"));
    } finally {
        if (null != this.userProfileManager.getEntityPrototype("AAA")) {
            ((IEntityTypesConfigurer) this.userProfileManager).removeEntityPrototype("AAA");
        }
    }
}
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 83 with ResultActions

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

the class ProfileTypeControllerIntegrationTest method testGetUserProfileAttribute.

// ------------------------------------
@Test
public void testGetUserProfileAttribute() 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());
        ResultActions result1 = mockMvc.perform(get("/profileTypes/{profileTypeCode}/attribute/{attributeCode}", new Object[] { "XXX", "TextAttribute" }).header("Authorization", "Bearer " + accessToken));
        result1.andExpect(status().isNotFound());
        result1.andExpect(jsonPath("$.payload", Matchers.hasSize(0)));
        result1.andExpect(jsonPath("$.errors", Matchers.hasSize(1)));
        result1.andExpect(jsonPath("$.metaData.size()", is(0)));
        ResultActions result2 = mockMvc.perform(get("/profileTypes/{profileTypeCode}/attribute/{attributeCode}", new Object[] { "TST", "WrongCpde" }).header("Authorization", "Bearer " + accessToken));
        result2.andExpect(status().isNotFound());
        result2.andExpect(jsonPath("$.payload", Matchers.hasSize(0)));
        result2.andExpect(jsonPath("$.errors", Matchers.hasSize(1)));
        result2.andExpect(jsonPath("$.metaData.size()", is(0)));
        ResultActions result3 = mockMvc.perform(get("/profileTypes/{profileTypeCode}/attribute/{attributeCode}", new Object[] { "TST", "TextAttribute" }).header("Authorization", "Bearer " + accessToken));
        result3.andExpect(status().isOk());
        result3.andExpect(jsonPath("$.payload.code", is("TextAttribute")));
        result3.andExpect(jsonPath("$.payload.type", is("Text")));
        result3.andExpect(jsonPath("$.errors", Matchers.hasSize(0)));
        result3.andExpect(jsonPath("$.metaData.size()", is(1)));
        result3.andExpect(jsonPath("$.metaData.profileTypeCode", is("TST")));
    } finally {
        if (null != this.userProfileManager.getEntityPrototype("TST")) {
            ((IEntityTypesConfigurer) this.userProfileManager).removeEntityPrototype("TST");
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) 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 84 with ResultActions

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

the class UserProfileControllerIntegrationTest method testGetInvalidUserProfileType.

@Test
public void testGetInvalidUserProfileType() throws Exception {
    String accessToken = this.createAccessToken();
    ResultActions result = mockMvc.perform(get("/userProfiles/{username}", new Object[] { "xxxxx" }).header("Authorization", "Bearer " + accessToken));
    System.out.println(result.andReturn().getResponse().getContentAsString());
    result.andExpect(status().isNotFound());
}
Also used : ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 85 with ResultActions

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

the class UserProfileControllerIntegrationTest method executeProfileGet.

private ResultActions executeProfileGet(String username, String accessToken, ResultMatcher expected) throws Exception {
    ResultActions result = mockMvc.perform(get("/userProfiles/{username}", new Object[] { username }).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