Skip to content

Commit

Permalink
#374 - Extend API to save and load cohort and dataselection
Browse files Browse the repository at this point in the history
- update ontology tag in github integration test
- add debug output to check which curl cmd fails
- add check for data storage limits on updates in DataqueryHandlerTest
  • Loading branch information
michael-82 committed Feb 27, 2025
1 parent 50afdbe commit 0369e10
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .github/scripts/post-test-query.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e

access_token="$(curl -s --request POST \
access_token="$(curl -vvv --request POST \
--url http://localhost:8083/auth/realms/dataportal/protocol/openid-connect/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data grant_type=password \
Expand All @@ -9,7 +9,7 @@ access_token="$(curl -s --request POST \
--data password=testpassword \
--data scope=openid | jq '.access_token' | tr -d '"')"

response=$(curl -s -i \
response=$(curl -vvv -i \
--url http://localhost:8091/api/v5/query/feasibility \
--header "Authorization: Bearer $access_token" \
--header 'Content-Type: application/json' \
Expand Down Expand Up @@ -50,7 +50,7 @@ response=$(curl -s -i \

result_location=$(echo "$response" | grep -i location | awk '{print $2}')
sleep 5
nr_of_pats=$(curl -v \
nr_of_pats=$(curl -vvv \
--url "${result_location%?}/summary-result" \
--header "Authorization: Bearer $access_token" | jq '.totalNumberOfPatients')

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ jobs:
needs: tests
runs-on: ubuntu-latest
env:
ONTOLOGY_GIT_TAG: v3.0.2-alpha.5
ONTOLOGY_GIT_TAG: v3.1.0
ELASTIC_HOST: http://localhost:9200
ELASTIC_FILEPATH: https://github.com/medizininformatik-initiative/fhir-ontology-generator/releases/download/TAGPLACEHOLDER/
ELASTIC_FILENAME: elastic.zip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,51 @@ void updateDataquery_throwsOnNotFound() {
assertThrows(DataqueryException.class, () -> dataqueryHandler.updateDataquery(1L, createDataquery(), CREATOR));
}

@ParameterizedTest
@CsvSource({"true,true", "true,false", "false,true", "false,false"})
@DisplayName("updateDataquery() -> check if storage full exceptions are thrown correctly")
void updateDataquery_throwsOnNoFreeSlots(boolean withResultNew, boolean withResultOld) throws JsonProcessingException {
var dataqueryHandler = createDataqueryHandler();
var dataquery = createDataquery(withResultNew);
var dataqueryEntity = createDataqueryEntity(withResultOld);

lenient().doReturn(Optional.of(dataqueryEntity)).when(dataqueryRepository).findById(any(Long.class));
lenient().doReturn(Long.valueOf(MAX_QUERIES_PER_USER)).when(dataqueryRepository).countByCreatedByWhereResultIsNotNull(any(String.class));
lenient().doReturn(createDataqueryEntity()).when(dataqueryRepository).save(any(de.numcodex.feasibility_gui_backend.query.persistence.Dataquery.class));

// When the new dataquery has no result, this should never throw. It should only throw if the old had no result and the new has a result
if (withResultNew && !withResultOld) {
assertThrows(DataqueryStorageFullException.class, () -> dataqueryHandler.updateDataquery(1L, dataquery, CREATOR));
} else {
assertDoesNotThrow(() -> dataqueryHandler.updateDataquery(1L, dataquery, CREATOR));
}
}

@ParameterizedTest
@CsvSource({
"-1,true,true", "-1,true,false", "-1,false,true", "-1,false,false",
"0,true,true", "0,true,false", "0,false,true", "0,false,false",
"1,true,true", "1,true,false", "1,false,true", "1,false,false"
})
@DisplayName("updateDataquery() -> checking around the query limit")
void updateDataquery_testFreeSlotOnEdgeCases(long offset, boolean withResultNew, boolean withResultOld) throws JsonProcessingException {
var dataqueryHandler = createDataqueryHandler();
var dataquery = createDataquery(withResultNew);
var dataqueryEntity = createDataqueryEntity(withResultOld);

lenient().doReturn(Optional.of(dataqueryEntity)).when(dataqueryRepository).findById(any(Long.class));
lenient().doReturn(MAX_QUERIES_PER_USER + offset).when(dataqueryRepository).countByCreatedByWhereResultIsNotNull(any(String.class));
lenient().doReturn(createDataqueryEntity()).when(dataqueryRepository).save(any(de.numcodex.feasibility_gui_backend.query.persistence.Dataquery.class));

// It should only throw when the new query has a result, the old didn't have one and the storage is full
// If the storage is full but the old query already had a result, it should not fail.
if (withResultNew && !withResultOld && offset >= 0) {
assertThrows(DataqueryStorageFullException.class, () -> dataqueryHandler.updateDataquery(1L, dataquery, CREATOR));
} else {
assertDoesNotThrow(() -> dataqueryHandler.updateDataquery(1L, dataquery, CREATOR));
}
}

@Test
@DisplayName("getDataqueriesByAuthor() -> succeeds")
void getDataqueriesByAuthor_succeedsWithEntry() throws JsonProcessingException {
Expand Down Expand Up @@ -352,15 +397,19 @@ private StructuredQuery createValidStructuredQuery() {
.build();
}

private de.numcodex.feasibility_gui_backend.query.persistence.Dataquery createDataqueryEntity() throws JsonProcessingException {
private de.numcodex.feasibility_gui_backend.query.persistence.Dataquery createDataqueryEntity(boolean withResult) throws JsonProcessingException {
de.numcodex.feasibility_gui_backend.query.persistence.Dataquery out = new de.numcodex.feasibility_gui_backend.query.persistence.Dataquery();
out.setId(1L);
out.setLabel(LABEL);
out.setComment(COMMENT);
out.setLastModified(Timestamp.valueOf(TIME_STRING));
out.setCreatedBy(CREATOR);
out.setResultSize(123L);
out.setResultSize(withResult ? 123L : null);
out.setCrtdl(jsonUtil.writeValueAsString(createCrtdl()));
return out;
}

private de.numcodex.feasibility_gui_backend.query.persistence.Dataquery createDataqueryEntity() throws JsonProcessingException {
return createDataqueryEntity(false);
}
}

0 comments on commit 0369e10

Please sign in to comment.