1
+ /*
2
+ * Copyright 2018 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package org.utplsql.sqldev.test.runner
17
+
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
25
+
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
+
35
+ --%context(test context)
36
+
37
+ --%test(test 1 - OK)
38
+ PROCEDURE test_1_ok;
39
+
40
+ --%test(test 2 - NOK)
41
+ PROCEDURE test_2_nok;
42
+
43
+ --%endcontext
44
+ END;
45
+ ' ' ' )
46
+ jdbcTemplate. execute(' ' '
47
+ CREATE OR REPLACE PACKAGE BODY junit_utplsql_test1_pkg IS
48
+ PROCEDURE test_1_ok IS
49
+ BEGIN
50
+ dbms_session.sleep(1);
51
+ ut.expect(1).to_equal(1);
52
+ END;
53
+
54
+ PROCEDURE test_2_nok IS
55
+ BEGIN
56
+ dbms_session.sleep(2);
57
+ ut.expect(1).to_equal(2);
58
+ END;
59
+ END;
60
+ ' ' ' )
61
+ }
62
+
63
+ @AfterClass
64
+ def static void teardown () {
65
+ try {
66
+ jdbcTemplate. execute(" DROP PACKAGE junit_utplsql_test1_pkg" )
67
+ } catch (BadSqlGrammarException e) {
68
+ // ignore
69
+ }
70
+ }
71
+
72
+ @Test
73
+ def void runSlowTests () {
74
+ var ds1 = new SingleConnectionDataSource ()
75
+ ds1. driverClassName = " oracle.jdbc.OracleDriver"
76
+ ds1. url = dataSource. url
77
+ ds1. username = dataSource. username
78
+ ds1. password = dataSource. password
79
+ var ds2 = new SingleConnectionDataSource ()
80
+ ds2. driverClassName = " oracle.jdbc.OracleDriver"
81
+ ds2. url = dataSource. url
82
+ ds2. username = dataSource. username
83
+ ds2. password = dataSource. password
84
+ var runner = new UtplsqlRunner (#[" :a" ], ds1. connection, ds2. connection)
85
+ runner. runAsync
86
+ runner. producerThread. join(20000 )
87
+ runner. consumerThread. join(20000 )
88
+ runner. dispose
89
+ }
90
+
91
+ }
0 commit comments