Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,16 @@ public ResponseEntity<String> downloadData(
parameters.put(DatasetDownloadEnums.Parameter.UUID.getValue(), id);
parameters.put(DatasetDownloadEnums.Parameter.START_DATE.getValue(), startDate);
parameters.put(DatasetDownloadEnums.Parameter.END_DATE.getValue(), endDate);
parameters.put(DatasetDownloadEnums.Parameter.MULTI_POLYGON.getValue(), objectMapper.writeValueAsString(polygons));
parameters.put(DatasetDownloadEnums.Parameter.RECIPIENT.getValue(), recipient);
if (polygons == null || polygons.toString().isEmpty()) {
throw new IllegalArgumentException("Polygons parameter should now be null. If users didn't specify polygons, a 'non-specified' should be sent.");

// String (e.g. "non-specified") is working weird with function ObjectMapper.writeValueAsString(), so handle it separately
} else if (polygons.toString().equals("non-specified")) {
parameters.put(DatasetDownloadEnums.Parameter.MULTI_POLYGON.getValue(), polygons.toString());
} else {
parameters.put(DatasetDownloadEnums.Parameter.MULTI_POLYGON.getValue(), objectMapper.writeValueAsString(polygons));
}

parameters.put(
DatasetDownloadEnums.Parameter.TYPE.getValue(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
Expand Down Expand Up @@ -68,4 +69,27 @@ public void testDownloadDataJsonProcessingException() throws JsonProcessingExcep
assertEquals("Error", e.getMessage());
}
}

@Test
public void testDownloadDataCapturesSubmitJobRequest() throws JsonProcessingException {
// Arrange
String jobId = "12345";
SubmitJobResponse submitJobResponse = SubmitJobResponse.builder().jobId(jobId).build();
when(batchClient.submitJob(any(SubmitJobRequest.class))).thenReturn(submitJobResponse);
when(objectMapper.writeValueAsString(any())).thenReturn("test-multipolygon");

// Act
ResponseEntity<String> response = restServices.downloadData(
"test-uuid", "2023-01-01", "2023-01-31", "non-specified", "test@example.com");

// Capture the submitted request
ArgumentCaptor<SubmitJobRequest> captor =
ArgumentCaptor.forClass(SubmitJobRequest.class);
verify(batchClient, times(1)).submitJob(captor.capture());
SubmitJobRequest captured = captor.getValue();

// Assert relevant parameters
assertEquals("non-specified", captured.parameters().get("multi_polygon"));
assertEquals(ResponseEntity.ok("Job submitted with ID: " + jobId), response);
}
}