Skip to content

Commit

Permalink
Merge pull request #227 from jaboehri/add-integration-test-for-questi…
Browse files Browse the repository at this point in the history
…onnaire-and-questionnaire-response-creation-as-bundle

Add integration test for questionnaire and questionnaire response creation as bundle
  • Loading branch information
hhund authored Sep 9, 2024
2 parents 32241f1 + a5aab93 commit d2d75ab
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package dev.dsf.fhir.integration;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.Optional;
import java.util.UUID;

import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Questionnaire;
import org.hl7.fhir.r4.model.QuestionnaireResponse;
import org.hl7.fhir.r4.model.ResourceType;
import org.hl7.fhir.r4.model.StringType;
import org.junit.Test;

Expand Down Expand Up @@ -146,4 +150,40 @@ public void testQuestionnaireResponseValidatesAgainstQuestionnaireProfileVersion
assertNotNull(updatedQr.getIdElement().getIdPart());
assertNotNull(updatedQr.getIdElement().getVersionIdPart());
}

@Test
public void testPostQuestionnaireAndCorrespondingQuestionnaireResponseInTransactionBundleOrderQuestionnaireBeforeQuestionnaireResponse()
throws Exception
{
Questionnaire questionnaire = createQuestionnaireProfileVersion150("1.5.3");
QuestionnaireResponse questionnaireResponse = createQuestionnaireResponse("1.5.3");

Bundle bundle = new Bundle();
bundle.setType(Bundle.BundleType.TRANSACTION);
bundle.addEntry().setResource(questionnaire).setFullUrl("urn:uuid:" + UUID.randomUUID().toString()).getRequest()
.setMethod(Bundle.HTTPVerb.POST).setUrl(ResourceType.Questionnaire.name());
bundle.addEntry().setResource(questionnaireResponse).setFullUrl("urn:uuid:" + UUID.randomUUID().toString())
.getRequest().setMethod(Bundle.HTTPVerb.POST).setUrl(ResourceType.QuestionnaireResponse.name());

assertTrue(getWebserviceClient().postBundle(bundle).getEntry().stream()
.allMatch(entry -> entry.getResponse().getStatus().equals("201 Created")));
}

@Test
public void testPostQuestionnaireAndCorrespondingQuestionnaireResponseInTransactionBundleOrderQuestionnaireResponseBeforeQuestionnaire()
throws Exception
{
Questionnaire questionnaire = createQuestionnaireProfileVersion150("1.5.3");
QuestionnaireResponse questionnaireResponse = createQuestionnaireResponse("1.5.3");

Bundle bundle = new Bundle();
bundle.setType(Bundle.BundleType.TRANSACTION);
bundle.addEntry().setResource(questionnaireResponse).setFullUrl("urn:uuid:" + UUID.randomUUID().toString())
.getRequest().setMethod(Bundle.HTTPVerb.POST).setUrl(ResourceType.QuestionnaireResponse.name());
bundle.addEntry().setResource(questionnaire).setFullUrl("urn:uuid:" + UUID.randomUUID().toString()).getRequest()
.setMethod(Bundle.HTTPVerb.POST).setUrl(ResourceType.Questionnaire.name());

assertTrue(getWebserviceClient().postBundle(bundle).getEntry().stream()
.allMatch(entry -> entry.getResponse().getStatus().equals("201 Created")));
}
}

0 comments on commit d2d75ab

Please sign in to comment.