Add remaining cases to test
@@ -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 matchResourceLinksLongCompareToString() {
- ResourceTable source = new ResourceTable();
- source.setResourceType("Patient");
-
- ResourceTable target = new ResourceTable();
- target.setResourceType("Organization");
+ public void matchResourceLinksStringCompareToString() {
+ ReferenceParam referenceParam = getReferenceParam(STRING_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);
+ boolean result = myParams.matchResourceLinks("Patient", "organization", referenceParam, "organization");
+ assertTrue(result);
+ }
+
+ @Test
+ public void matchResourceLinksLongCompareToString() {
+ ReferenceParam referenceParam = getReferenceParam(LONG_ID);
+ ForcedId forcedid = new ForcedId();
+ forcedid.setForcedId(STRING_ID);
+ myTarget.setForcedId(forcedid);
- 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;
+ }
+
}
