Search in sources :

Example 1 with GraphQLEngine

use of org.hl7.fhir.r4b.utils.GraphQLEngine in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngineTests method testResource.

private void testResource(Resource resource, String output, String source) throws IOException, EGraphEngine, EGraphQLException {
    GraphQLEngine gql = new GraphQLEngine(TestingUtilities.context());
    gql.setServices(this);
    if (resource != null) {
        gql.setFocus(resource);
    }
    gql.setGraphQL(Parser.parseFile(TestingUtilities.resourceNameToFile("graphql", source)));
    gql.getGraphQL().setOperationName(null);
    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 str = new StringBuilder();
        gql.getOutput().setWriteWrapper(false);
        gql.getOutput().write(str, 0);
        TextFile.stringToFile(str.toString(), TestingUtilities.resourceNameToFile("graphql", output + ".out"));
        msg = TestingUtilities.checkJsonIsSame(TestingUtilities.resourceNameToFile("graphql", output + ".out"), TestingUtilities.resourceNameToFile("graphql", output));
        Assertions.assertTrue(Utilities.noString(msg), msg);
    } else
        Assertions.assertTrue(output.equals("$error"), "Error, but proper output was expected (" + msg + ")");
}
Also used : GraphQLEngine(org.hl7.fhir.r4.utils.GraphQLEngine) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 2 with GraphQLEngine

use of org.hl7.fhir.r4b.utils.GraphQLEngine 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.getSharedWorkerContext());
    gql.setServices(this);
    if (resource != null)
        gql.setFocus(resource);
    gql.setGraphQL(Parser.parse(TestingUtilities.loadTestResource("r5", "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 str = new StringBuilder();
        gql.getOutput().setWriteWrapper(false);
        gql.getOutput().write(str, 0);
        IOUtils.copy(CompareUtilities.loadTestResourceStream("r5", "graphql", source), new FileOutputStream(CompareUtilities.tempFile("graphql", source)));
        IOUtils.copy(CompareUtilities.loadTestResourceStream("r5", "graphql", output), new FileOutputStream(CompareUtilities.tempFile("graphql", output)));
        TextFile.stringToFile(str.toString(), CompareUtilities.tempFile("graphql", output + ".out"));
        msg = CompareUtilities.checkJsonIsSame(CompareUtilities.tempFile("graphql", output), CompareUtilities.tempFile("graphql", output + ".out"));
        Assertions.assertTrue(Utilities.noString(msg), msg);
    } else
        Assertions.assertTrue(output.equals("$error"), "Error, but proper output was expected (" + msg + ")");
}
Also used : GraphQLEngine(org.hl7.fhir.r5.utils.GraphQLEngine) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 3 with GraphQLEngine

use of org.hl7.fhir.r4b.utils.GraphQLEngine 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 + ")");
}
Also used : GraphQLEngine(org.hl7.fhir.r4b.utils.GraphQLEngine) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

IOException (java.io.IOException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 SAXException (org.xml.sax.SAXException)3 FileOutputStream (java.io.FileOutputStream)2 FileNotFoundException (java.io.FileNotFoundException)1 GraphQLEngine (org.hl7.fhir.r4.utils.GraphQLEngine)1 GraphQLEngine (org.hl7.fhir.r4b.utils.GraphQLEngine)1 GraphQLEngine (org.hl7.fhir.r5.utils.GraphQLEngine)1