Skip to content

Commit

Permalink
Add missing unit tests for querying requests by date (#443) (#445)
Browse files Browse the repository at this point in the history
Signed-off-by: Angelica Ochoa <[email protected]>
  • Loading branch information
ao508 authored Oct 27, 2021
1 parent 1a0026e commit da8296a
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.mskcc.cmo.metadb.persistence.MetadbRequestRepository;
import org.mskcc.cmo.metadb.service.MetadbRequestService;
import org.mskcc.cmo.metadb.service.MetadbSampleService;
import org.mskcc.cmo.metadb.service.exception.MetadbWebServiceException;
import org.mskcc.cmo.metadb.service.util.RequestStatusLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -247,7 +246,7 @@ public List<MetadbSample> getRequestSamplesWithUpdates(MetadbRequest request) th
@Override
public List<List<String>> getRequestsByDate(String startDate, String endDate) throws Exception {
if (Strings.isNullOrEmpty(startDate)) {
return null;
throw new RuntimeException("Start date " + startDate + " cannot be null or empty");
}
if (Strings.isNullOrEmpty(endDate)) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,91 @@ public void testRequestMetadataHistoryByRequestId() throws Exception {
Assertions.assertThat(existingRequestHistoryList.size()).isEqualTo(1);
}

/**
* Test for getRequestsByDate
* Case 1: Tests when end date is null
* @throws Exception
*/

@Test
public void testGetRequestsByNullEndDate() throws Exception {
String startDate = "2021-10-25";
List<List<String>> requestDataList = requestService.getRequestsByDate(startDate, null);
Assertions.assertThat(requestDataList.size()).isEqualTo(3);
}

/**
* Test for getRequestsByDate
* Case 2: Test when both start and end date are null,
* Expected to throw an exception
* @throws Exception
*/
@Test
public void testGetRequestsByNullDates() throws Exception {
Assertions.assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> {
requestService.getRequestsByDate(null, null);
});
}

/**
* Test for getRequestsByDate
* Case 3: Test when start date is null and end date isn't,
* Expected to throw an exception
* @throws Exception
*/
@Test
public void testGetRequestsByNullStartDate() throws Exception {
String endDate = "2021-10-25";
Assertions.assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> {
requestService.getRequestsByDate(null, endDate);
});
}

/**
* Test for getRequestsByDate
* Case 4: Test when end date is less than start date,
* Expected to throw an exception
* @throws Exception
*/
@Test
public void testGetRequestsByInvalidDateRange() throws Exception {
String endDate = "2021-10-24";
String startDate = "2021-10-25";
Assertions.assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> {
requestService.getRequestsByDate(startDate, endDate);
});
}

/**
* Test for getRequestsByDate
* Case 5: Test when dates are invalid(example: 2021-13-34),
* Expected to throw an exception
* @throws Exception
*/
@Test
public void testGetRequestsByInvalidDate() throws Exception {
String startDate = "2021-13-25";
Assertions.assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> {
requestService.getRequestsByDate(startDate, null);
});
}

/**
* Test for getRequestsByDate
* Case 6: Test when dates are in invalid format(example: 10/10/2021),
* Expected to throw an exception
* @throws Exception
*/
@Test
public void testGetRequestsByInvalidDateFormat() throws Exception {
String startDate = "25/10/2021";
Assertions.assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> {
requestService.getRequestsByDate(startDate, null);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@ private ResponseEntity requestNotFoundHandler(String message) {
return new ResponseEntity<>(map, HttpStatus.NOT_FOUND);
}

public class DateRange {
static class DateRange {
String startDate;
String endDate;

DateRange(){}

String getStartDate() {
return startDate;
}
Expand All @@ -200,8 +202,8 @@ void setEndDate(String endDate) {
}

public enum ReturnTypeDetails {
REQUEST_ID_LIST("Request ID list"),
REQUEST_SUMMARY_LIST("Request Summary list");
REQUEST_ID_LIST("REQUEST_ID_LIST"),
REQUEST_SUMMARY_LIST("REQUEST_SUMMARY_LIST");

private String value;

Expand Down

0 comments on commit da8296a

Please sign in to comment.