From 2436f748aaae00058a49ed98d4c6587b4e94056a Mon Sep 17 00:00:00 2001 From: Jimmy Deng Date: Wed, 22 Sep 2021 14:38:53 -0400 Subject: [PATCH] fix test --- .../jpa/dao/expunge/DeleteExpungeDaoTest.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/DeleteExpungeDaoTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/DeleteExpungeDaoTest.java index bb28b8dd050..ba7712066cb 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/DeleteExpungeDaoTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/DeleteExpungeDaoTest.java @@ -17,9 +17,11 @@ import org.hl7.fhir.r4.model.OperationOutcome; import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Reference; +import org.hl7.fhir.r5.model.StructureDefinition; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.stubbing.Answer; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.beans.factory.annotation.Autowired; @@ -30,6 +32,8 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.nullable; +import static org.mockito.Mockito.when; class DeleteExpungeDaoTest extends BaseJpaR4Test { @Autowired @@ -66,14 +70,29 @@ class DeleteExpungeDaoTest extends BaseJpaR4Test { IIdType patientId = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); // Try to delete _cascade and _expunge on the organization - BaseServerResponseException e = assertThrows(BaseServerResponseException.class, () -> {myOrganizationDao - .deleteByUrl("Organization?" + "_cascade=delete&" + JpaConstants.PARAM_DELETE_EXPUNGE + "=true", mySrd);}); + BaseServerResponseException e = assertThrows(BaseServerResponseException.class, () -> { + myOrganizationDao + .deleteByUrl("Organization?" + "_cascade=delete&" + JpaConstants.PARAM_DELETE_EXPUNGE + "=true", mySrd); + }); + + // Get not implemented HTTP 400 error + assertEquals(Constants.STATUS_HTTP_400_BAD_REQUEST, e.getStatusCode()); + assertEquals("_expunge cannot be used with _cascade", e.getMessage()); + + + // Try to delete with header 'X-Cascade' = delete + when(mySrd.getHeader(Constants.HEADER_CASCADE)).thenReturn(Constants.CASCADE_DELETE); + e = assertThrows(BaseServerResponseException.class, () -> { + myOrganizationDao + .deleteByUrl("Organization?" + JpaConstants.PARAM_DELETE_EXPUNGE + "=true", mySrd); + }); // Get not implemented HTTP 400 error assertEquals(Constants.STATUS_HTTP_400_BAD_REQUEST, e.getStatusCode()); assertEquals("_expunge cannot be used with _cascade", e.getMessage()); } + @Test public void testDeleteExpungeThrowExceptionIfForeignKeyLinksExists() { // setup