Search in sources :

Example 1 with STGroupFile

use of org.stringtemplate.v4.STGroupFile in project jdbi by jdbi.

the class StringTemplateSqlLocator method readStringTemplateGroup.

private static STGroup readStringTemplateGroup(ClassLoader classLoader, String path) {
    try {
        URL resource = classLoader.getResource(path);
        STGroupFile group = new STGroupFile(resource, "UTF-8", '<', '>');
        group.load();
        return group;
    } catch (Exception e) {
        throw new RuntimeException("Unable to read StringTemplate group file at " + path + " on classpath", e);
    }
}
Also used : STGroupFile(org.stringtemplate.v4.STGroupFile) URL(java.net.URL) IOException(java.io.IOException)

Example 2 with STGroupFile

use of org.stringtemplate.v4.STGroupFile in project webcert by sklintyg.

the class SendMessageToCareIT method setup.

@Before
public void setup() throws IOException {
    // Setup String template resource
    templateGroup = new STGroupFile("integrationtestTemplates/sendMessageToCare.v2.stg");
    requestTemplate = templateGroup.getInstanceOf("request");
    xsdInputstream = ClasspathSchemaResourceResolver.load("interactions/SendMessageToCareInteraction/SendMessageToCareResponder_2.0.xsd");
    // We want to validate against the body of the response, and not the entire soap response. This filter will
    // extract that for us.
    responseBodyExtractorFilter = new BodyExtractorFilter(ImmutableMap.of("lc", "urn:riv:clinicalprocess:healthcond:certificate:SendMessageToCareResponder:2"), "soap:Envelope/soap:Body/lc:SendMessageToCareResponse");
}
Also used : STGroupFile(org.stringtemplate.v4.STGroupFile) Before(org.junit.Before)

Example 3 with STGroupFile

use of org.stringtemplate.v4.STGroupFile in project webcert by sklintyg.

the class ListCertificatesForCareWithQAIT method setup.

@Before
public void setup() throws IOException {
    // Setup String template resource
    templateGroup = new STGroupFile("integrationtestTemplates/listCertificatesForCareWithQA.v3.stg");
    requestTemplate = templateGroup.getInstanceOf("request");
    xsdInputstream = ClasspathSchemaResourceResolver.load("interactions/ListCertificatesForCareWithQAInteraction/ListCertificatesForCareWithQAResponder_3.1.xsd");
    // We want to validate against the body of the response, and not the entire soap response. This filter will
    // extract that for us.
    responseBodyExtractorFilter = new BodyExtractorFilter(ImmutableMap.of("lc", "urn:riv:clinicalprocess:healthcond:certificate:ListCertificatesForCareWithQAResponder:3"), "soap:Envelope/soap:Body/lc:ListCertificatesForCareWithQAResponse");
}
Also used : STGroupFile(org.stringtemplate.v4.STGroupFile) Before(org.junit.Before)

Example 4 with STGroupFile

use of org.stringtemplate.v4.STGroupFile in project antlr4 by tunnelvisionlabs.

the class TestGenerator method generateTestFile.

protected void generateTestFile(STGroup index, STGroup targetGroup, String testdir, Collection<String> testTemplates) {
    ErrorBuffer errors = new ErrorBuffer();
    targetGroup.setListener(errors);
    File targetFolder = getOutputDir(testdir);
    String testName = testdir.substring(testdir.lastIndexOf('/') + 1);
    File targetFile = new File(targetFolder, "Test" + testName + ".java");
    // System.out.println("Generating file "+targetFile.getAbsolutePath());
    List<ST> templates = new ArrayList<ST>();
    for (String template : testTemplates) {
        STGroup testGroup = new STGroupFile(testdir + "/" + template + STGroup.GROUP_FILE_EXTENSION);
        importLanguageTemplates(testGroup, targetGroup);
        ST testType = testGroup.getInstanceOf("TestType");
        if (testType == null) {
            warn(String.format("Unable to generate tests for %s: no TestType specified.", template));
            continue;
        }
        ST testMethodTemplate = targetGroup.getInstanceOf(testType.render() + "TestMethod");
        if (testMethodTemplate == null) {
            warn(String.format("Unable to generate tests for %s: TestType '%s' is not supported by the current runtime.", template, testType.render()));
            continue;
        }
        testMethodTemplate.add(testMethodTemplate.impl.formalArguments.keySet().iterator().next(), testGroup);
        templates.add(testMethodTemplate);
    }
    ST testFileTemplate = targetGroup.getInstanceOf("TestFile");
    testFileTemplate.addAggr("file.{Options,name,tests}", index.rawGetDictionary("Options"), testName, templates);
    if (visualize) {
        STViz viz = testFileTemplate.inspect();
        try {
            viz.waitForClose();
        } catch (InterruptedException ex) {
        }
    }
    try {
        String output = testFileTemplate.render();
        if (errors.errors.size() > 0) {
            System.err.println("errors in " + targetGroup.getName() + ": " + errors);
        }
        writeFile(targetFile, output);
    } catch (IOException ex) {
        error(String.format("Failed to write output file: %s", targetFile), ex);
    }
}
Also used : ST(org.stringtemplate.v4.ST) ErrorBuffer(org.stringtemplate.v4.misc.ErrorBuffer) STGroup(org.stringtemplate.v4.STGroup) ArrayList(java.util.ArrayList) IOException(java.io.IOException) STGroupFile(org.stringtemplate.v4.STGroupFile) File(java.io.File) STGroupFile(org.stringtemplate.v4.STGroupFile) STViz(org.stringtemplate.v4.gui.STViz)

Example 5 with STGroupFile

use of org.stringtemplate.v4.STGroupFile in project antlr4 by tunnelvisionlabs.

the class TestGenerator method execute.

public void execute() {
    STGroup targetGroup = new STGroupFile(runtimeTemplates.getPath());
    targetGroup.registerModelAdaptor(STGroup.class, new STGroupModelAdaptor());
    targetGroup.registerRenderer(String.class, new StringRenderer(), true);
    targetGroup.defineDictionary("escape", new JavaEscapeStringMap());
    targetGroup.defineDictionary("lines", new LinesStringMap());
    targetGroup.defineDictionary("strlen", new StrlenStringMap());
    String rootFolder = "org/antlr/v4/test/runtime/templates";
    generateCodeForFoldersInIndex(targetGroup, rootFolder);
}
Also used : STGroup(org.stringtemplate.v4.STGroup) StringRenderer(org.stringtemplate.v4.StringRenderer) STGroupFile(org.stringtemplate.v4.STGroupFile)

Aggregations

STGroupFile (org.stringtemplate.v4.STGroupFile)26 STGroup (org.stringtemplate.v4.STGroup)12 StringRenderer (org.stringtemplate.v4.StringRenderer)7 URL (java.net.URL)6 Before (org.junit.Before)6 ST (org.stringtemplate.v4.ST)5 File (java.io.File)4 ArrayList (java.util.ArrayList)3 NumberRenderer (org.stringtemplate.v4.NumberRenderer)3 STErrorListener (org.stringtemplate.v4.STErrorListener)3 STMessage (org.stringtemplate.v4.misc.STMessage)3 IOException (java.io.IOException)2 CodeGenerator (org.antlr.v4.codegen.CodeGenerator)2 Pair (org.antlr.v4.runtime.misc.Pair)2 BodyExtractorFilter (se.inera.intyg.webcert.web.integration.integrationtest.BodyExtractorFilter)2 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 MultiMap (org.antlr.v4.runtime.misc.MultiMap)1 NotNull (org.antlr.v4.runtime.misc.NotNull)1 Primitive (org.eclipse.collections.codegenerator.model.Primitive)1