Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed Nov 15, 2024
1 parent 6f0c23b commit fcd59f6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public IResourceLookup<JpaPid> resolveResourceIdentity(
resolveResourceIdentities(theRequestPartitionId, ids, theExcludeDeleted);

// We only pass 1 input in so only 0..1 will come back
if (outcome.isEmpty()) {
if (!outcome.containsKey(id)) {
throw new ResourceNotFoundException(Msg.code(2001) + "Resource " + id + " is not known");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,5 @@ public void testResolveResourcePersistentIds_mapDefaultFunctionality(){
assertEquals(2L, result.get("B").getId());
assertEquals(3L, result.get("C").getId());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -439,11 +441,19 @@ public void testCreateWithIdFails() {
}
}

@Test
public void testCreateWithIllegalReference() {
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testCreateWithIllegalReference_WrongTypeForId(boolean theClientAssignedId) {
IIdType id1;

Observation o1 = new Observation();
o1.getCode().addCoding().setSystem("foo").setCode("testChoiceParam01");
IIdType id1 = myObservationDao.create(o1, mySrd).getId().toUnqualifiedVersionless();
if (theClientAssignedId) {
o1.setId("A");
id1 = myObservationDao.update(o1, mySrd).getId().toUnqualifiedVersionless();
} else {
id1 = myObservationDao.create(o1, mySrd).getId().toUnqualifiedVersionless();
}

try {
Patient p = new Patient();
Expand All @@ -459,16 +469,24 @@ public void testCreateWithIllegalReference() {
p.getManagingOrganization().setReference(new IdDt("Organization", id1.getIdPart()));
myPatientDao.create(p, mySrd);
fail("");
} catch (UnprocessableEntityException e) {
assertEquals(Msg.code(1095) + "Resource contains reference to unknown resource ID Organization/" + id1.getIdPart(), e.getMessage());
} catch (InvalidRequestException e) {
assertEquals(Msg.code(1094) + "Resource Organization/" + id1.getIdPart() + " not found, specified in path: Patient.managingOrganization", e.getMessage());
}
}

// Now with a forced ID
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testCreateWithIllegalReference_InvalidTypeForElement(boolean theClientAssignedId) {

o1 = new Observation();
o1.setId("testCreateWithIllegalReference");
Observation o1 = new Observation();
o1.getCode().addCoding().setSystem("foo").setCode("testChoiceParam01");
id1 = myObservationDao.update(o1, mySrd).getId().toUnqualifiedVersionless();
IIdType id1;
if (theClientAssignedId) {
o1.setId("testCreateWithIllegalReference");
id1 = myObservationDao.update(o1, mySrd).getId().toUnqualifiedVersionless();
} else {
id1 = myObservationDao.create(o1, mySrd).getId().toUnqualifiedVersionless();
}

try {
Patient p = new Patient();
Expand All @@ -479,15 +497,6 @@ public void testCreateWithIllegalReference() {
assertEquals(Msg.code(931) + "Invalid reference found at path 'Patient.managingOrganization'. Resource type 'Observation' is not valid for this path", e.getMessage());
}

try {
Patient p = new Patient();
p.getManagingOrganization().setReference(new IdDt("Organization", id1.getIdPart()));
myPatientDao.create(p, mySrd);
fail("");
} catch (InvalidRequestException e) {
assertEquals(Msg.code(1094) + "Resource Organization/testCreateWithIllegalReference not found, specified in path: Patient.managingOrganization", e.getMessage());
}

}

@Test
Expand Down Expand Up @@ -677,8 +686,8 @@ public void testDeleteResource() {
}

/**
* See #773
*/
* See #773
*/
@Test
public void testDeleteResourceWithOutboundDeletedResources() {
myStorageSettings.setEnforceReferentialIntegrityOnDelete(false);
Expand Down Expand Up @@ -1387,8 +1396,8 @@ public void testInstanceMetaOperations() {
}

/**
* See #196
*/
* See #196
*/
@Test
public void testInvalidChainNames() {
ReferenceParam param = null;
Expand Down

0 comments on commit fcd59f6

Please sign in to comment.