Skip to content

Commit 578ceec

Browse files
committed
Updated tests
1 parent bd7798c commit 578ceec

14 files changed

Lines changed: 107 additions & 166 deletions

File tree

pom.xml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,6 @@
144144
<scope>test</scope>
145145
</dependency>
146146

147-
<dependency>
148-
<groupId>org.powermock</groupId>
149-
<artifactId>powermock-module-junit4</artifactId>
150-
<version>${powermock.version}</version>
151-
<scope>test</scope>
152-
</dependency>
153-
<dependency>
154-
<groupId>org.powermock</groupId>
155-
<artifactId>powermock-api-mockito2</artifactId>
156-
<version>${powermock.version}</version>
157-
<scope>test</scope>
158-
</dependency>
159-
160147
<dependency>
161148
<groupId>commons-io</groupId>
162149
<artifactId>commons-io</artifactId>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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;

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

Lines changed: 22 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,28 @@
11
package org.utplsql.maven.plugin;
22

3-
import org.apache.commons.lang3.tuple.Pair;
43
import org.apache.maven.plugin.MojoExecutionException;
54
import org.apache.maven.plugin.testing.MojoRule;
6-
import org.junit.Before;
75
import org.junit.Rule;
86
import org.junit.Test;
9-
import org.junit.runner.RunWith;
10-
import org.mockito.Mock;
11-
import org.powermock.core.classloader.annotations.PrepareForTest;
12-
import org.powermock.modules.junit4.PowerMockRunner;
13-
import org.utplsql.api.DBHelper;
147
import org.utplsql.api.FileMapperOptions;
15-
import org.utplsql.api.Version;
16-
import org.utplsql.api.reporter.Reporter;
17-
import org.utplsql.api.reporter.ReporterFactory;
18-
import org.utplsql.maven.plugin.io.ReportWriter;
198
import org.utplsql.maven.plugin.model.ReporterParameter;
209

2110
import java.io.ByteArrayOutputStream;
2211
import java.io.File;
2312
import java.io.PrintStream;
24-
import java.sql.Connection;
25-
import java.util.ArrayList;
2613
import java.util.List;
2714

2815
import static org.junit.Assert.assertEquals;
2916
import static org.junit.Assert.assertFalse;
3017
import static org.junit.Assert.assertNotNull;
3118
import static org.junit.Assert.assertThrows;
3219
import static org.junit.Assert.assertTrue;
33-
import static org.mockito.ArgumentMatchers.anyString;
34-
import static org.mockito.Mockito.mock;
35-
import static org.mockito.Mockito.times;
36-
import static org.mockito.Mockito.verify;
37-
import static org.mockito.Mockito.verifyNoMoreInteractions;
38-
import static org.powermock.api.mockito.PowerMockito.mockStatic;
39-
import static org.powermock.api.mockito.PowerMockito.when;
40-
41-
@RunWith(PowerMockRunner.class)
42-
@PrepareForTest({DBHelper.class, ReporterFactory.class})
20+
4321
public class MojoRuleTest {
4422

4523
@Rule
4624
public final MojoRule rule = new MojoRule();
4725

48-
@Mock
49-
public Connection mockConnection;
50-
51-
@Mock
52-
public Version mockVersion;
53-
54-
@Mock
55-
public ReporterFactory mockReporterFactory;
56-
57-
@Before
58-
public void setUp() throws Exception {
59-
mockStatic(DBHelper.class);
60-
when(DBHelper.getDatabaseFrameworkVersion(mockConnection)).thenReturn(mockVersion);
61-
62-
mockStatic(ReporterFactory.class);
63-
when(ReporterFactory.createEmpty()).thenReturn(mockReporterFactory);
64-
}
65-
6626
/**
6727
* Invalid Sources Directory
6828
* <p>
@@ -72,7 +32,7 @@ public void setUp() throws Exception {
7232
*/
7333
@Test
7434
public void invalidSourcesDirectory() throws Exception {
75-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
35+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
7636
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/invalid-sources-directories/"), "test");
7737
assertNotNull(utplsqlMojo);
7838

@@ -90,7 +50,7 @@ public void invalidSourcesDirectory() throws Exception {
9050
*/
9151
@Test
9252
public void invalidTestsDirectory() throws Exception {
93-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
53+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
9454
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/invalid-tests-sources-directories/"), "test");
9555
assertNotNull(utplsqlMojo);
9656

@@ -108,7 +68,7 @@ public void invalidTestsDirectory() throws Exception {
10868
*/
10969
@Test
11070
public void sourcesTestsParameters() throws Exception {
111-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
71+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
11272
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/test-sources-tests-params/"), "test");
11373
assertNotNull(utplsqlMojo);
11474

@@ -151,7 +111,7 @@ public void sourcesTestsParameters() throws Exception {
151111
*/
152112
@Test
153113
public void sourcesAndTestsParameterDoesNotExist() throws Exception {
154-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule.lookupConfiguredMojo(
114+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule.lookupConfiguredMojo(
155115
new File("src/test/resources/unit-tests/test-no-sources-tests-params/directory-does-not-exist/"), "test");
156116
assertNotNull(utplsqlMojo);
157117

@@ -173,7 +133,7 @@ public void sourcesAndTestsParameterDoesNotExist() throws Exception {
173133
*/
174134
@Test
175135
public void sourcesAndTestsParameterDoesNotExistButDefaultDirectoryExists() throws Exception {
176-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
136+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
177137
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/test-no-sources-tests-params/directory-exists/"), "test");
178138
assertNotNull(utplsqlMojo);
179139

@@ -199,7 +159,7 @@ public void sourcesAndTestsParameterDoesNotExistButDefaultDirectoryExists() thro
199159
*/
200160
@Test
201161
public void sourcesAndTestsParameterHaveNotDirectoryTag() throws Exception {
202-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
162+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
203163
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/partial-source-and-test-tag/missing-directory/"), "test");
204164
assertNotNull(utplsqlMojo);
205165

@@ -226,7 +186,7 @@ public void sourcesAndTestsParameterHaveNotDirectoryTag() throws Exception {
226186
*/
227187
@Test
228188
public void sourcesAndTestsParameterHaveNotIncludesTag() throws Exception {
229-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
189+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
230190
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/partial-source-and-test-tag/missing-includes/"), "test");
231191
assertNotNull(utplsqlMojo);
232192

@@ -248,83 +208,50 @@ public void sourcesAndTestsParameterHaveNotIncludesTag() throws Exception {
248208
*/
249209
@Test
250210
public void defaultConsoleBehaviour() throws Exception {
251-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
211+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
252212
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/default-console-output-behaviour/"), "test");
253213
assertNotNull(utplsqlMojo);
254214

255-
List<Reporter> reporterList = new ArrayList<>();
256-
when(mockReporterFactory.createReporter(anyString())).thenAnswer(invocation -> {
257-
Reporter mockReporter = mock(Reporter.class);
258-
reporterList.add(mockReporter);
259-
return mockReporter;
260-
});
261-
262-
ReportWriter reportWriter = new ReportWriter(utplsqlMojo.targetDir, mockVersion, utplsqlMojo.getLog());
263-
utplsqlMojo.initReporters(mockConnection, reportWriter, mockReporterFactory);
264-
265-
// Assert that we called the creation reporter with the correct parameters.
266-
verify(mockReporterFactory, times(2)).createReporter("UT_DOCUMENTATION_REPORTER");
267-
verify(mockReporterFactory).createReporter("UT_COVERAGE_SONAR_REPORTER");
268-
verify(mockReporterFactory).createReporter("UT_SONAR_TEST_REPORTER");
269-
verifyNoMoreInteractions(mockReporterFactory);
270-
271-
// Assert that all reporters have been initialized.
272-
for (Reporter mockReporter : reporterList) {
273-
verify(mockReporter).init(mockConnection);
274-
verifyNoMoreInteractions(mockReporter);
275-
}
215+
utplsqlMojo.execute();
276216

277217
// Assert that we added only the necessary reporters to the writer.
278-
List<Pair<Reporter, ReporterParameter>> reporters = reportWriter.getReporters();
218+
List<ReporterParameter> reporters = utplsqlMojo.reporters;
279219
assertEquals(3, reporters.size());
280220

281-
ReporterParameter reporterParameter1 = reporters.get(0).getRight();
221+
ReporterParameter reporterParameter1 = reporters.get(0);
282222
assertTrue(reporterParameter1.isConsoleOutput());
283223
assertFalse(reporterParameter1.isFileOutput());
284224

285-
ReporterParameter reporterParameter2 = reporters.get(1).getRight();
225+
ReporterParameter reporterParameter2 = reporters.get(1);
286226
assertFalse(reporterParameter2.isConsoleOutput());
287227
assertTrue(reporterParameter2.isFileOutput());
288228

289-
ReporterParameter reporterParameter3 = reporters.get(2).getRight();
229+
ReporterParameter reporterParameter3 = reporters.get(2);
290230
assertTrue(reporterParameter3.isConsoleOutput());
291231
assertTrue(reporterParameter3.isFileOutput());
292232
}
293233

294234
/**
295-
* Add Default Reporter
235+
* Default Reporter
296236
*/
297237
@Test
298-
public void addDefaultReporter() throws Exception {
299-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
300-
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/default-console-output-behaviour/"), "test");
238+
public void defaultReporter() throws Exception {
239+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
240+
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/default-reporter/"), "test");
301241
assertNotNull(utplsqlMojo);
302242

303-
List<Reporter> reporterList = new ArrayList<>();
304-
when(mockReporterFactory.createReporter(anyString())).thenAnswer(invocation -> {
305-
Reporter mockReporter = mock(Reporter.class);
306-
when(mockReporter.getTypeName()).thenReturn(invocation.getArgument(0));
307-
reporterList.add(mockReporter);
308-
return mockReporter;
309-
});
310-
311-
List<ReporterParameter> reporterParameters = utplsqlMojo.reporters;
312-
reporterParameters.clear();
313-
314-
ReportWriter reportWriter = new ReportWriter(utplsqlMojo.targetDir, mockVersion, utplsqlMojo.getLog());
315-
utplsqlMojo.initReporters(mockConnection, reportWriter, mockReporterFactory);
243+
utplsqlMojo.execute();
316244

317-
assertEquals(1, reporterList.size());
318-
assertEquals("UT_DOCUMENTATION_REPORTER", reporterList.get(0).getTypeName());
319-
verify(reporterList.get(0)).init(mockConnection);
245+
assertEquals(1, utplsqlMojo.reporters.size());
246+
assertEquals("UT_DOCUMENTATION_REPORTER", utplsqlMojo.reporters.get(0).getName());
320247
}
321248

322249
/**
323250
* Skip utPLSQL Tests
324251
*/
325252
@Test
326253
public void skipUtplsqlTests() throws Exception {
327-
UtPLSQLMojo utplsqlMojo = (UtPLSQLMojo) rule
254+
UtPlsqlMojo utplsqlMojo = (UtPlsqlMojo) rule
328255
.lookupConfiguredMojo(new File("src/test/resources/unit-tests/skip-utplsql-tests/"), "test");
329256
assertNotNull(utplsqlMojo);
330257

src/test/java/org/utplsql/maven/plugin/ReportWriterTest.java renamed to src/test/java/org/utplsql/maven/plugin/UtPlsqlMojoTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
import static org.junit.Assert.assertTrue;
1313

14-
public class ReportWriterTest {
14+
public class UtPlsqlMojoTest {
1515

16-
private static UtPLSQLMojo utPLSQLMojo;
16+
private static UtPlsqlMojo utPLSQLMojo;
1717

1818
@BeforeClass
1919
public static void setUp() {
20-
utPLSQLMojo = new UtPLSQLMojo();
20+
utPLSQLMojo = new UtPlsqlMojo();
2121
utPLSQLMojo.project = new MavenProject();
2222
utPLSQLMojo.targetDir = "target";
2323

src/test/resources/unit-tests/default-console-output-behaviour/pom.xml

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
<url>http://utplsql.org</url>
1515

1616
<properties>
17-
<dbUrl>jdbc:oracle:thin:@180.129.3.101:1521:xe</dbUrl>
18-
<dbUser>ut3</dbUser>
19-
<dbPass>XNtxj8eEgA6X6b6f</dbPass>
17+
<dbUrl>jdbc:oracle:thin:@127.0.0.1:1521:xe</dbUrl>
18+
<dbUser>UT3</dbUser>
19+
<dbPass>UT3</dbPass>
2020
</properties>
2121

2222
<build>
@@ -37,46 +37,24 @@
3737
<ignoreFailure>false</ignoreFailure>
3838

3939
<paths>
40-
<path>:plsql</path>
40+
<path>app</path>
4141
</paths>
4242

4343
<reporters>
4444
<reporter>
4545
<name>UT_DOCUMENTATION_REPORTER</name>
4646
</reporter>
47-
<reporter>
48-
<name>UT_DOCUMENTATION_REPORTER</name>
49-
<consoleOutput>false</consoleOutput>
50-
</reporter>
5147
<reporter>
5248
<name>UT_COVERAGE_SONAR_REPORTER</name>
5349
<fileOutput>coverage-sonar-report.xml</fileOutput>
50+
<consoleOutput>false</consoleOutput>
5451
</reporter>
5552
<reporter>
5653
<name>UT_SONAR_TEST_REPORTER</name>
5754
<fileOutput>utplsql/sonar-test-report.xml</fileOutput>
5855
<consoleOutput>true</consoleOutput>
5956
</reporter>
6057
</reporters>
61-
62-
<sources>
63-
<source>
64-
<directory>foo</directory>
65-
<includes>
66-
<include>**/*sql</include>
67-
</includes>
68-
</source>
69-
</sources>
70-
71-
<tests>
72-
<test>
73-
<directory>bar</directory>
74-
<includes>
75-
<include>**/*.spc</include>
76-
<include>**/*.bdy</include>
77-
</includes>
78-
</test>
79-
</tests>
8058
</configuration>
8159
</plugin>
8260
</plugins>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.utplsql</groupId>
7+
<artifactId>utplsql-maven-plugin-test</artifactId>
8+
<version>3.1.0-SNAPSHOT</version>
9+
10+
<packaging>pom</packaging>
11+
12+
<name>utplsql-maven-plugin Maven Plugin Test</name>
13+
14+
<url>http://utplsql.org</url>
15+
16+
<properties>
17+
<dbUrl>jdbc:oracle:thin:@127.0.0.1:1521:xe</dbUrl>
18+
<dbUser>UT3</dbUser>
19+
<dbPass>UT3</dbPass>
20+
</properties>
21+
22+
<build>
23+
24+
<directory>../../../target/</directory>
25+
26+
<plugins>
27+
<plugin>
28+
<groupId>org.utplsql</groupId>
29+
<artifactId>utplsql-maven-plugin</artifactId>
30+
<version>{project.version}</version>
31+
32+
<goals>
33+
<goal>test</goal>
34+
</goals>
35+
36+
<configuration>
37+
<ignoreFailure>false</ignoreFailure>
38+
39+
<paths>
40+
<path>app</path>
41+
</paths>
42+
43+
<reporters>
44+
<reporter>
45+
<name>UT_DOCUMENTATION_REPORTER</name>
46+
</reporter>
47+
</reporters>
48+
</configuration>
49+
</plugin>
50+
</plugins>
51+
</build>
52+
</project>

0 commit comments

Comments
 (0)