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