|
| 1 | +/* |
| 2 | + * Copyright 2021 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 java.sql.Connection; |
| 19 | +import java.util.Collections; |
| 20 | +import java.util.LinkedHashMap; |
| 21 | + |
| 22 | +import org.junit.After; |
| 23 | +import org.junit.Assert; |
| 24 | +import org.junit.Before; |
| 25 | +import org.junit.Test; |
| 26 | +import org.springframework.jdbc.datasource.SingleConnectionDataSource; |
| 27 | +import org.utplsql.sqldev.model.DatabaseTools; |
| 28 | +import org.utplsql.sqldev.model.SystemTools; |
| 29 | +import org.utplsql.sqldev.model.runner.ItemNode; |
| 30 | +import org.utplsql.sqldev.runner.UtplsqlRunner; |
| 31 | +import org.utplsql.sqldev.test.AbstractJdbcTest; |
| 32 | + |
| 33 | +public class UtplsqlRunnerAggregationTest extends AbstractJdbcTest { |
| 34 | + static final int SHOW_GUI_AFTER_RUN_COMPLETION_IN_SECONDS = 0; |
| 35 | + |
| 36 | + @Before |
| 37 | + public void setup() { |
| 38 | + // based on https://github.com/utPLSQL/utPLSQL-SQLDeveloper/issues/126 |
| 39 | + jdbcTemplate.execute( |
| 40 | + "create or replace package x is\n" |
| 41 | + + "\n" |
| 42 | + + " --%suite(suite x)\n" |
| 43 | + + " --%suitepath(foo.bar)\n" |
| 44 | + + "\n" |
| 45 | + + " --%test(feature a)\n" |
| 46 | + + " --%disabled\n" |
| 47 | + + " procedure test_a;\n" |
| 48 | + + "\n" |
| 49 | + + " --%test(feature b)\n" |
| 50 | + + " --%disabled\n" |
| 51 | + + " procedure test_b;\n" |
| 52 | + + "\n" |
| 53 | + + "end;"); |
| 54 | + jdbcTemplate.execute( |
| 55 | + "create or replace package y is\n" |
| 56 | + + "\n" |
| 57 | + + " --%suite(suite y)\n" |
| 58 | + + " --%suitepath(foo.bar)\n" |
| 59 | + + "\n" |
| 60 | + + " --%test(feature c)\n" |
| 61 | + + " --%disabled\n" |
| 62 | + + " procedure test_c;\n" |
| 63 | + + "\n" |
| 64 | + + " --%test(feature d)\n" |
| 65 | + + " --%disabled\n" |
| 66 | + + " procedure test_d;\n" |
| 67 | + + "\n" |
| 68 | + + "end;"); |
| 69 | + } |
| 70 | + |
| 71 | + @After |
| 72 | + public void teardown() { |
| 73 | + executeAndIgnore(jdbcTemplate, "DROP PACKAGE x"); |
| 74 | + executeAndIgnore(jdbcTemplate, "DROP PACKAGE y"); |
| 75 | + } |
| 76 | + |
| 77 | + private Connection getNewConnection() { |
| 78 | + final SingleConnectionDataSource ds = new SingleConnectionDataSource(); |
| 79 | + ds.setDriverClassName("oracle.jdbc.OracleDriver"); |
| 80 | + ds.setUrl(dataSource.getUrl()); |
| 81 | + ds.setUsername(dataSource.getUsername()); |
| 82 | + ds.setPassword(dataSource.getPassword()); |
| 83 | + return DatabaseTools.getConnection(ds); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void aggregateDescription() { |
| 88 | + UtplsqlRunner runner = new UtplsqlRunner(Collections.singletonList(":foo"), getNewConnection(), getNewConnection()); |
| 89 | + runner.runTestAsync(); |
| 90 | + SystemTools.waitForThread(runner.getProducerThread(), 10000); |
| 91 | + SystemTools.waitForThread(runner.getConsumerThread(), 10000); |
| 92 | + Assert.assertNotNull(runner); |
| 93 | + LinkedHashMap<String, ItemNode> nodes = runner.getRun().getItemNodes(); |
| 94 | + Assert.assertEquals(9, nodes.size()); // 8 + 1 for the run node |
| 95 | + Assert.assertNotNull(nodes.get(runner.getRun().getReporterId())); |
| 96 | + Assert.assertNull(nodes.get("foo").getDescription()); |
| 97 | + Assert.assertNull(nodes.get("foo.bar").getDescription()); |
| 98 | + Assert.assertEquals("suite y", nodes.get("foo.bar.y").getDescription()); |
| 99 | + Assert.assertEquals("suite x", nodes.get("foo.bar.x").getDescription()); |
| 100 | + Assert.assertEquals("feature c", nodes.get("foo.bar.y.test_c").getDescription()); |
| 101 | + Assert.assertEquals("feature d", nodes.get("foo.bar.y.test_d").getDescription()); |
| 102 | + Assert.assertEquals("feature a", nodes.get("foo.bar.x.test_a").getDescription()); |
| 103 | + Assert.assertEquals("feature b", nodes.get("foo.bar.x.test_b").getDescription()); |
| 104 | + SystemTools.sleep(SHOW_GUI_AFTER_RUN_COMPLETION_IN_SECONDS * 1000); |
| 105 | + runner.dispose(); |
| 106 | + } |
| 107 | + |
| 108 | +} |
0 commit comments