Skip to content

Commit

Permalink
Merge pull request #1808 from hapifhir/do-20241113-fix-mode-headers-t…
Browse files Browse the repository at this point in the history
…erm-test

Fix mode based header addition in TxTester
  • Loading branch information
grahamegrieve authored Nov 14, 2024
2 parents a64ea3d + b0b79cd commit fd530e0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.ToolingClientLogger;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.http.HTTPHeader;

public class TerminologyClientR2 implements ITerminologyClient {

Expand Down Expand Up @@ -211,7 +212,7 @@ public CanonicalResource read(String type, String id) {
}

@Override
public ClientHeaders getClientHeaders() {
public Iterable<HTTPHeader> getClientHeaders() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.ToolingClientLogger;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.http.HTTPHeader;

public class TerminologyClientR3 implements ITerminologyClient {

Expand Down Expand Up @@ -201,8 +202,8 @@ public CanonicalResource read(String type, String id) {
}

@Override
public ClientHeaders getClientHeaders() {
return clientHeaders;
public Iterable<HTTPHeader> getClientHeaders() {
return clientHeaders.headers();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.ToolingClientLogger;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.http.HTTPHeader;

public class TerminologyClientR4 implements ITerminologyClient {

Expand Down Expand Up @@ -226,8 +227,8 @@ public CanonicalResource read(String type, String id) {
}

@Override
public ClientHeaders getClientHeaders() {
return clientHeaders;
public Iterable<HTTPHeader> getClientHeaders() {
return clientHeaders.headers();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.r5.utils.client.network.ClientHeaders;
import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.ToolingClientLogger;
import org.hl7.fhir.utilities.http.HTTPHeader;

import java.util.EnumSet;
import java.util.Map;
Expand Down Expand Up @@ -67,7 +68,7 @@ public interface ITerminologyClient {
Parameters translate(Parameters params) throws FHIRException;
Bundle validateBatch(Bundle batch);
CanonicalResource read(String type, String id);
ClientHeaders getClientHeaders();
Iterable<HTTPHeader> getClientHeaders();
ITerminologyClient setClientHeaders(ClientHeaders clientHeaders);
ITerminologyClient setUserAgent(String userAgent);
ITerminologyClient setAcceptLanguage(String lang);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.utilities.FhirPublication;
import org.hl7.fhir.utilities.ToolingClientLogger;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.http.HTTPHeader;

public class TerminologyClientR5 implements ITerminologyClient {

Expand Down Expand Up @@ -215,8 +216,8 @@ public CanonicalResource read(String type, String id) {
}

@Override
public ClientHeaders getClientHeaders() {
return clientHeaders;
public Iterable<HTTPHeader> getClientHeaders() {
return clientHeaders.headers();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.io.DataInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Expand All @@ -17,7 +16,6 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
Expand All @@ -32,7 +30,6 @@
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r4b.context.TextClientLogger;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.model.CapabilityStatement;
import org.hl7.fhir.r5.model.OperationOutcome;
Expand All @@ -43,6 +40,7 @@
import org.hl7.fhir.r5.terminologies.client.ITerminologyClient;
import org.hl7.fhir.r5.test.utils.CompareUtilities;
import org.hl7.fhir.r5.utils.client.EFhirClientException;
import org.hl7.fhir.r5.utils.client.network.ClientHeaders;
import org.hl7.fhir.utilities.*;
import org.hl7.fhir.utilities.filesystem.ManagedFileAccess;
import org.hl7.fhir.utilities.http.HTTPHeader;
Expand All @@ -64,7 +62,7 @@ public interface ITxTesterLoader {
private ITxTesterLoader loader;
private String error;
private String output;
private ITerminologyClient tx;
private ITerminologyClient terminologyClient;
private boolean tight;
private JsonObject externals;
private String software;
Expand Down Expand Up @@ -113,7 +111,7 @@ public boolean execute(String version, List<String> modes, String filter) throws
json.add("date", new SimpleDateFormat("EEE, MMM d, yyyy HH:mmZ", new Locale("en", "US")).format(Calendar.getInstance().getTime()) + timezone());
try {
JsonObject tests = loadTests();
tx = connectToServer(modes);
terminologyClient = connectToServer(modes);
boolean ok = checkClient();
for (JsonObject suite : tests.getJsonObjects("suites")) {
if ((!suite.has("mode") || modes.contains(suite.asString("mode")))) {
Expand Down Expand Up @@ -160,11 +158,11 @@ private String timezone() {
}

private boolean checkClient() {
cstmt = tx.getCapabilitiesStatement();
cstmt = terminologyClient.getCapabilitiesStatement();
if (cstmt.hasSoftware()) {
software = cstmt.getSoftware().getName()+" v"+cstmt.getSoftware().getVersion();
}
tc = tx.getTerminologyCapabilities();
tc = terminologyClient.getTerminologyCapabilities();
return true;
}

Expand Down Expand Up @@ -205,8 +203,8 @@ private ITerminologyClient connectToServer(List<String> modes) throws URISyntaxE

public String executeTest(JsonObject suite, JsonObject test, List<String> modes) throws URISyntaxException, FHIRFormatError, FileNotFoundException, IOException {
error = null;
if (tx == null) {
tx = connectToServer(modes);
if (terminologyClient == null) {
terminologyClient = connectToServer(modes);
checkClient();
}
List<Resource> setup = loadSetupResources(suite);
Expand Down Expand Up @@ -255,7 +253,7 @@ private boolean runTest(JsonObject suite, JsonObject test, List<Resource> setup,
JsonObject hdr = test.getJsonObject("header");
if (hdr.has("mode") && modes.contains(hdr.asString("mode"))) {
header = new HTTPHeader(hdr.asString("name"), hdr.asString("value"));
tx.getClientHeaders().addHeader(header);
terminologyClient.setClientHeaders(new ClientHeaders(List.of(header)));
}
}

Expand Down Expand Up @@ -302,7 +300,7 @@ private boolean runTest(JsonObject suite, JsonObject test, List<Resource> setup,
outputT.add("message", msg);
}
if (header != null) {
tx.getClientHeaders().removeHeader(header);
terminologyClient.setClientHeaders(new ClientHeaders());
}
return msg == null;
} catch (Exception e) {
Expand All @@ -312,7 +310,7 @@ private boolean runTest(JsonObject suite, JsonObject test, List<Resource> setup,
error = e.getMessage();
e.printStackTrace();
if (header != null) {
tx.getClientHeaders().removeHeader(header);
terminologyClient.setClientHeaders(new ClientHeaders());
}
return false;
}
Expand Down Expand Up @@ -383,12 +381,12 @@ private String lookup(String id, List<Resource> setup, Parameters p, String resp
for (Resource r : setup) {
p.addParameter().setName("tx-resource").setResource(r);
}
tx.setContentLanguage(lang);
terminologyClient.setContentLanguage(lang);
p.getParameter().addAll(profile.getParameter());
int code = 0;
String pj;
try {
Parameters po = tx.lookupCode(p);
Parameters po = terminologyClient.lookupCode(p);
TxTesterScrubbers.scrubParams(po);
TxTesterSorters.sortParameters(po);
pj = new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(po);
Expand All @@ -414,12 +412,12 @@ private String translate(String id, List<Resource> setup, Parameters p, String r
for (Resource r : setup) {
p.addParameter().setName("tx-resource").setResource(r);
}
tx.setContentLanguage(lang);
terminologyClient.setContentLanguage(lang);
p.getParameter().addAll(profile.getParameter());
int code = 0;
String pj;
try {
Parameters po = tx.translate(p);
Parameters po = terminologyClient.translate(p);
TxTesterScrubbers.scrubParams(po);
TxTesterSorters.sortParameters(po);
pj = new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(po);
Expand All @@ -445,12 +443,12 @@ private String expand(String id, List<Resource> setup, Parameters p, String resp
for (Resource r : setup) {
p.addParameter().setName("tx-resource").setResource(r);
}
tx.setContentLanguage(lang);
terminologyClient.setContentLanguage(lang);
p.getParameter().addAll(profile.getParameter());
int code = 0;
String vsj;
try {
ValueSet vs = tx.expandValueset(null, p);
ValueSet vs = terminologyClient.expandValueset(null, p);
TxTesterScrubbers.scrubVS(vs, tight);
TxTesterSorters.sortValueSet(vs);
vsj = new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(vs);
Expand Down Expand Up @@ -488,11 +486,11 @@ private String validate(String id, List<Resource> setup, Parameters p, String re
p.addParameter().setName("tx-resource").setResource(r);
}
p.getParameter().addAll(profile.getParameter());
tx.setContentLanguage(lang);
terminologyClient.setContentLanguage(lang);
int code = 0;
String pj;
try {
Parameters po = tx.validateVS(p);
Parameters po = terminologyClient.validateVS(p);
TxTesterScrubbers.scrubParams(po);
TxTesterSorters.sortParameters(po);
pj = new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(po);
Expand Down Expand Up @@ -520,11 +518,11 @@ private String validateCS(String id, List<Resource> setup, Parameters p, String
p.addParameter().setName("tx-resource").setResource(r);
}
p.getParameter().addAll(profile.getParameter());
tx.setContentLanguage(lang);
terminologyClient.setContentLanguage(lang);
int code = 0;
String pj;
try {
Parameters po = tx.validateCS(p);
Parameters po = terminologyClient.validateCS(p);
TxTesterScrubbers.scrubParams(po);
TxTesterSorters.sortParameters(po);
pj = new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).composeString(po);
Expand All @@ -549,7 +547,7 @@ private String validateCS(String id, List<Resource> setup, Parameters p, String

private Map<String, String> vars() {
Map<String, String> vars = new HashMap<String, String>();
vars.put("version", tx.getActualVersion().toCode());
vars.put("version", terminologyClient.getActualVersion().toCode());
return vars;

}
Expand Down

0 comments on commit fd530e0

Please sign in to comment.