Skip to content

Commit

Permalink
Cleanup visitor test data (#568)
Browse files Browse the repository at this point in the history
* Cleanup Delete, Withdraw, Retire Visitor Tests & Data

* Shrink naive expansion bundle for Package Visitor Tests

* Remove bloated Bundle-ersd-example.json and replace with smaller bundle

-Updated tests to reflect file change
-Apply spotless

* Remove Bundle-ersd-release-bundle

-Use Bundle-small-approved-draft in it's place, update test assertions to reflect

* Apply spotless

* Add profile dependency and non-owned component to Release Tests

* Update test data to restore lost coverage & update assertion style

* refactor data to restore coverage
  • Loading branch information
Chris0296 authored Nov 8, 2024
1 parent f9ffc9a commit c6e417f
Show file tree
Hide file tree
Showing 36 changed files with 2,278 additions and 676,256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void setup() {
@Test
void library_draft_test() {
Bundle bundle = (Bundle)
jsonParser.parseResource(DraftVisitorTests.class.getResourceAsStream("Bundle-ersd-example.json"));
jsonParser.parseResource(DraftVisitorTests.class.getResourceAsStream("Bundle-ersd-small-active.json"));
repo.transaction(bundle);
IKnowledgeArtifactVisitor draftVisitor = new DraftVisitor();
Library library = repo.read(Library.class, new IdType("Library/SpecificationLibrary"))
Expand Down Expand Up @@ -123,15 +123,14 @@ void library_draft_test() {
@Test
void draftOperation_no_effectivePeriod_test() {
Bundle bundle = (Bundle)
jsonParser.parseResource(DraftVisitorTests.class.getResourceAsStream("Bundle-ersd-example.json"));
jsonParser.parseResource(DraftVisitorTests.class.getResourceAsStream("Bundle-ersd-small-active.json"));
repo.transaction(bundle);
Library baseLib = repo.read(Library.class, new IdType("Library/SpecificationLibrary"))
.copy();
assertTrue(baseLib.hasEffectivePeriod());
ILibraryAdapter libraryAdapter = new AdapterFactory().createLibrary(baseLib);
IKnowledgeArtifactVisitor draftVisitor = new DraftVisitor();
PlanDefinition planDef = repo.read(
PlanDefinition.class, new IdType("PlanDefinition/plandefinition-ersd-instance-example"))
PlanDefinition planDef = repo.read(PlanDefinition.class, new IdType("PlanDefinition/us-ecr-specification"))
.copy();
assertTrue(planDef.hasEffectivePeriod());
String version = "1.01.21";
Expand All @@ -151,12 +150,12 @@ PlanDefinition.class, new IdType("PlanDefinition/plandefinition-ersd-instance-ex
@Test
void draftOperation_version_conflict_test() {
Bundle bundle = (Bundle)
jsonParser.parseResource(DraftVisitorTests.class.getResourceAsStream("Bundle-ersd-example.json"));
jsonParser.parseResource(DraftVisitorTests.class.getResourceAsStream("Bundle-ersd-small-active.json"));
Library versionConflictLibrary = (Library)
jsonParser.parseResource(DraftVisitorTests.class.getResourceAsStream("Library-version-conflict.json"));
repo.transaction(bundle);
repo.update(versionConflictLibrary);
Parameters params = parameters(part("version", "1.0.0"));
Parameters params = parameters(part("version", "1.2.3"));
String maybeException = null;
Library baseLib =
repo.read(Library.class, new IdType(specificationLibReference)).copy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void visitLibraryTest() {
@Test
@Disabled("This test needs a ValueSet that cannot be naively expanded")
void packageOperation_should_fail_no_credentials() {
Bundle loadedBundle = (Bundle)
jsonParser.parseResource(PackageVisitorTests.class.getResourceAsStream("Bundle-ersd-example.json"));
Bundle loadedBundle = (Bundle) jsonParser.parseResource(
PackageVisitorTests.class.getResourceAsStream("Bundle-ersd-small-active.json"));
repo.transaction(loadedBundle);
PackageVisitor packageVisitor = new PackageVisitor(fhirContext);
Library library = repo.read(Library.class, new IdType("Library/SpecificationLibrary"))
Expand All @@ -106,8 +106,8 @@ void packageOperation_should_fail_no_credentials() {
@Test
@Disabled("This test needs a ValueSet that cannot be naively expanded")
void packageOperation_should_fail_credentials_missing_username() {
Bundle loadedBundle = (Bundle)
jsonParser.parseResource(PackageVisitorTests.class.getResourceAsStream("Bundle-ersd-example.json"));
Bundle loadedBundle = (Bundle) jsonParser.parseResource(
PackageVisitorTests.class.getResourceAsStream("Bundle-ersd-small-active.json"));
repo.transaction(loadedBundle);
PackageVisitor packageVisitor = new PackageVisitor(fhirContext);
Library library = repo.read(Library.class, new IdType("Library/SpecificationLibrary"))
Expand All @@ -129,8 +129,8 @@ void packageOperation_should_fail_credentials_missing_username() {
@Test
@Disabled("This test needs a ValueSet that cannot be naively expanded")
void packageOperation_should_fail_credentials_missing_apikey() {
Bundle loadedBundle = (Bundle)
jsonParser.parseResource(PackageVisitorTests.class.getResourceAsStream("Bundle-ersd-example.json"));
Bundle loadedBundle = (Bundle) jsonParser.parseResource(
PackageVisitorTests.class.getResourceAsStream("Bundle-ersd-small-active.json"));
repo.transaction(loadedBundle);
PackageVisitor packageVisitor = new PackageVisitor(fhirContext);
Library library = repo.read(Library.class, new IdType("Library/SpecificationLibrary"))
Expand All @@ -152,8 +152,8 @@ void packageOperation_should_fail_credentials_missing_apikey() {
@Test
@Disabled("This test needs a ValueSet that cannot be naively expanded")
void packageOperation_should_fail_credentials_invalid() {
Bundle loadedBundle = (Bundle)
jsonParser.parseResource(PackageVisitorTests.class.getResourceAsStream("Bundle-ersd-example.json"));
Bundle loadedBundle = (Bundle) jsonParser.parseResource(
PackageVisitorTests.class.getResourceAsStream("Bundle-ersd-small-active.json"));
repo.transaction(loadedBundle);
PackageVisitor packageVisitor = new PackageVisitor(fhirContext);
Library library = repo.read(Library.class, new IdType("Library/SpecificationLibrary"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@ void bothCRMIandCQFMEffectiveDataRequirementsTest() {
@Test
void visitLibraryTest() {
Bundle bundle = (Bundle) jsonParser.parseResource(
ReleaseVisitorTests.class.getResourceAsStream("Bundle-ersd-release-bundle.json"));
ReleaseVisitorTests.class.getResourceAsStream("Bundle-small-approved-draft.json"));
repo.transaction(bundle);
ReleaseVisitor releaseVisitor = new ReleaseVisitor();
Library library = repo.read(Library.class, new IdType("Library/ReleaseSpecificationLibrary"))
Library library = repo.read(Library.class, new IdType("Library/SpecificationLibrary"))
.copy();
library.addRelatedArtifact()
.setResource(new Reference("should-be-deleted-1"))
Expand Down Expand Up @@ -296,67 +296,16 @@ void visitLibraryTest() {
// the parameters
assertEquals(releasedLibrary.getVersion(), existingVersion);
var expectedErsdTestArtifactDependencies = Arrays.asList(
"http://ersd.aimsplatform.org/fhir/PlanDefinition/release-us-ecr-specification|" + existingVersion,
"http://ersd.aimsplatform.org/fhir/Library/release-rctc|" + existingVersion,
"http://ersd.aimsplatform.org/fhir/ValueSet/release-dxtc|" + existingVersion,
"http://ersd.aimsplatform.org/fhir/ValueSet/release-ostc|" + existingVersion,
"http://ersd.aimsplatform.org/fhir/ValueSet/release-lotc|" + existingVersion,
"http://ersd.aimsplatform.org/fhir/ValueSet/release-lrtc|" + existingVersion,
"http://ersd.aimsplatform.org/fhir/ValueSet/release-mrtc|" + existingVersion,
"http://ersd.aimsplatform.org/fhir/ValueSet/release-sdtc|" + existingVersion,
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.6|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1063|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.360|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.120|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.362|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.528|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.408|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.409|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1469|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1866|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1906|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.480|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.481|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.761|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1223|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1182|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1181|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1184|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1601|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1600|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1603|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1602|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1082|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1439|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1436|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1435|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1446|2022-10-19",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1438|2022-10-19",
"http://notOwnedTest.com/Library/notOwnedRoot|0.1.1",
"http://notOwnedTest.com/Library/notOwnedLeaf|0.1.1",
"http://notOwnedTest.com/Library/notOwnedLeaf1|0.1.1",
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient",
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-condition",
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-encounter",
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-medicationrequest",
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-immunization",
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-lab",
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-diagnosticreport-lab",
"http://hl7.org/fhir/us/ecr/StructureDefinition/eicr-document-bundle",
"http://hl7.org/fhir/StructureDefinition/ServiceRequest",
"http://hl7.org/fhir/us/ecr/StructureDefinition/ersd-valueset-library",
"http://ersd.aimsplatform.org/fhir/PlanDefinition/us-ecr-specification|" + existingVersion,
"http://ersd.aimsplatform.org/fhir/Library/rctc|" + existingVersion,
"http://ersd.aimsplatform.org/fhir/ValueSet/dxtc|" + existingVersion,
"http://hl7.org/fhir/us/ecr/StructureDefinition/us-ph-triggering-valueset-library",
"http://hl7.org/fhir/us/ecr/StructureDefinition/ersd-plandefinition",
"http://hl7.org/fhir/us/ecr/StructureDefinition/us-ph-plandefinition",
"http://hl7.org/fhir/us/ecr/StructureDefinition/ersd-valueset",
"http://hl7.org/fhir/us/ecr/StructureDefinition/us-ph-triggering-valueset",
"http://snomed.info/sct",
"http://hl7.org/fhir/sid/icd-10-cm",
"http://loinc.org",
"http://www.nlm.nih.gov/research/umls/rxnorm");
"http://notOwnedTest.com/Library/notOwnedRoot|0.1.1",
"http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.6|20210526",
"http://snomed.info/sct");
var expectedErsdTestArtifactComponents = Arrays.asList(
"http://ersd.aimsplatform.org/fhir/PlanDefinition/release-us-ecr-specification|" + existingVersion,
"http://ersd.aimsplatform.org/fhir/Library/release-rctc|" + existingVersion,
"http://ersd.aimsplatform.org/fhir/PlanDefinition/us-ecr-specification|" + existingVersion,
"http://ersd.aimsplatform.org/fhir/Library/rctc|" + existingVersion,
"http://notOwnedTest.com/Library/notOwnedRoot|0.1.1");
var dependenciesOnReleasedArtifact = releasedLibrary.getRelatedArtifact().stream()
.filter(ra -> ra.getType().equals(RelatedArtifact.RelatedArtifactType.DEPENDSON))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.opencds.cqf.fhir.utility.visitor.r4;

import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.*;
import static org.opencds.cqf.fhir.utility.r4.Parameters.parameters;
import static org.opencds.cqf.fhir.utility.r4.Parameters.part;

Expand Down Expand Up @@ -37,12 +37,12 @@ void setup() {

@Test
void library_delete_test() {
Bundle bundle =
(Bundle) jsonParser.parseResource(DeleteVisitorTests.class.getResourceAsStream("Bundle-delete.json"));
Bundle bundle = (Bundle)
jsonParser.parseResource(DeleteVisitorTests.class.getResourceAsStream("Bundle-small-retired.json"));
Bundle tsBundle = repo.transaction(bundle);
// Resource is uploaded using POST - need to get id like this
String id = tsBundle.getEntry().get(0).getResponse().getLocation();
String version = "1.1.0";
String version = "1.2.3";
Library library = repo.read(Library.class, new IdType(id)).copy();
ILibraryAdapter libraryAdapter = new AdapterFactory().createLibrary(library);
IKnowledgeArtifactVisitor deleteVisitor = new DeleteVisitor();
Expand All @@ -51,46 +51,40 @@ void library_delete_test() {

var res = returnedBundle.getEntry();

assert (res.size() == 9);
assertEquals(4, res.size());
}

@Test
void library_delete_active_test() {
try {
Bundle bundle = (Bundle)
jsonParser.parseResource(DeleteVisitorTests.class.getResourceAsStream("Bundle-ersd-example.json"));
repo.transaction(bundle);
String version = "1.0.0";
Library library = repo.read(Library.class, new IdType("Library/SpecificationLibrary"))
.copy();
ILibraryAdapter libraryAdapter = new AdapterFactory().createLibrary(library);
IKnowledgeArtifactVisitor deleteVisitor = new DeleteVisitor();
Parameters params = parameters(part("version", version));
libraryAdapter.accept(deleteVisitor, repo, params);
Bundle bundle = (Bundle)
jsonParser.parseResource(DeleteVisitorTests.class.getResourceAsStream("Bundle-ersd-small-active.json"));
repo.transaction(bundle);
String version = "1.2.3";
Library library = repo.read(Library.class, new IdType("Library/SpecificationLibrary"))
.copy();
ILibraryAdapter libraryAdapter = new AdapterFactory().createLibrary(library);
IKnowledgeArtifactVisitor deleteVisitor = new DeleteVisitor();
Parameters params = parameters(part("version", version));

fail("Trying to withdraw an active Library should throw an Exception");
} catch (PreconditionFailedException e) {
assert (e.getMessage().contains("Cannot delete an artifact that is not in retired status"));
}
var exception = assertThrows(
PreconditionFailedException.class, () -> libraryAdapter.accept(deleteVisitor, repo, params));
assertTrue(exception.getMessage().contains("Cannot delete an artifact that is not in retired status"));
}

@Test
void library_delete_draft_test() {
try {
Bundle bundle = (Bundle)
jsonParser.parseResource(DeleteVisitorTests.class.getResourceAsStream("Bundle-withdraw.json"));
Bundle tsBundle = repo.transaction(bundle);
String id = tsBundle.getEntry().get(0).getResponse().getLocation();
String version = "1.1.0-draft";
Library library = repo.read(Library.class, new IdType(id)).copy();
ILibraryAdapter libraryAdapter = new AdapterFactory().createLibrary(library);
IKnowledgeArtifactVisitor deleteVisitor = new DeleteVisitor();
Parameters params = parameters(part("version", version));
libraryAdapter.accept(deleteVisitor, repo, params);
Bundle bundle = (Bundle) jsonParser.parseResource(
DeleteVisitorTests.class.getResourceAsStream("Bundle-small-approved-draft.json"));
Bundle tsBundle = repo.transaction(bundle);
String id = tsBundle.getEntry().get(0).getResponse().getLocation();
String version = "1.2.3-draft";
Library library = repo.read(Library.class, new IdType(id)).copy();
ILibraryAdapter libraryAdapter = new AdapterFactory().createLibrary(library);
IKnowledgeArtifactVisitor deleteVisitor = new DeleteVisitor();
Parameters params = parameters(part("version", version));

fail("Trying to withdraw a draft Library should throw an Exception");
} catch (PreconditionFailedException e) {
assert (e.getMessage().contains("Cannot delete an artifact that is not in retired status"));
}
var exception = assertThrows(
PreconditionFailedException.class, () -> libraryAdapter.accept(deleteVisitor, repo, params));
assertTrue(exception.getMessage().contains("Cannot delete an artifact that is not in retired status"));
}
}
Loading

0 comments on commit c6e417f

Please sign in to comment.