Search in sources :

Example 86 with ResultActions

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

the class WidgetControllerIntegrationTest method executeWidgetUsage.

private ResultActions executeWidgetUsage(String widgetTypeCode, String accessToken, ResultMatcher expected) throws Exception {
    ResultActions result = mockMvc.perform(get("/widgets/{code}/usage", new Object[] { widgetTypeCode }).header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken));
    result.andExpect(expected);
    return result;
}
Also used : ResultActions(org.springframework.test.web.servlet.ResultActions)

Example 87 with ResultActions

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

the class WidgetControllerIntegrationTest method testAddUpdateWidget_1.

@Test
public void testAddUpdateWidget_1() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    String newCode = "test_new_type_1";
    Assert.assertNull(this.widgetTypeManager.getWidgetType(newCode));
    try {
        WidgetRequest request = new WidgetRequest();
        request.setCode(newCode);
        request.setGroup(Group.FREE_GROUP_NAME);
        Map<String, String> titles = new HashMap<>();
        titles.put("it", "Titolo ITA");
        titles.put("en", "Title EN");
        request.setTitles(titles);
        request.setCustomUi("<h1>Custom UI</h1>");
        request.setGroup(Group.FREE_GROUP_NAME);
        ResultActions result = this.executeWidgetPost(request, accessToken, status().isOk());
        result.andExpect(jsonPath("$.payload.code", is(newCode)));
        WidgetType widgetType = this.widgetTypeManager.getWidgetType(newCode);
        Assert.assertNotNull(widgetType);
        Assert.assertEquals("Title EN", widgetType.getTitles().getProperty("en"));
        request.setGroup("invalid");
        titles.put("en", "Title EN modified");
        result = this.executeWidgetPut(request, newCode, accessToken, status().isBadRequest());
        result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_WIDGET_GROUP_INVALID)));
        request.setGroup("helpdesk");
        request.setCustomUi("");
        result = this.executeWidgetPut(request, newCode, accessToken, status().isBadRequest());
        result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_NOT_BLANK)));
        titles.put("en", "Title EN modified");
        request.setCustomUi("New Custom Ui");
        result = this.executeWidgetPut(request, newCode, accessToken, status().isOk());
        result.andExpect(jsonPath("$.payload.group", is("helpdesk")));
        widgetType = this.widgetTypeManager.getWidgetType(newCode);
        Assert.assertNotNull(widgetType);
        Assert.assertEquals("Title EN modified", widgetType.getTitles().getProperty("en"));
        Assert.assertEquals("helpdesk", widgetType.getMainGroup());
        result = this.executeWidgetDelete(newCode, accessToken, status().isOk());
        result.andExpect(jsonPath("$.payload.code", is(newCode)));
        widgetType = this.widgetTypeManager.getWidgetType(newCode);
        Assert.assertNull(widgetType);
    } catch (Exception e) {
        throw e;
    } finally {
        this.widgetTypeManager.deleteWidgetType(newCode);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) HashMap(java.util.HashMap) ResultActions(org.springframework.test.web.servlet.ResultActions) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) WidgetRequest(org.entando.entando.web.widget.model.WidgetRequest) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 88 with ResultActions

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

the class WidgetControllerIntegrationTest method testGetWidgetsWithoutPermission.

@Test
public void testGetWidgetsWithoutPermission() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("normal_user", "0x24").build();
    String accessToken = mockOAuthInterceptor(user);
    ResultActions result = mockMvc.perform(get("/widgets").header(HttpHeaders.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 89 with ResultActions

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

the class WidgetControllerIntegrationTest method executeWidgetDelete.

private ResultActions executeWidgetDelete(String widgetTypeCode, String accessToken, ResultMatcher expected) throws Exception {
    ResultActions result = mockMvc.perform(delete("/widgets/{code}", new Object[] { widgetTypeCode }).header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken));
    result.andExpect(expected);
    return result;
}
Also used : ResultActions(org.springframework.test.web.servlet.ResultActions)

Example 90 with ResultActions

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

the class WidgetControllerIntegrationTest method addPage.

private void addPage(String accessToken, PageRequest pageRequest) throws Exception {
    ResultActions result = mockMvc.perform(post("/pages").content(mapper.writeValueAsString(pageRequest)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
}
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