Skip to content

Commit 01e3f3b

Browse files
authored
Create H2JUnitTest.java (#17949)
1 parent 8806dfd commit 01e3f3b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.baeldung.libraries.h2;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
import java.sql.*;
6+
7+
public class H2JUnitTest {
8+
9+
@Test
10+
public static void whenConnectingToSpecificSchema_ShouldReturnTheSpecificSchema() throws Exception {
11+
Connection conn = DriverManager.getConnection(
12+
"jdbc:h2:~/TEST_DB;INIT=CREATE SCHEMA IF NOT EXISTS TEST_SCHEMA\\;SET SCHEMA TEST_SCHEMA",
13+
"sa",
14+
"");
15+
16+
Statement stmt=conn.createStatement();
17+
18+
ResultSet rs=stmt.executeQuery("SELECT CURRENT_SCHEMA");
19+
rs.first();
20+
21+
String actualSchema = rs.getString(1);
22+
String expectedSchema = new String("TEST_SCHEMA");
23+
24+
Assertions.assertTrue(actualSchema.equals(expectedSchema));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)