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.embedded;
015
016import static org.junit.jupiter.api.Assertions.assertEquals;
017import static org.junit.jupiter.api.Assertions.assertNotEquals;
018
019import org.junit.jupiter.api.Test;
020
021public class DatabaseManagerTest {
022
023    @Test
024    public void testSingleDatabase() throws Exception {
025        try (DatabaseManager manager = DatabaseManager.singleDatabase()
026                .withInstancePreparer(EmbeddedPostgres.Builder::withDefaults)
027                .build()
028                .start()) {
029
030            // every call to getConnectionInfo returns the same db
031            DatabaseInfo firstDatabaseInfo = manager.getDatabaseInfo();
032            DatabaseInfo secondDatabaseInfo = manager.getDatabaseInfo();
033
034            assertEquals(firstDatabaseInfo, secondDatabaseInfo);
035        }
036    }
037
038    @Test
039    public void testMultiDatabase() throws Exception {
040        try (DatabaseManager manager = DatabaseManager.multiDatabases()
041                .withInstancePreparer(EmbeddedPostgres.Builder::withDefaults)
042                .build()
043                .start()) {
044
045            // every call to getConnectionInfo returns a new db
046            DatabaseInfo firstDatabaseInfo = manager.getDatabaseInfo();
047            DatabaseInfo secondDatabaseInfo = manager.getDatabaseInfo();
048
049            assertNotEquals(firstDatabaseInfo, secondDatabaseInfo);
050        }
051    }
052}