Skip to content

Commit

Permalink
Merge pull request #2552 from IBM/issue-1922b
Browse files Browse the repository at this point in the history
Issue #1922 - don't run reindex tests during search tests
  • Loading branch information
michaelwschroeder authored Jun 25, 2021
2 parents 7c992d1 + 6b62c97 commit 3cf996c
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2017,2019
* (C) Copyright IBM Corp. 2017, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -28,6 +28,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

import javax.ws.rs.client.Entity;
Expand Down Expand Up @@ -56,6 +57,14 @@
import com.ibm.fhir.model.util.JsonSupport;

public class SortingTest extends FHIRServerTestBase {
private static final String TAG_SYSTEM = "http://ibm.com/fhir/sort-test";
private static final String TAG_CODE = "sort-test-" + UUID.randomUUID().toString();
private static final String TAG_DISPLAY = TAG_CODE;
public static final Coding TAG = Coding.builder()
.system(Uri.of(TAG_SYSTEM))
.code(Code.of(TAG_CODE))
.display(string(TAG_DISPLAY))
.build();

private static final boolean DEBUG_SEARCH = false;

Expand All @@ -78,6 +87,7 @@ public void testCreatePatient1() throws Exception {

// Build a new Patient and then call the 'create' API.
Patient patient = TestUtil.readLocalResource("Patient_JohnDoe.json");
patient = FHIRUtil.addTag(patient, TAG);

patient = patient.toBuilder().gender(AdministrativeGender.MALE).build();
Entity<Patient> entity = Entity.entity(patient, FHIRMediaType.APPLICATION_FHIR_JSON);
Expand All @@ -101,6 +111,7 @@ public void testCreatePatient2() throws Exception {

// Build a new Patient and then call the 'create' API.
Patient patient = TestUtil.readLocalResource("Patient_DavidOrtiz.json");
patient = FHIRUtil.addTag(patient, TAG);

patient = patient.toBuilder().gender(AdministrativeGender.MALE).build();
Entity<Patient> entity = Entity.entity(patient, FHIRMediaType.APPLICATION_FHIR_JSON);
Expand All @@ -124,6 +135,7 @@ public void testCreatePatient3() throws Exception {

// Build a new Patient and then call the 'create' API.
Patient patient = TestUtil.readLocalResource("patient-example-a.json");
patient = FHIRUtil.addTag(patient, TAG);

Entity<Patient> entity = Entity.entity(patient, FHIRMediaType.APPLICATION_FHIR_JSON);
Response response = target.path("Patient").request().post(entity, Response.class);
Expand All @@ -146,6 +158,7 @@ public void testCreatePatient4() throws Exception {

// Build a new Patient and then call the 'create' API.
Patient patient = TestUtil.readLocalResource("patient-example-c.json");
patient = FHIRUtil.addTag(patient, TAG);

Entity<Patient> entity = Entity.entity(patient, FHIRMediaType.APPLICATION_FHIR_JSON);
Response response = target.path("Patient").request().post(entity, Response.class);
Expand All @@ -168,6 +181,7 @@ public void testCreatePatient5() throws Exception {

// Build a new Patient and then call the 'create' API.
Patient patient = TestUtil.readLocalResource("patient-example-a1.json");
patient = FHIRUtil.addTag(patient, TAG);

Entity<Patient> entity = Entity.entity(patient, FHIRMediaType.APPLICATION_FHIR_JSON);
Response response = target.path("Patient").request().post(entity, Response.class);
Expand All @@ -189,6 +203,7 @@ public void testCreateObservation1() throws Exception {
WebTarget target = getWebTarget();

Observation observation = TestUtil.buildPatientObservation(patientId, "Observation1.json");
observation = FHIRUtil.addTag(observation, TAG);
Entity<Observation> entity = Entity.entity(observation, FHIRMediaType.APPLICATION_FHIR_JSON);
Response response = target.path("Observation").request().post(entity, Response.class);
assertResponse(response, Response.Status.CREATED.getStatusCode());
Expand All @@ -212,6 +227,7 @@ public void testCreateObservation2() throws Exception {
WebTarget target = getWebTarget();

Observation observation = TestUtil.buildPatientObservation(patientId, "Observation2.json");
observation = FHIRUtil.addTag(observation, TAG);
Entity<Observation> entity = Entity.entity(observation, FHIRMediaType.APPLICATION_FHIR_JSON);
Response response = target.path("Observation").request().post(entity, Response.class);
assertResponse(response, Response.Status.CREATED.getStatusCode());
Expand All @@ -235,6 +251,7 @@ public void testCreateObservation3() throws Exception {
WebTarget target = getWebTarget();

Observation observation = TestUtil.buildPatientObservation(patientId, "Observation3.json");
observation = FHIRUtil.addTag(observation, TAG);
Entity<Observation> entity = Entity.entity(observation, FHIRMediaType.APPLICATION_FHIR_JSON);
Response response = target.path("Observation").request().post(entity, Response.class);
assertResponse(response, Response.Status.CREATED.getStatusCode());
Expand All @@ -258,6 +275,7 @@ public void testCreateObservation5() throws Exception {
WebTarget target = getWebTarget();

Observation observation = TestUtil.buildPatientObservation("1", "Observation5.json");
observation = FHIRUtil.addTag(observation, TAG);
Entity<Observation> entity = Entity.entity(observation, FHIRMediaType.APPLICATION_FHIR_JSON);
Response response = target.path("Observation").request().post(entity, Response.class);
assertResponse(response, Response.Status.CREATED.getStatusCode());
Expand All @@ -276,13 +294,14 @@ public void testCreateObservation5() throws Exception {
TestUtil.assertResourceEquals(observation, responseObservation);
}

// Patient?gender=male&_sort=family
// Patient?gender=male&_sort=family&_tag=TAG_DISPLAY
@Test(groups = { "server-search" }, dependsOnMethods = { "testCreatePatient1",
"testCreatePatient2", "testCreatePatient3", "testCreatePatient4", "testCreatePatient5" })
public void testSortAscending() {
WebTarget target = getWebTarget();
Response response =
target.path("Patient").queryParam("gender", "male").queryParam("_count", "50")
.queryParam("_tag", TAG_CODE)
.queryParam("_sort", "family").request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
assertResponse(response, Response.Status.OK.getStatusCode());
Bundle bundle = response.readEntity(Bundle.class);
Expand Down Expand Up @@ -317,6 +336,7 @@ public void testSortAscending_filter_elements() throws Exception {
WebTarget target = getWebTarget();
Response response =
target.path("Patient").queryParam("gender", "male").queryParam("_count", "50")
.queryParam("_tag", TAG_CODE)
.queryParam("_sort", "family").queryParam("_elements", "gender,name")
.request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
assertResponse(response, Response.Status.OK.getStatusCode());
Expand Down Expand Up @@ -390,6 +410,7 @@ public void testSortDescending() {
WebTarget target = getWebTarget();
Response response =
target.path("Patient").queryParam("gender", "male").queryParam("_count", "50")
.queryParam("_tag", TAG_CODE)
.queryParam("_sort", "-family").request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
assertResponse(response, Response.Status.OK.getStatusCode());
Bundle bundle = response.readEntity(Bundle.class);
Expand Down Expand Up @@ -424,6 +445,7 @@ public void testSortTelecom() {
WebTarget target = getWebTarget();
Response response =
target.path("Patient").queryParam("gender", "male").queryParam("_count", "50")
.queryParam("_tag", TAG_CODE)
.queryParam("_sort", "telecom").request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
assertResponse(response, Response.Status.OK.getStatusCode());
Bundle bundle = response.readEntity(Bundle.class);
Expand Down Expand Up @@ -458,6 +480,7 @@ public void testSortBirthDate() {
WebTarget target = getWebTarget();
Response response =
target.path("Patient").queryParam("gender", "male").queryParam("_count", "50")
.queryParam("_tag", TAG_CODE)
.queryParam("_sort", "-birthdate").request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
assertResponse(response, Response.Status.OK.getStatusCode());
Bundle bundle = response.readEntity(Bundle.class);
Expand All @@ -480,6 +503,7 @@ public void testSortTwoParameters() {
WebTarget target = getWebTarget();
Response response =
target.path("Patient").queryParam("_count", "50")
.queryParam("_tag", TAG_CODE)
.queryParam("_sort", "-family,birthdate").request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
assertResponse(response, Response.Status.OK.getStatusCode());
Bundle bundle = response.readEntity(Bundle.class);
Expand Down Expand Up @@ -534,6 +558,7 @@ public void testSortTwoParametersDescending() {
WebTarget target = getWebTarget();
Response response =
target.path("Patient").queryParam("_count", "50")
.queryParam("_tag", TAG_CODE)
.queryParam("_sort", "-family,-birthdate").request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
assertResponse(response, Response.Status.OK.getStatusCode());
Bundle bundle = response.readEntity(Bundle.class);
Expand Down Expand Up @@ -586,6 +611,7 @@ public void testSortValueQuantityAscending() {
// we do support coding instead of code for the pipe search.
Response response =
target.path("Observation").queryParam("status", "final").queryParam("code", "55284-4")
.queryParam("_tag", TAG_CODE)
.queryParam("_count", "100").queryParam("_sort", "component-value-quantity")
.request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
assertResponse(response, Response.Status.OK.getStatusCode());
Expand Down Expand Up @@ -662,7 +688,7 @@ private void assertTrueNaturalOrdering(List<BigDecimal> sortedList) {
BigDecimal current = iter.next();

if (DEBUG_SEARCH) {
System.out.println(prior + " " + current);
System.out.println(prior + " " + current + " compare=" + (prior.compareTo(current) <= 0));
}

assertTrue(prior.compareTo(current) <= 0);
Expand Down Expand Up @@ -783,6 +809,7 @@ public void testSortAscending_filter_summary() throws Exception {
WebTarget target = getWebTarget();
Response response =
target.path("Patient").queryParam("gender", "male")
.queryParam("_tag", TAG_CODE)
.queryParam("_count", "50").queryParam("_sort", "family")
.queryParam("_summary", "true").request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
assertResponse(response, Response.Status.OK.getStatusCode());
Expand Down Expand Up @@ -857,6 +884,7 @@ public void testSortAscending_filter_elements_summary() throws Exception {
// The _summary=true should be ignored.
Response response =
target.path("Patient").queryParam("gender", "male").queryParam("_count", "50")
.queryParam("_tag", TAG_CODE)
.queryParam("_sort", "family").queryParam("_elements", "gender,name")
.queryParam("_summary", "true")
.request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
Expand Down Expand Up @@ -932,8 +960,9 @@ public void testSortAscending_filter_summary_count() throws Exception {
WebTarget target = getWebTarget();
Response response =
target.path("Patient").queryParam("gender", "male").queryParam("_count", "50")
.queryParam("_sort", "family").queryParam("_summary", "count")
.request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
.queryParam("_tag", TAG_CODE)
.queryParam("_sort", "family").queryParam("_summary", "count")
.request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
assertResponse(response, Response.Status.OK.getStatusCode());
Bundle bundle = response.readEntity(Bundle.class);
assertNotNull(bundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,27 +144,31 @@ public void testReindex_ChangedExpression_Phase2_Search_Type() throws IOExceptio

@Test(groups = { "reindex" }, dependsOnMethods = {"testReindex_ChangedExpression_Phase2_Search_Type"})
public void testReindexWithInstanceExists_Phase2() {
List<Parameter> parameters = new ArrayList<>();
parameters.add(Parameter.builder()
.name(string("resourceCount"))
.value(of(5))
.build());
if (runIt) {
List<Parameter> parameters = new ArrayList<>();
parameters.add(Parameter.builder()
.name(string("resourceCount"))
.value(of(5))
.build());

Parameters.Builder builder = Parameters.builder();
builder.id(UUID.randomUUID().toString());
builder.parameter(parameters);
Parameters ps = builder.build();
Parameters.Builder builder = Parameters.builder();
builder.id(UUID.randomUUID().toString());
builder.parameter(parameters);
Parameters ps = builder.build();

Entity<Parameters> entity = Entity.entity(ps, FHIRMediaType.APPLICATION_FHIR_JSON);
Entity<Parameters> entity = Entity.entity(ps, FHIRMediaType.APPLICATION_FHIR_JSON);

Response r = getWebTarget()
.path("/Patient/REIN-DEX-TEST-1/$reindex")
.request(FHIRMediaType.APPLICATION_FHIR_JSON)
.header("X-FHIR-TENANT-ID", "default")
.header("X-FHIR-DSID", "default")
.post(entity, Response.class);
Response r = getWebTarget()
.path("/Patient/REIN-DEX-TEST-1/$reindex")
.request(FHIRMediaType.APPLICATION_FHIR_JSON)
.header("X-FHIR-TENANT-ID", "default")
.header("X-FHIR-DSID", "default")
.post(entity, Response.class);

assertEquals(r.getStatus(), Status.OK.getStatusCode());
assertEquals(r.getStatus(), Status.OK.getStatusCode());
} else {
System.out.println("Skipping Phase 2 of Reindex Operation Tests");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,41 @@
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.UUID;

import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.ibm.fhir.core.FHIRMediaType;
import com.ibm.fhir.model.resource.Parameters;
import com.ibm.fhir.model.resource.Parameters.Parameter;
import com.ibm.fhir.model.test.TestUtil;
import com.ibm.fhir.server.test.FHIRServerTestBase;

/**
* This integration tests the <b>fhir-operation-reindex</b> $reindex operation.
* These reindex test always run.
*/
public class ReindexOperationTest extends FHIRServerTestBase {
private boolean runIt = true;

@BeforeClass(enabled = false)
public void setup() throws Exception {
Properties testProperties = TestUtil.readTestProperties("test.properties");
runIt = Boolean.parseBoolean(testProperties.getProperty("test.reindex.enabled", "false"));
}

@Test(groups = { "reindex" })
public void testReindex() {
if (!runIt) {
System.out.println("Skipping over $reindex IT test");
return;
}
List<Parameter> parameters = new ArrayList<>();
parameters.add(Parameter.builder()
.name(string("resourceCount"))
Expand All @@ -60,6 +74,10 @@ public void testReindex() {

@Test(groups = { "reindex" })
public void testReindexWithType() {
if (!runIt) {
System.out.println("Skipping over $reindex IT test");
return;
}
List<Parameter> parameters = new ArrayList<>();
parameters.add(Parameter.builder()
.name(string("resourceCount"))
Expand Down Expand Up @@ -138,6 +156,10 @@ public void testReindexWithInstanceDoesntExist() {

@Test(groups = { "reindex" }, dependsOnMethods = {})
public void testReindexFromTimestampInstant() {
if (!runIt) {
System.out.println("Skipping over $reindex IT test");
return;
}
List<Parameter> parameters = new ArrayList<>();
parameters.add(Parameter.builder()
.name(string("resourceCount"))
Expand Down Expand Up @@ -167,6 +189,10 @@ public void testReindexFromTimestampInstant() {

@Test(groups = { "reindex" }, dependsOnMethods = {})
public void testReindexFromTimestampDayTimeFormat() {
if (!runIt) {
System.out.println("Skipping over $reindex IT test");
return;
}
ZonedDateTime zdt = ZonedDateTime.now();
String tstamp =
zdt.getYear()
Expand Down Expand Up @@ -245,6 +271,10 @@ public void testReindexUsingUnsupportedGet() {

@Test(groups = { "reindex" }, dependsOnMethods = {})
public void testReindexWithLogicalIdDoesntExist() {
if (!runIt) {
System.out.println("Skipping over $reindex IT test");
return;
}
/*
* Note, this still passes, and ends up reindexing the default number of resources.
*/
Expand Down Expand Up @@ -273,6 +303,10 @@ public void testReindexWithLogicalIdDoesntExist() {

@Test(groups = { "reindex" }, dependsOnMethods = {})
public void testReindexWithSpecificTypeLogicalId() {
if (!runIt) {
System.out.println("Skipping over $reindex IT test");
return;
}
List<Parameter> parameters = new ArrayList<>();
parameters.add(Parameter.builder()
.name(string("resourceLogicalId"))
Expand All @@ -298,6 +332,10 @@ public void testReindexWithSpecificTypeLogicalId() {

@Test(groups = { "reindex" }, dependsOnMethods = {})
public void testReindexWithSpecificTypeMissingLogicalId() {
if (!runIt) {
System.out.println("Skipping over $reindex IT test");
return;
}
List<Parameter> parameters = new ArrayList<>();
parameters.add(Parameter.builder()
.name(string("resourceLogicalId"))
Expand Down Expand Up @@ -348,6 +386,10 @@ public void testReindexWithSpecificTypeThatDoesntExist() {

@Test(groups = { "reindex" }, dependsOnMethods = {})
public void testReindexWithPatientResourceType() {
if (!runIt) {
System.out.println("Skipping over $reindex IT test");
return;
}
List<Parameter> parameters = new ArrayList<>();
parameters.add(Parameter.builder()
.name(string("resourceLogicalId"))
Expand Down

0 comments on commit 3cf996c

Please sign in to comment.