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