Skip to content

Commit 08065ba

Browse files
authored
Merge pull request #33 from utPLSQL/feature/issue-28-optional-reporters-tag
Optional reporters tag
2 parents 4417c12 + 0dd57b9 commit 08065ba

File tree

2 files changed

+51
-23
lines changed

2 files changed

+51
-23
lines changed

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

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.utplsql.api.TestRunner;
2525
import org.utplsql.api.Version;
2626
import org.utplsql.api.exception.SomeTestsFailedException;
27+
import org.utplsql.api.reporter.CoreReporters;
2728
import org.utplsql.api.reporter.Reporter;
2829
import org.utplsql.api.reporter.ReporterFactory;
2930
import org.utplsql.maven.plugin.helper.PluginDefault;
@@ -138,21 +139,25 @@ public void execute() throws MojoExecutionException {
138139
try {
139140
FileMapperOptions sourceMappingOptions = buildSourcesOptions();
140141
FileMapperOptions testMappingOptions = buildTestsOptions();
141-
142-
// Create the Connection to the Database
142+
143143
connection = DriverManager.getConnection(url, user, password);
144-
getLog().info("utPLSQL Version = " + DBHelper.getDatabaseFrameworkVersion(connection));
145-
146-
List<Reporter> reporterList = initReporters(connection);
147-
144+
145+
Version utlVersion = DBHelper.getDatabaseFrameworkVersion(connection);
146+
getLog().info("utPLSQL Version = " + utlVersion);
147+
148+
List<Reporter> reporterList = initReporters(connection, utlVersion, ReporterFactory.createEmpty());
149+
148150
logParameters(sourceMappingOptions, testMappingOptions, reporterList);
149151

150-
TestRunner runner = new TestRunner().addPathList(paths).addReporterList(reporterList)
151-
.sourceMappingOptions(sourceMappingOptions).testMappingOptions(testMappingOptions)
152-
.skipCompatibilityCheck(skipCompatibilityCheck).colorConsole(colorConsole)
152+
TestRunner runner = new TestRunner()
153+
.addPathList(paths)
154+
.addReporterList(reporterList)
155+
.sourceMappingOptions(sourceMappingOptions)
156+
.testMappingOptions(testMappingOptions)
157+
.skipCompatibilityCheck(skipCompatibilityCheck)
158+
.colorConsole(colorConsole)
153159
.failOnErrors(!ignoreFailure);
154-
155-
// Setting Optional Parameters
160+
156161
if (StringUtils.isNotBlank(excludeObject)) {
157162
runner.excludeObject(excludeObject);
158163
}
@@ -170,9 +175,9 @@ public void execute() throws MojoExecutionException {
170175
throw new MojoExecutionException(e.getMessage(), e);
171176
} finally {
172177
try {
173-
// Write Reporters
174-
if (connection != null)
178+
if (null != connection) {
175179
reporterWriter.writeReporters(connection);
180+
}
176181
} catch (Exception e) {
177182
getLog().error(e.getMessage(), e);
178183
}
@@ -205,7 +210,6 @@ private void loadConfFromEnvironment() {
205210
*/
206211
private FileMapperOptions buildSourcesOptions() throws MojoExecutionException {
207212
try {
208-
// Check if this element is empty
209213
if (sources.isEmpty()) {
210214
File defaultSourceDirectory = new File(project.getBasedir(),PluginDefault.SOURCE_DIRECTORY);
211215
if (defaultSourceDirectory.exists()) {
@@ -262,7 +266,6 @@ private FileMapperOptions buildSourcesOptions() throws MojoExecutionException {
262266
*/
263267
private FileMapperOptions buildTestsOptions() throws MojoExecutionException {
264268
try {
265-
// Check if this element is empty
266269
if (tests.isEmpty()) {
267270
File defaultTestDirectory = new File(project.getBasedir(),PluginDefault.TEST_DIRECTORY);
268271
if (defaultTestDirectory.exists()) {
@@ -318,15 +321,18 @@ private FileMapperOptions buildTestsOptions() throws MojoExecutionException {
318321
* @return
319322
* @throws SQLException
320323
*/
321-
private List<Reporter> initReporters(Connection connection) throws SQLException {
322-
List<Reporter> reporterList = new ArrayList<>();
323-
324-
Version utlVersion = DBHelper.getDatabaseFrameworkVersion(connection);
324+
private List<Reporter> initReporters(
325+
Connection connection, Version utlVersion, ReporterFactory reporterFactory) throws SQLException {
325326

326-
// Initialized Reporters
327+
List<Reporter> reporterList = new ArrayList<>();
327328
reporterWriter = new ReporterWriter(targetDir, utlVersion);
328329

329-
ReporterFactory reporterFactory = ReporterFactory.createEmpty();
330+
if (reporters.isEmpty()) {
331+
ReporterParameter reporterParameter = new ReporterParameter();
332+
reporterParameter.setConsoleOutput(true);
333+
reporterParameter.setName(CoreReporters.UT_DOCUMENTATION_REPORTER.name());
334+
reporters.add(reporterParameter);
335+
}
330336

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

361-
// Do nothing when the debug is disabled
362367
if (!log.isDebugEnabled()) {
363368
return;
364369
}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public void testDefaultConsoleBehaviour() throws Exception {
266266
return mockReporter;
267267
});
268268

269-
Whitebox.invokeMethod(utplsqlMojo, "initReporters", mockConnection);
269+
Whitebox.invokeMethod(utplsqlMojo, "initReporters", mockConnection, mockVersion, mockReporterFactory);
270270

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

301+
@Test
302+
public void testAddDefaultReporter() throws Exception {
303+
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(new File("src/test/resources/defaultConsoleOutputBehaviour/"), "test");
304+
Assert.assertNotNull(utplsqlMojo);
305+
306+
List<Reporter> reporterList = new ArrayList<>();
307+
when(mockReporterFactory.createReporter(anyString())).thenAnswer(invocation -> {
308+
Reporter mockReporter = mock(Reporter.class);
309+
when(mockReporter.getTypeName()).thenReturn(invocation.getArgument(0));
310+
reporterList.add(mockReporter);
311+
return mockReporter;
312+
});
313+
314+
List<ReporterParameter> reporterParameters = Whitebox.getInternalState(utplsqlMojo, "reporters");
315+
reporterParameters.clear();
316+
317+
Whitebox.invokeMethod(utplsqlMojo, "initReporters", mockConnection, mockVersion, mockReporterFactory);
318+
319+
assertEquals(1, reporterList.size());
320+
assertEquals("UT_DOCUMENTATION_REPORTER", reporterList.get(0).getTypeName());
321+
verify(reporterList.get(0)).init(mockConnection);
322+
}
323+
301324
}

0 commit comments

Comments
 (0)