Skip to content

Commit 16b9963

Browse files
add add CodeCoverageReporterDialogTest.java generated by Xtend 2.20.0
1 parent 02fbed8 commit 16b9963

File tree

1 file changed

+157
-97
lines changed

1 file changed

+157
-97
lines changed
Lines changed: 157 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/**
22
* Copyright 2018 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,101 +13,161 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.utplsql.sqldev.test.coverage
16+
package org.utplsql.sqldev.test.coverage;
1717

18-
import java.io.File
19-
import java.nio.charset.StandardCharsets
20-
import java.nio.file.Files
21-
import java.nio.file.Path
22-
import java.util.Comparator
23-
import org.junit.AfterClass
24-
import org.junit.Assert
25-
import org.junit.BeforeClass
26-
import org.junit.Test
27-
import org.springframework.jdbc.BadSqlGrammarException
28-
import org.springframework.jdbc.datasource.SingleConnectionDataSource
29-
import org.utplsql.sqldev.coverage.CodeCoverageReporter
30-
import org.utplsql.sqldev.test.AbstractJdbcTest
18+
import java.io.File;
19+
import java.nio.charset.StandardCharsets;
20+
import java.nio.file.Files;
21+
import java.nio.file.Path;
22+
import java.sql.Connection;
23+
import java.util.Collections;
24+
import java.util.Comparator;
25+
import java.util.List;
26+
import java.util.Optional;
27+
import java.util.function.Predicate;
28+
import java.util.function.ToLongFunction;
29+
import org.eclipse.xtend2.lib.StringConcatenation;
30+
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
31+
import org.eclipse.xtext.xbase.lib.Exceptions;
32+
import org.junit.AfterClass;
33+
import org.junit.Assert;
34+
import org.junit.BeforeClass;
35+
import org.junit.Test;
36+
import org.springframework.jdbc.BadSqlGrammarException;
37+
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
38+
import org.utplsql.sqldev.coverage.CodeCoverageReporter;
39+
import org.utplsql.sqldev.test.AbstractJdbcTest;
3140

32-
class CodeCoverageReporterTest extends AbstractJdbcTest{
33-
34-
@BeforeClass
35-
def static void setup() {
36-
jdbcTemplate.execute('''
37-
CREATE OR REPLACE FUNCTION f RETURN INTEGER IS
38-
BEGIN
39-
RETURN 1;
40-
END f;
41-
''')
42-
jdbcTemplate.execute('''
43-
CREATE OR REPLACE PACKAGE test_f IS
44-
--%suite
45-
46-
--%test
47-
PROCEDURE f;
48-
END test_f;
49-
''')
50-
jdbcTemplate.execute('''
51-
CREATE OR REPLACE PACKAGE BODY test_f IS
52-
--%test
53-
PROCEDURE f IS
54-
l_expected INTEGER := 1;
55-
l_actual INTEGER;
56-
BEGIN
57-
l_actual := scott.f();
58-
ut.expect(l_actual).to_equal(l_expected);
59-
END f;
60-
END test_f;
61-
''')
62-
}
63-
64-
private def Path getNewestOutputFile() {
65-
val file = File.createTempFile("test", ".txt")
66-
val dir = file.parentFile
67-
file.delete
68-
val last = Files.list(dir.toPath)
69-
.filter([f | !f.toFile.directory])
70-
.filter([f | f.fileName.toString.startsWith("utplsql_")])
71-
.filter([f | f.fileName.toString.endsWith(".html")])
72-
.max(Comparator.comparingLong([f|f.toFile().lastModified()]))
73-
return last.get
74-
}
75-
76-
@Test
77-
def void produceReportAndCloseConnection() {
78-
// create temporary dataSource, closed by reporter
79-
var ds = new SingleConnectionDataSource()
80-
ds.driverClassName = "oracle.jdbc.OracleDriver"
81-
ds.url = dataSource.url
82-
ds.username = dataSource.username
83-
ds.password = dataSource.password
84-
val conn = ds.connection
85-
val pathList=#[':test_f']
86-
val includeObjectList = #['f']
87-
val reporter = new CodeCoverageReporter(pathList, includeObjectList, conn)
88-
val run = reporter.runAsync
89-
run.join(20000)
90-
Assert.assertEquals(true, conn.isClosed)
91-
val outputFile = getNewestOutputFile
92-
Assert.assertTrue(outputFile !== null)
93-
val content = new String(Files.readAllBytes(outputFile), StandardCharsets.UTF_8)
94-
Assert.assertTrue(content.contains('<h3>SCOTT.F</h3><h4><span class="green">100 %</span> lines covered</h4>'))
95-
}
96-
97-
@AfterClass
98-
def static void teardown() {
99-
try {
100-
jdbcTemplate.execute("DROP PACKAGE test_f")
101-
} catch (BadSqlGrammarException e) {
102-
// ignore
103-
}
104-
try {
105-
jdbcTemplate.execute("DROP FUNCTION f")
106-
} catch (BadSqlGrammarException e) {
107-
// ignore
108-
}
109-
}
110-
111-
112-
113-
}
41+
@SuppressWarnings("all")
42+
public class CodeCoverageReporterTest extends AbstractJdbcTest {
43+
@BeforeClass
44+
public static void setup() {
45+
StringConcatenation _builder = new StringConcatenation();
46+
_builder.append("CREATE OR REPLACE FUNCTION f RETURN INTEGER IS");
47+
_builder.newLine();
48+
_builder.append("BEGIN");
49+
_builder.newLine();
50+
_builder.append(" ");
51+
_builder.append("RETURN 1;");
52+
_builder.newLine();
53+
_builder.append("END f;");
54+
_builder.newLine();
55+
AbstractJdbcTest.jdbcTemplate.execute(_builder.toString());
56+
StringConcatenation _builder_1 = new StringConcatenation();
57+
_builder_1.append("CREATE OR REPLACE PACKAGE test_f IS");
58+
_builder_1.newLine();
59+
_builder_1.append(" ");
60+
_builder_1.append("--%suite");
61+
_builder_1.newLine();
62+
_builder_1.newLine();
63+
_builder_1.append(" ");
64+
_builder_1.append("--%test");
65+
_builder_1.newLine();
66+
_builder_1.append(" ");
67+
_builder_1.append("PROCEDURE f;");
68+
_builder_1.newLine();
69+
_builder_1.append("END test_f;");
70+
_builder_1.newLine();
71+
AbstractJdbcTest.jdbcTemplate.execute(_builder_1.toString());
72+
StringConcatenation _builder_2 = new StringConcatenation();
73+
_builder_2.append("CREATE OR REPLACE PACKAGE BODY test_f IS");
74+
_builder_2.newLine();
75+
_builder_2.append(" ");
76+
_builder_2.append("--%test");
77+
_builder_2.newLine();
78+
_builder_2.append(" ");
79+
_builder_2.append("PROCEDURE f IS");
80+
_builder_2.newLine();
81+
_builder_2.append(" ");
82+
_builder_2.append("l_expected INTEGER := 1;");
83+
_builder_2.newLine();
84+
_builder_2.append(" ");
85+
_builder_2.append("l_actual INTEGER;");
86+
_builder_2.newLine();
87+
_builder_2.append(" ");
88+
_builder_2.append("BEGIN");
89+
_builder_2.newLine();
90+
_builder_2.append(" ");
91+
_builder_2.append("l_actual := scott.f();");
92+
_builder_2.newLine();
93+
_builder_2.append(" ");
94+
_builder_2.append("ut.expect(l_actual).to_equal(l_expected);");
95+
_builder_2.newLine();
96+
_builder_2.append(" ");
97+
_builder_2.append("END f;");
98+
_builder_2.newLine();
99+
_builder_2.append("END test_f;");
100+
_builder_2.newLine();
101+
AbstractJdbcTest.jdbcTemplate.execute(_builder_2.toString());
102+
}
103+
104+
private Path getNewestOutputFile() {
105+
try {
106+
final File file = File.createTempFile("test", ".txt");
107+
final File dir = file.getParentFile();
108+
file.delete();
109+
final Predicate<Path> _function = (Path f) -> {
110+
boolean _isDirectory = f.toFile().isDirectory();
111+
return (!_isDirectory);
112+
};
113+
final Predicate<Path> _function_1 = (Path f) -> {
114+
return f.getFileName().toString().startsWith("utplsql_");
115+
};
116+
final Predicate<Path> _function_2 = (Path f) -> {
117+
return f.getFileName().toString().endsWith(".html");
118+
};
119+
final ToLongFunction<Path> _function_3 = (Path f) -> {
120+
return f.toFile().lastModified();
121+
};
122+
final Optional<Path> last = Files.list(dir.toPath()).filter(_function).filter(_function_1).filter(_function_2).max(Comparator.<Path>comparingLong(_function_3));
123+
return last.get();
124+
} catch (Throwable _e) {
125+
throw Exceptions.sneakyThrow(_e);
126+
}
127+
}
128+
129+
@Test
130+
public void produceReportAndCloseConnection() {
131+
try {
132+
SingleConnectionDataSource ds = new SingleConnectionDataSource();
133+
ds.setDriverClassName("oracle.jdbc.OracleDriver");
134+
ds.setUrl(AbstractJdbcTest.dataSource.getUrl());
135+
ds.setUsername(AbstractJdbcTest.dataSource.getUsername());
136+
ds.setPassword(AbstractJdbcTest.dataSource.getPassword());
137+
final Connection conn = ds.getConnection();
138+
final List<String> pathList = Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(":test_f"));
139+
final List<String> includeObjectList = Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("f"));
140+
final CodeCoverageReporter reporter = new CodeCoverageReporter(pathList, includeObjectList, conn);
141+
final Thread run = reporter.runAsync();
142+
run.join(20000);
143+
Assert.assertEquals(Boolean.valueOf(true), Boolean.valueOf(conn.isClosed()));
144+
final Path outputFile = this.getNewestOutputFile();
145+
Assert.assertTrue((outputFile != null));
146+
byte[] _readAllBytes = Files.readAllBytes(outputFile);
147+
final String content = new String(_readAllBytes, StandardCharsets.UTF_8);
148+
Assert.assertTrue(content.contains("<h3>SCOTT.F</h3><h4><span class=\"green\">100 %</span> lines covered</h4>"));
149+
} catch (Throwable _e) {
150+
throw Exceptions.sneakyThrow(_e);
151+
}
152+
}
153+
154+
@AfterClass
155+
public static void teardown() {
156+
try {
157+
AbstractJdbcTest.jdbcTemplate.execute("DROP PACKAGE test_f");
158+
} catch (final Throwable _t) {
159+
if (_t instanceof BadSqlGrammarException) {
160+
} else {
161+
throw Exceptions.sneakyThrow(_t);
162+
}
163+
}
164+
try {
165+
AbstractJdbcTest.jdbcTemplate.execute("DROP FUNCTION f");
166+
} catch (final Throwable _t_1) {
167+
if (_t_1 instanceof BadSqlGrammarException) {
168+
} else {
169+
throw Exceptions.sneakyThrow(_t_1);
170+
}
171+
}
172+
}
173+
}

0 commit comments

Comments
 (0)