Monday, April 3, 2023

Sunday, April 2, 2023

TestContainers MSSQLServerContainer Sınıfı

Maven
Şöyle yaparız
<dependency>
  <groupId>org.testcontainers</groupId>
  <artifactId>mssqlserver</artifactId>
  <version>1.18.10</version>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>com.microsoft.sqlserver</groupId>
  <artifactId>mssql-jdbc</artifactId>
  <version>11.2.2.jre8</version>
  <scope>test</scope>
</dependency>
Örnek
Şöyle yaparız
@Container
private static final MSSQLServerContainer<?> SQLSERVER_CONTAINER =
 new MSSQLServerContainer<>("mcr.microsoft.com/mssql/server:2022-latest").acceptLicense();
acceptLicense metodu
Örnek
Şöyle yaparız
MSQLServerContainer mssqlserver = new MSSQLServerContainer<>(...).acceptLicense();
getDatabaseName metodu
UnsupportedOperationException fırlatıyor. Neden bilmiyorum

withDatabaseName metodu
UnsupportedOperationException fırlatıyor. Neden bilmiyorum
 
withUrlParam metodu
Örnek
Şöyle yaparız
MSSQLServerContainer<> container = 
  new MSSQLServerContainer<>("mcr.microsoft.com/mssql/server:2017-CU12");
container.withUrlParam("user", container.getUsername())
         .withUrlParam("password", container.getPassword());
container.start();
String jdbcUrl = container.getJdbcUrl();
withStartupCheckStrategy metodu
Örnek
Şöyle yaparız
new MSSQLServerContainer<>("mcr.microsoft.com/mssql/server:2017-latest")
  .withStartupCheckStrategy(
    new MinimumDurationRunningStartupCheckStrategy(Duration.ofSeconds(5)));




Testcontainers JDBC URL Kullanımı

Giriş
src/test/resources/container-license-acceptance.txt dosyası yaratılır. Dosyada
mcr.microsoft.com/mssql/server:2017-CU12 
veya
mcr.microsoft.com/mssql/server:latest
cümlesi yazar

Örnek
Şöyle yaparız
<dependency>
  <groupId>org.testcontainers</groupId>
  <artifactId>mssqlserver</artifactId>
  <version>1.17.6</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>com.microsoft.sqlserver</groupId>
  <artifactId>mssql-jdbc</artifactId>
  <version>11.2.2.jre8</version>
  <scope>test</scope>
</dependency>
Şöyle yaparız
String jdbcUrl = "jdbc:tc:sqlserver:latest:///mydbName";
try (Connection conn = DriverManager.getConnection(jdbcUrl)) {
  ...
}
Şöyle yaparız
String jdbcUrl = "jdbc:tc:sqlserver:2017-CU12:///mydbName";
try (Connection conn = DriverManager.getConnection(jdbcUrl)) {
  ...
}

Sütun Tipleri - VARCHAR - UNICODE Karakterler İçindir

Giriş UNICODE olmayan normal karakterler İçindir Örnek Şöyle yaparız CREATE TABLE ExampleTable (     ExampleColumn VARCHAR(255) ); INSERT IN...