Skip to content

Commit b9dfb47

Browse files
committed
Revert "Removed UtPlsqlMojoTest to test coverage"
This reverts commit 1d4cc73.
1 parent 1d4cc73 commit b9dfb47

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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.BeforeClass;
6+
import org.junit.Test;
7+
import org.utplsql.api.reporter.CoreReporters;
8+
import org.utplsql.maven.plugin.model.ReporterParameter;
9+
10+
import java.io.ByteArrayOutputStream;
11+
import java.io.File;
12+
import java.io.PrintStream;
13+
14+
import static org.junit.Assert.assertTrue;
15+
16+
public class UtPlsqlMojoTest {
17+
18+
private static UtPlsqlMojo utPLSQLMojo;
19+
20+
@BeforeClass
21+
public static void setUp() {
22+
utPLSQLMojo = new UtPlsqlMojo();
23+
utPLSQLMojo.project = new MavenProject();
24+
utPLSQLMojo.targetDir = "target";
25+
26+
utPLSQLMojo.url = "jdbc:oracle:thin:@127.0.0.1:1521:XE";
27+
utPLSQLMojo.user = "UT3";
28+
utPLSQLMojo.password = "UT3";
29+
}
30+
31+
@Test
32+
public void junitReporter() throws MojoExecutionException {
33+
ReporterParameter junitReporter = new ReporterParameter();
34+
junitReporter.setConsoleOutput(true);
35+
junitReporter.setFileOutput("junit-report.xml");
36+
junitReporter.setName(CoreReporters.UT_JUNIT_REPORTER.name());
37+
utPLSQLMojo.reporters.add(junitReporter);
38+
39+
utPLSQLMojo.execute();
40+
41+
assertTrue(new File("target/junit-report.xml").exists());
42+
}
43+
44+
@Test
45+
public void absolutPath() throws MojoExecutionException {
46+
ReporterParameter junitReporter = new ReporterParameter();
47+
junitReporter.setConsoleOutput(true);
48+
49+
String os = System.getProperty("os.name");
50+
if (os.contains("Windows")) {
51+
junitReporter.setFileOutput("c:/tmp/junit-report.xml");
52+
} else {
53+
junitReporter.setFileOutput("/tmp/junit-report.xml");
54+
}
55+
junitReporter.setName(CoreReporters.UT_JUNIT_REPORTER.name());
56+
utPLSQLMojo.reporters.add(junitReporter);
57+
58+
utPLSQLMojo.execute();
59+
if (os.contains("Windows")) {
60+
assertTrue(new File("c:/tmp/junit-report.xml").exists());
61+
} else {
62+
assertTrue(new File("/tmp/junit-report.xml").exists());
63+
}
64+
}
65+
66+
@Test
67+
public void parentDoesNotExist() throws MojoExecutionException {
68+
ReporterParameter junitReporter = new ReporterParameter();
69+
junitReporter.setConsoleOutput(true);
70+
junitReporter.setFileOutput("not-exist/junit-report.xml");
71+
junitReporter.setName(CoreReporters.UT_JUNIT_REPORTER.name());
72+
utPLSQLMojo.reporters.add(junitReporter);
73+
74+
utPLSQLMojo.execute();
75+
76+
assertTrue(new File("target/not-exist/junit-report.xml").exists());
77+
}
78+
79+
@Test
80+
public void onlyConsoleOutput() throws MojoExecutionException {
81+
ReporterParameter junitReporter = new ReporterParameter();
82+
junitReporter.setConsoleOutput(true);
83+
junitReporter.setName(CoreReporters.UT_JUNIT_REPORTER.name());
84+
utPLSQLMojo.reporters.add(junitReporter);
85+
86+
utPLSQLMojo.execute();
87+
88+
assertTrue(new File("target/not-exist/junit-report.xml").exists());
89+
}
90+
91+
@Test
92+
public void onlyFileOutput() throws MojoExecutionException {
93+
ReporterParameter junitReporter = new ReporterParameter();
94+
junitReporter.setConsoleOutput(false);
95+
junitReporter.setFileOutput("not-exist/junit-report.xml");
96+
junitReporter.setName(CoreReporters.UT_JUNIT_REPORTER.name());
97+
utPLSQLMojo.reporters.add(junitReporter);
98+
99+
utPLSQLMojo.execute();
100+
101+
assertTrue(new File("target/not-exist/junit-report.xml").exists());
102+
}
103+
104+
@Test
105+
public void skipUtplsqlTests() throws MojoExecutionException {
106+
utPLSQLMojo.skipUtplsqlTests = true;
107+
108+
final ByteArrayOutputStream console = new ByteArrayOutputStream();
109+
System.setOut(new PrintStream(console));
110+
111+
utPLSQLMojo.execute();
112+
113+
String standardOutput = console.toString();
114+
115+
assertTrue(standardOutput.contains("utPLSQLTests are skipped."));
116+
}
117+
118+
@Test
119+
public void defaultReport() throws MojoExecutionException {
120+
utPLSQLMojo.execute();
121+
}
122+
123+
}

0 commit comments

Comments
 (0)