Skip to content

Commit

Permalink
Merge pull request #91 from medizininformatik-initiative/feature/84-V…
Browse files Browse the repository at this point in the history
…alidation-endpoint-for-imported-Structured-Query

#84 - Validation endpoint for imported structured query
  • Loading branch information
juliangruendner authored Mar 17, 2023
2 parents 6fa148b + df50eb0 commit 1cdd6f1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ public ResponseEntity<Object> getQueryContent(@PathVariable("id") Long queryId,
return new ResponseEntity<>(queryContent, HttpStatus.OK);
}

@PostMapping("/validate")
public ResponseEntity<Object> validateStructuredQuery(@Valid @RequestBody StructuredQuery query) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

private boolean hasAccess(Long queryId, Authentication authentication) {
Set<String> roles = authentication.getAuthorities().stream()
.map(GrantedAuthority::getAuthority).collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,40 @@ public void testRunQueryEndpoint_FailsOnDownstreamServiceError() throws Exceptio
mockMvc.perform(asyncDispatch(mvcResult))
.andExpect(status().is(HttpStatus.INTERNAL_SERVER_ERROR.value()));
}

@Test
@WithMockUser(roles = "FEASIBILITY_TEST_USER", username = "test")
public void testValidateQueryEndpoint_SucceedsOnValidQuery() throws Exception {
var termCode = new TermCode();
termCode.setCode("LL2191-6");
termCode.setSystem("http://loinc.org");
termCode.setDisplay("Geschlecht");

var inclusionCriterion = new Criterion();
inclusionCriterion.setTermCodes(new ArrayList<>(List.of(termCode)));

var testQuery = new StructuredQuery();
testQuery.setInclusionCriteria(List.of(List.of(inclusionCriterion)));
testQuery.setExclusionCriteria(List.of());
testQuery.setDisplay("foo");
testQuery.setVersion(URI.create("http://to_be_decided.com/draft-2/schema#"));

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

mockMvc.perform(post(URI.create("/api/v2/query/validate")).with(csrf())
.contentType(APPLICATION_JSON)
.content(jsonUtil.writeValueAsString(testQuery)))
.andExpect(status().isNoContent());
}

@Test
@WithMockUser(roles = "FEASIBILITY_TEST_USER")
public void testValidateQueryEndpoint_FailsOnInvalidStructuredQueryWith400() throws Exception {
var testQuery = new StructuredQuery();

mockMvc.perform(post(URI.create("/api/v2/query/validate")).with(csrf())
.contentType(APPLICATION_JSON)
.content(jsonUtil.writeValueAsString(testQuery)))
.andExpect(status().isBadRequest());
}
}

0 comments on commit 1cdd6f1

Please sign in to comment.