Skip to content

Commit 50da81e

Browse files
committed
Sets the console output on by default if no output option specified
1 parent d163a29 commit 50da81e

File tree

7 files changed

+267
-67
lines changed

7 files changed

+267
-67
lines changed

README.md

Lines changed: 69 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -101,66 +101,75 @@ You have to be a fully utPLSQL environment available compatible with the Java AP
101101
The next snippet is a sample of declaration of the pom
102102
```xml
103103
<project xmlns="http://maven.apache.org/POM/4.0.0"
104-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
105-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
106-
<modelVersion>4.0.0</modelVersion>
107-
108-
<groupId>org.my_org</groupId>
109-
<artifactId>my-artifact-name</artifactId>
110-
<version>1.0.0</version>
111-
112-
<properties>
113-
<dbUrl>url_of_connection</dbUrl>
114-
<dbUser>user</dbUser>
115-
<dbPass>password</dbPass>
116-
</properties>
117-
<plugin>
118-
<groupId>org.utplsql</groupId>
119-
<artifactId>utplsql-maven-plugin</artifactId>
120-
<version>3.1.0</version>
121-
<goals>
122-
<goal>test</goal>
123-
</goals>
124-
<configuration>
125-
<ignoreFailure>false</ignoreFailure>
126-
<paths>
127-
<path>schema_name</path>
128-
</paths>
129-
<reporters>
130-
<reporter>
131-
<name>UT_COVERAGE_SONAR_REPORTER</name>
132-
<fileOutput>utplsql/coverage-sonar-reporter.xml</fileOutput>
133-
<consoleOutput>true</consoleOutput>
134-
</reporter>
135-
<reporter>
136-
<name>UT_SONAR_TEST_REPORTER</name>
137-
<fileOutput>utplsql/sonar-test-reporter.xml</fileOutput>
138-
<consoleOutput>false</consoleOutput>
139-
</reporter>
140-
<reporter>
141-
<name>UT_TEAMCITY_REPORTER</name>
142-
</reporter>
143-
</reporters>
144-
<sources>
145-
<source>
146-
<directory>src/test/resources/scripts/sources</directory>
147-
<includes>
148-
<include>**/*pkg</include>
149-
<include>**/*pkb</include>
150-
</includes>
151-
</source>
152-
</sources>
153-
<tests>
154-
<test>
155-
<directory>src/test/resources/scripts/test</directory>
156-
<includes>
157-
<include>**/*pkg</include>
158-
<include>**/*pkb</include>
159-
</includes>
160-
</test>
161-
</tests>
162-
</configuration>
163-
</plugin>
104+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
105+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
106+
<modelVersion>4.0.0</modelVersion>
107+
108+
<groupId>org.my_org</groupId>
109+
<artifactId>my-artifact-name</artifactId>
110+
<version>1.0.0</version>
111+
112+
<properties>
113+
<dbUrl>url_of_connection</dbUrl>
114+
<dbUser>user</dbUser>
115+
<dbPass>password</dbPass>
116+
</properties>
117+
118+
<build>
119+
<plugins>
120+
<plugin>
121+
<groupId>org.utplsql</groupId>
122+
<artifactId>utplsql-maven-plugin</artifactId>
123+
<version>3.1.0</version>
124+
<executions>
125+
<execution>
126+
<goals>
127+
<goal>test</goal>
128+
</goals>
129+
<configuration>
130+
<ignoreFailure>false</ignoreFailure>
131+
<paths>
132+
<path>schema_name</path>
133+
</paths>
134+
<reporters>
135+
<reporter>
136+
<name>UT_COVERAGE_SONAR_REPORTER</name>
137+
<fileOutput>utplsql/coverage-sonar-reporter.xml</fileOutput>
138+
<consoleOutput>true</consoleOutput>
139+
</reporter>
140+
<reporter>
141+
<name>UT_SONAR_TEST_REPORTER</name>
142+
<fileOutput>utplsql/sonar-test-reporter.xml</fileOutput>
143+
<consoleOutput>false</consoleOutput>
144+
</reporter>
145+
<reporter>
146+
<name>UT_TEAMCITY_REPORTER</name>
147+
</reporter>
148+
</reporters>
149+
<sources>
150+
<source>
151+
<directory>src/test/resources/scripts/sources</directory>
152+
<includes>
153+
<include>**/*pkg</include>
154+
<include>**/*pkb</include>
155+
</includes>
156+
</source>
157+
</sources>
158+
<tests>
159+
<test>
160+
<directory>src/test/resources/scripts/test</directory>
161+
<includes>
162+
<include>**/*pkg</include>
163+
<include>**/*pkb</include>
164+
</includes>
165+
</test>
166+
</tests>
167+
</configuration>
168+
</execution>
169+
</executions>
170+
</plugin>
171+
</plugins>
172+
</build>
164173
</project>
165174
```
166175

utplsql-maven-plugin-it/src/it/java/org/utpsql/maven/plugin/test/UtPLSQLMojoIT.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,16 @@ private void checkReportsGenerated(String projectName, String... files) {
174174
// Path separator is set to "/" to ensure windows / linux / mac compatibility
175175
Stream<String> stream = Files
176176
.lines(Paths.get("target", "test-classes", projectName, "target", filename));
177-
String outputContent = stream.map(line -> line.replaceAll("(duration=\"[0-9\\.]*\")", "duration=\"1\""))
177+
178+
String outputContent = stream
179+
.map(line -> line.replaceAll("(encoding=\"[^\"]*\")", "encoding=\"WINDOWS-1252\""))
180+
.map(line -> line.replaceAll("(duration=\"[0-9\\.]*\")", "duration=\"1\""))
178181
.map(line -> line.replaceAll("\\\\", "/"))
179182
.map(line -> line.replaceAll("\r", "").replaceAll("\n", "")).collect(Collectors.joining("\n"));
180183

181184
stream.close();
182-
Assert.assertEquals("The files differ!", outputContent,
183-
FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r", ""));
185+
Assert.assertEquals("The files differ!",
186+
FileUtils.readFileToString(expectedOutputFile, "utf-8").replace("\r", ""), outputContent);
184187
} catch (IOException e) {
185188
// TODO Auto-generated catch block
186189
e.printStackTrace();

utplsql-maven-plugin/pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<properties>
2020
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2121
<java.version>1.8</java.version>
22+
<powermock.version>1.7.4</powermock.version>
2223
</properties>
2324
<dependencies>
2425

@@ -64,9 +65,16 @@
6465
<dependency>
6566
<groupId>org.powermock</groupId>
6667
<artifactId>powermock-module-junit4</artifactId>
67-
<version>1.7.4</version>
68+
<version>${powermock.version}</version>
6869
<scope>test</scope>
6970
</dependency>
71+
72+
<dependency>
73+
<groupId>org.powermock</groupId>
74+
<artifactId>powermock-api-mockito2</artifactId>
75+
<version>${powermock.version}</version>
76+
<scope>test</scope>
77+
</dependency>
7078

7179
<dependency>
7280
<groupId>org.apache.maven.plugin-testing</groupId>

utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ private List<Reporter> initReporters(Connection connection) throws SQLException
332332
Reporter reporter = reporterFactory.createReporter(reporterParameter.getName());
333333
reporter.init(connection);
334334
reporterList.add(reporter);
335+
336+
// Turns the console output on by default if both file and console output are empty.
337+
if (!reporterParameter.isFileOutput() && null == reporterParameter.getConsoleOutput()) {
338+
reporterParameter.setConsoleOutput(true);
339+
}
335340

336341
// Only added the reporter if at least one of the output is required
337342
if (StringUtils.isNotBlank(reporterParameter.getFileOutput()) || reporterParameter.isConsoleOutput()) {

utplsql-maven-plugin/src/main/java/org/utplsql/maven/plugin/model/ReporterParameter.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class ReporterParameter
1212
private String fileOutput;
1313

1414
// Writes the report to console
15-
private boolean consoleOutput;
15+
private Boolean consoleOutput;
1616

1717
/**
1818
*
@@ -55,13 +55,17 @@ public void setFileOutput(String fileOutput)
5555
{
5656
this.fileOutput = fileOutput;
5757
}
58+
59+
public Boolean getConsoleOutput() {
60+
return consoleOutput;
61+
}
5862

5963
/**
6064
* @return the consoleOutput
6165
*/
62-
public boolean isConsoleOutput()
66+
public Boolean isConsoleOutput()
6367
{
64-
return consoleOutput;
68+
return null != consoleOutput && consoleOutput;
6569
}
6670

6771
/**

utplsql-maven-plugin/src/test/java/org/utplsql/maven/plugin/test/UtPLSQLMojoTest.java

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,47 @@
11
package org.utplsql.maven.plugin.test;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
45
import static org.junit.Assert.assertTrue;
6+
import static org.mockito.ArgumentMatchers.anyString;
7+
import static org.mockito.Mockito.mock;
8+
import static org.mockito.Mockito.times;
9+
import static org.mockito.Mockito.verify;
10+
import static org.mockito.Mockito.verifyNoMoreInteractions;
11+
import static org.powermock.api.mockito.PowerMockito.mockStatic;
12+
import static org.powermock.api.mockito.PowerMockito.when;
513

614
import java.io.File;
15+
import java.sql.Connection;
16+
import java.util.ArrayList;
717
import java.util.List;
818

19+
import org.apache.commons.lang3.tuple.Pair;
920
import org.apache.maven.plugin.MojoExecutionException;
1021
import org.apache.maven.plugin.testing.MojoRule;
1122
import org.junit.Assert;
23+
import org.junit.Before;
1224
import org.junit.Rule;
1325
import org.junit.Test;
1426
import org.junit.rules.ExpectedException;
27+
import org.junit.runner.RunWith;
28+
import org.mockito.Mock;
29+
import org.powermock.core.classloader.annotations.PrepareForTest;
30+
import org.powermock.modules.junit4.PowerMockRunner;
1531
import org.powermock.reflect.Whitebox;
32+
import org.utplsql.api.DBHelper;
1633
import org.utplsql.api.FileMapperOptions;
34+
import org.utplsql.api.Version;
35+
import org.utplsql.api.reporter.Reporter;
36+
import org.utplsql.api.reporter.ReporterFactory;
1737
import org.utplsql.maven.plugin.UtPLSQLMojo;
38+
import org.utplsql.maven.plugin.model.ReporterParameter;
39+
import org.utplsql.maven.plugin.reporter.ReporterWriter;
1840

41+
@RunWith(PowerMockRunner.class)
42+
@PrepareForTest({
43+
DBHelper.class,
44+
ReporterFactory.class})
1945
public class UtPLSQLMojoTest {
2046

2147
@Rule
@@ -24,6 +50,24 @@ public class UtPLSQLMojoTest {
2450
@Rule
2551
public ExpectedException thrown = ExpectedException.none();
2652

53+
@Mock
54+
public Connection mockConnection;
55+
56+
@Mock
57+
public Version mockVersion;
58+
59+
@Mock
60+
public ReporterFactory mockReporterFactory;
61+
62+
@Before
63+
public void setUp() throws Exception {
64+
mockStatic(DBHelper.class);
65+
when(DBHelper.getDatabaseFrameworkVersion(mockConnection)).thenReturn(mockVersion);
66+
67+
mockStatic(ReporterFactory.class);
68+
when(ReporterFactory.createEmpty()).thenReturn(mockReporterFactory);
69+
}
70+
2771
/**
2872
* testInvalidSourcesDirectory.
2973
*
@@ -210,5 +254,48 @@ public void testSourcesAndTestsParameterHaveNotIncludesTag() throws Exception {
210254
assertTrue(tests.getFilePaths().contains("src/test/bar/f2.pkg"));
211255
}
212256

257+
@Test
258+
public void testDefaultConsoleBehaviour() throws Exception {
259+
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/defaultConsoleOutputBehaviour/"), "test");
260+
Assert.assertNotNull(utplsqlMojo);
261+
262+
List<Reporter> reporterList = new ArrayList<>();
263+
when(mockReporterFactory.createReporter(anyString())).thenAnswer(invocation -> {
264+
Reporter mockReporter = mock(Reporter.class);
265+
reporterList.add(mockReporter);
266+
return mockReporter;
267+
});
268+
269+
Whitebox.invokeMethod(utplsqlMojo, "initReporters", mockConnection);
270+
271+
// Assert that we called the create reporter with the correct parameters.
272+
verify(mockReporterFactory, times(2)).createReporter("UT_DOCUMENTATION_REPORTER");
273+
verify(mockReporterFactory).createReporter("UT_COVERAGE_SONAR_REPORTER");
274+
verify(mockReporterFactory).createReporter("UT_SONAR_TEST_REPORTER");
275+
verifyNoMoreInteractions(mockReporterFactory);
276+
277+
// Assert that all reporters have been initialized.
278+
for (Reporter mockReporter : reporterList) {
279+
verify(mockReporter).init(mockConnection);
280+
verifyNoMoreInteractions(mockReporter);
281+
}
282+
283+
// Assert that we added only the necessary reporters to the writer.
284+
ReporterWriter reporterWritter = Whitebox.getInternalState(utplsqlMojo, "reporterWriter");
285+
List<Pair<Reporter, ReporterParameter>> listReporters = Whitebox.getInternalState(reporterWritter, "listReporters");
286+
assertEquals(3, listReporters.size());
287+
288+
ReporterParameter reporterParameter1 = listReporters.get(0).getRight();
289+
assertTrue(reporterParameter1.isConsoleOutput());
290+
assertFalse(reporterParameter1.isFileOutput());
291+
292+
ReporterParameter reporterParameter2 = listReporters.get(1).getRight();
293+
assertFalse(reporterParameter2.isConsoleOutput());
294+
assertTrue(reporterParameter2.isFileOutput());
295+
296+
ReporterParameter reporterParameter3 = listReporters.get(2).getRight();
297+
assertTrue(reporterParameter3.isConsoleOutput());
298+
assertTrue(reporterParameter3.isFileOutput());
299+
}
213300

214301
}

0 commit comments

Comments
 (0)