Search in sources :

Example 96 with ResultActions

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

the class WidgetControllerIntegrationTest method testGetWidgetList_1.

@Test
public void testGetWidgetList_1() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").withAuthorization(Group.FREE_GROUP_NAME, "managePages", Permission.MANAGE_PAGES).build();
    String accessToken = mockOAuthInterceptor(user);
    // @formatter:off
    ResultActions result = mockMvc.perform(get("/widgets").param("pageSize", "100").header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken));
    result.andExpect(status().isOk());
    result.andExpect(jsonPath("$.payload", Matchers.hasSize(6)));
    result.andExpect(jsonPath("$.metaData.pageSize", is(100)));
    result.andExpect(jsonPath("$.metaData.totalItems", is(6)));
    String response = result.andReturn().getResponse().getContentAsString();
    assertNotNull(response);
}
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 97 with ResultActions

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

the class WidgetControllerIntegrationTest method testAddUpdateWidget_2.

@Test
public void testAddUpdateWidget_2() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    String newCode = "test_new_type_2";
    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 2");
        titles.put("en", "Title EN 2");
        request.setTitles(titles);
        request.setCustomUi("");
        request.setGroup(Group.FREE_GROUP_NAME);
        ResultActions result = this.executeWidgetPost(request, accessToken, status().isBadRequest());
        result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_NOT_BLANK)));
        titles.put("en", "");
        request.setCustomUi("Custom UI");
        result = this.executeWidgetPost(request, accessToken, status().isBadRequest());
        result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_MISSING_TITLE)));
        titles.put("en", "Title EN 2 bis");
        result = this.executeWidgetPut(request, newCode, accessToken, status().isNotFound());
        result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_WIDGET_NOT_FOUND)));
        result = this.executeWidgetPost(request, accessToken, status().isOk());
        result.andExpect(jsonPath("$.payload.group", is(Group.FREE_GROUP_NAME)));
        WidgetType widgetType = this.widgetTypeManager.getWidgetType(newCode);
        Assert.assertNotNull(widgetType);
        Assert.assertEquals("Title EN 2 bis", widgetType.getTitles().getProperty("en"));
        titles.put("it", "");
        result = this.executeWidgetPut(request, newCode, accessToken, status().isBadRequest());
        result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_MISSING_TITLE)));
    } catch (Exception e) {
        throw e;
    } finally {
        this.widgetTypeManager.deleteWidgetType(newCode);
        Assert.assertNull(this.widgetTypeManager.getWidgetType(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 98 with ResultActions

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

the class ActivityStreamControllerIntegrationTest method initTestObjects.

private void initTestObjects(String accessToken, String... pageCodes) throws Exception {
    for (String pageCode : pageCodes) {
        PageModel pageModel = this.pageModelManager.getPageModel("internal");
        Page mockPage = createPage(pageCode, pageModel);
        mockPage.setWidgets(new Widget[pageModel.getFrames().length]);
        this.pageManager.addPage(mockPage);
        IPage onlinePage = this.pageManager.getOnlinePage(pageCode);
        assertThat(onlinePage, is(nullValue()));
        IPage draftPage = this.pageManager.getDraftPage(pageCode);
        assertThat(draftPage, is(not(nullValue())));
        // execute and action
        ResultActions result = mockMvc.perform(put("/pages/{pageCode}/configuration/defaultWidgets", new Object[] { pageCode }).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        synchronized (this) {
            this.wait(1000);
        }
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) ResultActions(org.springframework.test.web.servlet.ResultActions)

Example 99 with ResultActions

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

the class ActivityStreamControllerIntegrationTest method testGetActivityStream.

@Test
public void testGetActivityStream() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    ResultActions result = mockMvc.perform(get("/activityStream").param("sort", "createdAt").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)

Example 100 with ResultActions

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

the class ActivityStreamControllerIntegrationTest method testGetActivityStreamDate.

@Test
public void testGetActivityStreamDate() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    String start = new Timestamp(DateConverter.parseDate("2017/01/01", "yyyy/MM/dd").getTime()).toString();
    String end = new Timestamp(DateConverter.parseDate("2017/01/01", "yyyy/MM/dd").getTime()).toString();
    ResultActions result = mockMvc.perform(get("/activityStream").param("sort", "createdAt").param("filters[0].attribute", "createdAt").param("filters[0].value", String.format("[%s TO %s]", start, end)).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) Timestamp(java.sql.Timestamp) 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