Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.utplsql.api.TestRunner;
import org.utplsql.api.Version;
import org.utplsql.api.exception.SomeTestsFailedException;
import org.utplsql.api.reporter.CoreReporters;
import org.utplsql.api.reporter.Reporter;
import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.maven.plugin.helper.PluginDefault;
Expand Down Expand Up @@ -138,21 +139,25 @@ public void execute() throws MojoExecutionException {
try {
FileMapperOptions sourceMappingOptions = buildSourcesOptions();
FileMapperOptions testMappingOptions = buildTestsOptions();

// Create the Connection to the Database

connection = DriverManager.getConnection(url, user, password);
getLog().info("utPLSQL Version = " + DBHelper.getDatabaseFrameworkVersion(connection));

List<Reporter> reporterList = initReporters(connection);


Version utlVersion = DBHelper.getDatabaseFrameworkVersion(connection);
getLog().info("utPLSQL Version = " + utlVersion);

List<Reporter> reporterList = initReporters(connection, utlVersion, ReporterFactory.createEmpty());

logParameters(sourceMappingOptions, testMappingOptions, reporterList);

TestRunner runner = new TestRunner().addPathList(paths).addReporterList(reporterList)
.sourceMappingOptions(sourceMappingOptions).testMappingOptions(testMappingOptions)
.skipCompatibilityCheck(skipCompatibilityCheck).colorConsole(colorConsole)
TestRunner runner = new TestRunner()
.addPathList(paths)
.addReporterList(reporterList)
.sourceMappingOptions(sourceMappingOptions)
.testMappingOptions(testMappingOptions)
.skipCompatibilityCheck(skipCompatibilityCheck)
.colorConsole(colorConsole)
.failOnErrors(!ignoreFailure);

// Setting Optional Parameters

if (StringUtils.isNotBlank(excludeObject)) {
runner.excludeObject(excludeObject);
}
Expand All @@ -170,9 +175,9 @@ public void execute() throws MojoExecutionException {
throw new MojoExecutionException(e.getMessage(), e);
} finally {
try {
// Write Reporters
if (connection != null)
if (null != connection) {
reporterWriter.writeReporters(connection);
}
} catch (Exception e) {
getLog().error(e.getMessage(), e);
}
Expand Down Expand Up @@ -205,7 +210,6 @@ private void loadConfFromEnvironment() {
*/
private FileMapperOptions buildSourcesOptions() throws MojoExecutionException {
try {
// Check if this element is empty
if (sources.isEmpty()) {
File defaultSourceDirectory = new File(project.getBasedir(),PluginDefault.SOURCE_DIRECTORY);
if (defaultSourceDirectory.exists()) {
Expand Down Expand Up @@ -262,7 +266,6 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException {
*/
private FileMapperOptions buildTestsOptions() throws MojoExecutionException {
try {
// Check if this element is empty
if (tests.isEmpty()) {
File defaultTestDirectory = new File(project.getBasedir(),PluginDefault.TEST_DIRECTORY);
if (defaultTestDirectory.exists()) {
Expand Down Expand Up @@ -318,15 +321,18 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException {
* @return
* @throws SQLException
*/
private List<Reporter> initReporters(Connection connection) throws SQLException {
List<Reporter> reporterList = new ArrayList<>();

Version utlVersion = DBHelper.getDatabaseFrameworkVersion(connection);
private List<Reporter> initReporters(
Connection connection, Version utlVersion, ReporterFactory reporterFactory) throws SQLException {

// Initialized Reporters
List<Reporter> reporterList = new ArrayList<>();
reporterWriter = new ReporterWriter(targetDir, utlVersion);

ReporterFactory reporterFactory = ReporterFactory.createEmpty();
if (reporters.isEmpty()) {
ReporterParameter reporterParameter = new ReporterParameter();
reporterParameter.setConsoleOutput(true);
reporterParameter.setName(CoreReporters.UT_DOCUMENTATION_REPORTER.name());
reporters.add(reporterParameter);
}

for (ReporterParameter reporterParameter : reporters) {
Reporter reporter = reporterFactory.createReporter(reporterParameter.getName());
Expand Down Expand Up @@ -358,7 +364,6 @@ private void logParameters(FileMapperOptions sourceMappingOptions, FileMapperOpt
Log log = getLog();
log.info("Invoking TestRunner with: " + targetDir);

// Do nothing when the debug is disabled
if (!log.isDebugEnabled()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public void testDefaultConsoleBehaviour() throws Exception {
return mockReporter;
});

Whitebox.invokeMethod(utplsqlMojo, "initReporters", mockConnection);
Whitebox.invokeMethod(utplsqlMojo, "initReporters", mockConnection, mockVersion, mockReporterFactory);

// Assert that we called the create reporter with the correct parameters.
verify(mockReporterFactory, times(2)).createReporter("UT_DOCUMENTATION_REPORTER");
Expand Down Expand Up @@ -298,4 +298,27 @@ public void testDefaultConsoleBehaviour() throws Exception {
assertTrue(reporterParameter3.isFileOutput());
}

@Test
public void testAddDefaultReporter() throws Exception {
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/defaultConsoleOutputBehaviour/"), "test");
Assert.assertNotNull(utplsqlMojo);

List<Reporter> reporterList = new ArrayList<>();
when(mockReporterFactory.createReporter(anyString())).thenAnswer(invocation -> {
Reporter mockReporter = mock(Reporter.class);
when(mockReporter.getTypeName()).thenReturn(invocation.getArgument(0));
reporterList.add(mockReporter);
return mockReporter;
});

List<ReporterParameter> reporterParameters = Whitebox.getInternalState(utplsqlMojo, "reporters");
reporterParameters.clear();

Whitebox.invokeMethod(utplsqlMojo, "initReporters", mockConnection, mockVersion, mockReporterFactory);

assertEquals(1, reporterList.size());
assertEquals("UT_DOCUMENTATION_REPORTER", reporterList.get(0).getTypeName());
verify(reporterList.get(0)).init(mockConnection);
}

}