-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #2421 - Add terminology clear-cache operations The terminology subsystem caches terminology resources by URL and/or URL + version. If the user tries to update a CodeSystem or ValueSet resource keeping the same URL + version, the cache does not get cleared and some operations (e.g. validate-code) do not return the expected results after update. This change adds an operation ($clear-cache) that can be called on either terminology resource and will clear the appropriate caches. Signed-off-by: Corey Sanders <corey.thecolonel@gmail.com> * Address test failure due to unexpected test interactions. Signed-off-by: Corey Sanders <corey.thecolonel@gmail.com> * Fix issue with operation ordering on clean database All my testing has been done on a dirty database. There are automated build failures that appear to be related to test order and a resource not existing yet on a clean database. Flipping the order of the resource puts and initial clear cache operations so that the resource is guaranteed to be in place. Signed-off-by: Corey Sanders <corey.thecolonel@gmail.com> * Address code format issues Signed-off-by: Corey Sanders <corey.thecolonel@gmail.com> * Split term cache operations into a separate module Per discussion with the team, the cache operations are being split into a separate module that will not be included in the default server build. Since it isn't automatically included, the build automation scripts needed to be updated. Signed-off-by: Corey Sanders <corey.thecolonel@gmail.com> * Update POM version for new module Signed-off-by: Corey Sanders <corey.thecolonel@gmail.com> * Fix Windows integration, update README Signed-off-by: Corey Sanders <corey.thecolonel@gmail.com> * Apply suggested change Signed-off-by: Corey Sanders <corey.thecolonel@gmail.com> * Apply suggested change Signed-off-by: Corey Sanders <corey.thecolonel@gmail.com> Co-authored-by: Lee Surprenant <lmsurpre@us.ibm.com> * change package name from javax.json to jakarta.json Signed-off-by: Corey Sanders <corey.thecolonel@gmail.com> Co-authored-by: Lee Surprenant <lmsurpre@us.ibm.com>
- Loading branch information
Showing
24 changed files
with
1,176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...src/test/java/com/ibm/fhir/server/test/terminology/CodeSystemClearCacheOperationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2021 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.ibm.fhir.server.test.terminology; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
|
||
import java.io.ByteArrayInputStream; | ||
|
||
import javax.ws.rs.core.Response; | ||
|
||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import com.ibm.fhir.model.format.Format; | ||
import com.ibm.fhir.model.parser.FHIRParser; | ||
import com.ibm.fhir.model.resource.Parameters; | ||
|
||
/** | ||
* These tests exercise the $clear-cache operation on a CodeSystem. | ||
*/ | ||
public class CodeSystemClearCacheOperationTest extends TerminologyOperationTestBase { | ||
|
||
private static final String SNOMED_CT = "http://snomed.info/sct"; | ||
// Test Specific | ||
public static final String TEST_GROUP_NAME = "terminology"; | ||
public static final boolean DEBUG = false; | ||
|
||
// URLs to call against the instance | ||
public static final String BASE_VALID_URL = "/CodeSystem"; | ||
|
||
public static final String CODE_SYSTEM_ID = "test"; | ||
public static final String CODE_SYSTEM_URL = "http://ibm.com/fhir/CodeSystem/test"; | ||
public static final String CODE_SYSTEM_VERSION = "1.0.0"; | ||
|
||
@BeforeClass | ||
public void setup() throws Exception { | ||
Response response = doPut("CodeSystem", CODE_SYSTEM_ID, "testdata/CodeSystem-test.json"); | ||
assertEquals(response.getStatusInfo().getFamily(), Response.Status.Family.SUCCESSFUL); | ||
} | ||
|
||
@Test(groups = { TEST_GROUP_NAME }) | ||
public void testClearCacheParameterVariations() throws Exception { | ||
Response response; | ||
|
||
response = doGet(BASE_VALID_URL + "/$clear-cache"); | ||
assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); | ||
|
||
response = doGet(BASE_VALID_URL + "/$clear-cache", "url", CODE_SYSTEM_URL); | ||
assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); | ||
|
||
response = doGet(BASE_VALID_URL + "/$clear-cache", "url", CODE_SYSTEM_URL, "codeSystemVersion", CODE_SYSTEM_VERSION); | ||
assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); | ||
|
||
clearCache(); | ||
} | ||
|
||
@Test(groups = { TEST_GROUP_NAME }) | ||
public void testClearCacheValidateCode() throws Exception { | ||
Response response; | ||
Parameters parameters; | ||
|
||
// Make sure the resource is there | ||
response = doPut("CodeSystem", CODE_SYSTEM_ID, "testdata/CodeSystem-test.json"); | ||
assertEquals(response.getStatusInfo().getFamily(), Response.Status.Family.SUCCESSFUL); | ||
|
||
// Once to make sure it is gone from the cache | ||
clearCache(); | ||
|
||
// Twice to see what happens when it is empty | ||
clearCache(); | ||
|
||
// Subsumes to reload the cache | ||
parameters = validateCode(SNOMED_CT, "K"); | ||
assertEquals(getBooleanParameterValue(parameters, "result"), Boolean.TRUE); | ||
|
||
// Update the resource | ||
response = doPut("CodeSystem", CODE_SYSTEM_ID, "testdata/CodeSystem-test-updated.json"); | ||
assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); | ||
|
||
parameters = validateCode(SNOMED_CT, "K"); | ||
assertEquals(getBooleanParameterValue(parameters, "result"), Boolean.TRUE); | ||
|
||
// After cache is cleared, subsumes outcome should be updated | ||
clearCache(); | ||
|
||
parameters = validateCode(SNOMED_CT, "K"); | ||
assertEquals(getBooleanParameterValue(parameters, "result"), Boolean.FALSE); | ||
} | ||
|
||
private Parameters validateCode(String system, String code) throws Exception { | ||
Response response = doGet(BASE_VALID_URL + "/" + CODE_SYSTEM_ID + "/$validate-code", "system", system, "code", code); | ||
String responseBody = response.readEntity(String.class); | ||
assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), responseBody); | ||
return FHIRParser.parser(Format.JSON).parse(new ByteArrayInputStream(responseBody.getBytes())); | ||
} | ||
|
||
private void clearCache() { | ||
Response response = doGet(BASE_VALID_URL + "/" + CODE_SYSTEM_ID + "/$clear-cache"); | ||
assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...test/src/test/java/com/ibm/fhir/server/test/terminology/TerminologyOperationTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2021 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.ibm.fhir.server.test.terminology; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.util.Properties; | ||
|
||
import jakarta.json.JsonObject; | ||
import javax.ws.rs.client.Entity; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.testng.annotations.BeforeClass; | ||
|
||
import com.ibm.fhir.core.FHIRMediaType; | ||
import com.ibm.fhir.model.format.Format; | ||
import com.ibm.fhir.model.parser.FHIRParser; | ||
import com.ibm.fhir.model.parser.exception.FHIRParserException; | ||
import com.ibm.fhir.model.resource.Parameters; | ||
import com.ibm.fhir.model.resource.Resource; | ||
import com.ibm.fhir.model.test.TestUtil; | ||
import com.ibm.fhir.server.test.FHIRServerTestBase; | ||
|
||
public abstract class TerminologyOperationTestBase extends FHIRServerTestBase { | ||
|
||
public static final String FORMAT = "application/json"; | ||
|
||
private final String tenantName = "default"; | ||
private final String dataStoreId = "default"; | ||
|
||
@BeforeClass | ||
public void setup() throws Exception { | ||
Properties testProperties = TestUtil.readTestProperties("test.properties"); | ||
setUp(testProperties); | ||
} | ||
|
||
public Response doPut(String resourceType, String id, String resourcePath) throws Exception { | ||
JsonObject jsonObject = TestUtil.readJsonObject(resourcePath); | ||
Entity<JsonObject> entity = Entity.entity(jsonObject, FHIRMediaType.APPLICATION_FHIR_JSON); | ||
|
||
Response response = getWebTarget().path(resourceType + "/" + id).request().put(entity, Response.class); | ||
String responseBody = response.readEntity(String.class); | ||
assertEquals(response.getStatusInfo().getFamily(), Response.Status.Family.SUCCESSFUL, responseBody); | ||
return response; | ||
} | ||
|
||
public Response doGet(String path, String... params) { | ||
|
||
WebTarget target = getWebTarget(); | ||
target = target.path(path); | ||
|
||
// When the path is passed in with the parameters, the ?, &, etc. | ||
// get escaped and it causes failures, so we are doing some | ||
// hacking here. | ||
if (params != null && params.length > 0) { | ||
assert (params.length % 2 == 0); | ||
for (int i = 0; i < params.length; i += 2) { | ||
target = target.queryParam(params[i], params[i + 1]); | ||
} | ||
} | ||
|
||
return target.request(FORMAT).header("X-FHIR-TENANT-ID", tenantName).header("X-FHIR-DSID", dataStoreId).get(Response.class); | ||
} | ||
|
||
public Resource parseResource(String responseBody) throws FHIRParserException { | ||
Resource resource = FHIRParser.parser(Format.JSON).parse(new ByteArrayInputStream(responseBody.getBytes())); | ||
return resource; | ||
} | ||
|
||
public Parameters.Parameter getParameter(Resource resource, String propertyName) { | ||
assertTrue(resource instanceof Parameters); | ||
Parameters parameters = (Parameters) resource; | ||
return parameters.getParameter().stream().filter(p -> p.getName().getValue().equals(propertyName)).reduce((a, b) -> { | ||
throw new IllegalStateException("More than one parameter found with the same name '" + propertyName + "'"); | ||
}).get(); | ||
} | ||
|
||
public Boolean getBooleanParameterValue(Resource resource, String propertyName) { | ||
return ((com.ibm.fhir.model.type.Boolean) getParameter(resource, propertyName).getValue()).getValue(); | ||
} | ||
} |
Oops, something went wrong.