Skip to content

Commit

Permalink
moar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Stevens committed Dec 24, 2024
1 parent e5ef9a7 commit 6067641
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ private IBaseParameters replaceReferencesPreferSync(
.execute(() -> getAllPidsWithLimit(theReplaceReferencesRequest));

if (accumulator.isTruncated()) {
throw new PreconditionFailedException("Number of resources with references to " +
theReplaceReferencesRequest.sourceId +
" exceeds the resource-limit " +
theReplaceReferencesRequest.resourceLimit +
". Submit the request asynchronsly by adding the HTTP Header 'Prefer: respond-async'.");
throw new PreconditionFailedException(
"Number of resources with references to " + theReplaceReferencesRequest.sourceId
+ " exceeds the resource-limit "
+ theReplaceReferencesRequest.resourceLimit
+ ". Submit the request asynchronsly by adding the HTTP Header 'Prefer: respond-async'.");
}

Bundle result = myReplaceReferencesPatchBundleSvc.patchReferencingResources(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ca.uhn.fhir.rest.gclient.IOperationUntypedWithInput;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import jakarta.annotation.Nonnull;
import jakarta.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -226,6 +227,20 @@ public void testMerge(boolean withDelete, boolean withInputResultPatient, boolea
}
}

@Test
void testMerge_smallResourceLimit() {
ReplaceReferencesTestHelper.PatientMergeInputParameters inParams = new ReplaceReferencesTestHelper.PatientMergeInputParameters();
myTestHelper.setSourceAndTarget(inParams);

inParams.resourceLimit = 5;
Parameters inParameters = inParams.asParametersResource();

// exec
assertThatThrownBy(() -> callMergeOperation(inParameters, false))
.isInstanceOf(PreconditionFailedException.class)
.satisfies(ex -> assertThat(extractFailureMessage((BaseServerResponseException) ex)).isEqualTo("Number of resources with references to "+ myTestHelper.getSourcePatientId() + " exceeds the resource-limit 5. Submit the request asynchronsly by adding the HTTP Header 'Prefer: respond-async'."));
}

@Test
void testMerge_SourceResourceCannotBeDeletedBecauseAnotherResourceReferencingSourceWasAddedWhileJobIsRunning_JobFails() {
ReplaceReferencesTestHelper.PatientMergeInputParameters inParams = new ReplaceReferencesTestHelper.PatientMergeInputParameters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ public class ProviderConstants {
* exceeds this amount, the operation will fail with 412 Precondition Failed.
*/

// FIXME KHS change tests and var names
public static final String OPERATION_REPLACE_REFERENCES_RESOURCE_LIMIT = "resource-limit";

/**
Expand Down

0 comments on commit 6067641

Please sign in to comment.