mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-03-02 09:29:13 +00:00
Test that no requests are made for cached tests
This commit is contained in:
parent
4826424499
commit
7d8569e9e7
@ -0,0 +1,50 @@
|
||||
package org.hl7.fhir.utilities.tests;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.hl7.fhir.utilities.ToolingClientLogger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CacheVerificationLogger implements ToolingClientLogger {
|
||||
|
||||
public static final String FHIR_TXCACHE_REBUILD = "fhir.txcache.rebuild";
|
||||
|
||||
@Getter
|
||||
int requests = 0;
|
||||
|
||||
@Override
|
||||
public void logRequest(String method, String url, List<String> headers, byte[] body) {
|
||||
requests++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logResponse(String outcome, List<String> headers, byte[] body) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLastId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearLastId() {
|
||||
|
||||
}
|
||||
|
||||
public boolean verifyHasNoRequests() {
|
||||
String isRebuildingCache = System.getProperty(FHIR_TXCACHE_REBUILD);
|
||||
|
||||
if (isRebuildingCache != null && "TRUE".equals(isRebuildingCache.toUpperCase())) {
|
||||
return true;
|
||||
} else {
|
||||
if (requests != 0) {
|
||||
System.err.println("Unexpected TX server request during test. If a new test has been added, you may need to " +
|
||||
"rebuild the TX Cache for the test using the 'mvn test -D" + FHIR_TXCACHE_REBUILD + "=true' option");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package org.hl7.fhir.validation.tests;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.utilities.tests.CacheVerificationLogger;
|
||||
import org.hl7.fhir.validation.tests.utilities.TestConstants;
|
||||
import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat;
|
||||
import org.hl7.fhir.r5.model.FhirPublication;
|
||||
@ -16,6 +17,8 @@ import org.hl7.fhir.validation.tests.utilities.TestUtilities;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ValidationEngineTests {
|
||||
|
||||
public static final String DEF_TX = "http://tx.fhir.org";
|
||||
@ -28,6 +31,8 @@ public class ValidationEngineTests {
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println("TestCurrentXml: Validate patient-example.xml in Current version");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", DEF_TX, null, FhirPublication.R4, "4.0.1", "fhir/test-cases");
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
ve.getContext().getTxClient().setLogger(logger);
|
||||
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient-example.xml"), null);
|
||||
int e = errors(op);
|
||||
int w = warnings(op);
|
||||
@ -41,6 +46,7 @@ public class ValidationEngineTests {
|
||||
Assertions.assertEquals(0, e);
|
||||
Assertions.assertEquals(0, w);
|
||||
Assertions.assertEquals(1, h);
|
||||
assertTrue(logger.verifyHasNoRequests(), "Unexpected request to TX server");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -48,6 +54,8 @@ public class ValidationEngineTests {
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println("TestCurrentJson: Validate patient-example.json in Current version");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", DEF_TX, null, FhirPublication.R4, "4.0.1", "fhir/test-cases");
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
ve.getContext().getTxClient().setLogger(logger);
|
||||
OperationOutcome op = ve.validate(FhirFormat.JSON, TestingUtilities.loadTestResourceStream("validator", "patient-example.json"), null);
|
||||
int e = errors(op);
|
||||
int w = warnings(op);
|
||||
@ -55,6 +63,7 @@ public class ValidationEngineTests {
|
||||
Assertions.assertEquals(0, e);
|
||||
Assertions.assertEquals(0, w);
|
||||
Assertions.assertEquals(1, h);
|
||||
assertTrue(logger.verifyHasNoRequests(), "Unexpected request to TX server");
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
|
||||
}
|
||||
@ -68,7 +77,8 @@ public class ValidationEngineTests {
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println("Test140: Validate patient-example.xml in v1.4.0 version");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2b.core#1.4.0", DEF_TX, null, FhirPublication.DSTU2016May, "1.4.0", "fhir/test-cases");
|
||||
ve.getContext().setUserAgent("fhir/test-cases");
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
ve.getContext().getTxClient().setLogger(logger);
|
||||
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient140.xml"), null);
|
||||
if (!TestUtilities.silent)
|
||||
for (OperationOutcomeIssueComponent iss : op.getIssue()) {
|
||||
@ -80,6 +90,7 @@ public class ValidationEngineTests {
|
||||
Assertions.assertEquals(1, e);
|
||||
Assertions.assertEquals(0, w);
|
||||
Assertions.assertEquals(0, h);
|
||||
assertTrue(logger.verifyHasNoRequests(), "Unexpected request to TX server");
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
|
||||
}
|
||||
@ -94,6 +105,8 @@ public class ValidationEngineTests {
|
||||
System.out.println("Test102: Validate patient-example.xml in v1.0.2 version");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", DEF_TX, null, FhirPublication.DSTU2, "1.0.2", "fhir/test-cases");
|
||||
ve.setNoInvariantChecks(true);
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
ve.getContext().getTxClient().setLogger(logger);
|
||||
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient102.xml"), null);
|
||||
if (!TestUtilities.silent)
|
||||
for (OperationOutcomeIssueComponent iss : op.getIssue()) {
|
||||
@ -105,6 +118,7 @@ public class ValidationEngineTests {
|
||||
Assertions.assertEquals(1, e);
|
||||
Assertions.assertEquals(0, w);
|
||||
Assertions.assertEquals(0, h);
|
||||
assertTrue(logger.verifyHasNoRequests(), "Unexpected request to TX server");
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
|
||||
}
|
||||
@ -119,6 +133,8 @@ public class ValidationEngineTests {
|
||||
System.out.println("TestObs102: Validate patient-example.xml in v1.0.2 version");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", DEF_TX, null, FhirPublication.DSTU2, "1.0.2", "fhir/test-cases");
|
||||
ve.setNoInvariantChecks(true);
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
ve.getContext().getTxClient().setLogger(logger);
|
||||
OperationOutcome op = ve.validate(FhirFormat.JSON, TestingUtilities.loadTestResourceStream("validator", "observation102.json"), null);
|
||||
if (!TestUtilities.silent)
|
||||
for (OperationOutcomeIssueComponent iss : op.getIssue()) {
|
||||
@ -130,6 +146,7 @@ public class ValidationEngineTests {
|
||||
Assertions.assertEquals(1, e);
|
||||
Assertions.assertEquals(0, w);
|
||||
Assertions.assertEquals(1, h);
|
||||
assertTrue(logger.verifyHasNoRequests(), "Unexpected request to TX server");
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
|
||||
}
|
||||
@ -140,6 +157,8 @@ public class ValidationEngineTests {
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println("Test301: Validate observation301.xml against Core");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", DEF_TX, null, FhirPublication.STU3, "3.0.2", "fhir/test-cases");
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
ve.getContext().getTxClient().setLogger(logger);
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println(" .. load USCore");
|
||||
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "observation301.xml"), null);
|
||||
@ -150,6 +169,7 @@ public class ValidationEngineTests {
|
||||
int w = warnings(op);
|
||||
int h = hints(op);
|
||||
Assertions.assertEquals(0, e);
|
||||
assertTrue(logger.verifyHasNoRequests(), "Unexpected request to TX server");
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
|
||||
}
|
||||
@ -159,6 +179,8 @@ public class ValidationEngineTests {
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println("Test301USCore: Validate patient300.xml against US-Core");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", DEF_TX, null, FhirPublication.STU3, "3.0.2", "fhir/test-cases");
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
ve.getContext().getTxClient().setLogger(logger);
|
||||
IgLoader igLoader = new IgLoader(ve.getPcm(), ve.getContext(), ve.getVersion(), true);
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println(" .. load USCore");
|
||||
@ -175,6 +197,7 @@ public class ValidationEngineTests {
|
||||
Assertions.assertEquals(1, e);
|
||||
Assertions.assertEquals(0, w);
|
||||
Assertions.assertEquals(0, h);
|
||||
assertTrue(logger.verifyHasNoRequests(), "Unexpected request to TX server");
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println(" .. done: " + Integer.toString(e) + " errors, " + Integer.toString(w) + " warnings, " + Integer.toString(h) + " information messages");
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.hl7.fhir.utilities.*;
|
||||
import org.hl7.fhir.utilities.tests.CacheVerificationLogger;
|
||||
import org.hl7.fhir.validation.tests.utilities.TestUtilities;
|
||||
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_50;
|
||||
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_50;
|
||||
@ -54,11 +56,7 @@ import org.hl7.fhir.r5.utils.validation.BundleValidationRule;
|
||||
import org.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher;
|
||||
import org.hl7.fhir.r5.utils.validation.constants.ContainedReferenceValidationPolicy;
|
||||
import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy;
|
||||
import org.hl7.fhir.utilities.SimpleHTTPClient;
|
||||
import org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult;
|
||||
import org.hl7.fhir.utilities.TextFile;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.VersionUtilities;
|
||||
import org.hl7.fhir.utilities.json.JSONUtil;
|
||||
import org.hl7.fhir.utilities.npm.NpmPackage;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||
@ -80,6 +78,8 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class ValidationTests implements IEvaluationContext, IValidatorResourceFetcher, IValidationPolicyAdvisor {
|
||||
|
||||
@ -113,6 +113,8 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
|
||||
private String name;
|
||||
|
||||
private static Map<String, ValidationEngine> ve = new HashMap<>();
|
||||
|
||||
|
||||
private static ValidationEngine vCurr;
|
||||
private static IgLoader igLoader;
|
||||
|
||||
@ -124,6 +126,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
long setup = System.nanoTime();
|
||||
|
||||
this.name = name;
|
||||
@ -157,6 +160,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
|
||||
throw new Exception("unknown version " + version);
|
||||
}
|
||||
vCurr = ve.get(version);
|
||||
vCurr.getContext().getTxClient().setLogger(logger);
|
||||
igLoader = new IgLoader(vCurr.getPcm(), vCurr.getContext(), vCurr.getVersion(), true);
|
||||
if (TestingUtilities.fcontexts == null) {
|
||||
TestingUtilities.fcontexts = new HashMap<>();
|
||||
@ -330,10 +334,10 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
|
||||
}
|
||||
checkOutcomes(errorsLogical, logical, "logical", name);
|
||||
}
|
||||
|
||||
vCurr.getContext().getTxCache().getHitCount();
|
||||
assertTrue(logger.verifyHasNoRequests(), "Unexpected request to TX server");
|
||||
}
|
||||
|
||||
|
||||
private FhirFormat determineFormat(JsonObject config, byte[] cnt) throws IOException {
|
||||
String name = JSONUtil.str(config, "file");
|
||||
return org.hl7.fhir.validation.ResourceChecker.checkIsResource(vCurr.getContext(), true, cnt, name, !JSONUtil.bool(config, "guess-format"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user