Skip to content

Commit ec0ae72

Browse files
add UtplsqlRunnerTest generated by Xtend 2.20.0
1 parent d05dac8 commit ec0ae72

File tree

1 file changed

+247
-120
lines changed

1 file changed

+247
-120
lines changed
Lines changed: 247 additions & 120 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,124 +13,251 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.utplsql.sqldev.test.runner
16+
package org.utplsql.sqldev.test.runner;
1717

18-
import org.junit.AfterClass
19-
import org.junit.BeforeClass
20-
import org.junit.Test
21-
import org.springframework.jdbc.BadSqlGrammarException
22-
import org.springframework.jdbc.datasource.SingleConnectionDataSource
23-
import org.utplsql.sqldev.runner.UtplsqlRunner
24-
import org.utplsql.sqldev.test.AbstractJdbcTest
18+
import java.sql.Connection;
19+
import java.util.Collections;
20+
import org.eclipse.xtend2.lib.StringConcatenation;
21+
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
22+
import org.eclipse.xtext.xbase.lib.Exceptions;
23+
import org.junit.AfterClass;
24+
import org.junit.BeforeClass;
25+
import org.junit.Test;
26+
import org.springframework.jdbc.BadSqlGrammarException;
27+
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
28+
import org.utplsql.sqldev.runner.UtplsqlRunner;
29+
import org.utplsql.sqldev.test.AbstractJdbcTest;
2530

26-
class UtplsqlRunnerTest extends AbstractJdbcTest {
27-
28-
@BeforeClass
29-
def static void setup() {
30-
jdbcTemplate.execute('''
31-
CREATE OR REPLACE PACKAGE junit_utplsql_test1_pkg is
32-
--%suite(JUnit testing)
33-
--%suitepath(a)
34-
/* tags annotation without parameter will raise a warning */
35-
--%tags
36-
37-
--%context(test context)
38-
39-
--%test(test 1 - OK)
40-
PROCEDURE test_1_ok;
41-
42-
--%test(test 2 - NOK)
43-
PROCEDURE test_2_nok;
44-
45-
--%test(test 3 - disabled)
46-
--%disabled
47-
PROCEDURE test_3_disabled;
48-
49-
--%test(test 4 - errored)
50-
PROCEDURE test_4_errored;
51-
52-
--%test(test 5 - warnings)
53-
PROCEDURE test_5_warnings;
54-
55-
--%endcontext
56-
57-
--%afterall
58-
procedure print_and_raise;
59-
END;
60-
''')
61-
jdbcTemplate.execute('''
62-
CREATE OR REPLACE PACKAGE BODY junit_utplsql_test1_pkg IS
63-
PROCEDURE test_1_ok IS
64-
BEGIN
65-
dbms_output.put_line('start test 1');
66-
dbms_session.sleep(1);
67-
ut.expect(1).to_equal(1);
68-
dbms_output.put_line('end test 1');
69-
END;
70-
71-
PROCEDURE test_2_nok IS
72-
BEGIN
73-
dbms_output.put_line('start test 2');
74-
dbms_session.sleep(2);
75-
ut.expect(1, 'first assert.').to_equal(2);
76-
ut.expect(1, 'second assert.').to_equal(2);
77-
dbms_output.put_line('end test 2');
78-
END;
79-
80-
PROCEDURE test_3_disabled IS
81-
BEGIN
82-
NULL;
83-
END;
84-
85-
PROCEDURE test_4_errored IS
86-
BEGIN
87-
EXECUTE IMMEDIATE 'bla bla';
88-
END;
89-
90-
PROCEDURE test_5_warnings IS
91-
BEGIN
92-
COMMIT; -- will raise a warning
93-
ut.expect(1).to_equal(1);
94-
END;
95-
96-
PROCEDURE print_and_raise IS
97-
BEGIN
98-
dbms_output.put_line('Now, a no_data_found exception is raised');
99-
dbms_output.put_line('dbms_output and error stack is reported for this suite.');
100-
dbms_output.put_line('A runtime error in afterall is counted as a warning.');
101-
RAISE no_data_found;
102-
END;
103-
END;
104-
''')
105-
}
106-
107-
@AfterClass
108-
def static void teardown() {
109-
try {
110-
jdbcTemplate.execute("DROP PACKAGE junit_utplsql_test1_pkg")
111-
} catch (BadSqlGrammarException e) {
112-
// ignore
113-
}
114-
}
115-
116-
@Test
117-
def void runTestsWithMaxTime() {
118-
var ds1 = new SingleConnectionDataSource()
119-
ds1.driverClassName = "oracle.jdbc.OracleDriver"
120-
ds1.url = dataSource.url
121-
ds1.username = dataSource.username
122-
ds1.password = dataSource.password
123-
var ds2 = new SingleConnectionDataSource()
124-
ds2.driverClassName = "oracle.jdbc.OracleDriver"
125-
ds2.url = dataSource.url
126-
ds2.username = dataSource.username
127-
ds2.password = dataSource.password
128-
var runner = new UtplsqlRunner(#[":a"], ds1.connection, ds2.connection)
129-
runner.runTestAsync
130-
runner.producerThread.join(200000)
131-
runner.consumerThread.join(200000)
132-
Thread.sleep(4 * 1000)
133-
runner.dispose
134-
}
135-
136-
}
31+
@SuppressWarnings("all")
32+
public class UtplsqlRunnerTest extends AbstractJdbcTest {
33+
@BeforeClass
34+
public static void setup() {
35+
StringConcatenation _builder = new StringConcatenation();
36+
_builder.append("CREATE OR REPLACE PACKAGE junit_utplsql_test1_pkg is");
37+
_builder.newLine();
38+
_builder.append(" ");
39+
_builder.append("--%suite(JUnit testing)");
40+
_builder.newLine();
41+
_builder.append(" ");
42+
_builder.append("--%suitepath(a)");
43+
_builder.newLine();
44+
_builder.append(" ");
45+
_builder.append("/* tags annotation without parameter will raise a warning */");
46+
_builder.newLine();
47+
_builder.append(" ");
48+
_builder.append("--%tags");
49+
_builder.newLine();
50+
_builder.newLine();
51+
_builder.append(" ");
52+
_builder.append("--%context(test context)");
53+
_builder.newLine();
54+
_builder.newLine();
55+
_builder.append(" ");
56+
_builder.append("--%test(test 1 - OK) ");
57+
_builder.newLine();
58+
_builder.append(" ");
59+
_builder.append("PROCEDURE test_1_ok;");
60+
_builder.newLine();
61+
_builder.newLine();
62+
_builder.append(" ");
63+
_builder.append("--%test(test 2 - NOK)");
64+
_builder.newLine();
65+
_builder.append(" ");
66+
_builder.append("PROCEDURE test_2_nok;");
67+
_builder.newLine();
68+
_builder.newLine();
69+
_builder.append(" ");
70+
_builder.append("--%test(test 3 - disabled)");
71+
_builder.newLine();
72+
_builder.append(" ");
73+
_builder.append("--%disabled");
74+
_builder.newLine();
75+
_builder.append(" ");
76+
_builder.append("PROCEDURE test_3_disabled;");
77+
_builder.newLine();
78+
_builder.newLine();
79+
_builder.append(" ");
80+
_builder.append("--%test(test 4 - errored)");
81+
_builder.newLine();
82+
_builder.append(" ");
83+
_builder.append("PROCEDURE test_4_errored;");
84+
_builder.newLine();
85+
_builder.append(" ");
86+
_builder.newLine();
87+
_builder.append(" ");
88+
_builder.append("--%test(test 5 - warnings)");
89+
_builder.newLine();
90+
_builder.append(" ");
91+
_builder.append("PROCEDURE test_5_warnings;");
92+
_builder.newLine();
93+
_builder.newLine();
94+
_builder.append(" ");
95+
_builder.append("--%endcontext");
96+
_builder.newLine();
97+
_builder.newLine();
98+
_builder.append(" ");
99+
_builder.append("--%afterall");
100+
_builder.newLine();
101+
_builder.append(" ");
102+
_builder.append("procedure print_and_raise;");
103+
_builder.newLine();
104+
_builder.append("END;");
105+
_builder.newLine();
106+
AbstractJdbcTest.jdbcTemplate.execute(_builder.toString());
107+
StringConcatenation _builder_1 = new StringConcatenation();
108+
_builder_1.append("CREATE OR REPLACE PACKAGE BODY junit_utplsql_test1_pkg IS");
109+
_builder_1.newLine();
110+
_builder_1.append(" ");
111+
_builder_1.append("PROCEDURE test_1_ok IS");
112+
_builder_1.newLine();
113+
_builder_1.append(" ");
114+
_builder_1.append("BEGIN");
115+
_builder_1.newLine();
116+
_builder_1.append(" ");
117+
_builder_1.append("dbms_output.put_line(\'start test 1\');");
118+
_builder_1.newLine();
119+
_builder_1.append(" ");
120+
_builder_1.append("dbms_session.sleep(1);");
121+
_builder_1.newLine();
122+
_builder_1.append(" ");
123+
_builder_1.append("ut.expect(1).to_equal(1);");
124+
_builder_1.newLine();
125+
_builder_1.append(" ");
126+
_builder_1.append("dbms_output.put_line(\'end test 1\');");
127+
_builder_1.newLine();
128+
_builder_1.append(" ");
129+
_builder_1.append("END;");
130+
_builder_1.newLine();
131+
_builder_1.newLine();
132+
_builder_1.append(" ");
133+
_builder_1.append("PROCEDURE test_2_nok IS");
134+
_builder_1.newLine();
135+
_builder_1.append(" ");
136+
_builder_1.append("BEGIN");
137+
_builder_1.newLine();
138+
_builder_1.append(" ");
139+
_builder_1.append("dbms_output.put_line(\'start test 2\');");
140+
_builder_1.newLine();
141+
_builder_1.append(" ");
142+
_builder_1.append("dbms_session.sleep(2);");
143+
_builder_1.newLine();
144+
_builder_1.append(" ");
145+
_builder_1.append("ut.expect(1, \'first assert.\').to_equal(2);");
146+
_builder_1.newLine();
147+
_builder_1.append(" ");
148+
_builder_1.append("ut.expect(1, \'second assert.\').to_equal(2);");
149+
_builder_1.newLine();
150+
_builder_1.append(" ");
151+
_builder_1.append("dbms_output.put_line(\'end test 2\');");
152+
_builder_1.newLine();
153+
_builder_1.append(" ");
154+
_builder_1.append("END;");
155+
_builder_1.newLine();
156+
_builder_1.append(" ");
157+
_builder_1.newLine();
158+
_builder_1.append(" ");
159+
_builder_1.append("PROCEDURE test_3_disabled IS");
160+
_builder_1.newLine();
161+
_builder_1.append(" ");
162+
_builder_1.append("BEGIN");
163+
_builder_1.newLine();
164+
_builder_1.append(" ");
165+
_builder_1.append("NULL;");
166+
_builder_1.newLine();
167+
_builder_1.append(" ");
168+
_builder_1.append("END;");
169+
_builder_1.newLine();
170+
_builder_1.newLine();
171+
_builder_1.append(" ");
172+
_builder_1.append("PROCEDURE test_4_errored IS");
173+
_builder_1.newLine();
174+
_builder_1.append(" ");
175+
_builder_1.append("BEGIN");
176+
_builder_1.newLine();
177+
_builder_1.append(" ");
178+
_builder_1.append("EXECUTE IMMEDIATE \'bla bla\';");
179+
_builder_1.newLine();
180+
_builder_1.append(" ");
181+
_builder_1.append("END;");
182+
_builder_1.newLine();
183+
_builder_1.newLine();
184+
_builder_1.append(" ");
185+
_builder_1.append("PROCEDURE test_5_warnings IS");
186+
_builder_1.newLine();
187+
_builder_1.append(" ");
188+
_builder_1.append("BEGIN");
189+
_builder_1.newLine();
190+
_builder_1.append(" ");
191+
_builder_1.append("COMMIT; -- will raise a warning");
192+
_builder_1.newLine();
193+
_builder_1.append("\t ");
194+
_builder_1.append("ut.expect(1).to_equal(1);");
195+
_builder_1.newLine();
196+
_builder_1.append(" ");
197+
_builder_1.append("END;");
198+
_builder_1.newLine();
199+
_builder_1.newLine();
200+
_builder_1.append(" ");
201+
_builder_1.append("PROCEDURE print_and_raise IS");
202+
_builder_1.newLine();
203+
_builder_1.append(" ");
204+
_builder_1.append("BEGIN");
205+
_builder_1.newLine();
206+
_builder_1.append(" ");
207+
_builder_1.append("dbms_output.put_line(\'Now, a no_data_found exception is raised\');");
208+
_builder_1.newLine();
209+
_builder_1.append(" ");
210+
_builder_1.append("dbms_output.put_line(\'dbms_output and error stack is reported for this suite.\');");
211+
_builder_1.newLine();
212+
_builder_1.append(" ");
213+
_builder_1.append("dbms_output.put_line(\'A runtime error in afterall is counted as a warning.\');");
214+
_builder_1.newLine();
215+
_builder_1.append(" ");
216+
_builder_1.append("RAISE no_data_found;");
217+
_builder_1.newLine();
218+
_builder_1.append(" ");
219+
_builder_1.append("END;");
220+
_builder_1.newLine();
221+
_builder_1.append("END;");
222+
_builder_1.newLine();
223+
AbstractJdbcTest.jdbcTemplate.execute(_builder_1.toString());
224+
}
225+
226+
@AfterClass
227+
public static void teardown() {
228+
try {
229+
AbstractJdbcTest.jdbcTemplate.execute("DROP PACKAGE junit_utplsql_test1_pkg");
230+
} catch (final Throwable _t) {
231+
if (_t instanceof BadSqlGrammarException) {
232+
} else {
233+
throw Exceptions.sneakyThrow(_t);
234+
}
235+
}
236+
}
237+
238+
@Test
239+
public void runTestsWithMaxTime() {
240+
try {
241+
SingleConnectionDataSource ds1 = new SingleConnectionDataSource();
242+
ds1.setDriverClassName("oracle.jdbc.OracleDriver");
243+
ds1.setUrl(AbstractJdbcTest.dataSource.getUrl());
244+
ds1.setUsername(AbstractJdbcTest.dataSource.getUsername());
245+
ds1.setPassword(AbstractJdbcTest.dataSource.getPassword());
246+
SingleConnectionDataSource ds2 = new SingleConnectionDataSource();
247+
ds2.setDriverClassName("oracle.jdbc.OracleDriver");
248+
ds2.setUrl(AbstractJdbcTest.dataSource.getUrl());
249+
ds2.setUsername(AbstractJdbcTest.dataSource.getUsername());
250+
ds2.setPassword(AbstractJdbcTest.dataSource.getPassword());
251+
Connection _connection = ds1.getConnection();
252+
Connection _connection_1 = ds2.getConnection();
253+
UtplsqlRunner runner = new UtplsqlRunner(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(":a")), _connection, _connection_1);
254+
runner.runTestAsync();
255+
runner.getProducerThread().join(200000);
256+
runner.getConsumerThread().join(200000);
257+
Thread.sleep((4 * 1000));
258+
runner.dispose();
259+
} catch (Throwable _e) {
260+
throw Exceptions.sneakyThrow(_e);
261+
}
262+
}
263+
}

0 commit comments

Comments
 (0)