All Downloads are FREE. Search and download functionalities are using the official Maven repository.

generator.server.springboot.database.mssql.MsSQLTestContainerExtension.mustache Maven / Gradle / Ivy

There is a newer version: 1.22.0
Show newest version
package {{packageName}};

import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.testcontainers.containers.MSSQLServerContainer;

import java.util.concurrent.atomic.AtomicBoolean;

public class MsSQLTestContainerExtension implements BeforeAllCallback {

  private static AtomicBoolean started = new AtomicBoolean(false);

  private static MSSQLServerContainer container =  new MSSQLServerContainer<>("{{mssqlDockerImageWithVersion}}")
    .withUrlParam("trustServerCertificate","true")
    .acceptLicense();

    @Override
    public void beforeAll(ExtensionContext extensionContext) throws Exception {
      if (!started.get()) {
        container.start();
        System.setProperty("spring.datasource.url", container.getJdbcUrl());
        System.setProperty("spring.datasource.password", container.getPassword());
        System.setProperty("spring.datasource.username", container.getUsername());
        System.setProperty("spring.datasource.driver-class-name","com.microsoft.sqlserver.jdbc.SQLServerDriver");
        started.set(true);
      }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy