Skip to content

Commit 99b4d24

Browse files
convert UtplsqlRunnerTest to Java, removing Xtend dependencies
1 parent ec0ae72 commit 99b4d24

File tree

1 file changed

+117
-237
lines changed

1 file changed

+117
-237
lines changed
Lines changed: 117 additions & 237 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");
@@ -16,248 +16,128 @@
1616
package org.utplsql.sqldev.test.runner;
1717

1818
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;
19+
import java.util.Arrays;
20+
21+
import org.junit.After;
22+
import org.junit.Assert;
23+
import org.junit.Before;
2524
import org.junit.Test;
26-
import org.springframework.jdbc.BadSqlGrammarException;
2725
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
26+
import org.utplsql.sqldev.model.DatabaseTools;
27+
import org.utplsql.sqldev.model.SystemTools;
2828
import org.utplsql.sqldev.runner.UtplsqlRunner;
2929
import org.utplsql.sqldev.test.AbstractJdbcTest;
3030

31-
@SuppressWarnings("all")
3231
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-
}
32+
33+
@Before
34+
public void setup() {
35+
StringBuilder sb = new StringBuilder();
36+
sb.append("CREATE OR REPLACE PACKAGE junit_utplsql_test1_pkg is\n");
37+
sb.append(" --%suite(JUnit testing)\n");
38+
sb.append(" --%suitepath(a)\n");
39+
sb.append(" /* tags annotation without parameter will raise a warning */\n");
40+
sb.append(" --%tags\n\n");
41+
42+
sb.append(" --%context(test context)\n\n");
43+
44+
sb.append(" --%test(test 1 - OK)\n");
45+
sb.append(" PROCEDURE test_1_ok;\n\n");
46+
47+
sb.append(" --%test(test 2 - NOK)\n");
48+
sb.append(" PROCEDURE test_2_nok;\n\n");
49+
50+
sb.append(" --%test(test 3 - disabled)\n");
51+
sb.append(" --%disabled\n");
52+
sb.append(" PROCEDURE test_3_disabled;\n\n");
53+
54+
sb.append(" --%test(test 4 - errored)\n");
55+
sb.append(" PROCEDURE test_4_errored;\n\n");
56+
57+
sb.append(" --%test(test 5 - warnings)\n");
58+
sb.append(" PROCEDURE test_5_warnings;\n\n");
59+
60+
sb.append(" --%endcontext\n\n");
61+
62+
sb.append(" --%afterall\n");
63+
sb.append(" procedure print_and_raise;\n");
64+
sb.append("END;");
65+
jdbcTemplate.execute(sb.toString());
66+
67+
sb.setLength(0);
68+
sb.append("CREATE OR REPLACE PACKAGE BODY junit_utplsql_test1_pkg IS\n");
69+
sb.append(" PROCEDURE test_1_ok IS\n");
70+
sb.append(" BEGIN\n");
71+
sb.append(" dbms_output.put_line('start test 1');\n");
72+
sb.append(" dbms_session.sleep(1);\n");
73+
sb.append(" ut.expect(1).to_equal(1);\n");
74+
sb.append(" dbms_output.put_line('end test 1');\n");
75+
sb.append(" END;\n\n");
76+
77+
sb.append(" PROCEDURE test_2_nok IS\n");
78+
sb.append(" BEGIN\n");
79+
sb.append(" dbms_output.put_line('start test 2');\n");
80+
sb.append(" dbms_session.sleep(2);\n");
81+
sb.append(" ut.expect(1, 'first assert.').to_equal(2);\n");
82+
sb.append(" ut.expect(1, 'second assert.').to_equal(2);\n");
83+
sb.append(" dbms_output.put_line('end test 2');\n");
84+
sb.append(" END;\n\n");
85+
86+
sb.append(" PROCEDURE test_3_disabled IS\n");
87+
sb.append(" BEGIN\n");
88+
sb.append(" NULL;\n");
89+
sb.append(" END;\n\n");
90+
91+
sb.append(" PROCEDURE test_4_errored IS\n");
92+
sb.append(" BEGIN\n");
93+
sb.append(" EXECUTE IMMEDIATE 'bla bla';\n");
94+
sb.append(" END;\n\n");
95+
96+
sb.append(" PROCEDURE test_5_warnings IS\n");
97+
sb.append(" BEGIN\n");
98+
sb.append(" COMMIT; -- will raise a warning\n");
99+
sb.append(" ut.expect(1).to_equal(1);\n");
100+
sb.append(" END;\n\n");
101+
102+
sb.append(" PROCEDURE print_and_raise IS\n");
103+
sb.append(" BEGIN\n");
104+
sb.append(" dbms_output.put_line('Now, a no_data_found exception is raised');\n");
105+
sb.append(" dbms_output.put_line('dbms_output and error stack is reported for this suite.');\n");
106+
sb.append(" dbms_output.put_line('A runtime error in afterall is counted as a warning.');\n");
107+
sb.append(" RAISE no_data_found;\n");
108+
sb.append(" END;\n");
109+
sb.append("END;");
110+
jdbcTemplate.execute(sb.toString());
235111
}
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);
112+
113+
@After
114+
public void teardown() {
115+
executeAndIgnore(jdbcTemplate, "DROP PACKAGE junit_utplsql_test1_pkg");
116+
}
117+
118+
@Test
119+
public void runTestsWithMaxTime() {
120+
final SingleConnectionDataSource ds1 = new SingleConnectionDataSource();
121+
ds1.setDriverClassName("oracle.jdbc.OracleDriver");
122+
ds1.setUrl(dataSource.getUrl());
123+
ds1.setUsername(dataSource.getUsername());
124+
ds1.setPassword(dataSource.getPassword());
125+
final Connection producerConn = DatabaseTools.getConnection(ds1);
126+
127+
final SingleConnectionDataSource ds2 = new SingleConnectionDataSource();
128+
ds2.setDriverClassName("oracle.jdbc.OracleDriver");
129+
ds2.setUrl(dataSource.getUrl());
130+
ds2.setUsername(dataSource.getUsername());
131+
ds2.setPassword(dataSource.getPassword());
132+
final Connection consumerConn = DatabaseTools.getConnection(ds2);
133+
134+
UtplsqlRunner runner = new UtplsqlRunner(Arrays.asList(":a"), producerConn, consumerConn);
135+
runner.runTestAsync();
136+
137+
SystemTools.waitForThread(runner.getProducerThread(), 200000);
138+
SystemTools.waitForThread(runner.getConsumerThread(), 200000);
139+
SystemTools.sleep(4 * 1000);
140+
Assert.assertNotNull(runner);
141+
runner.dispose();
261142
}
262-
}
263143
}

0 commit comments

Comments
 (0)