-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for static port for Sql Server
- Loading branch information
1 parent
ea7ce72
commit d065c5b
Showing
3 changed files
with
117 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
.../src/test/java/com/infobip/testcontainers/spring/mssql/StaticPortSqlServerDockerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.infobip.testcontainers.spring.mssql; | ||
|
||
import static org.assertj.core.api.BDDAssertions.then; | ||
|
||
import java.sql.Driver; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.datasource.SimpleDriverDataSource; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.TestConstructor; | ||
import org.testcontainers.Testcontainers; | ||
|
||
@AllArgsConstructor | ||
@ActiveProfiles("static-port") | ||
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) | ||
@SpringBootTest(classes = Main.class) | ||
class StaticPortSqlServerDockerTest { | ||
|
||
private final Environment environment; | ||
private final DataSourceProperties properties; | ||
|
||
@Test | ||
void shouldCreateContainer() { | ||
// given | ||
JdbcTemplate jdbcTemplate = new JdbcTemplate(new SimpleDriverDataSource( | ||
getDriver(properties.getUrl()), | ||
properties.getUrl(), | ||
properties.getUsername(), | ||
properties.getPassword())); | ||
|
||
// when | ||
String actual = jdbcTemplate.queryForObject("SELECT db_name()", String.class); | ||
|
||
// then | ||
then(actual).isEqualTo("MicrosoftDriverTestDatabase"); | ||
} | ||
|
||
@Test | ||
void shouldReplaceHostInJdbcUrl() { | ||
// when | ||
String actual = environment.getProperty("spring.datasource.url"); | ||
|
||
// then | ||
then(actual).contains("localhost:1433"); | ||
} | ||
|
||
@Test | ||
void shouldReplaceHostInR2dbc() { | ||
// when | ||
String actual = environment.getProperty("spring.r2dbc.url"); | ||
|
||
// then | ||
then(actual).contains("localhost:1433"); | ||
} | ||
|
||
@Test | ||
void shouldReplaceHostInFlyway() { | ||
// when | ||
String actual = environment.getProperty("spring.flyway.url"); | ||
|
||
// then | ||
then(actual).contains("localhost:1433"); | ||
} | ||
|
||
private Driver getDriver(String jdbcUrl) { | ||
try { | ||
return DriverManager.getDriver(jdbcUrl); | ||
} catch (SQLException e) { | ||
throw new IllegalArgumentException(e); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...-mssql-testcontainers-spring-boot-starter/src/test/resources/application-static-port.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:sqlserver://<host>:1433;database=MicrosoftDriverTestDatabase | ||
r2dbc: | ||
url: r2dbc:pool:mssql://<host>:1433/InfobipSpringDataJdbcQuerydslTest | ||
flyway: | ||
url: jdbc:sqlserver://<host>:1433;database=MicrosoftDriverTestDatabase |