Skip to content

Commit

Permalink
#30669 add response to initBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinogiardino committed Nov 21, 2024
1 parent 9c82d66 commit b7c9c9d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,12 +54,13 @@ public ContentImportResource(final WebResource webResource, final ContentImportH
@Produces(MediaType.APPLICATION_JSON)
public ResponseEntityView<String> 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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<String> response = importResource.importContent(request, params);
validateSuccessfulResponse(response, contentType.name(), "1", List.of("title"), "workflow-action-id", CMD_PUBLISH);
ResponseEntityView<String> importContentResponse = importResource.importContent(request, response, params);
validateSuccessfulResponse(importContentResponse, contentType.name(), "1", List.of("title"), "workflow-action-id", CMD_PUBLISH);
}

/**
Expand All @@ -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<String> response = importResource.importContent(request, params);
validateSuccessfulResponse(response, contentType.name(), null, null, "workflow-action-id-2", CMD_PUBLISH);
ResponseEntityView<String> importContentResponse = importResource.importContent(request, response, params);
validateSuccessfulResponse(importContentResponse, contentType.name(), null, null, "workflow-action-id-2", CMD_PUBLISH);
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand Down

0 comments on commit b7c9c9d

Please sign in to comment.