Add remaining cases to test

This commit is contained in:
Ken Stevens 2019-08-06 15:25:22 -04:00
parent c11d719957
commit 15e549f345
1 changed files with 50 additions and 25 deletions

View File

@ -6,6 +6,7 @@ import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.param.ReferenceParam;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.Before;
import org.junit.Test;
import java.util.Date;
@ -14,44 +15,68 @@ import static org.junit.Assert.*;
public class ResourceIndexedSearchParamsTest {
@Test
public void matchResourceLinksStringCompareToLong() {
public static final String STRING_ID = "StringId";
public static final String LONG_ID = "123";
private ResourceIndexedSearchParams myParams;
private ResourceTable myTarget;
@Before
public void before() {
ResourceTable source = new ResourceTable();
source.setResourceType("Patient");
ResourceTable target = new ResourceTable();
target.setResourceType("Organization");
target.setId(123L);
myTarget = new ResourceTable();
myTarget.setResourceType("Organization");
ResourceIndexedSearchParams params = new ResourceIndexedSearchParams(source);
ResourceLink link = new ResourceLink("organization", source, target, new Date());
params.getResourceLinks().add(link);
myParams = new ResourceIndexedSearchParams(source);
ResourceLink link = new ResourceLink("organization", source, myTarget, new Date());
myParams.getResourceLinks().add(link);
}
ReferenceParam referenceParam = new ReferenceParam();
referenceParam.setValue("StringId");
boolean result = params.matchResourceLinks("Patient", "organization", referenceParam, "organization");
@Test
public void matchResourceLinksStringCompareToLong() {
ReferenceParam referenceParam = getReferenceParam(STRING_ID);
myTarget.setId(123L);
boolean result = myParams.matchResourceLinks("Patient", "organization", referenceParam, "organization");
assertFalse(result);
}
@Test
public void matchResourceLinksStringCompareToString() {
ReferenceParam referenceParam = getReferenceParam(STRING_ID);
ForcedId forcedid = new ForcedId();
forcedid.setForcedId(STRING_ID);
myTarget.setForcedId(forcedid);
boolean result = myParams.matchResourceLinks("Patient", "organization", referenceParam, "organization");
assertTrue(result);
}
@Test
public void matchResourceLinksLongCompareToString() {
ResourceTable source = new ResourceTable();
source.setResourceType("Patient");
ResourceTable target = new ResourceTable();
target.setResourceType("Organization");
ReferenceParam referenceParam = getReferenceParam(LONG_ID);
ForcedId forcedid = new ForcedId();
forcedid.setForcedId("StringId");
target.setForcedId(forcedid);
forcedid.setForcedId(STRING_ID);
myTarget.setForcedId(forcedid);
ResourceIndexedSearchParams params = new ResourceIndexedSearchParams(source);
ResourceLink link = new ResourceLink("organization", source, target, new Date());
params.getResourceLinks().add(link);
ReferenceParam referenceParam = new ReferenceParam();
referenceParam.setValue("123");
boolean result = params.matchResourceLinks("Patient", "organization", referenceParam, "organization");
boolean result = myParams.matchResourceLinks("Patient", "organization", referenceParam, "organization");
assertFalse(result);
}
@Test
public void matchResourceLinksLongCompareToLong() {
ReferenceParam referenceParam = getReferenceParam(LONG_ID);
myTarget.setId(123L);
boolean result = myParams.matchResourceLinks("Patient", "organization", referenceParam, "organization");
assertTrue(result);
}
private ReferenceParam getReferenceParam(String theId) {
ReferenceParam retval = new ReferenceParam();
retval.setValue(theId);
return retval;
}
}