|
| 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 | +packageorg.utplsql.sqldev.test.runner; |
| 17 | + |
| 18 | +importjava.sql.Connection; |
| 19 | +importjava.util.Collections; |
| 20 | +importjava.util.LinkedHashMap; |
| 21 | + |
| 22 | +importorg.junit.After; |
| 23 | +importorg.junit.Assert; |
| 24 | +importorg.junit.Before; |
| 25 | +importorg.junit.Test; |
| 26 | +importorg.springframework.jdbc.datasource.SingleConnectionDataSource; |
| 27 | +importorg.utplsql.sqldev.model.DatabaseTools; |
| 28 | +importorg.utplsql.sqldev.model.SystemTools; |
| 29 | +importorg.utplsql.sqldev.model.runner.ItemNode; |
| 30 | +importorg.utplsql.sqldev.runner.UtplsqlRunner; |
| 31 | +importorg.utplsql.sqldev.test.AbstractJdbcTest; |
| 32 | + |
| 33 | +publicclassUtplsqlRunnerAggregationTestextendsAbstractJdbcTest { |
| 34 | +staticfinalintSHOW_GUI_AFTER_RUN_COMPLETION_IN_SECONDS =0; |
| 35 | + |
| 36 | +@Before |
| 37 | +publicvoidsetup() { |
| 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 | +publicvoidteardown() { |
| 73 | +executeAndIgnore(jdbcTemplate,"DROP PACKAGE x"); |
| 74 | +executeAndIgnore(jdbcTemplate,"DROP PACKAGE y"); |
| 75 | + } |
| 76 | + |
| 77 | +privateConnectiongetNewConnection() { |
| 78 | +finalSingleConnectionDataSourceds =newSingleConnectionDataSource(); |
| 79 | +ds.setDriverClassName("oracle.jdbc.OracleDriver"); |
| 80 | +ds.setUrl(dataSource.getUrl()); |
| 81 | +ds.setUsername(dataSource.getUsername()); |
| 82 | +ds.setPassword(dataSource.getPassword()); |
| 83 | +returnDatabaseTools.getConnection(ds); |
| 84 | + } |
| 85 | + |
| 86 | +@Test |
| 87 | +publicvoidaggregateDescription() { |
| 88 | +UtplsqlRunnerrunner =newUtplsqlRunner(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 | +} |