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;
020
021import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
022import org.junit.jupiter.api.Order;
023import org.junit.jupiter.api.Test;
024import org.junit.jupiter.api.TestMethodOrder;
025import org.junit.jupiter.api.extension.RegisterExtension;
026
027@TestMethodOrder(OrderAnnotation.class)
028public class Junit5InstanceMemberTest {
029
030    @RegisterExtension
031    public EmbeddedPgExtension singleDatabase = SingleDatabaseBuilder.instanceWithDefaults().build();
032
033    @RegisterExtension
034    public EmbeddedPgExtension multiDatabase = MultiDatabaseBuilder.instanceWithDefaults().build();
035
036    @Test
037    @Order(1)
038    public void testTableCreation() throws Exception {
039        // create tables in a single and a multi database
040        // the extension creates a new database for each test
041        createTable(singleDatabase, "table1");
042        createTable(multiDatabase, "table2");
043    }
044
045    @Test
046    @Order(2)
047    public void testTableExists() throws Exception {
048        // neither database is shared across tests
049        assertFalse(existsTable(singleDatabase, "table1"));
050        assertFalse(existsTable(multiDatabase, "table2"));
051    }
052}