use of org.hl7.fhir.utilities.graphql.Argument in project org.hl7.fhir.core by hapifhir.
the class GraphQLEngineTests method testResource.
private void testResource(Resource resource, String output, String source, String operation) throws IOException, EGraphEngine, EGraphQLException {
GraphQLEngine gql = new GraphQLEngine(TestingUtilities.context());
gql.setServices(this);
if (resource != null) {
gql.setFocus(resource);
}
gql.setGraphQL(Parser.parse(TestingUtilities.loadTestResource("r4b", "graphql", source)));
gql.getGraphQL().setOperationName(operation);
gql.getGraphQL().getVariables().add(new Argument("var", new NameValue("true")));
boolean ok = false;
String msg = null;
try {
gql.execute();
ok = true;
} catch (Exception e) {
if (!output.equals("$error"))
e.printStackTrace();
ok = false;
msg = e.getMessage();
}
if (ok) {
Assertions.assertTrue(!output.equals("$error"), "Expected to fail, but didn't");
StringBuilder actualStringBuilder = new StringBuilder();
gql.getOutput().setWriteWrapper(false);
gql.getOutput().write(actualStringBuilder, 0);
IOUtils.copy(TestingUtilities.loadTestResourceStream("r4b", "graphql", source), new FileOutputStream(TestingUtilities.tempFile("graphql", source)));
IOUtils.copy(TestingUtilities.loadTestResourceStream("r4b", "graphql", output), new FileOutputStream(TestingUtilities.tempFile("graphql", output)));
TextFile.stringToFile(actualStringBuilder.toString(), TestingUtilities.tempFile("graphql", output + ".out"));
msg = TestingUtilities.checkJsonIsSame(TestingUtilities.tempFile("graphql", output + ".out"), TestingUtilities.tempFile("graphql", output));
Assertions.assertTrue(Utilities.noString(msg), msg);
} else
Assertions.assertTrue(output.equals("$error"), "Error, but proper output was expected (" + msg + ")");
}
use of org.hl7.fhir.utilities.graphql.Argument in project org.hl7.fhir.core by hapifhir.
the class GraphQLEngineTests method search.
@Override
public Bundle search(Object appInfo, String type, List<Argument> searchParams) throws FHIRException {
try {
Bundle bnd = new Bundle();
BundleLinkComponent bl = bnd.addLink();
bl.setRelation("next");
bl.setUrl("http://test.fhir.org/r4/Patient?_format=text/xhtml&search-id=77c97e03-8a6c-415f-a63d-11c80cf73f&&active=true&_sort=_id&search-offset=50&_count=50");
bl = bnd.addLink();
bl.setRelation("self");
bl.setUrl("http://test.fhir.org/r4/Patient?_format=text/xhtml&search-id=77c97e03-8a6c-415f-a63d-11c80cf73f&&active=true&_sort=_id&search-offset=0&_count=50");
BundleEntryComponent be = bnd.addEntry();
be.setFullUrl("http://hl7.org/fhir/Patient/example");
be.setResource(new XmlParser().parse(TestingUtilities.loadTestResourceStream("r4b", "patient-example.xml")));
be = bnd.addEntry();
be.setFullUrl("http://hl7.org/fhir/Patient/example");
be.setResource(new XmlParser().parse(TestingUtilities.loadTestResourceStream("r4b", "patient-example-xds.xml")));
be.getSearch().setScore(0.5);
be.getSearch().setMode(SearchEntryMode.MATCH);
bnd.setTotal(50);
return bnd;
} catch (Exception e) {
throw new FHIRException(e);
}
}
Aggregations