Skip to content

Commit 76d3d75

Browse files
committed
UtPlsqlMojo per test method
1 parent 9bb239f commit 76d3d75

File tree

2 files changed

+50
-36
lines changed

2 files changed

+50
-36
lines changed

src/main/java/org/utplsql/maven/plugin/UtPlsqlMojo.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.apache.maven.model.Resource;
66
import org.apache.maven.plugin.AbstractMojo;
77
import org.apache.maven.plugin.MojoExecutionException;
8-
import org.apache.maven.plugin.logging.Log;
98
import org.apache.maven.plugins.annotations.LifecyclePhase;
109
import org.apache.maven.plugins.annotations.Mojo;
1110
import org.apache.maven.plugins.annotations.Parameter;
@@ -278,6 +277,8 @@ private FileMapperOptions createFileMapperOptions(List<String> scripts, String o
278277
List<Reporter> initReporters(Connection connection, ReportWriter reportWriter, ReporterFactory reporterFactory) throws SQLException {
279278
List<Reporter> reporterList = new ArrayList<>();
280279
if (reporters.isEmpty()) {
280+
getLog().debug("No reporters configured using default");
281+
281282
ReporterParameter reporterParameter = new ReporterParameter();
282283
reporterParameter.setConsoleOutput(true);
283284
reporterParameter.setName(CoreReporters.UT_DOCUMENTATION_REPORTER.name());
@@ -302,20 +303,19 @@ List<Reporter> initReporters(Connection connection, ReportWriter reportWriter, R
302303
}
303304

304305
private void logParameters(FileMapperOptions sourceMappingOptions, FileMapperOptions testMappingOptions, List<Reporter> reporterList) {
305-
Log log = getLog();
306-
log.info("Invoking TestRunner with: " + targetDir);
306+
getLog().info("Invoking TestRunner with: " + targetDir);
307307

308-
if (log.isDebugEnabled()) {
309-
log.debug("Invoking TestRunner with: ");
308+
if (getLog().isDebugEnabled()) {
309+
getLog().debug("Invoking TestRunner with: ");
310310

311-
log.debug("reporters=");
312-
reporterList.forEach((Reporter r) -> log.debug(r.getTypeName()));
311+
getLog().debug("reporters=");
312+
reporterList.forEach((Reporter r) -> getLog().debug(r.getTypeName()));
313313

314-
log.debug("sources=");
315-
sourceMappingOptions.getFilePaths().forEach(log::debug);
314+
getLog().debug("sources=");
315+
sourceMappingOptions.getFilePaths().forEach(getLog()::debug);
316316

317-
log.debug("tests=");
318-
testMappingOptions.getFilePaths().forEach(log::debug);
317+
getLog().debug("tests=");
318+
testMappingOptions.getFilePaths().forEach(getLog()::debug);
319319
}
320320
}
321321

src/test/java/org/utplsql/maven/plugin/UtPlsqlMojoTest.java

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.apache.maven.plugin.MojoExecutionException;
44
import org.apache.maven.project.MavenProject;
5-
import org.junit.BeforeClass;
65
import org.junit.Test;
76
import org.utplsql.api.reporter.CoreReporters;
87
import org.utplsql.maven.plugin.model.ReporterParameter;
@@ -15,34 +14,39 @@
1514

1615
public class UtPlsqlMojoTest {
1716

18-
private static UtPlsqlMojo utPLSQLMojo;
17+
private UtPlsqlMojo createUtPlsqlMojo() {
18+
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug");
1919

20-
@BeforeClass
21-
public static void setUp() {
22-
utPLSQLMojo = new UtPlsqlMojo();
23-
utPLSQLMojo.project = new MavenProject();
24-
utPLSQLMojo.targetDir = "target";
20+
UtPlsqlMojo utPlsqlMojo = new UtPlsqlMojo();
21+
utPlsqlMojo.project = new MavenProject();
22+
utPlsqlMojo.targetDir = "target";
2523

26-
utPLSQLMojo.url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
27-
utPLSQLMojo.user = "UT3";
28-
utPLSQLMojo.password = "UT3";
24+
utPlsqlMojo.url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
25+
utPlsqlMojo.user = "UT3";
26+
utPlsqlMojo.password = "UT3";
27+
28+
return utPlsqlMojo;
2929
}
3030

3131
@Test
3232
public void junitReporter() throws MojoExecutionException {
33+
UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo();
34+
3335
ReporterParameter junitReporter = new ReporterParameter();
3436
junitReporter.setConsoleOutput(true);
3537
junitReporter.setFileOutput("junit-report.xml");
3638
junitReporter.setName(CoreReporters.UT_JUNIT_REPORTER.name());
37-
utPLSQLMojo.reporters.add(junitReporter);
39+
utPlsqlMojo.reporters.add(junitReporter);
3840

39-
utPLSQLMojo.execute();
41+
utPlsqlMojo.execute();
4042

4143
assertTrue(new File("target/junit-report.xml").exists());
4244
}
4345

4446
@Test
4547
public void absolutPath() throws MojoExecutionException {
48+
UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo();
49+
4650
ReporterParameter junitReporter = new ReporterParameter();
4751
junitReporter.setConsoleOutput(true);
4852

@@ -53,9 +57,9 @@ public void absolutPath() throws MojoExecutionException {
5357
junitReporter.setFileOutput("/tmp/junit-report.xml");
5458
}
5559
junitReporter.setName(CoreReporters.UT_JUNIT_REPORTER.name());
56-
utPLSQLMojo.reporters.add(junitReporter);
60+
utPlsqlMojo.reporters.add(junitReporter);
5761

58-
utPLSQLMojo.execute();
62+
utPlsqlMojo.execute();
5963
if (os.contains("Windows")) {
6064
assertTrue(new File("c:/tmp/junit-report.xml").exists());
6165
} else {
@@ -65,50 +69,58 @@ public void absolutPath() throws MojoExecutionException {
6569

6670
@Test
6771
public void parentDoesNotExist() throws MojoExecutionException {
72+
UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo();
73+
6874
ReporterParameter junitReporter = new ReporterParameter();
6975
junitReporter.setConsoleOutput(true);
7076
junitReporter.setFileOutput("not-exist/junit-report.xml");
7177
junitReporter.setName(CoreReporters.UT_JUNIT_REPORTER.name());
72-
utPLSQLMojo.reporters.add(junitReporter);
78+
utPlsqlMojo.reporters.add(junitReporter);
7379

74-
utPLSQLMojo.execute();
80+
utPlsqlMojo.execute();
7581

7682
assertTrue(new File("target/not-exist/junit-report.xml").exists());
7783
}
7884

7985
@Test
8086
public void onlyConsoleOutput() throws MojoExecutionException {
87+
UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo();
88+
8189
ReporterParameter junitReporter = new ReporterParameter();
8290
junitReporter.setConsoleOutput(true);
8391
junitReporter.setName(CoreReporters.UT_JUNIT_REPORTER.name());
84-
utPLSQLMojo.reporters.add(junitReporter);
92+
utPlsqlMojo.reporters.add(junitReporter);
8593

86-
utPLSQLMojo.execute();
94+
utPlsqlMojo.execute();
8795

8896
assertTrue(new File("target/not-exist/junit-report.xml").exists());
8997
}
9098

9199
@Test
92100
public void onlyFileOutput() throws MojoExecutionException {
101+
UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo();
102+
93103
ReporterParameter junitReporter = new ReporterParameter();
94104
junitReporter.setConsoleOutput(false);
95105
junitReporter.setFileOutput("not-exist/junit-report.xml");
96106
junitReporter.setName(CoreReporters.UT_JUNIT_REPORTER.name());
97-
utPLSQLMojo.reporters.add(junitReporter);
107+
utPlsqlMojo.reporters.add(junitReporter);
98108

99-
utPLSQLMojo.execute();
109+
utPlsqlMojo.execute();
100110

101111
assertTrue(new File("target/not-exist/junit-report.xml").exists());
102112
}
103113

104114
@Test
105115
public void skipUtplsqlTests() throws MojoExecutionException {
106-
utPLSQLMojo.skipUtplsqlTests = true;
116+
UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo();
117+
118+
utPlsqlMojo.skipUtplsqlTests = true;
107119

108120
final ByteArrayOutputStream console = new ByteArrayOutputStream();
109121
System.setOut(new PrintStream(console));
110122

111-
utPLSQLMojo.execute();
123+
utPlsqlMojo.execute();
112124

113125
String standardOutput = console.toString();
114126

@@ -117,10 +129,12 @@ public void skipUtplsqlTests() throws MojoExecutionException {
117129

118130
@Test
119131
public void defaultReportAndExcludes() throws MojoExecutionException {
120-
utPLSQLMojo.excludeObject = "abc";
121-
utPLSQLMojo.includeObject = "xyz";
132+
UtPlsqlMojo utPlsqlMojo = createUtPlsqlMojo();
133+
134+
utPlsqlMojo.excludeObject = "abc";
135+
utPlsqlMojo.includeObject = "xyz";
122136

123-
utPLSQLMojo.execute();
137+
utPlsqlMojo.execute();
124138
}
125139

126140
}

0 commit comments

Comments
 (0)