use of org.apache.maven.plugins.checkstyle.CheckstyleReport in project maven-plugins by apache.
the class CheckstyleReportTest method generateReport.
private File generateReport(String pluginXml) throws Exception {
File pluginXmlFile = new File(getBasedir(), "src/test/plugin-configs/" + pluginXml);
ResourceBundle bundle = ResourceBundle.getBundle("checkstyle-report", Locale.getDefault(), this.getClassLoader());
CheckstyleReport mojo = (CheckstyleReport) lookupMojo("checkstyle", pluginXmlFile);
assertNotNull("Mojo found.", mojo);
PluginDescriptor descriptorStub = new PluginDescriptor();
descriptorStub.setGroupId("org.apache.maven.plugins");
descriptorStub.setArtifactId("maven-checkstyle-plugin");
setVariableValueToObject(mojo, "plugin", descriptorStub);
mojo.execute();
File outputFile = (File) getVariableValueFromObject(mojo, "outputFile");
assertNotNull("Test output file", outputFile);
assertTrue("Test output file exists", outputFile.exists());
String cacheFile = (String) getVariableValueFromObject(mojo, "cacheFile");
if (cacheFile != null) {
assertTrue("Test cache file exists", new File(cacheFile).exists());
}
MavenReport reportMojo = mojo;
File outputDir = reportMojo.getReportOutputDirectory();
Boolean rss = (Boolean) getVariableValueFromObject(mojo, "enableRSS");
if (rss) {
File rssFile = new File(outputDir, "checkstyle.rss");
assertTrue("Test rss file exists", rssFile.exists());
}
File useFile = (File) getVariableValueFromObject(mojo, "useFile");
if (useFile != null) {
assertTrue("Test useFile exists", useFile.exists());
}
String filename = reportMojo.getOutputName() + ".html";
File outputHtml = new File(outputDir, filename);
renderer(mojo, outputHtml);
assertTrue(outputHtml.getAbsolutePath() + " not generated!", outputHtml.exists());
assertTrue(outputHtml.getAbsolutePath() + " is empty!", outputHtml.length() > 0);
String htmlString = FileUtils.fileRead(outputHtml);
boolean searchHeaderFound = (htmlString.indexOf("<h2>" + bundle.getString("report.checkstyle.rules")) > 0);
Boolean rules = (Boolean) getVariableValueFromObject(mojo, "enableRulesSummary");
if (rules) {
assertTrue("Test for Rules Summary", searchHeaderFound);
} else {
assertFalse("Test for Rules Summary", searchHeaderFound);
}
searchHeaderFound = (htmlString.indexOf("<h2>" + bundle.getString("report.checkstyle.summary")) > 0);
Boolean severity = (Boolean) getVariableValueFromObject(mojo, "enableSeveritySummary");
if (severity) {
assertTrue("Test for Severity Summary", searchHeaderFound);
} else {
assertFalse("Test for Severity Summary", searchHeaderFound);
}
searchHeaderFound = (htmlString.indexOf("<h2>" + bundle.getString("report.checkstyle.files")) > 0);
Boolean files = (Boolean) getVariableValueFromObject(mojo, "enableFilesSummary");
if (files) {
assertTrue("Test for Files Summary", searchHeaderFound);
} else {
assertFalse("Test for Files Summary", searchHeaderFound);
}
return outputHtml;
}
use of org.apache.maven.plugins.checkstyle.CheckstyleReport in project maven-plugins by apache.
the class CheckstyleReportTest method testNoSource.
public void testNoSource() throws Exception {
File pluginXmlFile = new File(getBasedir(), "src/test/plugin-configs/no-source-plugin-config.xml");
CheckstyleReport mojo = (CheckstyleReport) lookupMojo("checkstyle", pluginXmlFile);
assertNotNull("Mojo found.", mojo);
mojo.execute();
File outputFile = (File) getVariableValueFromObject(mojo, "outputFile");
renderer(mojo, outputFile);
assertTrue(outputFile.getAbsolutePath() + " not generated!", outputFile.exists());
assertTrue(outputFile.getAbsolutePath() + " is empty!", outputFile.length() <= 0);
}
Aggregations