diff --git a/plugins/entando-plugin-jacms/pom.xml b/plugins/entando-plugin-jacms/pom.xml index 52d79d4ae7..3c27029938 100644 --- a/plugins/entando-plugin-jacms/pom.xml +++ b/plugins/entando-plugin-jacms/pom.xml @@ -196,11 +196,5 @@ 1.18.2 - - org.springframework.security - spring-security-test - ${spring.version} - test - diff --git a/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/content/ContentControllerIntegrationTest.java b/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/content/ContentControllerIntegrationTest.java index b781cce03c..4b275befbe 100644 --- a/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/content/ContentControllerIntegrationTest.java +++ b/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/content/ContentControllerIntegrationTest.java @@ -26,7 +26,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import com.agiletec.aps.system.common.FieldSearchFilter; import com.agiletec.aps.system.common.entity.IEntityManager; @@ -98,7 +97,7 @@ public class ContentControllerIntegrationTest extends AbstractControllerIntegrat private ObjectMapper mapper = new ObjectMapper(); public static final String PLACEHOLDER_STRING = "resourceIdPlaceHolder"; - + @Test public void testGetContentWithModel() throws Exception { UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24") @@ -110,7 +109,7 @@ public void testGetContentWithModel() throws Exception { result.andExpect(status().isOk()); String html1 = JsonPath.read(result1, "$.payload.html"); Assert.assertTrue(!StringUtils.isBlank(html1)); - + result.andExpect(MockMvcResultMatchers.jsonPath("$.payload.html", Matchers.anything())); result = this.performGetContent("ART180", "11", true, null, true, user); String result2 = result.andReturn().getResponse().getContentAsString(); @@ -127,7 +126,7 @@ public void testGetContentWithModel() throws Exception { String htmlCopy = JsonPath.read(result1_copy, "$.payload.html"); Assert.assertTrue(!StringUtils.isBlank(htmlCopy)); Assert.assertEquals(html1, htmlCopy); - + result = this.performGetContent("ART180", "list", true, null, true, user); result.andExpect(MockMvcResultMatchers.jsonPath("$.payload.html", Matchers.anything())); String result2_copy = result.andReturn().getResponse().getContentAsString(); @@ -272,42 +271,42 @@ public void testAddContentWithLinkAttribute() throws Exception { Assert.assertNotNull(this.contentManager.getEntityPrototype("LNK")); ResultActions result = this.executeContentPost("1_POST_valid_with_links.json", accessToken, status().isOk()) - .andDo(print()) - .andExpect(jsonPath("$.payload.size()", is(1))) - .andExpect(jsonPath("$.errors.size()", is(0))) - .andExpect(jsonPath("$.metaData.size()", is(0))) - - .andExpect(jsonPath("$.payload[0].id", Matchers.anything())) - .andExpect(jsonPath("$.payload[0].attributes[0].code", is("link1"))) - .andExpect(jsonPath("$.payload[0].attributes[0].value.destType", is(SymbolicLink.URL_TYPE))) - .andExpect(jsonPath("$.payload[0].attributes[0].value.urlDest", is("https://myurl.com"))) - .andExpect(jsonPath("$.payload[0].attributes[0].value.symbolicDestination", is("#!U;https://myurl.com!#"))) - .andExpect(jsonPath("$.payload[0].attributes[0].values.it", is("My URL Link"))) - - .andExpect(jsonPath("$.payload[0].attributes[1].code", is("link2"))) - .andExpect(jsonPath("$.payload[0].attributes[1].value.destType", is(SymbolicLink.PAGE_TYPE))) - .andExpect(jsonPath("$.payload[0].attributes[1].value.pageDest", is("pagina_11"))) - .andExpect(jsonPath("$.payload[0].attributes[1].value.symbolicDestination", is("#!P;pagina_11!#"))) - .andExpect(jsonPath("$.payload[0].attributes[1].values.it", is("My Page Link"))) - - .andExpect(jsonPath("$.payload[0].attributes[2].code", is("link3"))) - .andExpect(jsonPath("$.payload[0].attributes[2].value.destType", is(SymbolicLink.CONTENT_TYPE))) - .andExpect(jsonPath("$.payload[0].attributes[2].value.contentDest", is("ART1"))) - .andExpect(jsonPath("$.payload[0].attributes[2].value.symbolicDestination", is("#!C;ART1!#"))) - .andExpect(jsonPath("$.payload[0].attributes[2].values.it", is("My Content Link"))) - - .andExpect(jsonPath("$.payload[0].attributes[3].code", is("link4"))) - .andExpect(jsonPath("$.payload[0].attributes[3].value.destType", is(SymbolicLink.CONTENT_ON_PAGE_TYPE))) - .andExpect(jsonPath("$.payload[0].attributes[3].value.pageDest", is("pagina_11"))) - .andExpect(jsonPath("$.payload[0].attributes[3].value.contentDest", is("ART1"))) - .andExpect(jsonPath("$.payload[0].attributes[3].value.symbolicDestination", is("#!O;ART1;pagina_11!#"))) - .andExpect(jsonPath("$.payload[0].attributes[3].values.it", is("My Page with Content Link"))) - - .andExpect(jsonPath("$.payload[0].attributes[4].code", is("link5"))) - .andExpect(jsonPath("$.payload[0].attributes[4].value.destType", is(SymbolicLink.RESOURCE_TYPE))) - .andExpect(jsonPath("$.payload[0].attributes[4].value.resourceDest", is("44"))) - .andExpect(jsonPath("$.payload[0].attributes[4].value.symbolicDestination", is("#!R;44!#"))) - .andExpect(jsonPath("$.payload[0].attributes[4].values.it", is("My Resource Link"))); + .andDo(print()) + .andExpect(jsonPath("$.payload.size()", is(1))) + .andExpect(jsonPath("$.errors.size()", is(0))) + .andExpect(jsonPath("$.metaData.size()", is(0))) + + .andExpect(jsonPath("$.payload[0].id", Matchers.anything())) + .andExpect(jsonPath("$.payload[0].attributes[0].code", is("link1"))) + .andExpect(jsonPath("$.payload[0].attributes[0].value.destType", is(SymbolicLink.URL_TYPE))) + .andExpect(jsonPath("$.payload[0].attributes[0].value.urlDest", is("https://myurl.com"))) + .andExpect(jsonPath("$.payload[0].attributes[0].value.symbolicDestination", is("#!U;https://myurl.com!#"))) + .andExpect(jsonPath("$.payload[0].attributes[0].values.it", is("My URL Link"))) + + .andExpect(jsonPath("$.payload[0].attributes[1].code", is("link2"))) + .andExpect(jsonPath("$.payload[0].attributes[1].value.destType", is(SymbolicLink.PAGE_TYPE))) + .andExpect(jsonPath("$.payload[0].attributes[1].value.pageDest", is("pagina_11"))) + .andExpect(jsonPath("$.payload[0].attributes[1].value.symbolicDestination", is("#!P;pagina_11!#"))) + .andExpect(jsonPath("$.payload[0].attributes[1].values.it", is("My Page Link"))) + + .andExpect(jsonPath("$.payload[0].attributes[2].code", is("link3"))) + .andExpect(jsonPath("$.payload[0].attributes[2].value.destType", is(SymbolicLink.CONTENT_TYPE))) + .andExpect(jsonPath("$.payload[0].attributes[2].value.contentDest", is("ART1"))) + .andExpect(jsonPath("$.payload[0].attributes[2].value.symbolicDestination", is("#!C;ART1!#"))) + .andExpect(jsonPath("$.payload[0].attributes[2].values.it", is("My Content Link"))) + + .andExpect(jsonPath("$.payload[0].attributes[3].code", is("link4"))) + .andExpect(jsonPath("$.payload[0].attributes[3].value.destType", is(SymbolicLink.CONTENT_ON_PAGE_TYPE))) + .andExpect(jsonPath("$.payload[0].attributes[3].value.pageDest", is("pagina_11"))) + .andExpect(jsonPath("$.payload[0].attributes[3].value.contentDest", is("ART1"))) + .andExpect(jsonPath("$.payload[0].attributes[3].value.symbolicDestination", is("#!O;ART1;pagina_11!#"))) + .andExpect(jsonPath("$.payload[0].attributes[3].values.it", is("My Page with Content Link"))) + + .andExpect(jsonPath("$.payload[0].attributes[4].code", is("link5"))) + .andExpect(jsonPath("$.payload[0].attributes[4].value.destType", is(SymbolicLink.RESOURCE_TYPE))) + .andExpect(jsonPath("$.payload[0].attributes[4].value.resourceDest", is("44"))) + .andExpect(jsonPath("$.payload[0].attributes[4].value.symbolicDestination", is("#!R;44!#"))) + .andExpect(jsonPath("$.payload[0].attributes[4].values.it", is("My Resource Link"))); String bodyResult = result.andReturn().getResponse().getContentAsString(); newContentId = JsonPath.read(bodyResult, "$.payload[0].id"); @@ -1817,8 +1816,8 @@ public void testAddContentInvalidResourceGroup() throws Exception { Assert.assertNotNull(contentManager.getEntityPrototype("TST")); executeContentPost("1_POST_invalid_resource.json", accessToken, status().isBadRequest()) - .andDo(print()) - .andExpect(jsonPath("$.errors.size()", is(1))); + .andDo(print()) + .andExpect(jsonPath("$.errors.size()", is(1))); } finally { if (null != contentManager.getEntityPrototype("TST")) { ((IEntityTypesConfigurer) contentManager).removeEntityPrototype("TST"); @@ -1856,32 +1855,32 @@ public void testAddUpdateContentCategories() throws Exception { Assert.assertNotNull(this.contentManager.getEntityPrototype("TST")); ResultActions result = executeContentPost("1_POST_valid.json", accessToken, status().isOk()) - .andDo(print()) - .andExpect(jsonPath("$.payload.size()", is(1))) - .andExpect(jsonPath("$.payload[0].id", Matchers.anything())) - .andExpect(jsonPath("$.payload[0].firstEditor", is("jack_bauer"))) - .andExpect(jsonPath("$.payload[0].lastEditor", is("jack_bauer"))) - .andExpect(jsonPath("$.payload[0].version", is("0.1"))) - .andExpect(jsonPath("$.payload[0].attributes.size()", is(13))) - .andExpect(jsonPath("$.errors.size()", is(0))) - .andExpect(jsonPath("$.metaData.size()", is(0))); + .andDo(print()) + .andExpect(jsonPath("$.payload.size()", is(1))) + .andExpect(jsonPath("$.payload[0].id", Matchers.anything())) + .andExpect(jsonPath("$.payload[0].firstEditor", is("jack_bauer"))) + .andExpect(jsonPath("$.payload[0].lastEditor", is("jack_bauer"))) + .andExpect(jsonPath("$.payload[0].version", is("0.1"))) + .andExpect(jsonPath("$.payload[0].attributes.size()", is(13))) + .andExpect(jsonPath("$.errors.size()", is(0))) + .andExpect(jsonPath("$.metaData.size()", is(0))); newContentId = JsonPath.read(result.andReturn().getResponse().getContentAsString(), "$.payload[0].id"); result = executeContentPut("1_PUT_categories.json", newContentId, accessToken, status().isOk()) - .andExpect(jsonPath("$.payload.size()", is(1))) - .andExpect(jsonPath("$.errors.size()", is(0))) - .andExpect(jsonPath("$.metaData.size()", is(0))) - .andExpect(jsonPath("$.payload[0].id", is(newContentId))) - .andExpect(jsonPath("$.payload[0].attributes.size()", is(13))) - .andExpect(jsonPath("$.payload[0].firstEditor", is("jack_bauer"))) - .andExpect(jsonPath("$.payload[0].lastEditor", is("jack_bauer"))) - .andExpect(jsonPath("$.payload[0].description", is("New Content for test"))) - .andExpect(jsonPath("$.payload[0].mainGroup", is("free"))) - .andExpect(jsonPath("$.payload[0].categories.size()", is(2))) - .andExpect(jsonPath("$.payload[0].categories[0]", is("resCat1"))) - .andExpect(jsonPath("$.payload[0].categories[1]", is("resCat2"))) - .andExpect(jsonPath("$.payload[0].version", is("0.2"))); + .andExpect(jsonPath("$.payload.size()", is(1))) + .andExpect(jsonPath("$.errors.size()", is(0))) + .andExpect(jsonPath("$.metaData.size()", is(0))) + .andExpect(jsonPath("$.payload[0].id", is(newContentId))) + .andExpect(jsonPath("$.payload[0].attributes.size()", is(13))) + .andExpect(jsonPath("$.payload[0].firstEditor", is("jack_bauer"))) + .andExpect(jsonPath("$.payload[0].lastEditor", is("jack_bauer"))) + .andExpect(jsonPath("$.payload[0].description", is("New Content for test"))) + .andExpect(jsonPath("$.payload[0].mainGroup", is("free"))) + .andExpect(jsonPath("$.payload[0].categories.size()", is(2))) + .andExpect(jsonPath("$.payload[0].categories[0]", is("resCat1"))) + .andExpect(jsonPath("$.payload[0].categories[1]", is("resCat2"))) + .andExpect(jsonPath("$.payload[0].version", is("0.2"))); } finally { if (null != newContentId) { Content newContent = this.contentManager.loadContent(newContentId, false); @@ -1923,7 +1922,7 @@ public void testAddDeleteContent() throws Exception { .perform(put("/plugins/cms/contents/{code}/status", newContentId) .content(mapper.writeValueAsString(contentStatusRequest)) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); newPublicContent = this.contentManager.loadContent(newContentId, true); Assert.assertNotNull(newPublicContent); @@ -1933,7 +1932,7 @@ public void testAddDeleteContent() throws Exception { .perform(put("/plugins/cms/contents/{code}/status", newContentId) .content(mapper.writeValueAsString(contentStatusRequest)) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); newPublicContent = this.contentManager.loadContent(newContentId, true); Assert.assertNull(newPublicContent); @@ -1942,7 +1941,7 @@ public void testAddDeleteContent() throws Exception { .perform(delete("/plugins/cms/contents") .contentType(MediaType.APPLICATION_JSON_VALUE) .content(mapper.writeValueAsString(new String[] { newContentId })) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result.andExpect(jsonPath("$.payload.size()", is(1))); result.andExpect(jsonPath("$.payload[0]", is(newContentId))); @@ -1990,7 +1989,7 @@ public void testUpdateContents() throws Exception { .perform(put("/plugins/cms/contents/status") .content(mapper.writeValueAsString(batchContentStatusRequest)) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); newPublicContent = this.contentManager.loadContent(newContentId, true); Assert.assertNotNull(newPublicContent); @@ -2000,7 +1999,7 @@ public void testUpdateContents() throws Exception { .perform(put("/plugins/cms/contents/{code}/status", newContentId) .content(mapper.writeValueAsString(batchContentStatusRequest)) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); newPublicContent = this.contentManager.loadContent(newContentId, true); Assert.assertNull(newPublicContent); @@ -2009,7 +2008,7 @@ public void testUpdateContents() throws Exception { .perform(delete("/plugins/cms/contents") .contentType(MediaType.APPLICATION_JSON_VALUE) .content(mapper.writeValueAsString(new String[] { newContentId })) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result.andExpect(jsonPath("$.payload.size()", is(1))); result.andExpect(jsonPath("$.payload[0]", is(newContentId))); @@ -2077,7 +2076,7 @@ public void testUpdateContentsBatch() throws Exception { .perform(put("/plugins/cms/contents/status") .content(mapper.writeValueAsString(batchContentStatusRequest)) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); batchContentStatusRequest.getCodes().stream().forEach(code -> { @@ -2095,7 +2094,7 @@ public void testUpdateContentsBatch() throws Exception { .perform(put("/plugins/cms/contents/status") .content(mapper.writeValueAsString(batchContentStatusRequest)) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); batchContentStatusRequest.getCodes().stream().forEach(code -> { @@ -2154,8 +2153,8 @@ private ResultActions performGetContent(String code, String modelId, String accessToken = mockOAuthInterceptor(user); return mockMvc.perform( get(path, code) - .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .sessionAttr("user", user) + .header("Authorization", "Bearer " + accessToken)); } private ResultActions executeContentPost(String fileName, String accessToken, ResultMatcher expected) throws Exception { @@ -2179,7 +2178,7 @@ private ResultActions executeContentPost(String fileName, String accessToken, Re .perform(post("/plugins/cms/contents") .content(jsonPostValid) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()); result.andExpect(expected); return result; @@ -2200,7 +2199,7 @@ private ResultActions executeContentPut(String fileName, String valueToReplace, .perform(put("/plugins/cms/contents") .content(jsonPutValid) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()).andExpect(expected); return result; } @@ -2212,7 +2211,7 @@ private ResultActions executeContentTypePost(String fileName, String accessToken .perform(post("/plugins/cms/contentTypes") .content(jsonPostValid) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(expected); return result; } @@ -2236,7 +2235,7 @@ private ResultActions performCreateResource(String accessToken, String type, Str MockHttpServletRequestBuilder request = multipart(path) .file(file) .param("metadata", mapper.writeValueAsString(resourceRequest)) - .header("Authorization", "Bearer " + accessToken).with(csrf()); + .header("Authorization", "Bearer " + accessToken); if (type != null) { request.param("type", type); @@ -2249,7 +2248,7 @@ private ResultActions performDeleteResource(String accessToken, String type, Str String path = String.format("/plugins/cms/assets/%s", resourceId); return mockMvc.perform( delete(path) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); } @Test @@ -2264,7 +2263,7 @@ public void testGetContents() throws Exception { .param("filter[0].operator", "eq") .param("filter[0].value", "EVN") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); System.out.println(result.andReturn().getResponse().getContentAsString()); result.andExpect(jsonPath("$.payload", Matchers.hasSize(Matchers.greaterThan(0)))); @@ -2282,7 +2281,7 @@ public void testGetContentsPaginated() throws Exception { .param("filter[0].operator", "eq") .param("filter[0].value", "EVN") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result .andDo(print()) .andExpect(status().isOk()) @@ -2349,7 +2348,7 @@ public void testLoadPublicEvents_1() throws Exception { .param("filters[0].value", "EVN") .param("pageSize", "20") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); String bodyResult = result.andReturn().getResponse().getContentAsString(); result.andExpect(status().isOk()); List expectedFreeContentsId = Arrays.asList("EVN194", "EVN193", @@ -2372,7 +2371,7 @@ public void testLoadPublicEvents_1() throws Exception { .param("filters[0].value", "EVN") .param("pageSize", "20") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); bodyResult = result.andReturn().getResponse().getContentAsString(); result.andExpect(status().isOk()); payloadSize = JsonPath.read(bodyResult, "$.payload.size()"); @@ -2405,11 +2404,11 @@ public void testLoadPublicEvents_2() throws Exception { .param("filters[1].type", "date") .param("filters[1].value", "2020-09-19 01:00:00") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); String bodyResult = result.andReturn().getResponse().getContentAsString(); result.andExpect(status().isOk()); String[] expected = {"EVN25", "EVN21", "EVN20", "EVN41", "EVN193", - "EVN192", "EVN103", "EVN23", "EVN24"}; + "EVN192", "EVN103", "EVN23", "EVN24"}; int payloadSize = JsonPath.read(bodyResult, "$.payload.size()"); Assert.assertEquals(expected.length, payloadSize); for (int i = 0; i < expected.length; i++) { @@ -2440,7 +2439,7 @@ public void testLoadPublicEvents_3() throws Exception { .param("filters[2].type", "date") .param("filters[2].value", "2020-09-19 01:00:00") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); String bodyResult = result.andReturn().getResponse().getContentAsString(); result.andExpect(status().isOk()); String[] expected = {"EVN193", "EVN192"}; @@ -2467,11 +2466,11 @@ public void testLoadOrderedPublicEvents_1() throws Exception { .param("filters[0].operator", "eq") .param("filters[0].value", "EVN") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); String bodyResult = result.andReturn().getResponse().getContentAsString(); result.andExpect(status().isOk()); String[] expectedFreeContentsId = {"EVN24", "EVN23", - "EVN191", "EVN192", "EVN193", "EVN194", "EVN20", "EVN21", "EVN25"}; + "EVN191", "EVN192", "EVN193", "EVN194", "EVN20", "EVN21", "EVN25"}; int payloadSize = JsonPath.read(bodyResult, "$.payload.size()"); Assert.assertEquals(expectedFreeContentsId.length, payloadSize); for (int i = 0; i < expectedFreeContentsId.length; i++) { @@ -2493,7 +2492,7 @@ public void testLoadOrderedPublicEvents_2() throws Exception { .param("filters[0].value", "EVN")); result.andExpect(status().isOk()); String[] expectedFreeOrderedContentsId_1 = {"EVN191", "EVN192", - "EVN193", "EVN194", "EVN20", "EVN23", "EVN24", "EVN25", "EVN21"}; + "EVN193", "EVN194", "EVN20", "EVN23", "EVN24", "EVN25", "EVN21"}; result.andExpect(jsonPath("$.payload", Matchers.hasSize(expectedFreeOrderedContentsId_1.length))); for (int i = 0; i < expectedFreeOrderedContentsId_1.length; i++) { String expectedId = expectedFreeOrderedContentsId_1[expectedFreeOrderedContentsId_1.length - i - 1]; @@ -2537,11 +2536,11 @@ public void testLoadOrderedPublicEvents_3() throws Exception { .param("filters[1].value", "EVN") .param("pageSize", "5") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); String bodyResult = result.andReturn().getResponse().getContentAsString(); result.andExpect(status().isOk()); String[] expectedFreeOrderedContentsId_1 = {"EVN194", "EVN193", "EVN24", - "EVN23", "EVN25"}; + "EVN23", "EVN25"}; int payloadSize = JsonPath.read(bodyResult, "$.payload.size()"); Assert.assertEquals(expectedFreeOrderedContentsId_1.length, payloadSize); for (int i = 0; i < expectedFreeOrderedContentsId_1.length; i++) { @@ -2561,7 +2560,7 @@ public void testLoadOrderedPublicEvents_3() throws Exception { .param("filters[1].value", "EVN") .param("pageSize", "6") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); bodyResult = result.andReturn().getResponse().getContentAsString(); result.andExpect(status().isOk()); String[] expectedFreeOrderedContentsId_2 = {"EVN191", "EVN192", "EVN21", "EVN20", "EVN25", "EVN23"}; @@ -2596,11 +2595,11 @@ public void testLoadOrderedPublicEvents_4() throws Throwable { .param("filters[1].entityAttr", "DataInizio") .param("filters[1].order", FieldSearchFilter.DESC_ORDER) .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); String bodyResult = result.andReturn().getResponse().getContentAsString(); result.andExpect(status().isOk()); String[] expectedFreeOrderedContentsId = {"EVN194", masterContent.getId(), - "EVN193", "EVN24", "EVN23", "EVN25", "EVN20", "EVN21", "EVN192", "EVN191"}; + "EVN193", "EVN24", "EVN23", "EVN25", "EVN20", "EVN21", "EVN192", "EVN191"}; int payloadSize = JsonPath.read(bodyResult, "$.payload.size()"); Assert.assertEquals(expectedFreeOrderedContentsId.length, payloadSize); for (int i = 0; i < expectedFreeOrderedContentsId.length; i++) { @@ -2632,7 +2631,7 @@ public void testLoadOrderedPublicEvents_5() throws Throwable { .param("filters[0].operator", "eq") .param("filters[0].value", "EVN") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -2662,7 +2661,7 @@ public void testLoadOrderedPublicEvents_6() throws Throwable { .param("filters[0].operator", "eq") .param("filters[0].value", "EVN") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -2684,7 +2683,7 @@ public void testLoadOrderedPublicEvents_7() throws Throwable { .param("filters[0].operator", "eq") .param("filters[0].value", "EVN") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$.payload.size()", is(3))); @@ -2704,7 +2703,7 @@ public void testLoadOrderedPublicEvents_8() throws Throwable { .param("filters[0].operator", "eq") .param("filters[0].value", "EVN") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$.payload.size()", is(9))) @@ -2733,7 +2732,7 @@ public void testLoadOrderedPublicEvents_9() throws Throwable { .param("filters[0].operator", "eq") .param("filters[0].value", "EVN") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$.payload.size()", is(9))) @@ -2762,7 +2761,7 @@ public void testLoadOrderedPublicEvents_10() throws Throwable { .param("filters[0].operator", "eq") .param("filters[0].value", "EVN") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$.payload.size()", is(9))) @@ -2791,7 +2790,7 @@ public void testLoadOrderedPublicEvents_11() throws Throwable { .param("filters[0].operator", "eq") .param("filters[0].value", "EVN") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$.payload.size()", is(9))) @@ -2818,7 +2817,7 @@ public void testFilteredContent_1() throws Throwable { .param("filters[0].attribute", "description") .param("filters[0].value", "Sagra") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -2839,7 +2838,7 @@ public void testFilteredContent_2() throws Throwable { .param("filters[0].attribute", "id") .param("filters[0].value", "EVN194") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -2858,7 +2857,7 @@ public void testFilteredContent_3() throws Throwable { .param("filters[0].attribute", "firsteditor") .param("filters[0].value", "admin") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -2880,7 +2879,7 @@ public void testFilteredContent_4() throws Throwable { .param("filters[1].value", "editor1") .param("filters[1].operator", "eq") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -2902,7 +2901,7 @@ public void testFilteredContent_5() throws Throwable { .param("filters[1].value", "editor2") .param("filters[1].operator", "eq") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -2923,7 +2922,7 @@ public void testFilteredContent_6() throws Throwable { .param("filters[1].attribute", "firsteditor") .param("filters[1].value", "editor2") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -2945,7 +2944,7 @@ public void testFilteredContent_7() throws Throwable { .param("filters[1].value", "editor1") .param("filters[1].operator", "not") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -2967,7 +2966,7 @@ public void testFilteredContent_8() throws Throwable { .param("filters[1].value", "free") .param("filters[1].operator", "eq") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -2989,7 +2988,7 @@ public void testFilteredContent_9() throws Throwable { .param("filters[1].value", "free") .param("filters[1].operator", "not") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -3009,7 +3008,7 @@ public void testFilteredContent_10() throws Throwable { .param("filters[0].value", "EVN") .param("categories[0]", "general_cat1") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -3030,7 +3029,7 @@ public void testFilteredContent_11() throws Throwable { .param("categories[0]", "general_cat1") .param("categories[1]", "general_cat2") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -3050,7 +3049,7 @@ public void testFilteredContent_12() throws Throwable { .param("filters[0].value", "EVN") .param("categories[0]", "general_cat2") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -3070,13 +3069,13 @@ public void testFilteredContent_13() throws Throwable { .param("filters[0].value", "EVN") .param("categories[0]", "general_cat3") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$.payload.size()", is(0))); } - + @Test public void testFilteredContent_14() throws Throwable { UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24") @@ -3091,13 +3090,13 @@ public void testFilteredContent_14() throws Throwable { .param("filters[1].attribute", "group") .param("filters[1].value", "group1") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$.payload.size()", is(3))); } - + @Test public void testFilteredContent_15() throws Throwable { UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24") @@ -3118,13 +3117,13 @@ public void testFilteredContent_15() throws Throwable { .param("filters[4].attribute", "group") .param("filters[4].value", "group3") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) .andExpect(jsonPath("$.payload.size()", is(1))); } - + @Test public void testFilteredContent_16() throws Throwable { UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24") @@ -3139,7 +3138,7 @@ public void testFilteredContent_16() throws Throwable { .param("filters[1].attribute", "restriction") .param("filters[1].value", "OPEN") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -3160,7 +3159,7 @@ public void testFilteredContent_17() throws Throwable { .param("filters[1].attribute", "restriction") .param("filters[1].value", "RESTRICTED") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isOk()) @@ -3235,7 +3234,7 @@ public void testLoadPublicContentsForCategory_1() throws Exception { .param("status", IContentService.STATUS_ONLINE) .param("categories[0]", "evento") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); String bodyResult = result.andReturn().getResponse().getContentAsString(); result.andExpect(status().isOk()); List expectedFreeContentsId = Arrays.asList("EVN192", "EVN193"); @@ -3255,7 +3254,7 @@ public void testLoadPublicContentsForCategory_1() throws Exception { .param("filters[0].type", "date") .param("filters[0].value", "2005-02-13 01:00:00") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); bodyResult = result.andReturn().getResponse().getContentAsString(); result.andExpect(status().isOk()); int newPayloadSize = JsonPath.read(bodyResult, "$.payload.size()"); @@ -3274,7 +3273,7 @@ public void testLoadPublicEventsForCategory_2() throws Exception { .param("categories[0]", "general_cat3") .param("categories[1]", "general_cat2") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); String bodyResult = result.andReturn().getResponse().getContentAsString(); result.andExpect(status().isOk()); int payloadSize = JsonPath.read(bodyResult, "$.payload.size()"); @@ -3289,7 +3288,7 @@ public void testLoadPublicEventsForCategory_2() throws Exception { .param("categories[1]", "general_cat2") .param("orClauseCategoryFilter", "true") .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); bodyResult = result.andReturn().getResponse().getContentAsString(); result.andExpect(status().isOk()); List expectedFreeContentsId = Arrays.asList("ART111", "ART120", "ART122", "EVN25"); @@ -3314,7 +3313,7 @@ public void testLoadWorkContentsByAttribute() throws Exception { .param("filters[1].type", "number") .param("filters[1].order", FieldSearchFilter.ASC_ORDER) .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); String bodyResult = result.andReturn().getResponse().getContentAsString(); result.andExpect(status().isOk()); String[] expectedContentsId = {"ART120", "ART121"}; @@ -3540,7 +3539,7 @@ public void testGetPageOnlineNoWidgetErrorMessage() throws Exception { .sessionAttr("user", user) .content(putPageOnlinePayload) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); this.executeContentPost("1_POST_invalid_with_link.json", accessToken, status().isBadRequest()) @@ -3583,7 +3582,7 @@ public void testGetPageOnlineWrongGroupErrorMessage() throws Exception { .sessionAttr("user", user) .content(putPageOnlinePayload) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); this.executeContentPost("1_POST_invalid_with_link.json", accessToken, status().isBadRequest()) @@ -3799,7 +3798,7 @@ public void testContentWithReference() throws Exception { .perform(put("/plugins/cms/contents/{code}/status", newContentId1) .content(mapper.writeValueAsString(contentStatusRequest)) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result = this.executeContentPost("1_POST_valid_with_link_to_content.json", accessToken, status().isOk(), newContentId1) @@ -3817,13 +3816,13 @@ public void testContentWithReference() throws Exception { .perform(put("/plugins/cms/contents/{code}/status", newContentId2) .content(mapper.writeValueAsString(contentStatusRequest)) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result = mockMvc .perform(get("/plugins/cms/contents/{code}", newContentId1) .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result .andDo(print()) .andExpect(jsonPath("$.payload.id", is(newContentId1))) @@ -3835,7 +3834,7 @@ public void testContentWithReference() throws Exception { .perform(put("/plugins/cms/contents/{code}/status", newContentId1) .content(mapper.writeValueAsString(contentStatusRequest)) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.errors.size()", is(1))) @@ -3897,7 +3896,7 @@ public void testContentWithReferenceBatch() throws Exception { .perform(put("/plugins/cms/contents/{code}/status", newContentId1) .content(mapper.writeValueAsString(contentStatusRequest)) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result = this.executeContentPost("1_POST_valid_with_empty_links.json", accessToken, status().isOk()) @@ -3918,7 +3917,7 @@ public void testContentWithReferenceBatch() throws Exception { .perform(put("/plugins/cms/contents/{code}/status", newContentId2) .content(mapper.writeValueAsString(contentStatusRequest)) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result = this.executeContentPost("1_POST_valid_with_link_to_contents.json", accessToken, status().isOk(), newContentId1, newContentId2) @@ -3938,13 +3937,13 @@ public void testContentWithReferenceBatch() throws Exception { .perform(put("/plugins/cms/contents/{code}/status", newContentId3) .content(mapper.writeValueAsString(contentStatusRequest)) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result = mockMvc .perform(get("/plugins/cms/contents/{code}", newContentId1) .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result .andDo(print()) .andExpect(jsonPath("$.payload.id", is(newContentId1))) @@ -3954,7 +3953,7 @@ public void testContentWithReferenceBatch() throws Exception { result = mockMvc .perform(get("/plugins/cms/contents/{code}", newContentId2) .sessionAttr("user", user) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result .andDo(print()) .andExpect(jsonPath("$.payload.id", is(newContentId2))) @@ -3970,7 +3969,7 @@ public void testContentWithReferenceBatch() throws Exception { .perform(put("/plugins/cms/contents/status") .content(mapper.writeValueAsString(batchContentStatusRequest)) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$.errors.size()", is(2))) diff --git a/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/content/ContentTypeResourceIntegrationTest.java b/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/content/ContentTypeResourceIntegrationTest.java index 6d71592991..658af05962 100644 --- a/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/content/ContentTypeResourceIntegrationTest.java +++ b/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/content/ContentTypeResourceIntegrationTest.java @@ -24,7 +24,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import com.agiletec.aps.system.common.entity.IEntityTypesConfigurer; import com.agiletec.aps.system.services.user.UserDetails; @@ -71,7 +70,7 @@ public void setupTest() { public void testGetReturnsList() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypes") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andDo(print()) @@ -100,7 +99,6 @@ public void testCreateUnauthorizedContentType() throws Exception { contentTypeRequest.setName("Content request"); mockMvc.perform( post("/plugins/cms/contentTypes") - .with(csrf()) .contentType(MediaType.APPLICATION_JSON_UTF8) .content(jsonMapper.writeValueAsString(contentTypeRequest)) .accept(MediaType.APPLICATION_JSON_UTF8)) @@ -123,7 +121,7 @@ public void testCreateContentType() throws Exception { contentTypeRequest.setName("Content request"); ResultActions result = mockMvc.perform( post("/plugins/cms/contentTypes") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .content(jsonMapper.writeValueAsString(contentTypeRequest)) .accept(MediaType.APPLICATION_JSON_UTF8)); @@ -156,7 +154,7 @@ public void testUpdateContentType() throws Exception { createdContentType.setDefaultContentModelList("Updated Model list"); ResultActions result = mockMvc.perform(put("/plugins/cms/contentTypes") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .content(jsonMapper.writeValueAsString(createdContentType)) .accept(MediaType.APPLICATION_JSON_UTF8)); @@ -184,7 +182,7 @@ public void testUpdateNonExistentContentType() throws Exception { createdContentType.setCode("999"); ResultActions result = mockMvc.perform(put("/plugins/cms/contentTypes") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .content(jsonMapper.writeValueAsString(createdContentType)) .accept(MediaType.APPLICATION_JSON_UTF8)); @@ -206,7 +204,7 @@ public void testDeleteContentType() throws Exception { this.createContentType(typeCode); mockMvc.perform( delete("/plugins/cms/contentTypes/{code}", typeCode) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()) @@ -231,13 +229,13 @@ public void testGetContentType() throws Exception { private void executeGetContentType(String typeCode, ResultMatcher expectedResult) throws Exception { mockMvc.perform( get("/plugins/cms/contentTypes/{code}", typeCode) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(expectedResult) .andReturn(); mockMvc.perform( get("/plugins/cms/contentTypes/{code}", typeCode) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(expectedResult) @@ -249,7 +247,7 @@ public void testCreateAndGetContentType() throws Exception { String typeCode = "TX4"; mockMvc.perform( get("/plugins/cms/contentTypes/{code}", typeCode) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isNotFound()) @@ -258,7 +256,7 @@ public void testCreateAndGetContentType() throws Exception { ContentTypeDto createdContentTypeDto = this.createContentType(typeCode); MvcResult mvcResult = mockMvc.perform( get("/plugins/cms/contentTypes/{code}", createdContentTypeDto.getCode()) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andDo(print()) @@ -278,7 +276,7 @@ public void testCreateAndGetContentType() throws Exception { public void testGetAllAttributes() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -297,7 +295,7 @@ public void testGetAllAttributes() throws Exception { public void testGetAttachAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "Attach") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -313,7 +311,7 @@ public void testGetAttachAttribute() throws Exception { public void testGetBooleanAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "Boolean") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -329,7 +327,7 @@ public void testGetBooleanAttribute() throws Exception { public void testGetCheckBoxAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "CheckBox") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -345,7 +343,7 @@ public void testGetCheckBoxAttribute() throws Exception { public void testGetCompositeAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "Composite") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -361,7 +359,7 @@ public void testGetCompositeAttribute() throws Exception { public void testGetDateAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "Date") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -377,7 +375,7 @@ public void testGetDateAttribute() throws Exception { public void testGetEnumeratorAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "Enumerator") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -393,7 +391,7 @@ public void testGetEnumeratorAttribute() throws Exception { public void testGetEnumeratorMapAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "EnumeratorMap") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -409,7 +407,7 @@ public void testGetEnumeratorMapAttribute() throws Exception { public void testGetHypertextAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "Hypertext") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -425,7 +423,7 @@ public void testGetHypertextAttribute() throws Exception { public void testGetImageAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "Image") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -441,7 +439,7 @@ public void testGetImageAttribute() throws Exception { public void testGetLinkAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "Link") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -457,7 +455,7 @@ public void testGetLinkAttribute() throws Exception { public void testGetListAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "List") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -473,7 +471,7 @@ public void testGetListAttribute() throws Exception { public void testGetLongtextAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "Longtext") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -489,7 +487,7 @@ public void testGetLongtextAttribute() throws Exception { public void testGetMonolistAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "Monolist") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -505,7 +503,7 @@ public void testGetMonolistAttribute() throws Exception { public void testGetMonotextAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "Monotext") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -521,7 +519,7 @@ public void testGetMonotextAttribute() throws Exception { public void testGetNumberAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "Number") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -537,7 +535,7 @@ public void testGetNumberAttribute() throws Exception { public void testGetTextAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "Text") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -553,7 +551,7 @@ public void testGetTextAttribute() throws Exception { public void testGetThreeStateAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "ThreeState") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -569,7 +567,7 @@ public void testGetThreeStateAttribute() throws Exception { public void testGetTimestampAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypeAttributes/{code}", "Timestamp") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -592,7 +590,7 @@ public void testCreateContentTypeAttribute() throws Exception { attribute.setName("My test attribute"); mockMvc.perform( post("/plugins/cms/contentTypes/{code}/attributes", contentType.getCode()) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .content(jsonMapper.writeValueAsString(attribute)) .accept(MediaType.APPLICATION_JSON_UTF8)) @@ -620,7 +618,7 @@ public void testGetAttributeFromContentType() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypes/{contentCode}/attributes/{code}", typeCode, contentTypeAttribute.getCode()) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -644,7 +642,7 @@ public void testListAttributesFromContentType() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypes/{contentCode}/attributes", typeCode) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -671,7 +669,7 @@ public void testUpdateAttributeFromContentType() throws Exception { mockMvc.perform( put("/plugins/cms/contentTypes/{contentCode}/attributes/{code}", typeCode, contentTypeAttribute.getCode()) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .content(jsonMapper.writeValueAsString(contentTypeAttribute)) .accept(MediaType.APPLICATION_JSON_UTF8)) @@ -696,7 +694,7 @@ public void testDeleteContentTypeAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypes/{contentCode}/attributes/{code}", typeCode, attribute.getCode()) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()) @@ -704,7 +702,7 @@ public void testDeleteContentTypeAttribute() throws Exception { mockMvc.perform( delete("/plugins/cms/contentTypes/{contentCode}/attributes/{code}", typeCode, attribute.getCode()) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) // .andDo(print()) @@ -714,7 +712,7 @@ public void testDeleteContentTypeAttribute() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypes/{contentCode}/attributes/{code}", typeCode, attribute.getCode()) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isNotFound()) @@ -734,7 +732,7 @@ public void testRefreshContentType() throws Exception { ContentTypeDto contentType = this.createContentType(typeCode); mockMvc.perform( post("/plugins/cms/contentTypes/refresh/{contentTypeCode}", contentType.getCode()) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()) @@ -752,7 +750,7 @@ public void testReloadReferences() throws Exception { ContentTypeRefreshRequest bodyRequest = new ContentTypeRefreshRequest(); mockMvc.perform( post("/plugins/cms/contentTypesStatus") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .content(jsonMapper.writeValueAsString(bodyRequest)) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) @@ -765,7 +763,7 @@ public void testReloadReferences() throws Exception { public void testExtractStatus() throws Exception { mockMvc.perform( get("/plugins/cms/contentTypesStatus") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()) @@ -780,7 +778,7 @@ public void moveAttributeUp() throws Exception { String code = attributes.get(1).getCode(); mockMvc.perform( put("/plugins/cms/contentTypes/{contentTypeCode}/attributes/{attributeCode}/moveUp", typeCode, code) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()) @@ -803,7 +801,7 @@ public void moveAttributeDown() throws Exception { String code = attributes.get(0).getCode(); mockMvc.perform( put("/plugins/cms/contentTypes/{contentTypeCode}/attributes/{attributeCode}/moveDown", typeCode, code) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()) @@ -823,7 +821,7 @@ public void testGetContentTypeUsage() throws Exception { String code = "ART"; mockMvc.perform(get("/plugins/cms/contentTypes/{code}/usage", code) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andDo(print()) @@ -845,7 +843,7 @@ private ContentTypeDto createContentType(String typeCode) throws Exception { contentTypeRequest.setName("Content request"); MvcResult mvcResult = mockMvc.perform( post("/plugins/cms/contentTypes") - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .content(jsonMapper.writeValueAsString(contentTypeRequest)) .accept(MediaType.APPLICATION_JSON_UTF8)).andReturn(); @@ -872,7 +870,7 @@ private EntityTypeAttributeFullDto postForAttribute(ContentTypeDto contentType, attribute.setType("Text"); MvcResult mvcResult = mockMvc.perform( post("/plugins/cms/contentTypes/{contentCode}/attributes", contentType.getCode()) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .content(jsonMapper.writeValueAsString(attribute)) .accept(MediaType.APPLICATION_JSON_UTF8)) @@ -904,7 +902,7 @@ private EntityTypeAttributeFullDto stringToEntityTypeDto(MvcResult mvcResult) th private void deleteContentType(String code) throws Exception { mockMvc.perform( delete("/plugins/cms/contentTypes/{code}", code) - .header("Authorization", "Bearer " + accessToken).with(csrf()) + .header("Authorization", "Bearer " + accessToken) .contentType(MediaType.APPLICATION_JSON_UTF8) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()) diff --git a/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/contentmodel/ContentModelControllerIntegrationTest.java b/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/contentmodel/ContentModelControllerIntegrationTest.java index 960ed54097..c14eff45c1 100644 --- a/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/contentmodel/ContentModelControllerIntegrationTest.java +++ b/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/contentmodel/ContentModelControllerIntegrationTest.java @@ -1,16 +1,5 @@ package org.entando.entando.plugins.jacms.web.contentmodel; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - import com.agiletec.aps.system.common.FieldSearchFilter; import com.agiletec.aps.system.services.user.UserDetails; import com.agiletec.plugins.jacms.aps.system.services.contentmodel.ContentModel; @@ -24,6 +13,16 @@ import org.springframework.http.MediaType; import org.springframework.test.web.servlet.ResultActions; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + public class ContentModelControllerIntegrationTest extends AbstractControllerIntegrationTest { private static final String BASE_URI = "/plugins/cms/contentmodels"; @@ -41,7 +40,7 @@ public void testGetContentModelsSortId() throws Exception { ResultActions result = mockMvc .perform(get(BASE_URI) .param("sort", "id") - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result.andExpect(jsonPath("$.payload[0].id", is(1))); @@ -49,7 +48,7 @@ public void testGetContentModelsSortId() throws Exception { .perform(get(BASE_URI) .param("direction", FieldSearchFilter.DESC_ORDER) .param("sort", "id") - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result.andExpect(jsonPath("$.payload[0].id", is(11))); @@ -61,7 +60,7 @@ public void testGetContentModelDefaultSorting() throws Exception { String accessToken = mockOAuthInterceptor(user); ResultActions result = mockMvc .perform(get(BASE_URI) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result.andExpect(jsonPath("$.metaData.pageSize", is(100))); result.andExpect(jsonPath("$.metaData.sort", is("id"))); @@ -77,7 +76,7 @@ public void testGetContentModelsSortByDescr() throws Exception { .perform(get(BASE_URI) .param("direction", FieldSearchFilter.ASC_ORDER) .param("sort", "descr") - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result.andExpect(jsonPath("$.payload[0].descr", is("List Model"))); @@ -85,7 +84,7 @@ public void testGetContentModelsSortByDescr() throws Exception { .perform(get(BASE_URI) .param("direction", FieldSearchFilter.DESC_ORDER) .param("sort", "descr") - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result.andExpect(jsonPath("$.payload[0].descr", is("scheda di un articolo"))); @@ -102,7 +101,7 @@ public void testGetContentModelsWithFilters() throws Exception { .param("sort", "descr") .param("filters[0].attribute", "contentType") .param("filters[0].value", "ART") - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result.andExpect(jsonPath("$.payload.length()", is(4))); @@ -114,7 +113,7 @@ public void testGetContentModelsWithFilters() throws Exception { .param("filters[0].value", "ART") .param("filters[1].attribute", "descr") .param("filters[1].value", "MoDeL") - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result.andExpect(jsonPath("$.payload.length()", is(2))); } @@ -126,7 +125,7 @@ public void testGetContentModelOk() throws Exception { String accessToken = mockOAuthInterceptor(user); ResultActions result = mockMvc .perform(get(BASE_URI + "/{modelId}", "1") - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result.andExpect(jsonPath("$.payload.id", is(1))); @@ -139,7 +138,7 @@ public void testGetContentModelKo() throws Exception { String accessToken = mockOAuthInterceptor(user); ResultActions result = mockMvc .perform(get(BASE_URI + "/{modelId}", "0") - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isNotFound()); result.andExpect(jsonPath("$.errors[0].code", is("1"))); } @@ -151,7 +150,7 @@ public void testGetContentModelDictionary() throws Exception { String accessToken = mockOAuthInterceptor(user); ResultActions result = mockMvc .perform(get(BASE_URI + "/dictionary") - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); } @@ -164,7 +163,7 @@ public void testGetContentModelDictionaryWithTypeCode() throws Exception { ResultActions result = mockMvc .perform(get(BASE_URI + "/dictionary") .param("typeCode", "EVN") - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result.andExpect(jsonPath("$.payload").isNotEmpty()); result.andExpect(jsonPath("$.payload.$content").isNotEmpty()); @@ -178,7 +177,7 @@ public void testGetContentModelDictionaryValidTypeCodeInvalid() throws Exception ResultActions result = mockMvc .perform(get(BASE_URI + "/dictionary") .param("typeCode", "LOL") - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isNotFound()); result.andExpect(jsonPath("$.errors[0].code", is("6"))); } @@ -204,7 +203,7 @@ public void testCrudContentModel() throws Exception { .perform(post(BASE_URI) .contentType(MediaType.APPLICATION_JSON_VALUE) .content(payload) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); ContentModel contentModelAdded = this.contentModelManager.getContentModel(modelId); @@ -226,7 +225,7 @@ public void testCrudContentModel() throws Exception { .perform(put(BASE_URI + "/{id}", modelId) .contentType(MediaType.APPLICATION_JSON_VALUE) .content(payload) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); contentModelAdded = this.contentModelManager.getContentModel(modelId); @@ -240,7 +239,7 @@ public void testCrudContentModel() throws Exception { .perform(delete(BASE_URI + "/{id}", modelId) .contentType(MediaType.APPLICATION_JSON_VALUE) .content(payload) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result.andExpect(jsonPath("$.payload.modelId", is(String.valueOf(modelId)))); @@ -278,7 +277,7 @@ public void testAddWithInvalidContentType() throws Exception { .perform(post(BASE_URI) .contentType(MediaType.APPLICATION_JSON_VALUE) .content(payload) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isConflict()); result.andExpect(jsonPath("$.errors[0].code", is("6"))); @@ -313,7 +312,7 @@ public void testAddWithIdAboveMax() throws Exception { .perform(post(BASE_URI) .contentType(MediaType.APPLICATION_JSON_VALUE) .content(payload) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isBadRequest()); result.andExpect(jsonPath("$.errors[0].code", is("56"))); @@ -348,7 +347,7 @@ public void testChangeContentType() throws Exception { .perform(post(BASE_URI) .contentType(MediaType.APPLICATION_JSON_VALUE) .content(payload) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); @@ -365,7 +364,7 @@ public void testChangeContentType() throws Exception { .perform(put(BASE_URI + "/{id}", modelId) .contentType(MediaType.APPLICATION_JSON_VALUE) .content(payload) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()) .andExpect(jsonPath("$.errors.size()", is(0))) @@ -401,7 +400,7 @@ public void testChangeWithInvalidContentType() throws Exception { .perform(post(BASE_URI) .contentType(MediaType.APPLICATION_JSON_VALUE) .content(payload) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); @@ -417,7 +416,7 @@ public void testChangeWithInvalidContentType() throws Exception { .perform(put(BASE_URI + "/{id}", modelId) .contentType(MediaType.APPLICATION_JSON_VALUE) .content(payload) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isConflict()) .andExpect(jsonPath("$.errors[0].code", is(String.valueOf("6")))); @@ -451,7 +450,7 @@ public void testChangeContentShapeToNull() throws Exception { .perform(post(BASE_URI) .contentType(MediaType.APPLICATION_JSON_VALUE) .content(payload) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); @@ -467,7 +466,7 @@ public void testChangeContentShapeToNull() throws Exception { .perform(put(BASE_URI + "/{id}", modelId) .contentType(MediaType.APPLICATION_JSON_VALUE) .content(payload) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isBadRequest()) .andExpect(jsonPath("$.errors.size()", is(1))); @@ -492,7 +491,7 @@ public void testDeleteReferencedModel() throws Throwable { ResultActions result = mockMvc .perform(delete(BASE_URI + "/{id}", 2) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isConflict()); result.andExpect(jsonPath("$.errors[0].code", is(String.valueOf("5")))); @@ -507,7 +506,7 @@ public void testGetModelPageReferences() throws Throwable { ResultActions result = mockMvc .perform(get(BASE_URI + "/{id}/pagereferences", 2) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); } diff --git a/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/page/PageConfigurationControllerIntegrationTest.java b/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/page/PageConfigurationControllerIntegrationTest.java index af8f28a0ba..c92d944af8 100644 --- a/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/page/PageConfigurationControllerIntegrationTest.java +++ b/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/page/PageConfigurationControllerIntegrationTest.java @@ -1,20 +1,9 @@ package org.entando.entando.plugins.jacms.web.page; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.isEmptyOrNullString; -import static org.junit.Assert.assertThat; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.agiletec.aps.util.FileTextReader; +import com.opensymphony.xwork2.mock.MockResult; +import java.io.InputStream; +import java.util.Map; import com.agiletec.aps.system.services.page.IPage; import com.agiletec.aps.system.services.page.IPageManager; @@ -26,21 +15,34 @@ import com.agiletec.aps.system.services.pagemodel.PageModel; import com.agiletec.aps.system.services.user.UserDetails; import com.agiletec.aps.util.ApsProperties; -import com.agiletec.aps.util.FileTextReader; import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.InputStream; -import java.util.Map; import org.entando.entando.aps.system.services.page.IPageService; import org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto; import org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager; import org.entando.entando.web.AbstractControllerIntegrationTest; import org.entando.entando.web.utils.OAuth2TestUtils; -import org.hamcrest.Matchers; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.ResultActions; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import org.hamcrest.Matchers; + +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.isEmptyOrNullString; +import static org.junit.Assert.assertThat; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + public class PageConfigurationControllerIntegrationTest extends AbstractControllerIntegrationTest { @Autowired @@ -61,7 +63,7 @@ public void testPageConfiguration() throws Exception { String accessToken = mockOAuthInterceptor(user); ResultActions result = mockMvc .perform(get("/pages/{pageCode}/configuration", "homepage") - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result.andExpect(jsonPath("$.payload.online", is(true))); @@ -103,13 +105,13 @@ public void testGetPageConfigurationOnLineNotFound() throws Exception { ResultActions result = mockMvc .perform(get("/pages/{pageCode}/configuration", new Object[]{pageCode}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result = mockMvc .perform(get("/pages/{pageCode}/configuration", new Object[]{pageCode}) .param("status", IPageService.STATUS_ONLINE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isBadRequest()); result.andExpect(jsonPath("$.errors[0].code", is("3"))); @@ -136,7 +138,7 @@ public void testPutPageConfiguration() throws Exception { ResultActions result = mockMvc .perform(get("/pages/{pageCode}/widgets/{frame}", new Object[]{pageCode, 0}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); String payloadWithOtherModelId = "{\n" @@ -151,7 +153,7 @@ public void testPutPageConfiguration() throws Exception { .param("status", IPageService.STATUS_DRAFT) .content(payloadWithOtherModelId) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result @@ -196,7 +198,7 @@ public void testPutPageConfigurationFilterFormat() throws Exception { .param("status", IPageService.STATUS_DRAFT) .content(payload) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result .andDo(print()) @@ -243,7 +245,7 @@ public void testPutPageConfigurationCategoriesFormat() throws Exception { .param("status", IPageService.STATUS_DRAFT) .content(payload) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result .andDo(print()) @@ -296,7 +298,7 @@ public void testPutPageConfigurationContentsFormat() throws Exception { .param("status", IPageService.STATUS_DRAFT) .content(payload) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result .andDo(print()) @@ -337,7 +339,7 @@ public void testPutPageConfigurationInvalidFrame() throws Exception { ResultActions result = mockMvc .perform(get("/pages/{pageCode}/widgets/{frame}", new Object[]{pageCode, "XXX"}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); String getResult = result.andReturn().getResponse().getContentAsString(); result.andExpect(status().isBadRequest()); @@ -363,7 +365,7 @@ public void testPutPageConfigurationWrongFrame() throws Exception { ResultActions result = mockMvc .perform(get("/pages/{pageCode}/widgets/{frame}", new Object[]{pageCode, "500"}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isNotFound()); result.andExpect(jsonPath("$.errors[0].code", is("2"))); @@ -389,7 +391,7 @@ public void testPutPageDescription() throws Exception { ResultActions result = mockMvc .perform(get("/pages/{pageCode}/widgets/{frame}", new Object[]{pageCode, 0}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); InputStream isJsonPostValid = this.getClass().getResourceAsStream("1_PUT_page_description_row_content_viewer_list.json"); @@ -400,7 +402,7 @@ public void testPutPageDescription() throws Exception { .param("status", IPageService.STATUS_DRAFT) .content(jsonPostValid) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()) .andDo(print()) .andExpect(jsonPath("$.errors", hasSize(0))) @@ -430,7 +432,7 @@ public void testPutDynamicProperties() throws Exception { ResultActions result = mockMvc .perform(get("/pages/{pageCode}/widgets/{frame}", new Object[]{pageCode, 0}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); InputStream isJsonPostValid = this.getClass().getResourceAsStream("1_PUT_dynamic_properties.json"); @@ -441,7 +443,7 @@ public void testPutDynamicProperties() throws Exception { .param("status", IPageService.STATUS_DRAFT) .content(jsonPostValid) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()) .andDo(print()) .andExpect(jsonPath("$.errors", hasSize(0))) @@ -478,7 +480,7 @@ public void testGetWithMultipleFrames() throws Exception { ResultActions result = mockMvc .perform(get("/pages/{pageCode}/widgets/{frame}", new Object[]{pageCode, 0}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); InputStream isJsonPostValid = this.getClass().getResourceAsStream("1_PUT_dynamic_properties.json"); @@ -489,7 +491,7 @@ public void testGetWithMultipleFrames() throws Exception { .param("status", IPageService.STATUS_DRAFT) .content(jsonPostValid) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()) .andDo(print()); @@ -498,7 +500,7 @@ public void testGetWithMultipleFrames() throws Exception { .param("status", IPageService.STATUS_DRAFT) .content(jsonPostValid) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()) .andDo(print()); @@ -506,7 +508,7 @@ public void testGetWithMultipleFrames() throws Exception { result = mockMvc .perform(get("/pages/{pageCode}/widgets", new Object[]{pageCode}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()) .andDo(print()) @@ -555,14 +557,14 @@ public void testDeletePageConfigurationWithInvalidFrameId() throws Exception { ResultActions result = mockMvc .perform(get("/pages/{pageCode}/widgets/{frame}", new Object[]{pageCode, 0}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result = mockMvc .perform(delete("/pages/{pageCode}/widgets/{frame}", new Object[]{pageCode, "XXX"}) .param("status", IPageService.STATUS_DRAFT) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isBadRequest()); @@ -591,14 +593,14 @@ public void testDeletePageConfigurationWithWrongFrameId() throws Exception { ResultActions result = mockMvc .perform(get("/pages/{pageCode}/widgets/{frame}", new Object[]{pageCode, 0}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); result = mockMvc .perform(delete("/pages/{pageCode}/widgets/{frame}", new Object[]{pageCode, 9999}) .param("status", IPageService.STATUS_DRAFT) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); @@ -624,14 +626,14 @@ public void testGetPageWidgetConfiguration() throws Exception { ResultActions result = mockMvc .perform(get("/pages/{pageCode}/widgets/{frame}", new Object[]{pageCode, 999}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isNotFound()); result.andExpect(jsonPath("$.errors[0].code", is("2"))); result = mockMvc .perform(get("/pages/{pageCode}/widgets/{frame}", new Object[]{pageCode, "ASD"}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isBadRequest()); result.andExpect(jsonPath("$.errors[0].code", is("40"))); @@ -665,7 +667,7 @@ public void testApplyDefautWidgets() throws Exception { ResultActions result = mockMvc .perform(get("/pages/{pageCode}/configuration", new Object[]{pageCode}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); Widget[] defaultWidgetConfiguration = pageModel.getDefaultWidget(); @@ -683,7 +685,7 @@ public void testApplyDefautWidgets() throws Exception { result = mockMvc .perform(put("/pages/{pageCode}/configuration/defaultWidgets", new Object[]{pageCode}) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); for (int i = 0; i < pageModel.getConfiguration().length; i++) { diff --git a/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/page/PageConfigurationControllerWidgetsIntegrationTest.java b/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/page/PageConfigurationControllerWidgetsIntegrationTest.java index 5e4c39e077..96b4a1be51 100644 --- a/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/page/PageConfigurationControllerWidgetsIntegrationTest.java +++ b/plugins/entando-plugin-jacms/src/test/java/org/entando/entando/plugins/jacms/web/page/PageConfigurationControllerWidgetsIntegrationTest.java @@ -1,17 +1,5 @@ package org.entando.entando.plugins.jacms.web.page; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertThat; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; - import com.agiletec.aps.system.services.page.IPage; import com.agiletec.aps.system.services.page.IPageManager; import com.agiletec.aps.system.services.page.Page; @@ -29,7 +17,18 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.ResultActions; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.Assert.assertThat; import org.springframework.test.web.servlet.ResultMatcher; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; public class PageConfigurationControllerWidgetsIntegrationTest extends AbstractControllerIntegrationTest { @@ -56,7 +55,7 @@ public void testConfigureListViewer() throws Exception { ResultActions result = mockMvc .perform(get("/pages/{pageCode}/configuration", new Object[]{pageCode}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); String payloadWithInvalidContentType = "{\n" @@ -72,7 +71,7 @@ public void testConfigureListViewer() throws Exception { .param("status", IPageService.STATUS_ONLINE) .content(payloadWithInvalidContentType) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isConflict()); @@ -91,7 +90,7 @@ public void testConfigureListViewer() throws Exception { .param("status", IPageService.STATUS_ONLINE) .content(payloadWithInvalidModelId) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isConflict()); @@ -115,7 +114,7 @@ public void testContentViewer() throws Exception { ResultActions result = mockMvc .perform(get("/pages/{pageCode}/configuration", new Object[]{pageCode}) .param("status", IPageService.STATUS_DRAFT) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); String payloadWithInvalidContentId = "{\n" + " \"code\": \"content_viewer\",\n" @@ -208,7 +207,7 @@ public void testConfigurationRestore() throws Exception { .sessionAttr("user", user) .content(putPageOnlinePayload) .contentType(MediaType.APPLICATION_JSON) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); //checking page online config @@ -236,7 +235,7 @@ public void testConfigurationRestore() throws Exception { //restoring page configuration result = mockMvc .perform(put("/pages/{pageCode}/configuration/restore", new Object[]{pageCode}) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(status().isOk()); //checking page draft config @@ -300,7 +299,7 @@ private ResultActions executeGetPageConfig(String pageCode, String pageStatus, S ResultActions result = mockMvc .perform(get("/pages/{pageCode}/configuration", new Object[]{pageCode}) .param("status", pageStatus) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); result.andExpect(rm); return result; } @@ -311,7 +310,7 @@ private ResultActions executePutPageConfig(String payload, String pageCode, .perform(put("/pages/{pageCode}/widgets/{frameId}", new Object[]{pageCode, pos}) .content(payload) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); System.out.println(result.andReturn().getResponse().getContentAsString()); result.andExpect(rm); return result; @@ -322,7 +321,7 @@ private ResultActions executeDeletePageConfig(String pageCode, ResultActions result = mockMvc .perform(delete("/pages/{pageCode}/widgets/{frameId}", new Object[]{pageCode, pos}) .contentType(MediaType.APPLICATION_JSON_VALUE) - .header("Authorization", "Bearer " + accessToken).with(csrf())); + .header("Authorization", "Bearer " + accessToken)); String response = result.andReturn().getResponse().getContentAsString(); System.out.println(response); result.andExpect(rm);