Skip to content

Commit 2803807

Browse files
committed
Added UtPlsqlMojoIT
1 parent b2abf7d commit 2803807

4 files changed

Lines changed: 57 additions & 48 deletions

File tree

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
<maven.compiler.source>1.8</maven.compiler.source>
5555
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5656
<maven.version>3.5.2</maven.version>
57-
<powermock.version>2.0.9</powermock.version>
5857
<jaxb.version>2.3.1</jaxb.version>
58+
<powermock.version>2.0.9</powermock.version>
5959
<sonar.organization>utplsql</sonar.organization>
6060
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
6161
</properties>

src/main/java/org/utplsql/maven/plugin/UtPLSQLMojo.java renamed to src/main/java/org/utplsql/maven/plugin/UtPlsqlMojo.java

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import org.utplsql.api.reporter.CoreReporters;
2323
import org.utplsql.api.reporter.Reporter;
2424
import org.utplsql.api.reporter.ReporterFactory;
25+
import org.utplsql.maven.plugin.io.ReportWriter;
26+
import org.utplsql.maven.plugin.io.SqlFileScanner;
2527
import org.utplsql.maven.plugin.model.CustomTypeMapping;
2628
import org.utplsql.maven.plugin.model.ReporterParameter;
27-
import org.utplsql.maven.plugin.io.SqlFileScanner;
28-
import org.utplsql.maven.plugin.io.ReportWriter;
2929

3030
import java.io.File;
3131
import java.sql.Connection;
@@ -44,7 +44,7 @@
4444
* @author Simon Martinelli
4545
*/
4646
@Mojo(name = "test", defaultPhase = LifecyclePhase.TEST)
47-
public class UtPLSQLMojo extends AbstractMojo {
47+
public class UtPlsqlMojo extends AbstractMojo {
4848

4949
@Parameter(readonly = true, defaultValue = "${project}")
5050
MavenProject project;
@@ -212,46 +212,36 @@ private void setDbConfiguration() {
212212
}
213213
}
214214

215-
FileMapperOptions buildSourcesOptions() throws MojoExecutionException {
216-
try {
217-
if (sources.isEmpty()) {
218-
File defaultSourceDirectory = new File(project.getBasedir(), Defaults.SOURCE_DIRECTORY);
219-
if (defaultSourceDirectory.exists()) {
220-
sources.add(Defaults.buildDefaultSource());
221-
} else {
222-
return new FileMapperOptions(new ArrayList<>());
223-
}
215+
FileMapperOptions buildSourcesOptions() {
216+
if (sources.isEmpty()) {
217+
File defaultSourceDirectory = new File(project.getBasedir(), Defaults.SOURCE_DIRECTORY);
218+
if (defaultSourceDirectory.exists()) {
219+
sources.add(Defaults.buildDefaultSource());
220+
} else {
221+
return new FileMapperOptions(new ArrayList<>());
224222
}
225-
226-
List<String> scripts = sqlFileScanner.findSqlScripts(project.getBasedir(), sources,
227-
Defaults.SOURCE_DIRECTORY, Defaults.SOURCE_FILE_PATTERN);
228-
return createFileMapperOptions(scripts, sourcesOwner, sourcesRegexExpression, sourcesOwnerSubexpression,
229-
sourcesNameSubexpression, sourcesTypeSubexpression, sourcesCustomTypeMapping);
230-
231-
} catch (Exception e) {
232-
throw new MojoExecutionException("Invalid <SOURCES> in your pom.xml", e);
233223
}
224+
225+
List<String> scripts = sqlFileScanner.findSqlScripts(project.getBasedir(), sources,
226+
Defaults.SOURCE_DIRECTORY, Defaults.SOURCE_FILE_PATTERN);
227+
return createFileMapperOptions(scripts, sourcesOwner, sourcesRegexExpression, sourcesOwnerSubexpression,
228+
sourcesNameSubexpression, sourcesTypeSubexpression, sourcesCustomTypeMapping);
234229
}
235230

236231
FileMapperOptions buildTestsOptions() throws MojoExecutionException {
237-
try {
238-
if (tests.isEmpty()) {
239-
File defaultTestDirectory = new File(project.getBasedir(), Defaults.TEST_DIRECTORY);
240-
if (defaultTestDirectory.exists()) {
241-
tests.add(Defaults.buildDefaultTest());
242-
} else {
243-
return new FileMapperOptions(new ArrayList<>());
244-
}
232+
if (tests.isEmpty()) {
233+
File defaultTestDirectory = new File(project.getBasedir(), Defaults.TEST_DIRECTORY);
234+
if (defaultTestDirectory.exists()) {
235+
tests.add(Defaults.buildDefaultTest());
236+
} else {
237+
return new FileMapperOptions(new ArrayList<>());
245238
}
246-
247-
List<String> scripts = sqlFileScanner.findSqlScripts(project.getBasedir(), tests, Defaults.TEST_DIRECTORY,
248-
Defaults.TEST_FILE_PATTERN);
249-
return createFileMapperOptions(scripts, testsOwner, testsRegexExpression, testsOwnerSubexpression,
250-
testsNameSubexpression, testsTypeSubexpression, testsCustomTypeMapping);
251-
252-
} catch (Exception e) {
253-
throw new MojoExecutionException("Invalid <TESTS> in your pom.xml: " + e.getMessage());
254239
}
240+
241+
List<String> scripts = sqlFileScanner.findSqlScripts(project.getBasedir(), tests, Defaults.TEST_DIRECTORY,
242+
Defaults.TEST_FILE_PATTERN);
243+
return createFileMapperOptions(scripts, testsOwner, testsRegexExpression, testsOwnerSubexpression,
244+
testsNameSubexpression, testsTypeSubexpression, testsCustomTypeMapping);
255245
}
256246

257247
private FileMapperOptions createFileMapperOptions(List<String> scripts, String objectOwner, String regexPattern,

‎src/test/java/org/utplsql/maven/plugin/MojoRuleTest.java‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void setUp() throws Exception {
7272
*/
7373
@Test
7474
public void invalidSourcesDirectory() throws Exception {
75-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
75+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
7676
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/invalid-sources-directories/"), "test");
7777
assertNotNull(utplsqlMojo);
7878

@@ -90,7 +90,7 @@ public void invalidSourcesDirectory() throws Exception {
9090
*/
9191
@Test
9292
public void invalidTestsDirectory() throws Exception {
93-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
93+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
9494
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/invalid-tests-sources-directories/"), "test");
9595
assertNotNull(utplsqlMojo);
9696

@@ -108,11 +108,10 @@ public void invalidTestsDirectory() throws Exception {
108108
*/
109109
@Test
110110
public void sourcesTestsParameters() throws Exception {
111-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
111+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
112112
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/test-sources-tests-params/"), "test");
113113
assertNotNull(utplsqlMojo);
114114

115-
// TODO : move to another test about reporters
116115
assertEquals(2, utplsqlMojo.reporters.size());
117116

118117
// check sources
@@ -152,7 +151,7 @@ public void sourcesTestsParameters() throws Exception {
152151
*/
153152
@Test
154153
public void sourcesAndTestsParameterDoesNotExist() throws Exception {
155-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(
154+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule.lookupConfiguredMojo(
156155
new File("src/test/resources/unit-tests/test-no-sources-tests-params/directory-does-not-exist/"), "test");
157156
assertNotNull(utplsqlMojo);
158157

@@ -174,7 +173,7 @@ public void sourcesAndTestsParameterDoesNotExist() throws Exception {
174173
*/
175174
@Test
176175
public void sourcesAndTestsParameterDoesNotExistButDefaultDirectoryExists() throws Exception {
177-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
176+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
178177
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/test-no-sources-tests-params/directory-exists/"), "test");
179178
assertNotNull(utplsqlMojo);
180179

@@ -200,7 +199,7 @@ public void sourcesAndTestsParameterDoesNotExistButDefaultDirectoryExists() thro
200199
*/
201200
@Test
202201
public void sourcesAndTestsParameterHaveNotDirectoryTag() throws Exception {
203-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
202+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
204203
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/partial-source-and-test-tag/missing-directory/"), "test");
205204
assertNotNull(utplsqlMojo);
206205

@@ -227,7 +226,7 @@ public void sourcesAndTestsParameterHaveNotDirectoryTag() throws Exception {
227226
*/
228227
@Test
229228
public void sourcesAndTestsParameterHaveNotIncludesTag() throws Exception {
230-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
229+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
231230
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/partial-source-and-test-tag/missing-includes/"), "test");
232231
assertNotNull(utplsqlMojo);
233232

@@ -249,7 +248,7 @@ public void sourcesAndTestsParameterHaveNotIncludesTag() throws Exception {
249248
*/
250249
@Test
251250
public void defaultConsoleBehaviour() throws Exception {
252-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
251+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
253252
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/default-console-output-behaviour/"), "test");
254253
assertNotNull(utplsqlMojo);
255254

@@ -297,7 +296,7 @@ public void defaultConsoleBehaviour() throws Exception {
297296
*/
298297
@Test
299298
public void addDefaultReporter() throws Exception {
300-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
299+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
301300
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/default-console-output-behaviour/"), "test");
302301
assertNotNull(utplsqlMojo);
303302

@@ -325,7 +324,7 @@ public void addDefaultReporter() throws Exception {
325324
*/
326325
@Test
327326
public void skipUtplsqlTests() throws Exception {
328-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
327+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
329328
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/skip-utplsql-tests/"), "test");
330329
assertNotNull(utplsqlMojo);
331330

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.utplsql.maven.plugin;
2+
3+
import org.apache.maven.plugin.MojoExecutionException;
4+
import org.apache.maven.project.MavenProject;
5+
import org.junit.Test;
6+
import org.mockito.Mock;
7+
8+
public class UtPlsqlMojoIT {
9+
10+
@Test
11+
public void execute() throws MojoExecutionException {
12+
UtPlsqlMojo utPLSQLMojo = new UtPlsqlMojo();
13+
utPLSQLMojo.project = new MavenProject();
14+
utPLSQLMojo.url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
15+
utPLSQLMojo.user = "UT3";
16+
utPLSQLMojo.password = "UT3";
17+
18+
utPLSQLMojo.execute();
19+
}
20+
}

0 commit comments

Comments
 (0)