Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Stream;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Bundle;
Expand All @@ -27,10 +28,12 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.opencds.cqf.fhir.test.Resources;
import org.opencds.cqf.fhir.utility.Ids;
import org.opencds.cqf.fhir.utility.search.Searches;
import org.opencds.cqf.fhir.utility.search.Searches.SearchBuilder;

class IgRepositoryTransactionTest {

private static final Map<String, String> HEADERS_EMPTY = Collections.emptyMap();

private static IgRepository repository;

@TempDir
Expand Down Expand Up @@ -124,8 +127,10 @@ void transactionPost_createsResourceVisibleInReadAndSearch(ResourceFixture fixtu
var read = repository.read(fixture.resourceClass, Ids.newId(fixture.resourceClass, id));
assertEquals(id, read.getIdElement().getIdPart());

var searchResult =
repository.search(Bundle.class, fixture.resourceClass, Searches.byUrl(fixture.urlPrefix + id));
var searchResult = repository.search(
Bundle.class,
fixture.resourceClass,
new SearchBuilder().withUriParam("url", fixture.urlPrefix + id).build());
assertEquals(1, searchResult.getEntry().size());
}

Expand Down Expand Up @@ -195,12 +200,20 @@ void transactionPut_overwritesExistingResource(ResourceFixture fixture) {
.setUrl(fixture.resourceType + "/" + id);
repository.transaction(putBundle, Collections.emptyMap());

var searchV1 =
repository.search(Bundle.class, fixture.resourceClass, Searches.byUrl(fixture.urlPrefix + id + "-v1"));
var searchV1 = repository.search(
Bundle.class,
fixture.resourceClass,
new SearchBuilder()
.withUriParam("url", fixture.urlPrefix + id + "-v1")
.build());
assertEquals(0, searchV1.getEntry().size());

var searchV2 =
repository.search(Bundle.class, fixture.resourceClass, Searches.byUrl(fixture.urlPrefix + id + "-v2"));
var searchV2 = repository.search(
Bundle.class,
fixture.resourceClass,
new SearchBuilder()
.withUriParam("url", fixture.urlPrefix + id + "-v2")
.build());
assertEquals(1, searchV2.getEntry().size());
}

Expand Down Expand Up @@ -229,8 +242,10 @@ void transactionDelete_removesResource(ResourceFixture fixture) {
assertNotNull(result);
assertEquals(1, result.getEntry().size());

var searchResult =
repository.search(Bundle.class, fixture.resourceClass, Searches.byUrl(fixture.urlPrefix + id));
var searchResult = repository.search(
Bundle.class,
fixture.resourceClass,
new SearchBuilder().withUriParam("url", fixture.urlPrefix + id).build());
assertEquals(0, searchResult.getEntry().size());
}

Expand All @@ -244,8 +259,7 @@ void transactionDelete_throwsWhenNotFound(ResourceFixture fixture) {
.setMethod(Bundle.HTTPVerb.DELETE)
.setUrl(fixture.resourceType + "/does-not-exist-" + fixture.label);

assertThrows(
ResourceNotFoundException.class, () -> repository.transaction(deleteBundle, Collections.emptyMap()));
assertThrows(ResourceNotFoundException.class, () -> repository.transaction(deleteBundle, HEADERS_EMPTY));
}

@ParameterizedTest(name = "{0}")
Expand Down Expand Up @@ -301,11 +315,17 @@ void transactionMixed_postThenPutThenDelete(ResourceFixture fixture) {
var searchRes1 = repository.search(
Bundle.class,
fixture.resourceClass,
Searches.byUrl(fixture.urlPrefix + "tx-mixed-1-" + suffix + "-updated"));
new SearchBuilder()
.withUriParam("url", fixture.urlPrefix + "tx-mixed-1-" + suffix + "-updated")
.build());
assertEquals(1, searchRes1.getEntry().size());

var searchRes2 = repository.search(
Bundle.class, fixture.resourceClass, Searches.byUrl(fixture.urlPrefix + "tx-mixed-2-" + suffix));
Bundle.class,
fixture.resourceClass,
new SearchBuilder()
.withUriParam("url", fixture.urlPrefix + "tx-mixed-2-" + suffix)
.build());
assertEquals(0, searchRes2.getEntry().size());

var readRes3 = repository.read(fixture.resourceClass, Ids.newId(fixture.resourceClass, "tx-mixed-3-" + suffix));
Expand All @@ -317,7 +337,6 @@ void transactionUnsupportedMethod_throws() {
var txBundle = new Bundle().setType(Bundle.BundleType.TRANSACTION);
txBundle.addEntry().getRequest().setMethod(Bundle.HTTPVerb.GET).setUrl("Library/123");

assertThrows(
NotImplementedOperationException.class, () -> repository.transaction(txBundle, Collections.emptyMap()));
assertThrows(NotImplementedOperationException.class, () -> repository.transaction(txBundle, HEADERS_EMPTY));
}
}
Loading