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);
}
}
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");
}
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");
}
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);
}
}
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);
}
Aggregations