Search in sources :

Example 16 with ResultActions

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

the class PageModelControllerTest method should_validate_add_page_model_frame_no_descr.

@Test
public void should_validate_add_page_model_frame_no_descr() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    PageModelRequest pageModel = new PageModelRequest();
    pageModel.setCode("test");
    pageModel.setDescr("test_descr");
    PageModelFrameReq frame0 = new PageModelFrameReq(0, "descr_0");
    PageModelFrameReq frame1 = new PageModelFrameReq(1, null);
    pageModel.getConfiguration().add(frame0);
    pageModel.getConfiguration().add(frame1);
    ObjectMapper mapper = new ObjectMapper();
    String payload = mapper.writeValueAsString(pageModel);
    ResultActions result = mockMvc.perform(post("/pagemodels").content(payload).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isBadRequest());
}
Also used : PageModelRequest(org.entando.entando.web.pagemodel.model.PageModelRequest) UserDetails(com.agiletec.aps.system.services.user.UserDetails) PageModelFrameReq(org.entando.entando.web.pagemodel.model.PageModelFrameReq) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 17 with ResultActions

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

the class PageModelControllerTest method should_validate_add_page_model_invalid_frames_progressive.

@Test
public void should_validate_add_page_model_invalid_frames_progressive() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    PageModelRequest pageModel = new PageModelRequest();
    pageModel.setCode("test");
    pageModel.setDescr("test_descr");
    PageModelFrameReq frame0 = new PageModelFrameReq(0, "descr_0");
    PageModelFrameReq frame1 = new PageModelFrameReq(0, "descr_1");
    PageModelFrameReq frame2 = new PageModelFrameReq(2, "descr_2");
    pageModel.getConfiguration().add(frame0);
    pageModel.getConfiguration().add(frame1);
    pageModel.getConfiguration().add(frame2);
    ObjectMapper mapper = new ObjectMapper();
    String payload = mapper.writeValueAsString(pageModel);
    ResultActions result = mockMvc.perform(post("/pagemodels").content(payload).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isBadRequest());
    result.andExpect(jsonPath("$.errors.length()", is(1)));
}
Also used : PageModelRequest(org.entando.entando.web.pagemodel.model.PageModelRequest) UserDetails(com.agiletec.aps.system.services.user.UserDetails) PageModelFrameReq(org.entando.entando.web.pagemodel.model.PageModelFrameReq) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 18 with ResultActions

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

the class PageModelControllerTest method should_validate_add_page_model_invalid_frames_first.

@Test
public void should_validate_add_page_model_invalid_frames_first() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    PageModelRequest pageModel = new PageModelRequest();
    pageModel.setCode("test");
    pageModel.setDescr("test_descr");
    PageModelFrameReq frame0 = new PageModelFrameReq();
    frame0.setPos(1);
    pageModel.getConfiguration().add(frame0);
    ObjectMapper mapper = new ObjectMapper();
    String payload = mapper.writeValueAsString(pageModel);
    ResultActions result = mockMvc.perform(post("/pagemodels").content(payload).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isBadRequest());
    result.andExpect(jsonPath("$.errors.length()", is(1)));
}
Also used : PageModelRequest(org.entando.entando.web.pagemodel.model.PageModelRequest) UserDetails(com.agiletec.aps.system.services.user.UserDetails) PageModelFrameReq(org.entando.entando.web.pagemodel.model.PageModelFrameReq) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 19 with ResultActions

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

the class PageModelControllerTest method should_validate_add_page_model_invalid_frames_last.

@Test
public void should_validate_add_page_model_invalid_frames_last() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    PageModelRequest pageModel = new PageModelRequest();
    pageModel.setCode("test");
    pageModel.setDescr("test_descr");
    PageModelFrameReq frame0 = new PageModelFrameReq(0, "descr_0");
    PageModelFrameReq frame1 = new PageModelFrameReq(2, "descr_1");
    pageModel.getConfiguration().add(frame0);
    pageModel.getConfiguration().add(frame1);
    ObjectMapper mapper = new ObjectMapper();
    String payload = mapper.writeValueAsString(pageModel);
    ResultActions result = mockMvc.perform(post("/pagemodels").content(payload).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isBadRequest());
    result.andExpect(jsonPath("$.errors.length()", is(1)));
}
Also used : PageModelRequest(org.entando.entando.web.pagemodel.model.PageModelRequest) UserDetails(com.agiletec.aps.system.services.user.UserDetails) PageModelFrameReq(org.entando.entando.web.pagemodel.model.PageModelFrameReq) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 20 with ResultActions

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

the class PageModelControllerTest method should_validate_add_page_model_empty.

@Test
public void should_validate_add_page_model_empty() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    PageModelRequest pageModel = new PageModelRequest();
    ObjectMapper mapper = new ObjectMapper();
    String payload = mapper.writeValueAsString(pageModel);
    ResultActions result = mockMvc.perform(post("/pagemodels").content(payload).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isBadRequest());
    result.andExpect(jsonPath("$.errors.length()", is(3)));
}
Also used : PageModelRequest(org.entando.entando.web.pagemodel.model.PageModelRequest) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Aggregations

ResultActions (org.springframework.test.web.servlet.ResultActions)600 Test (org.junit.Test)525 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)43 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)39 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)38 MvcResult (org.springframework.test.web.servlet.MvcResult)27 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)26 UUID (java.util.UUID)22 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)22 InputStream (java.io.InputStream)18 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)17 HashMap (java.util.HashMap)17 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)16 Test (org.junit.jupiter.api.Test)15 WebIntegrationBaseTest (org.nextprot.api.web.dbunit.base.mvc.WebIntegrationBaseTest)14 IPage (com.agiletec.aps.system.services.page.IPage)13 Page (com.agiletec.aps.system.services.page.Page)12