From b7c9c9d8bd88617db3e6316e7db22ccaee691748 Mon Sep 17 00:00:00 2001 From: valentinogiardino Date: Thu, 21 Nov 2024 13:09:04 -0300 Subject: [PATCH] #30669 add response to initBuilder --- .../contentImport/ContentImportResource.java | 4 +++- .../ContentUploadResourceIntegrationTest.java | 20 +++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/rest/api/v1/contentImport/ContentImportResource.java b/dotCMS/src/main/java/com/dotcms/rest/api/v1/contentImport/ContentImportResource.java index 48c2a14bdb2c..b1fe81a0f573 100644 --- a/dotCMS/src/main/java/com/dotcms/rest/api/v1/contentImport/ContentImportResource.java +++ b/dotCMS/src/main/java/com/dotcms/rest/api/v1/contentImport/ContentImportResource.java @@ -8,6 +8,7 @@ import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import javax.ws.rs.*; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; @@ -53,12 +54,13 @@ public ContentImportResource(final WebResource webResource, final ContentImportH @Produces(MediaType.APPLICATION_JSON) public ResponseEntityView importContent( @Context final HttpServletRequest request, + @Context final HttpServletResponse response, @BeanParam final ContentImportParams params) throws DotDataException, JsonProcessingException { final var initDataObject = new WebResource.InitBuilder(webResource) .requiredBackendUser(true) .requiredFrontendUser(false) - .requestAndResponse(request, null) + .requestAndResponse(request, response) .rejectWhenNoUser(true) .init(); diff --git a/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/content/upload/ContentUploadResourceIntegrationTest.java b/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/content/upload/ContentUploadResourceIntegrationTest.java index e3c952d80049..4ca219b2f576 100644 --- a/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/content/upload/ContentUploadResourceIntegrationTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/content/upload/ContentUploadResourceIntegrationTest.java @@ -12,6 +12,7 @@ import com.dotcms.jobs.business.job.Job; import com.dotcms.jobs.business.processor.impl.ImportContentletsProcessor; import com.dotcms.jobs.business.util.JobUtil; +import com.dotcms.mock.response.MockHttpResponse; import com.dotcms.rest.ResponseEntityView; import com.dotcms.rest.api.v1.JobQueueManagerHelper; import com.dotcms.rest.api.v1.contentImport.ContentImportForm; @@ -33,6 +34,7 @@ import javax.enterprise.context.ApplicationScoped; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -50,6 +52,7 @@ public class ContentUploadResourceIntegrationTest extends Junit5WeldBaseTest { private static User adminUser; private static HttpServletRequest request; + private static HttpServletResponse response; private static Host defaultSite; private static ObjectMapper mapper; private static ContentImportResource importResource; @@ -66,6 +69,7 @@ static void setUp() throws Exception { adminUser = TestUserUtils.getAdminUser(); defaultSite = APILocator.getHostAPI().findDefaultHost(adminUser, false); request = JobUtil.generateMockRequest(adminUser, defaultSite.getHostname()); + response = new MockHttpResponse(); mapper = new ObjectMapper(); JobQueueManagerHelper jobQueueManagerHelper = mock(JobQueueManagerHelper.class); @@ -89,8 +93,8 @@ public void test_import_content_with_valid_params() throws IOException, DotDataE ContentImportForm form = createContentImportForm(contentType.name(), "1", "workflow-action-id", List.of("title")); ContentImportParams params = createContentImportParams(csvFile, form); - ResponseEntityView response = importResource.importContent(request, params); - validateSuccessfulResponse(response, contentType.name(), "1", List.of("title"), "workflow-action-id", CMD_PUBLISH); + ResponseEntityView importContentResponse = importResource.importContent(request, response, params); + validateSuccessfulResponse(importContentResponse, contentType.name(), "1", List.of("title"), "workflow-action-id", CMD_PUBLISH); } /** @@ -106,8 +110,8 @@ public void test_import_content_without_optional_params() throws IOException, Do ContentImportForm form = createContentImportForm(contentType.name(), null, "workflow-action-id-2", null); ContentImportParams params = createContentImportParams(csvFile, form); - ResponseEntityView response = importResource.importContent(request, params); - validateSuccessfulResponse(response, contentType.name(), null, null, "workflow-action-id-2", CMD_PUBLISH); + ResponseEntityView importContentResponse = importResource.importContent(request, response, params); + validateSuccessfulResponse(importContentResponse, contentType.name(), null, null, "workflow-action-id-2", CMD_PUBLISH); } /** @@ -121,7 +125,7 @@ public void test_import_content_without_content_type_in_form() throws IOExceptio ContentImportForm form = createContentImportForm(null, null, "workflow-action-id", null); ContentImportParams params = createContentImportParams(csvFile, form); - assertThrows(ValidationException.class, () -> importResource.importContent(request, params)); + assertThrows(ValidationException.class, () -> importResource.importContent(request, response, params)); } /** @@ -137,7 +141,7 @@ public void test_import_content_without_workflow_action_in_form() throws IOExcep ContentImportForm form = createContentImportForm(contentType.name(), null, null, null); ContentImportParams params = createContentImportParams(csvFile, form); - assertThrows(ValidationException.class, () -> importResource.importContent(request, params)); + assertThrows(ValidationException.class, () -> importResource.importContent(request, response, params)); } /** @@ -153,7 +157,7 @@ public void test_import_content_missing_file() throws Exception { ContentImportParams params = new ContentImportParams(); params.setJsonForm(mapper.writeValueAsString(form)); - assertThrows(ValidationException.class, () -> importResource.importContent(request, params)); + assertThrows(ValidationException.class, () -> importResource.importContent(request, response, params)); } /** @@ -169,7 +173,7 @@ public void test_import_content_missing_form() throws Exception { params.setFileInputStream(new FileInputStream(csvFile)); params.setContentDisposition(createContentDisposition(csvFile.getName())); - assertThrows(ValidationException.class, () -> importResource.importContent(request, params)); + assertThrows(ValidationException.class, () -> importResource.importContent(request, response, params)); } /**