Skip to content

Commit

Permalink
#258 - Add an endpoint that takes a structured query and validates it
Browse files Browse the repository at this point in the history
- fix a test that should mock getInvalidCriteria instead of getInvalidTermcodes
- update blaze container in tests to 0.25
  • Loading branch information
michael-82 committed Mar 20, 2024
1 parent 59b460a commit 83775be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DirectBrokerClientCqlIT {
private static final Long TEST_BACKEND_QUERY_ID = 1L;

private final GenericContainer<?> blaze = new GenericContainer<>(
DockerImageName.parse("samply/blaze:0.18"))
DockerImageName.parse("samply/blaze:0.25"))
.withImagePullPolicy(PullPolicy.alwaysPull())
.withExposedPorts(8080)
.waitingFor(Wait.forHttp("/health").forStatusCodeMatching(c -> c >= 200 && c <= 500))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class DSFFhirWebClientProviderTest {

@Container
private GenericContainer<?> blaze = new GenericContainer<>("samply/blaze:0.23.3")
private GenericContainer<?> blaze = new GenericContainer<>("samply/blaze:0.25")
.withExposedPorts(8080)
.withNetwork(Network.newNetwork())
.withReuse(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void testRunQueryEndpoint_FailsOnSoftQuotaExceeded() throws Exception {

@Test
@WithMockUser(roles = "FEASIBILITY_TEST_USER", username = "test")
public void testValidate2QueryEndpoint_SucceedsOnValidQuery() throws Exception {
public void testValidateQueryEndpoint_SucceedsOnValidQuery() throws Exception {
StructuredQuery testQuery = createValidStructuredQuery();

doReturn(List.of()).when(termCodeValidation).getInvalidTermCodes(any(StructuredQuery.class));
Expand All @@ -193,27 +193,23 @@ public void testValidate2QueryEndpoint_SucceedsOnValidQuery() throws Exception {
.contentType(APPLICATION_JSON)
.content(jsonUtil.writeValueAsString(testQuery)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.invalidTerms").isEmpty());
.andExpect(jsonPath("$.invalidCriteria").isEmpty());
}

@Test
@WithMockUser(roles = "FEASIBILITY_TEST_USER")
public void testValidate2QueryEndpoint_SucceedsDespiteInvalidTermcodesWith200() throws Exception {
public void testValidateQueryEndpoint_SucceedsDespiteInvalidTermcodesWith200() throws Exception {
StructuredQuery testQuery = createValidStructuredQuery();
var invalidTermCode = TermCode.builder()
.code("LL2191-6")
.system("http://loinc.org")
.display("Geschlecht")
.build();
var invalidCriterion = createInvalidCriterion();

doReturn(List.of(invalidTermCode)).when(termCodeValidation).getInvalidTermCodes(any(StructuredQuery.class));
doReturn(List.of(invalidCriterion)).when(termCodeValidation).getInvalidCriteria(any(StructuredQuery.class));

mockMvc.perform(post(URI.create(PATH_API + PATH_QUERY + "/validate")).with(csrf())
.contentType(APPLICATION_JSON)
.content(jsonUtil.writeValueAsString(testQuery)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.invalidTerms").exists())
.andExpect(jsonPath("$.invalidTerms").isNotEmpty());
.andExpect(jsonPath("$.invalidCriteria").exists())
.andExpect(jsonPath("$.invalidCriteria").isNotEmpty());
}

@Test
Expand Down Expand Up @@ -711,6 +707,14 @@ private static TermCode createTermCode() {
.build();
}

@NotNull
private static Criterion createInvalidCriterion() {
return Criterion.builder()
.termCodes(List.of(createTermCode()))
.context(null)
.build();
}

@NotNull
private static Query createValidApiQuery(long id) {
return Query.builder()
Expand Down

0 comments on commit 83775be

Please sign in to comment.