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 */
014
015package de.softwareforge.testing.postgres.junit5;
016
017import static de.softwareforge.testing.postgres.junit5.Junit5ClassMemberTest.createTable;
018import static de.softwareforge.testing.postgres.junit5.Junit5ClassMemberTest.existsTable;
019import static org.junit.jupiter.api.Assertions.assertFalse;
020import static org.junit.jupiter.api.Assertions.assertTrue;
021import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
022
023import org.junit.jupiter.api.ClassOrderer.OrderAnnotation;
024import org.junit.jupiter.api.Nested;
025import org.junit.jupiter.api.Order;
026import org.junit.jupiter.api.Test;
027import org.junit.jupiter.api.TestClassOrder;
028import org.junit.jupiter.api.TestInstance;
029import org.junit.jupiter.api.extension.RegisterExtension;
030
031@TestClassOrder(OrderAnnotation.class)
032public class Junit5NestedTest {
033
034    @RegisterExtension
035    public static EmbeddedPgExtension singleDatabase = SingleDatabaseBuilder.instanceWithDefaults().build();
036
037    @RegisterExtension
038    public static EmbeddedPgExtension multiDatabase = MultiDatabaseBuilder.instanceWithDefaults().build();
039
040    @Nested
041    @Order(1)
042    @TestInstance(PER_CLASS)
043    class TableCreation {
044
045        @Test
046        public void testTableCreation() throws Exception {
047            // create tables in a single and a multi database
048            // the static extension is the same database across all tests.
049            createTable(singleDatabase, "table1");
050            createTable(multiDatabase, "table2");
051        }
052    }
053
054    @Nested
055    @Order(2)
056    @TestInstance(PER_CLASS)
057    class TableValidation {
058
059        @Test
060        public void testTableExists() throws Exception {
061            // single database is shared between tests
062            // multi database is not.
063            assertTrue(existsTable(singleDatabase, "table1"));
064            assertFalse(existsTable(multiDatabase, "table2"));
065        }
066    }
067}