use of org.apache.sling.scripting.sightly.java.compiler.ClassInfo in project sling by apache.
the class JavaClassBackendCompilerTest method testScript.
@Test
public void testScript() throws Exception {
CompilationUnit compilationUnit = TestUtils.readScriptFromClasspath("/test.html");
JavaClassBackendCompiler backendCompiler = new JavaClassBackendCompiler();
SightlyCompiler sightlyCompiler = new SightlyCompiler();
sightlyCompiler.compile(compilationUnit, backendCompiler);
ClassInfo classInfo = buildClassInfo("testScript");
String source = backendCompiler.build(classInfo);
StringWriter writer = new StringWriter();
Bindings bindings = new SimpleBindings();
RenderContext renderContext = buildRenderContext(bindings);
render(writer, classInfo, source, renderContext, new SimpleBindings());
String expectedOutput = IOUtils.toString(this.getClass().getResourceAsStream("/test-output.html"), "UTF-8");
assertEquals(expectedOutput, writer.toString());
}
use of org.apache.sling.scripting.sightly.java.compiler.ClassInfo in project sling by apache.
the class JavaClassBackendCompilerTest method sling_6094_2.
@Test
public void sling_6094_2() throws Exception {
CompilationUnit compilationUnit = TestUtils.readScriptFromClasspath("/SLING-6094.2.html");
JavaClassBackendCompiler backendCompiler = new JavaClassBackendCompiler();
SightlyCompiler sightlyCompiler = new SightlyCompiler();
sightlyCompiler.compile(compilationUnit, backendCompiler);
ClassInfo classInfo = buildClassInfo("sling_6094_2");
String source = backendCompiler.build(classInfo);
StringWriter writer = new StringWriter();
Bindings bindings = new SimpleBindings();
RenderContext renderContext = buildRenderContext(bindings);
render(writer, classInfo, source, renderContext, new SimpleBindings());
String expectedOutput = IOUtils.toString(this.getClass().getResourceAsStream("/SLING-6094.2.output.html"), "UTF-8");
assertEquals(expectedOutput, writer.toString());
}
use of org.apache.sling.scripting.sightly.java.compiler.ClassInfo in project sling by apache.
the class JavaClassBackendCompilerTest method sling_6094_1.
@Test
public void sling_6094_1() throws Exception {
CompilationUnit compilationUnit = TestUtils.readScriptFromClasspath("/SLING-6094.1.html");
JavaClassBackendCompiler backendCompiler = new JavaClassBackendCompiler();
SightlyCompiler sightlyCompiler = new SightlyCompiler();
sightlyCompiler.compile(compilationUnit, backendCompiler);
ClassInfo classInfo = buildClassInfo("sling_6094_1");
String source = backendCompiler.build(classInfo);
StringWriter writer = new StringWriter();
Bindings bindings = new SimpleBindings();
bindings.put("img", new HashMap<String, Object>() {
{
put("attributes", new HashMap<String, String>() {
{
put("v-bind:src", "replaced");
}
});
}
});
RenderContext renderContext = buildRenderContext(bindings);
render(writer, classInfo, source, renderContext, new SimpleBindings());
String expectedOutput = IOUtils.toString(this.getClass().getResourceAsStream("/SLING-6094.1.output.html"), "UTF-8");
assertEquals(expectedOutput, writer.toString());
}
Aggregations