Add tests
This commit is contained in:
parent
97e6073665
commit
febae3f07d
|
@ -204,10 +204,17 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
|
|||
if (isBlank(typeString)) {
|
||||
throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource type - " + nextValue.getReference().getValue());
|
||||
}
|
||||
Class<? extends IBaseResource> type = getContext().getResourceDefinition(typeString).getImplementingClass();
|
||||
RuntimeResourceDefinition resourceDefinition;
|
||||
try {
|
||||
resourceDefinition = getContext().getResourceDefinition(typeString);
|
||||
} catch (DataFormatException e) {
|
||||
throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Resource type is unknown or not supported on this server - " + nextValue.getReference().getValue());
|
||||
}
|
||||
|
||||
Class<? extends IBaseResource> type = resourceDefinition.getImplementingClass();
|
||||
String id = nextValue.getReference().getIdPart();
|
||||
if (StringUtils.isBlank(id)) {
|
||||
continue;
|
||||
throw new InvalidRequestException("Invalid resource reference found at path[" + nextPathsUnsplit + "] - Does not contain resource ID - " + nextValue.getReference().getValue());
|
||||
}
|
||||
|
||||
IFhirResourceDao<?> dao = getDao(type);
|
||||
|
@ -542,43 +549,6 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
|
|||
return true;
|
||||
}
|
||||
|
||||
protected List<IBaseResource> loadResourcesById(Set<? extends IIdType> theIncludePids) {
|
||||
Set<Long> pids = new HashSet<Long>();
|
||||
for (IIdType next : theIncludePids) {
|
||||
if (next.isIdPartValidLong()) {
|
||||
pids.add(next.getIdPartAsLong());
|
||||
} else {
|
||||
try {
|
||||
pids.add(translateForcedIdToPid(next));
|
||||
} catch (ResourceNotFoundException e) {
|
||||
ourLog.warn("Failed to translate forced ID [{}] to PID", next.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pids.isEmpty()) {
|
||||
return new ArrayList<IBaseResource>();
|
||||
}
|
||||
|
||||
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
|
||||
CriteriaQuery<ResourceTable> cq = builder.createQuery(ResourceTable.class);
|
||||
Root<ResourceTable> from = cq.from(ResourceTable.class);
|
||||
// cq.where(builder.equal(from.get("myResourceType"),
|
||||
// getContext().getResourceDefinition(myResourceType).getName()));
|
||||
// if (theIncludePids != null) {
|
||||
cq.where(from.get("myId").in(pids));
|
||||
// }
|
||||
TypedQuery<ResourceTable> q = myEntityManager.createQuery(cq);
|
||||
|
||||
ArrayList<IBaseResource> retVal = new ArrayList<IBaseResource>();
|
||||
for (ResourceTable next : q.getResultList()) {
|
||||
IResource resource = (IResource) toResource(next);
|
||||
retVal.add(resource);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
protected void notifyWriteCompleted() {
|
||||
for (IDaoListener next : myListeners) {
|
||||
next.writeCompleted();
|
||||
|
|
|
@ -99,9 +99,6 @@ import ca.uhn.fhir.model.api.TagList;
|
|||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||
import ca.uhn.fhir.model.base.composite.BaseIdentifierDt;
|
||||
import ca.uhn.fhir.model.base.composite.BaseQuantityDt;
|
||||
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
|
||||
import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
|
||||
import ca.uhn.fhir.model.dstu.resource.OperationOutcome.Issue;
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.model.dstu2.composite.CodingDt;
|
||||
import ca.uhn.fhir.model.dstu2.composite.MetaDt;
|
||||
|
@ -958,18 +955,6 @@ public abstract class BaseHapiFhirResourceDao<T extends IResource> extends BaseH
|
|||
return new HashSet<Long>(q.getResultList());
|
||||
}
|
||||
|
||||
private List<IBaseResource> addResourcesAsIncludesById(List<IBaseResource> theListToPopulate, Set<? extends IIdType> includePids, List<IBaseResource> resources) {
|
||||
if (!includePids.isEmpty()) {
|
||||
ourLog.info("Loading {} included resources", includePids.size());
|
||||
resources = loadResourcesById(includePids);
|
||||
for (IBaseResource next : resources) {
|
||||
ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IResource) next, BundleEntrySearchModeEnum.INCLUDE);
|
||||
}
|
||||
theListToPopulate.addAll(resources);
|
||||
}
|
||||
return resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTag(IIdType theId, TagTypeEnum theTagType, String theScheme, String theTerm, String theLabel) {
|
||||
StopWatch w = new StopWatch();
|
||||
|
|
|
@ -306,6 +306,50 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithInvalidReferenceNoId() {
|
||||
Patient p = new Patient();
|
||||
p.addName().addFamily("Hello");
|
||||
p.getManagingOrganization().setReference("Organization/");
|
||||
|
||||
try {
|
||||
myPatientDao.create(p);
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertThat(e.getMessage(), containsString("Does not contain resource ID"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithReferenceBadType() {
|
||||
Patient p = new Patient();
|
||||
p.addName().addFamily("Hello");
|
||||
p.getManagingOrganization().setReference("Blah/123");
|
||||
|
||||
try {
|
||||
myPatientDao.create(p);
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertThat(e.getMessage(), containsString("Does not contain resource ID"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithReferenceNoType() {
|
||||
Patient p = new Patient();
|
||||
p.addName().addFamily("Hello");
|
||||
p.getManagingOrganization().setReference("123");
|
||||
|
||||
try {
|
||||
myPatientDao.create(p);
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertThat(e.getMessage(), containsString("Does not contain resource type"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateWithIfNoneExistBasic() {
|
||||
String methodName = "testCreateWithIfNoneExistBasic";
|
||||
|
|
Loading…
Reference in New Issue