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 java.sql.Connection;
017import java.sql.ResultSet;
018import java.sql.Statement;
019
020import org.junit.jupiter.api.Test;
021
022import static org.junit.jupiter.api.Assertions.assertEquals;
023import static org.junit.jupiter.api.Assertions.assertFalse;
024import static org.junit.jupiter.api.Assertions.assertTrue;
025
026public class PostgresVersionTest {
027
028    @Test
029    public void testVersion() throws Exception {
030        try (EmbeddedPostgres pg = EmbeddedPostgres.defaultInstance()) {
031            String version = pg.getPostgresVersion();
032
033            try (Connection c = pg.createDefaultDataSource().getConnection();
034                    Statement s = c.createStatement()) {
035                try (ResultSet rs = s.executeQuery("SHOW server_version")) {
036                    assertTrue(rs.next());
037                    assertEquals(version, rs.getString(1));
038                    assertFalse(rs.next());
039                }
040            }
041        }
042    }
043}