001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 * http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package de.softwareforge.testing.postgres.junit5;
015
016import static de.softwareforge.testing.postgres.junit5.Junit5ClassMemberTest.createTable;
017import static de.softwareforge.testing.postgres.junit5.Junit5ClassMemberTest.existsTable;
018import static org.junit.jupiter.api.Assertions.assertFalse;
019import static org.junit.jupiter.api.Assertions.assertTrue;
020import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
021
022import org.junit.jupiter.api.ClassOrderer.OrderAnnotation;
023import org.junit.jupiter.api.Nested;
024import org.junit.jupiter.api.Order;
025import org.junit.jupiter.api.Test;
026import org.junit.jupiter.api.TestClassOrder;
027import org.junit.jupiter.api.TestInstance;
028import org.junit.jupiter.api.extension.RegisterExtension;
029
030@TestClassOrder(OrderAnnotation.class)
031public class Junit5NestedTest {
032
033    @RegisterExtension
034    public static EmbeddedPgExtension singleDatabase = SingleDatabaseBuilder.instanceWithDefaults().build();
035
036    @RegisterExtension
037    public static EmbeddedPgExtension multiDatabase = MultiDatabaseBuilder.instanceWithDefaults().build();
038
039    @Nested
040    @Order(1)
041    @TestInstance(PER_CLASS)
042    class TableCreation {
043
044        @Test
045        public void testTableCreation() throws Exception {
046            // create tables in a single and a multi database
047            // the static extension is the same database across all tests.
048            createTable(singleDatabase, "table1");
049            createTable(multiDatabase, "table2");
050        }
051    }
052
053    @Nested
054    @Order(2)
055    @TestInstance(PER_CLASS)
056    class TableValidation {
057
058        @Test
059        public void testTableExists() throws Exception {
060            // single database is shared between tests
061            // multi database is not.
062            assertTrue(existsTable(singleDatabase, "table1"));
063            assertFalse(existsTable(multiDatabase, "table2"));
064        }
065    }
066}