diff --git a/README.md b/README.md
index e7dbb4f..ce82511 100644
--- a/README.md
+++ b/README.md
@@ -101,66 +101,75 @@ You have to be a fully utPLSQL environment available compatible with the Java AP
The next snippet is a sample of declaration of the pom
```xml
- 4.0.0
-
- org.my_org
- my-artifact-name
- 1.0.0
-
-
- url_of_connection
- user
- password
-
-
- org.utplsql
- utplsql-maven-plugin
- 3.1.0
-
- test
-
-
- false
-
- schema_name
-
-
-
- UT_COVERAGE_SONAR_REPORTER
- utplsql/coverage-sonar-reporter.xml
- true
-
-
- UT_SONAR_TEST_REPORTER
- utplsql/sonar-test-reporter.xml
- false
-
-
- UT_TEAMCITY_REPORTER
-
-
-
-
- src/test/resources/scripts/sources
-
- **/*pkg
- **/*pkb
-
-
-
-
-
- src/test/resources/scripts/test
-
- **/*pkg
- **/*pkb
-
-
-
-
-
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
+
+ org.my_org
+ my-artifact-name
+ 1.0.0
+
+
+ url_of_connection
+ user
+ password
+
+
+
+
+
+ org.utplsql
+ utplsql-maven-plugin
+ 3.1.0
+
+
+
+ test
+
+
+ false
+
+ schema_name
+
+
+
+ UT_COVERAGE_SONAR_REPORTER
+ utplsql/coverage-sonar-reporter.xml
+ true
+
+
+ UT_SONAR_TEST_REPORTER
+ utplsql/sonar-test-reporter.xml
+ false
+
+
+ UT_TEAMCITY_REPORTER
+
+
+
+
+ src/test/resources/scripts/sources
+
+ **/*pkg
+ **/*pkb
+
+
+
+
+
+ src/test/resources/scripts/test
+
+ **/*pkg
+ **/*pkb
+
+
+
+
+
+
+
+
+
```
diff --git a/utplsql-maven-plugin-it/src/it/java/org/utpsql/maven/plugin/test/UtPLSQLMojoIT.java b/utplsql-maven-plugin-it/src/it/java/org/utpsql/maven/plugin/test/UtPLSQLMojoIT.java
index af730c8..1c2a301 100644
--- a/utplsql-maven-plugin-it/src/it/java/org/utpsql/maven/plugin/test/UtPLSQLMojoIT.java
+++ b/utplsql-maven-plugin-it/src/it/java/org/utpsql/maven/plugin/test/UtPLSQLMojoIT.java
@@ -174,13 +174,16 @@ private void checkReportsGenerated(String projectName, String... files) {
// Path separator is set to "/" to ensure windows / linux / mac compatibility
Stream stream = Files
.lines(Paths.get("target", "test-classes", projectName, "target", filename));
- String outputContent = stream.map(line -> line.replaceAll("(duration=\"[0-9\\.]*\")", "duration=\"1\""))
+
+ String outputContent = stream
+ .map(line -> line.replaceAll("(encoding=\"[^\"]*\")", "encoding=\"WINDOWS-1252\""))
+ .map(line -> line.replaceAll("(duration=\"[0-9\\.]*\")", "duration=\"1\""))
.map(line -> line.replaceAll("\\\\", "/"))
.map(line -> line.replaceAll("\r", "").replaceAll("\n", "")).collect(Collectors.joining("\n"));
stream.close();
- Assert.assertEquals("The files differ!", outputContent,
- FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r", ""));
+ Assert.assertEquals("The files differ!",
+ FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r", ""), outputContent);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
diff --git a/utplsql-maven-plugin/pom.xml b/utplsql-maven-plugin/pom.xml
index 9a4d6a9..32c92a3 100644
--- a/utplsql-maven-plugin/pom.xml
+++ b/utplsql-maven-plugin/pom.xml
@@ -19,6 +19,7 @@
UTF-8
1.8
+ 1.7.4
@@ -64,9 +65,16 @@
org.powermock
powermock-module-junit4
- 1.7.4
+ ${powermock.version}
test
+
+
+ org.powermock
+ powermock-api-mockito2
+ ${powermock.version}
+ test
+
org.apache.maven.plugin-testing
diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java
index 1dbcfd2..3f07121 100644
--- a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java
+++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java
@@ -332,6 +332,11 @@ private List initReporters(Connection connection) throws SQLException
Reporter reporter = reporterFactory.createReporter(reporterParameter.getName());
reporter.init(connection);
reporterList.add(reporter);
+
+ // Turns the console output on by default if both file and console output are empty.
+ if (!reporterParameter.isFileOutput() && null == reporterParameter.getConsoleOutput()) {
+ reporterParameter.setConsoleOutput(true);
+ }
// Only added the reporter if at least one of the output is required
if (StringUtils.isNotBlank(reporterParameter.getFileOutput()) || reporterParameter.isConsoleOutput()) {
diff --git a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/model/ReporterParameter.java b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/model/ReporterParameter.java
index 979d7cc..019c0e0 100644
--- a/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/model/ReporterParameter.java
+++ b/utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/model/ReporterParameter.java
@@ -12,7 +12,7 @@ public class ReporterParameter
private String fileOutput;
// Writes the report to console
- private boolean consoleOutput;
+ private Boolean consoleOutput;
/**
*
@@ -55,13 +55,17 @@ public void setFileOutput(String fileOutput)
{
this.fileOutput = fileOutput;
}
+
+ public Boolean getConsoleOutput() {
+ return consoleOutput;
+ }
/**
* @return the consoleOutput
*/
- public boolean isConsoleOutput()
+ public Boolean isConsoleOutput()
{
- return consoleOutput;
+ return null != consoleOutput && consoleOutput;
}
/**
diff --git a/utplsql-maven-plugin/src/test/java/org/utplsql/maven/plugin/test/UtPLSQLMojoTest.java b/utplsql-maven-plugin/src/test/java/org/utplsql/maven/plugin/test/UtPLSQLMojoTest.java
index b51bb7d..6cd6891 100644
--- a/utplsql-maven-plugin/src/test/java/org/utplsql/maven/plugin/test/UtPLSQLMojoTest.java
+++ b/utplsql-maven-plugin/src/test/java/org/utplsql/maven/plugin/test/UtPLSQLMojoTest.java
@@ -1,21 +1,47 @@
package org.utplsql.maven.plugin.test;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
import java.io.File;
+import java.sql.Connection;
+import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.lang3.tuple.Pair;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.testing.MojoRule;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
+import org.utplsql.api.DBHelper;
import org.utplsql.api.FileMapperOptions;
+import org.utplsql.api.Version;
+import org.utplsql.api.reporter.Reporter;
+import org.utplsql.api.reporter.ReporterFactory;
import org.utplsql.maven.plugin.UtPLSQLMojo;
+import org.utplsql.maven.plugin.model.ReporterParameter;
+import org.utplsql.maven.plugin.reporter.ReporterWriter;
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({
+ DBHelper.class,
+ ReporterFactory.class})
public class UtPLSQLMojoTest {
@Rule
@@ -24,6 +50,24 @@ public class UtPLSQLMojoTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
+ @Mock
+ public Connection mockConnection;
+
+ @Mock
+ public Version mockVersion;
+
+ @Mock
+ public ReporterFactory mockReporterFactory;
+
+ @Before
+ public void setUp() throws Exception {
+ mockStatic(DBHelper.class);
+ when(DBHelper.getDatabaseFrameworkVersion(mockConnection)).thenReturn(mockVersion);
+
+ mockStatic(ReporterFactory.class);
+ when(ReporterFactory.createEmpty()).thenReturn(mockReporterFactory);
+ }
+
/**
* testInvalidSourcesDirectory.
*
@@ -210,5 +254,48 @@ public void testSourcesAndTestsParameterHaveNotIncludesTag() throws Exception {
assertTrue(tests.getFilePaths().contains("src/test/bar/f2.pkg"));
}
+ @Test
+ public void testDefaultConsoleBehaviour() throws Exception {
+ UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/defaultConsoleOutputBehaviour/"), "test");
+ Assert.assertNotNull(utplsqlMojo);
+
+ List reporterList = new ArrayList<>();
+ when(mockReporterFactory.createReporter(anyString())).thenAnswer(invocation -> {
+ Reporter mockReporter = mock(Reporter.class);
+ reporterList.add(mockReporter);
+ return mockReporter;
+ });
+
+ Whitebox.invokeMethod(utplsqlMojo, "initReporters", mockConnection);
+
+ // Assert that we called the create reporter with the correct parameters.
+ verify(mockReporterFactory, times(2)).createReporter("UT_DOCUMENTATION_REPORTER");
+ verify(mockReporterFactory).createReporter("UT_COVERAGE_SONAR_REPORTER");
+ verify(mockReporterFactory).createReporter("UT_SONAR_TEST_REPORTER");
+ verifyNoMoreInteractions(mockReporterFactory);
+
+ // Assert that all reporters have been initialized.
+ for (Reporter mockReporter : reporterList) {
+ verify(mockReporter).init(mockConnection);
+ verifyNoMoreInteractions(mockReporter);
+ }
+
+ // Assert that we added only the necessary reporters to the writer.
+ ReporterWriter reporterWritter = Whitebox.getInternalState(utplsqlMojo, "reporterWriter");
+ List> listReporters = Whitebox.getInternalState(reporterWritter, "listReporters");
+ assertEquals(3, listReporters.size());
+
+ ReporterParameter reporterParameter1 = listReporters.get(0).getRight();
+ assertTrue(reporterParameter1.isConsoleOutput());
+ assertFalse(reporterParameter1.isFileOutput());
+
+ ReporterParameter reporterParameter2 = listReporters.get(1).getRight();
+ assertFalse(reporterParameter2.isConsoleOutput());
+ assertTrue(reporterParameter2.isFileOutput());
+
+ ReporterParameter reporterParameter3 = listReporters.get(2).getRight();
+ assertTrue(reporterParameter3.isConsoleOutput());
+ assertTrue(reporterParameter3.isFileOutput());
+ }
}
diff --git a/utplsql-maven-plugin/src/test/resources/defaultConsoleOutputBehaviour/pom.xml b/utplsql-maven-plugin/src/test/resources/defaultConsoleOutputBehaviour/pom.xml
new file mode 100644
index 0000000..0bfc40f
--- /dev/null
+++ b/utplsql-maven-plugin/src/test/resources/defaultConsoleOutputBehaviour/pom.xml
@@ -0,0 +1,84 @@
+
+ 4.0.0
+
+
+ org.utplsql
+ utplsql-maven-plugin-test
+ 3.1.0-SNAPSHOT
+
+ pom
+
+ utplsql-maven-plugin Maven Plugin Test
+
+ http://utplsql.org
+
+
+ jdbc:oracle:thin:@180.129.3.101:1521:xe
+ ut3
+ XNtxj8eEgA6X6b6f
+
+
+
+
+ ../../../target/
+
+
+ org.utplsql
+ utplsql-maven-plugin
+ {project.version}
+
+ test
+
+
+
+
+ false
+
+
+ :plsql
+
+
+
+
+ UT_DOCUMENTATION_REPORTER
+
+
+ UT_DOCUMENTATION_REPORTER
+ false
+
+
+ UT_COVERAGE_SONAR_REPORTER
+ coverage-sonar-reporter.xml
+
+
+ UT_SONAR_TEST_REPORTER
+ utplsql/sonar-test-reporter.xml
+ true
+
+
+
+
+
+ foo
+
+ **/*sql
+
+
+
+
+
+
+ bar
+
+ **/*.spc
+ **/*.bdy
+
+
+
+
+
+
+
+
\ No newline at end of file