Skip to content

Commit

Permalink
[APHL-469] tests for count, offset
Browse files Browse the repository at this point in the history
  • Loading branch information
taha.attari@smilecdr.com committed Aug 21, 2023
1 parent c341cb4 commit 0dc2315
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -610,20 +610,6 @@ public Bundle createPackageBundle(IdType id, FhirDal fhirDal, List<String> capab
} else {
recursivePackage(resource, packagedBundle, fhirDal, capability, include, canonicalVersion, checkCanonicalVersion, forceCanonicalVersion);
List<BundleEntryComponent> included = findUnsupportedInclude(packagedBundle.getEntry(),include);
// if the root artifact is not in the bundle
// and include contains "artifact" then add
// the root artifact to the bundle
if (include != null
&& include.contains("artifact")
&& !included.stream()
.map((entry) -> ((MetadataResource) entry.getResource()))
.anyMatch((includedResource) -> includedResource.getUrl().equals(resource.getUrl()) && includedResource.getVersion().equals(resource.getVersion()))) {
BundleEntryComponent entry = createEntry(resource);
// TODO: remove history from request.url
entry.getRequest().setMethod(HTTPVerb.POST);
entry.getRequest().setIfNoneExist("url="+resource.getUrl()+"&version="+resource.getVersion());
included.add(0, entry);
}
packagedBundle.setEntry(included);
}
packagedBundle.setTotal(packagedBundle.getEntry().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;

import org.hl7.fhir.r4.model.ActivityDefinition;
Expand All @@ -25,6 +26,7 @@
import org.hl7.fhir.r4.model.CanonicalType;
import org.hl7.fhir.r4.model.DateType;
import org.hl7.fhir.r4.model.Enumerations;
import org.hl7.fhir.r4.model.IntegerType;
import org.hl7.fhir.r4.model.Library;
import org.hl7.fhir.r4.model.Measure;
import org.hl7.fhir.r4.model.MetadataResource;
Expand Down Expand Up @@ -651,7 +653,7 @@ void packageOperation_should_fail_non_matching_capability() {
PreconditionFailedException maybeException = null;
try {
getClient().operation()
.onInstance("Library/SpecificationLibrary")
.onInstance(specificationLibReference)
.named("$package")
.withParameters(params)
.returnResourceType(Bundle.class)
Expand All @@ -667,7 +669,7 @@ void packageOperation_should_fail_non_matching_capability() {
part("capability", "executable")
);
Bundle packaged = getClient().operation()
.onInstance("Library/SpecificationLibrary")
.onInstance(specificationLibReference)
.named("$package")
.withParameters(allParams)
.returnResourceType(Bundle.class)
Expand All @@ -685,7 +687,7 @@ void packageOperation_should_apply_check_force_canonicalVersions() {
part("canonicalVersion", new CanonicalType("http://to-add-missing-version/ValueSet/dxtc|" + versionToUpdateTo))
);
Bundle updatedCanonicalVersionPackage = getClient().operation()
.onInstance("Library/SpecificationLibrary")
.onInstance(specificationLibReference)
.named("$package")
.withParameters(params)
.returnResourceType(Bundle.class)
Expand All @@ -705,7 +707,7 @@ void packageOperation_should_apply_check_force_canonicalVersions() {
UnprocessableEntityException checkCanonicalThrewError = null;
try {
getClient().operation()
.onInstance("Library/SpecificationLibrary")
.onInstance(specificationLibReference)
.named("$package")
.withParameters(params)
.returnResourceType(Bundle.class)
Expand All @@ -718,7 +720,7 @@ void packageOperation_should_apply_check_force_canonicalVersions() {
part("checkCanonicalVersion", new CanonicalType("http://to-check-version/Library/SpecificationLibrary|" + correctCheckVersion))
);
Bundle noErrorCheckCanonicalPackage = getClient().operation()
.onInstance("Library/SpecificationLibrary")
.onInstance(specificationLibReference)
.named("$package")
.withParameters(params)
.returnResourceType(Bundle.class)
Expand All @@ -734,7 +736,7 @@ void packageOperation_should_apply_check_force_canonicalVersions() {
part("forceCanonicalVersion", new CanonicalType("http://to-force-version/Library/rctc|" + versionToForceTo))
);
Bundle forcedVersionPackage = getClient().operation()
.onInstance("Library/SpecificationLibrary")
.onInstance(specificationLibReference)
.named("$package")
.withParameters(params)
.returnResourceType(Bundle.class)
Expand All @@ -749,9 +751,88 @@ void packageOperation_should_apply_check_force_canonicalVersions() {
}
@Test
void packageOperation_should_respect_count_offset() {
loadTransaction("ersd-small-active-bundle.json");
Parameters countZeroParams = parameters(
part("count", new IntegerType(0))
);
Bundle countZeroBundle = getClient().operation()
.onInstance(specificationLibReference)
.named("$package")
.withParameters(countZeroParams)
.returnResourceType(Bundle.class)
.execute();
// when count = 0 only show the total
assertTrue(countZeroBundle.getEntry().size() == 0);
assertTrue(countZeroBundle.getTotal() == 5);
Parameters count2Params = parameters(
part("count", new IntegerType(2))
);
Bundle count2Bundle = getClient().operation()
.onInstance(specificationLibReference)
.named("$package")
.withParameters(count2Params)
.returnResourceType(Bundle.class)
.execute();
assertTrue(count2Bundle.getEntry().size() == 2);
Parameters count2Offset2Params = parameters(
part("count", new IntegerType(2)),
part("offset", new IntegerType(2))
);
Bundle count2Offset2Bundle = getClient().operation()
.onInstance(specificationLibReference)
.named("$package")
.withParameters(count2Offset2Params)
.returnResourceType(Bundle.class)
.execute();
assertTrue(count2Offset2Bundle.getEntry().size() == 2);
Parameters offset4Params = parameters(
part("offset", new IntegerType(4))
);
Bundle offset4Bundle = getClient().operation()
.onInstance(specificationLibReference)
.named("$package")
.withParameters(offset4Params)
.returnResourceType(Bundle.class)
.execute();
assertTrue(offset4Bundle.getEntry().size() == (countZeroBundle.getTotal() - 4));
Parameters offsetMaxParams = parameters(
part("offset", new IntegerType(countZeroBundle.getTotal()))
);
Bundle offsetMaxBundle = getClient().operation()
.onInstance(specificationLibReference)
.named("$package")
.withParameters(offsetMaxParams)
.returnResourceType(Bundle.class)
.execute();
assertTrue(offsetMaxBundle.getEntry().size() == 0);
Parameters offsetMaxRandomCountParams = parameters(
part("offset", new IntegerType(countZeroBundle.getTotal())),
part("count", new IntegerType(ThreadLocalRandom.current().nextInt(3, 20)))
);
Bundle offsetMaxRandomCountBundle = getClient().operation()
.onInstance(specificationLibReference)
.named("$package")
.withParameters(offsetMaxRandomCountParams)
.returnResourceType(Bundle.class)
.execute();
assertTrue(offsetMaxRandomCountBundle.getEntry().size() == 0);
}
@Test
void packageOperation_should_conditionally_create() {
loadTransaction("ersd-small-active-bundle.json");
Parameters emptyParams = parameters();
Bundle packagedBundle = getClient().operation()
.onInstance(specificationLibReference)
.named("$package")
.withParameters(emptyParams)
.returnResourceType(Bundle.class)
.execute();
for (BundleEntryComponent component : packagedBundle.getEntry()) {
String ifNoneExist = component.getRequest().getIfNoneExist();
String url = ((MetadataResource) component.getResource()).getUrl();
String version = ((MetadataResource) component.getResource()).getVersion();
assertTrue(ifNoneExist.equals("url="+url+"&version="+version));
}
}
@Test
void packageOperation_should_respect_include() {
Expand Down Expand Up @@ -784,7 +865,7 @@ void packageOperation_should_respect_include() {
part("include", includedTypeURLs.getKey())
);
Bundle packaged = getClient().operation()
.onInstance("Library/SpecificationLibrary")
.onInstance(specificationLibReference)
.named("$package")
.withParameters(params)
.returnResourceType(Bundle.class)
Expand Down

0 comments on commit 0dc2315

Please sign in to comment.