diff --git a/maven/plugins/common/src/main/java/com/vmware/pscoe/maven/plugins/AbstractVroTestMojo.java b/maven/plugins/common/src/main/java/com/vmware/pscoe/maven/plugins/AbstractVroTestMojo.java index a3f53001e..e23066909 100644 --- a/maven/plugins/common/src/main/java/com/vmware/pscoe/maven/plugins/AbstractVroTestMojo.java +++ b/maven/plugins/common/src/main/java/com/vmware/pscoe/maven/plugins/AbstractVroTestMojo.java @@ -46,14 +46,18 @@ public abstract class AbstractVroTestMojo extends AbstractMojo { @Parameter(required = false, property = "test", defaultValue = "${test.*}") private Map test; + /** + * Triggers the unit tests execution. + * + * @throws MojoExecutionException + * @throws MojoFailureException + */ public void execute() throws MojoExecutionException, MojoFailureException { if (skipTests) { getLog().info("Tests are skipped."); - } - else if (!hasTests()) { + } else if (!hasTests()) { getLog().info("No test files found."); - } - else { + } else { Configuration config = new Configuration(test); printStarted(config); buildTestbed(config); @@ -61,10 +65,18 @@ else if (!hasTests()) { } } + /** + * @return A flag indicating whether or not tests exist for the project. + */ protected Boolean hasTests() { return new File(getCliPath()).exists(); } + /** + * Prints a message indicating the testing step is starting. + * + * @param config + */ protected void printStarted(Configuration config) { getLog().info(""); getLog().info("-------------------------------------------------------"); @@ -72,6 +84,13 @@ protected void printStarted(Configuration config) { getLog().info("-------------------------------------------------------"); } + /** + * Bootstrapping the unit tests. + * + * @param config + * @throws org.apache.maven.plugin.MojoExecutionException + * @throws org.apache.maven.plugin.MojoFailureException + */ protected void buildTestbed(Configuration config) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException { @@ -84,6 +103,12 @@ protected void buildTestbed(Configuration config) .execute(getLog()); } + /** + * Build the command for running the tests. + * + * @param config + * @return The command to be executed for running the tests. + */ protected List buildTestbedCommand(Configuration config) { String projectRoot = project.getBasedir().toPath().toString(); List cmd = new ArrayList<>(); @@ -121,7 +146,7 @@ protected List buildTestbedCommand(Configuration config) { cmd.add(coverageThresholds); } - if(config.isPerFileEnabled()){ + if (config.isPerFileEnabled()) { cmd.add("--per-file"); cmd.add("true"); } @@ -131,6 +156,12 @@ protected List buildTestbedCommand(Configuration config) { protected abstract void addTestbedPaths(List cmd, Configuration config); + /** + * Uses the project configuration it its pom file to build the tests coverage threshold values. + * + * @param config + * @return The threshold values list. + */ protected String buildCoverageThresholdToken(Configuration config) { List thresholds = new ArrayList(5); @@ -167,6 +198,13 @@ protected String buildCoverageThresholdToken(Configuration config) { return String.join(",", thresholds); } + /** + * Builds and executes the tests run. + * + * @param config + * @throws org.apache.maven.plugin.MojoExecutionException + * @throws org.apache.maven.plugin.MojoFailureException + */ protected void runTests(Configuration config) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException { new ProcessExecutor() @@ -178,6 +216,12 @@ protected void runTests(Configuration config) .execute(getLog()); } + /** + * Builds the command for running the tests. + * + * @param config + * @return + */ protected List buildRunCommand(Configuration config) { List cmd = new ArrayList<>(); cmd.add(getCliPath()); @@ -190,7 +234,11 @@ protected List buildRunCommand(Configuration config) { return cmd; } - + /** + * Returns the path tot the vrotest dependency. + * + * @return The path to the vrotest dependency. + */ protected String getCliPath() { String projectRoot = project.getBasedir().toPath().toString(); String vrotestCmd = SystemUtils.IS_OS_WINDOWS ? "vrotest.cmd" : "vrotest"; @@ -225,11 +273,21 @@ public Configuration(Map props) { this.props = props; } + /** + * Returns a flag whether or not code report is enabled. + * + * @return The flag value. + */ public Boolean isCoverageEnabled() { String value = props.get(COVERAGE_ENABLED); return value != null && Boolean.parseBoolean(value); } + /** + * Returns a a list of code coverage reports. + * + * @return The coverate list. + */ public List getCoverageReports() { String value = props.get(COVERAGE_REPORTS); return Arrays.asList((value != null ? value.trim() : "").split(",")).stream() @@ -237,81 +295,164 @@ public List getCoverageReports() { .collect(Collectors.toList()); } + /** + * Loads the configuration value for maximum allowed errors value. + * + * @return The configuration value. + */ public Integer getCoverageThresholdError() { String value = props.get(COVERAGE_THRESHOLD_ERROR); return value != null ? Integer.parseInt(value) : 0; } + /** + * Loads the configuration value for maximum allowed warnings value. + * + * @return The configuration value. + */ public Integer getCoverageThresholdWarn() { String value = props.get(COVERAGE_THRESHOLD_WARN); return value != null ? Integer.parseInt(value) : 0; } + /** + * Loads the configuration value for maximum allowed errors per branch value. + * + * @return The configuration value. + */ public Integer getCoverageBranchesThresholdError() { String value = props.get(COVERAGE_THRESHOLD_BRANCHES_ERROR); return value != null ? Integer.parseInt(value) : 0; } + /** + * Loads the configuration value for maximum allowed warnings per branch value. + * + * @return The configuration value. + */ public Integer getCoverageBranchesThresholdWarn() { String value = props.get(COVERAGE_THRESHOLD_BRANCHES_WARN); return value != null ? Integer.parseInt(value) : 0; } + /** + * Loads the configuration value for maximum allowed errors for lines. + * + * @return The configuration value. + */ public Integer getCoverageLinesThresholdError() { String value = props.get(COVERAGE_THRESHOLD_LINES_ERROR); return value != null ? Integer.parseInt(value) : 0; } + /** + * Loads the configuration value for maximum allowed warnings for lines. + * + * @return The configuration value. + */ public Integer getCoverageLinesThresholdWarn() { String value = props.get(COVERAGE_THRESHOLD_LINES_WARN); return value != null ? Integer.parseInt(value) : 0; } + /** + * Loads the configuration value for maximum allowed errors for functions. + * + * @return The configuration value. + */ public Integer getCoverageFunctionsThresholdError() { String value = props.get(COVERAGE_THRESHOLD_FUNCS_ERROR); return value != null ? Integer.parseInt(value) : 0; } + /** + * Loads the configuration value for maximum allowed warnings for functions. + * + * @return The configuration value. + */ public Integer getCoverageFunctionsThresholdWarn() { String value = props.get(COVERAGE_THRESHOLD_FUNCS_WARN); return value != null ? Integer.parseInt(value) : 0; } + /** + * Loads the configuration value for maximum allowed errors for statements. + * + * @return The configuration value. + */ public Integer getCoverageStatementsThresholdError() { String value = props.get(COVERAGE_THRESHOLD_STMTS_ERROR); return value != null ? Integer.parseInt(value) : 0; } + /** + * Loads the configuration value for maximum allowed warnings for statements. + * + * @return The configuration value. + */ public Integer getCoverageStatementsThresholdWarn() { String value = props.get(COVERAGE_THRESHOLD_STMTS_WARN); return value != null ? Integer.parseInt(value) : 0; } + /** + * Loads the configuration flag value for per-file coverate. + * + * @return The configuration value. + */ public Boolean isPerFileEnabled() { String value = props.get(COVERAGE_TEST_PERFILE); return value != null && Boolean.parseBoolean(value); } + /** + * Returns the framework package name - "jasmine" or "jest". + * + * @return The configuration value. + */ public String getFrameworkPackageName() { String value = props.get(FRAMEWORK_PACKAGE_NAME); return value != null ? value : ""; } + /** + * Returns the framework package version. + * + * @return The configuration value. + */ public String getFrameworkVersion() { String value = props.get(FRAMEWORK_VERSION); return value != null ? value : ""; } + /** + * Returns the version of the Jasmine reporters package. + * Supported when Jasmine is used as tests framework. + * + * @return The configuration value. + */ public String getJasmineReportersVersion() { String value = props.get(JASMINE_REPORTERS_VERSION); return value != null ? value : ""; } + /** + * Returns the version of the Ansi Colors package. + * Supported when Jasmine is used as tests framework. + * + * @return The configuration value. + */ public String getAnsiColorsVersion() { String value = props.get(ANSI_COLORS_VERSION); return value != null ? value : ""; } + /** + * Returns the type of tests runner to be used - supports either none or "swc". + * Supported when Jest is used as tests framework. + * + * @return The configuration value. + */ public String getTestsRunner() { String value = props.get(TESTS_RUNNER); return value != null ? value : "";