-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
YugabyteDBYSQLTest.java
81 lines (69 loc) · 2.71 KB
/
YugabyteDBYSQLTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package org.testcontainers.junit.yugabytedb;
import java.sql.SQLException;
import org.junit.Test;
import org.testcontainers.containers.YugabyteDBYSQLContainer;
import org.testcontainers.db.AbstractContainerDatabaseTest;
import org.testcontainers.utility.DockerImageName;
import static org.assertj.core.api.Assertions.assertThat;
/**
* YugabyteDB YSQL API unit test class
*
* @author srinivasa-vasu
*/
public class YugabyteDBYSQLTest extends AbstractContainerDatabaseTest {
private static final String IMAGE_NAME = "yugabytedb/yugabyte:2.14.3.1-b1";
private static final DockerImageName YBDB_TEST_IMAGE = DockerImageName.parse(IMAGE_NAME);
@Test
public void testSmoke() throws SQLException {
try (
// creatingYSQLContainer {
final YugabyteDBYSQLContainer ysqlContainer = new YugabyteDBYSQLContainer(IMAGE_NAME)
// }
) {
// startingYSQLContainer {
ysqlContainer.start();
// }
assertThat(performQuery(ysqlContainer, "SELECT 1").getInt(1)).as("A sample test query succeeds")
.isEqualTo(1);
}
}
@Test
public void testCustomDatabase() throws SQLException {
String key = "random";
try (final YugabyteDBYSQLContainer ysqlContainer = new YugabyteDBYSQLContainer(YBDB_TEST_IMAGE)
.withDatabaseName(key)) {
ysqlContainer.start();
assertThat(performQuery(ysqlContainer, "SELECT 1").getInt(1))
.as("A test query on a custom database succeeds").isEqualTo(1);
}
}
@Test
public void testInitScript() throws SQLException {
try (final YugabyteDBYSQLContainer ysqlContainer = new YugabyteDBYSQLContainer(YBDB_TEST_IMAGE)
.withInitScript("init/init_yql.sql")) {
ysqlContainer.start();
assertThat(performQuery(ysqlContainer, "SELECT greet FROM dsql").getString(1))
.as("A record match succeeds").isEqualTo("Hello DSQL");
}
}
@Test
public void testWithAdditionalUrlParamInJdbcUrl() {
try (final YugabyteDBYSQLContainer ysqlContainer = new YugabyteDBYSQLContainer(YBDB_TEST_IMAGE)
.withUrlParam("sslmode", "disable").withUrlParam("application_name", "yugabyte")) {
ysqlContainer.start();
String jdbcUrl = ysqlContainer.getJdbcUrl();
assertThat(jdbcUrl).contains("?").contains("&").contains("sslmode=disable")
.contains("application_name=yugabyte")
.as("A JDBC connection string with additional parameter validation succeeds");
}
}
@Test
public void testWithCustomRole() throws SQLException {
try (final YugabyteDBYSQLContainer ysqlContainer = new YugabyteDBYSQLContainer(YBDB_TEST_IMAGE)
.withDatabaseName("yugabyte").withPassword("yugabyte").withUsername("yugabyte")) {
ysqlContainer.start();
assertThat(performQuery(ysqlContainer, "SELECT 1").getInt(1))
.as("A sample test query with a custom role succeeds").isEqualTo(1);
}
}
}