use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-java by SonarSource.
the class JasperTest method test_exception_handling.
@Test
void test_exception_handling() throws Exception {
SensorContextTester ctx = jspContext("<%=");
Collection<GeneratedFile> inputFiles = new Jasper().generateFiles(ctx, emptyList());
assertThat(inputFiles).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).matches(logs -> logs.stream().anyMatch(line -> line.startsWith("Error transpiling src/main/webapp/WEB-INF/jsp/test.jsp.")));
assertThat(logTester.logs(LoggerLevel.WARN)).contains("Some JSP pages failed to transpile. Enable debug log for details.");
}
use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-java by SonarSource.
the class JasperTest method test_empty.
@Test
void test_empty() throws Exception {
SensorContextTester ctx = SensorContextTester.create(tempFolder);
ctx.fileSystem().setWorkDir(workDir);
Collection<GeneratedFile> generatedFiles = new Jasper().generateFiles(ctx, emptyList());
assertThat(generatedFiles).isEmpty();
assertThat(logTester.logs()).containsOnly("Found 0 JSP files.");
}
use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-java by SonarSource.
the class JasperTest method test_compilation.
@Test
void test_compilation() throws Exception {
SensorContextTester ctx = jspContext(JSP_SOURCE);
Collection<GeneratedFile> generatedFiles = new Jasper().generateFiles(ctx, emptyList());
assertThat(generatedFiles).hasSize(1);
InputFile generatedFile = generatedFiles.iterator().next();
List<String> generatedCode = Files.readAllLines(generatedFile.path());
assertThat(generatedCode).contains(" out.write(\"<html>\\n<body>\\n<h2>Hello World!</h2>\\n</body>\\n</html>\");");
}
use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-java by SonarSource.
the class JasperTest method test_with_classpath_jee6_jstl.
@Test
void test_with_classpath_jee6_jstl() throws Exception {
SensorContextTester ctx = jspContext("<%@ taglib uri = \"http://java.sun.com/jsp/jstl/core\" prefix = \"c\" %>\n" + "<html>\n" + "<body>\n" + "<h2>Hello World!</h2>\n" + "<c:if test=\"true\">what-if</c:if>\n" + "</body>\n" + "</html>");
Collection<GeneratedFile> generatedFiles = new Jasper().generateFiles(ctx, asList(jee6Jar, jstlJar));
assertThat(generatedFiles).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).matches(logs -> logs.stream().anyMatch(line -> line.startsWith("Error transpiling src/main/webapp/WEB-INF/jsp/test.jsp. Error:\njava.lang.ClassFormatError")));
}
use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-java by SonarSource.
the class JasperTest method test_exclude_unrelated_files.
@Test
void test_exclude_unrelated_files() throws Exception {
SensorContextTester ctx = jspContext(JSP_SOURCE);
ctx.setSettings(new MapSettings().setProperty("sonar.exclusions", "**/*something.xml"));
Collection<GeneratedFile> generatedFiles = new Jasper().generateFiles(ctx, emptyList());
assertThat(generatedFiles).hasSize(1);
}
Aggregations