use of org.entando.entando.aps.system.services.pagemodel.PageModelTestUtil.validPageModelRequest in project entando-core by entando.
the class PageModelControllerIntegrationTest method update_page_model_with_errors.
@Test
public void update_page_model_with_errors() throws Exception {
try {
PageModelRequest pageModelRequest = PageModelTestUtil.validPageModelRequest();
pageModelRequest.setCode(PAGE_MODEL_CODE);
ResultActions result = mockMvc.perform(post("/pageModels").content(createJson(pageModelRequest)).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andDo(print()).andExpect(status().isOk());
PageModel pageModel = this.pageModelManager.getPageModel(PAGE_MODEL_CODE);
Assert.assertNotNull(pageModel);
Assert.assertEquals(2, pageModel.getFrames().length);
PageModelFrameReq newFrames = new PageModelFrameReq(2, "Position 1");
newFrames.getDefaultWidget().setCode("invalid_widget");
pageModelRequest.getConfiguration().getFrames().add(newFrames);
result = mockMvc.perform(post("/pageModels").content(createJson(pageModelRequest)).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isConflict());
result.andExpect(jsonPath("$.payload.size()", is(0)));
result.andExpect(jsonPath("$.errors.size()", is(1)));
result.andExpect(jsonPath("$.errors[0].code", is("2")));
result.andExpect(jsonPath("$.metaData.size()", is(0)));
pageModel = this.pageModelManager.getPageModel(PAGE_MODEL_CODE);
Assert.assertNotNull(pageModel);
Assert.assertEquals(2, pageModel.getFrames().length);
result = mockMvc.perform(put("/pageModels/{code}", PAGE_MODEL_CODE).content(createJson(pageModelRequest)).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isBadRequest());
result.andExpect(jsonPath("$.payload.size()", is(0)));
result.andExpect(jsonPath("$.errors.size()", is(1)));
result.andExpect(jsonPath("$.errors[0].code", is("6")));
result.andExpect(jsonPath("$.metaData.size()", is(0)));
pageModel = this.pageModelManager.getPageModel(PAGE_MODEL_CODE);
Assert.assertNotNull(pageModel);
Assert.assertEquals(2, pageModel.getFrames().length);
pageModelRequest.setCode(NONEXISTENT_PAGE_MODEL);
result = mockMvc.perform(put("/pageModels/{code}", NONEXISTENT_PAGE_MODEL).content(createJson(pageModelRequest)).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isNotFound());
result.andExpect(jsonPath("$.payload.size()", is(0)));
result.andExpect(jsonPath("$.errors.size()", is(1)));
result.andExpect(jsonPath("$.errors[0].code", is("1")));
result.andExpect(jsonPath("$.metaData.size()", is(0)));
pageModel = this.pageModelManager.getPageModel(PAGE_MODEL_CODE);
Assert.assertNotNull(pageModel);
Assert.assertEquals(2, pageModel.getFrames().length);
} catch (Exception e) {
throw e;
} finally {
this.pageModelManager.deletePageModel(PAGE_MODEL_CODE);
}
}
use of org.entando.entando.aps.system.services.pagemodel.PageModelTestUtil.validPageModelRequest in project entando-core by entando.
the class PageModelControllerIntegrationTest method add_page_model_with_dot_return_OK.
@Test
public void add_page_model_with_dot_return_OK() throws Exception {
try {
PageModelRequest pageModelRequest = PageModelTestUtil.validPageModelRequest();
pageModelRequest.setCode(PAGE_MODEL_WITH_DOT_CODE);
ResultActions result = mockMvc.perform(post("/pageModels").content(createJson(pageModelRequest)).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.payload.code", is(PAGE_MODEL_WITH_DOT_CODE))).andExpect(jsonPath("$.payload.descr", is("description"))).andExpect(jsonPath("$.payload.configuration.frames[0].defaultWidget.code", is("leftmenu"))).andExpect(jsonPath("$.payload.configuration.frames[0].defaultWidget.properties.navSpec", is("code(homepage).subtree(5)"))).andExpect(jsonPath("$.payload.configuration.frames[1].defaultWidget", CoreMatchers.nullValue()));
PageModel pageModel = this.pageModelManager.getPageModel(PAGE_MODEL_WITH_DOT_CODE);
Assert.assertNotNull(pageModel);
Assert.assertEquals(2, pageModel.getFrames().length);
Assert.assertEquals(2, pageModel.getFramesConfig().length);
Assert.assertNotNull(pageModel.getFramesConfig()[0].getDefaultWidget());
Assert.assertEquals("leftmenu", pageModel.getFramesConfig()[0].getDefaultWidget().getType().getCode());
Assert.assertEquals(1, pageModel.getFramesConfig()[0].getDefaultWidget().getConfig().size());
Assert.assertEquals("code(homepage).subtree(5)", pageModel.getFramesConfig()[0].getDefaultWidget().getConfig().getProperty("navSpec"));
pageModelRequest.setDescr("description2");
result = mockMvc.perform(put("/pageModels/{code}", PAGE_MODEL_WITH_DOT_CODE).content(createJson(pageModelRequest)).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.payload.code", is(PAGE_MODEL_WITH_DOT_CODE))).andExpect(jsonPath("$.payload.descr", is("description2")));
result = mockMvc.perform(get("/pageModels/{code}", PAGE_MODEL_WITH_DOT_CODE).header("Authorization", "Bearer " + accessToken));
result.andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.payload.code", is(PAGE_MODEL_WITH_DOT_CODE))).andExpect(jsonPath("$.payload.descr", is("description2")));
} finally {
ResultActions result = mockMvc.perform(delete("/pageModels/{code}", PAGE_MODEL_WITH_DOT_CODE).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andDo(print()).andExpect(status().isOk());
}
}
use of org.entando.entando.aps.system.services.pagemodel.PageModelTestUtil.validPageModelRequest in project entando-core by entando.
the class PageModelControllerIntegrationTest method add_page_model_with_errors.
@Test
public void add_page_model_with_errors() throws Exception {
try {
PageModelRequest pageModelRequest = PageModelTestUtil.validPageModelRequest();
PageModelFrameReq newFrames = new PageModelFrameReq(2, "Position 1");
newFrames.getDefaultWidget().setCode("invalid_widget");
pageModelRequest.getConfiguration().getFrames().add(newFrames);
pageModelRequest.setCode(PAGE_MODEL_CODE);
ResultActions result = mockMvc.perform(post("/pageModels").content(createJson(pageModelRequest)).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isBadRequest());
result.andExpect(jsonPath("$.payload.size()", is(0)));
result.andExpect(jsonPath("$.errors.size()", is(1)));
result.andExpect(jsonPath("$.errors[0].code", is("6")));
result.andExpect(jsonPath("$.metaData.size()", is(0)));
PageModel pageModel = this.pageModelManager.getPageModel(PAGE_MODEL_CODE);
Assert.assertNull(pageModel);
newFrames.getDefaultWidget().setCode("leftmenu");
newFrames.getDefaultWidget().getProperties().put("wrongParam", "code(homepage).subtree(8)");
result = mockMvc.perform(post("/pageModels").content(createJson(pageModelRequest)).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isBadRequest());
result.andExpect(jsonPath("$.payload.size()", is(0)));
result.andExpect(jsonPath("$.errors.size()", is(1)));
result.andExpect(jsonPath("$.errors[0].code", is("7")));
result.andExpect(jsonPath("$.metaData.size()", is(0)));
pageModel = this.pageModelManager.getPageModel(PAGE_MODEL_CODE);
Assert.assertNull(pageModel);
newFrames.getDefaultWidget().getProperties().remove("wrongParam");
PageModelFrameReq newWrongFrames = new PageModelFrameReq(7, "Position 7");
pageModelRequest.getConfiguration().getFrames().add(newWrongFrames);
result = mockMvc.perform(post("/pageModels").content(createJson(pageModelRequest)).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isBadRequest());
result.andExpect(jsonPath("$.payload.size()", is(0)));
result.andExpect(jsonPath("$.errors.size()", is(1)));
result.andExpect(jsonPath("$.errors[0].code", is("5")));
result.andExpect(jsonPath("$.metaData.size()", is(0)));
pageModel = this.pageModelManager.getPageModel(PAGE_MODEL_CODE);
Assert.assertNull(pageModel);
} catch (Exception e) {
throw e;
} finally {
this.pageModelManager.deletePageModel(PAGE_MODEL_CODE);
}
}
Aggregations