Skip to content

Commit

Permalink
Rethrow exceptions encountered during value set expansion (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris0296 committed May 27, 2024
1 parent 333360d commit ae83f71
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ protected void expandValueSet(
valueSet, authoritativeSourceUrl, expansionParameters, username, apiKey);
valueSet.setExpansion(expandedValueSet.getExpansion());
} catch (Exception ex) {
System.out.println("Terminology Server expansion failed: {"
+ valueSet.getIdElement().getValue() + "}");
throw new UnprocessableEntityException(
"Terminology Server expansion failed for: " + valueSet.getId(), ex.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ protected void expandValueSet(
valueSet, authoritativeSourceUrl, expansionParameters, username, apiKey);
valueSet.setExpansion(expandedValueSet.getExpansion());
} catch (Exception ex) {
System.out.println("Terminology Server expansion failed: {"
+ valueSet.getIdElement().getValue() + "}");
throw new UnprocessableEntityException(
"Terminology Server expansion failed for: " + valueSet.getId(), ex.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ protected void expandValueSet(
valueSet, authoritativeSourceUrl, expansionParameters, username, apiKey);
valueSet.setExpansion(expandedValueSet.getExpansion());
} catch (Exception ex) {
System.out.println("Terminology Server expansion failed: {"
+ valueSet.getIdElement().getValue() + "}");
throw new UnprocessableEntityException(
"Terminology Server expansion failed for: " + valueSet.getId(), ex.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,32 @@ void packageOperation_should_fail_credentials_missing_apikey() {
assertTrue(maybeException.getMessage().contains("Cannot expand ValueSet without VSAC API Key: "));
}

@Test
void packageOperation_should_fail_credentials_invalid() {
Bundle loadedBundle = (Bundle) jsonParser.parseResource(
KnowledgeArtifactPackageVisitorTests.class.getResourceAsStream("Bundle-ersd-example.json"));
spyRepository.transaction(loadedBundle);
KnowledgeArtifactPackageVisitor packageVisitor = new KnowledgeArtifactPackageVisitor();
Library library = spyRepository
.read(Library.class, new IdType("Library/SpecificationLibrary"))
.copy();
LibraryAdapter libraryAdapter = new AdapterFactory().createLibrary(library);
Parameters params = new Parameters();
Endpoint terminologyEndpoint = new Endpoint();
terminologyEndpoint.addExtension(Constants.VSAC_USERNAME, new StringType("someUsername"));
terminologyEndpoint.addExtension(Constants.APIKEY, new StringType("some-api-key"));
params.addParameter().setName("terminologyEndpoint").setResource(terminologyEndpoint);

UnprocessableEntityException maybeException = null;
try {
libraryAdapter.accept(packageVisitor, spyRepository, params);
} catch (UnprocessableEntityException e) {
maybeException = e;
}
assertTrue(maybeException.getMessage().contains("Terminology Server expansion failed for: "));
assertTrue(maybeException.getAdditionalMessages().stream().allMatch(msg -> msg.contains("HTTP 401")));
}

@Test
void packageOperation_should_fail_non_matching_capability() {
Bundle bundle =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void packageOperation_should_fail_credentials_missing_username() {
}

@Test
void packageOperation_should_fail_credentials_missing_apiyey() {
void packageOperation_should_fail_credentials_missing_apikey() {
Bundle loadedBundle = (Bundle) jsonParser.parseResource(
KnowledgeArtifactPackageVisitorTests.class.getResourceAsStream("Bundle-ersd-example.json"));
spyRepository.transaction(loadedBundle);
Expand All @@ -168,6 +168,32 @@ void packageOperation_should_fail_credentials_missing_apiyey() {
assertTrue(maybeException.getMessage().contains("Cannot expand ValueSet without VSAC API Key: "));
}

@Test
void packageOperation_should_fail_credentials_invalid() {
Bundle loadedBundle = (Bundle) jsonParser.parseResource(
KnowledgeArtifactPackageVisitorTests.class.getResourceAsStream("Bundle-ersd-example.json"));
spyRepository.transaction(loadedBundle);
KnowledgeArtifactPackageVisitor packageVisitor = new KnowledgeArtifactPackageVisitor();
Library library = spyRepository
.read(Library.class, new IdType("Library/SpecificationLibrary"))
.copy();
LibraryAdapter libraryAdapter = new AdapterFactory().createLibrary(library);
Parameters params = new Parameters();
Endpoint terminologyEndpoint = new Endpoint();
terminologyEndpoint.addExtension(Constants.VSAC_USERNAME, new StringType("someUsername"));
terminologyEndpoint.addExtension(Constants.APIKEY, new StringType("some-api-key"));
params.addParameter().setName("terminologyEndpoint").setResource(terminologyEndpoint);

UnprocessableEntityException maybeException = null;
try {
libraryAdapter.accept(packageVisitor, spyRepository, params);
} catch (UnprocessableEntityException e) {
maybeException = e;
}
assertTrue(maybeException.getMessage().contains("Terminology Server expansion failed for:"));
assertTrue(maybeException.getAdditionalMessages().stream().allMatch(msg -> msg.contains("HTTP 401")));
}

@Test
void packageOperation_should_fail_non_matching_capability() {
Bundle bundle =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,32 @@ void packageOperation_should_fail_credentials_missing_apikey() {
assertTrue(maybeException.getMessage().contains("Cannot expand ValueSet without VSAC API Key: "));
}

@Test
void packageOperation_should_fail_credentials_invalid() {
Bundle loadedBundle = (Bundle) jsonParser.parseResource(
KnowledgeArtifactPackageVisitorTests.class.getResourceAsStream("Bundle-ersd-example.json"));
spyRepository.transaction(loadedBundle);
KnowledgeArtifactPackageVisitor packageVisitor = new KnowledgeArtifactPackageVisitor();
Library library = spyRepository
.read(Library.class, new IdType("Library/SpecificationLibrary"))
.copy();
LibraryAdapter libraryAdapter = new AdapterFactory().createLibrary(library);
Parameters params = new Parameters();
Endpoint terminologyEndpoint = new Endpoint();
terminologyEndpoint.addExtension(Constants.VSAC_USERNAME, new StringType("someUsername"));
terminologyEndpoint.addExtension(Constants.APIKEY, new StringType("some-api-key"));
params.addParameter().setName("terminologyEndpoint").setResource(terminologyEndpoint);

UnprocessableEntityException maybeException = null;
try {
libraryAdapter.accept(packageVisitor, spyRepository, params);
} catch (UnprocessableEntityException e) {
maybeException = e;
}
assertTrue(maybeException.getMessage().contains("Terminology Server expansion failed for: "));
assertTrue(maybeException.getAdditionalMessages().stream().allMatch(msg -> msg.contains("HTTP 401")));
}

@Test
void packageOperation_should_fail_non_matching_capability() {
Bundle bundle =
Expand Down

0 comments on commit ae83f71

Please sign in to comment.