org.testcontainers.containers.MSSQLServerContainer Java Examples

The following examples show how to use org.testcontainers.containers.MSSQLServerContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MSSQLRule.java    From vertx-sql-client with Apache License 2.0 6 votes vote down vote up
private MSSQLConnectOptions startMSSQL() {
    server = new MSSQLServer();
    server.withInitScript("init.sql");
    server.start();

    MSSQLConnectOptions options = new MSSQLConnectOptions()
      .setHost(server.getContainerIpAddress())
      .setPort(server.getMappedPort(MSSQLServerContainer.MS_SQL_SERVER_PORT))
      .setUser(server.getUsername())
      .setPassword(server.getPassword());
//      .setDatabase(server.getDatabaseName()); // unsupported by Testcontainers
    return options;
  }
 
Example #2
Source File: SimpleMSSQLServerTest.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void testSetupDatabase() throws SQLException {
    try (MSSQLServerContainer<?> mssqlServer = new MSSQLServerContainer<>()) {
        mssqlServer.start();
        DataSource ds = getDataSource(mssqlServer);
        Statement statement = ds.getConnection().createStatement();
        statement.executeUpdate("CREATE DATABASE [test];");
        statement = ds.getConnection().createStatement();
        statement.executeUpdate("CREATE TABLE [test].[dbo].[Foo](ID INT PRIMARY KEY);");
        statement = ds.getConnection().createStatement();
        statement.executeUpdate("INSERT INTO [test].[dbo].[Foo] (ID) VALUES (3);");
        statement = ds.getConnection().createStatement();
        statement.execute("SELECT * FROM [test].[dbo].[Foo];");
        ResultSet resultSet = statement.getResultSet();

        resultSet.next();
        int resultSetInt = resultSet.getInt("ID");
        assertEquals("A basic SELECT query succeeds", 3, resultSetInt);
    }
}
 
Example #3
Source File: SimpleMSSQLServerTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void testSimple() throws SQLException {
    try (MSSQLServerContainer<?> mssqlServer = new MSSQLServerContainer<>()) {
        mssqlServer.start();
        ResultSet resultSet = performQuery(mssqlServer, "SELECT 1");

        int resultSetInt = resultSet.getInt(1);
        assertEquals("A basic SELECT query succeeds", 1, resultSetInt);
    }
}
 
Example #4
Source File: SimpleMSSQLServerTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void testWithAdditionalUrlParamInJdbcUrl() {
    try (MSSQLServerContainer<?> mssqlServer = new MSSQLServerContainer<>()
        .withUrlParam("integratedSecurity", "false")
        .withUrlParam("applicationName", "MyApp")) {

        mssqlServer.start();

        String jdbcUrl = mssqlServer.getJdbcUrl();
        assertThat(jdbcUrl, containsString(";integratedSecurity=false;applicationName=MyApp"));
    }
}
 
Example #5
Source File: CustomPasswordMSSQLServerTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void runPasswordTests() {
    try {
        new MSSQLServerContainer<>().withPassword(this.password);
        if (!valid)
            fail("Password " + this.password + " is not valid. Expected exception");
    } catch (IllegalArgumentException e) {
        if (valid)
            fail("Password " + this.password + " should have been validated");
    }
}
 
Example #6
Source File: CustomizableMSSQLServerTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void testSqlServerConnection() throws SQLException {
    try (MSSQLServerContainer<?> mssqlServerContainer = new MSSQLServerContainer<>()
        .withPassword(STRONG_PASSWORD)) {

        mssqlServerContainer.start();

        ResultSet resultSet = performQuery(mssqlServerContainer, mssqlServerContainer.getTestQueryString());
        int resultSetInt = resultSet.getInt(1);
        assertEquals("A basic SELECT query succeeds", 1, resultSetInt);
    }
}
 
Example #7
Source File: DebeziumSqlserverTestResource.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@Override
protected MSSQLServerContainer createContainer() {
    return new MSSQLServerContainer<>().withEnv(Collections.singletonMap("MSSQL_AGENT_ENABLED", "True"))
            .withInitScript("initSqlserver.sql");
}
 
Example #8
Source File: MSSQLRule.java    From vertx-sql-client with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure() {
  this.addExposedPort(MSSQLServerContainer.MS_SQL_SERVER_PORT);
  this.addEnv("ACCEPT_EULA", "Y");
  this.addEnv("SA_PASSWORD", this.getPassword());
}
 
Example #9
Source File: DatabaseContainers.java    From spring-session with Apache License 2.0 4 votes vote down vote up
static MSSQLServerContainer sqlServer2017() {
	return new SqlServer2017Container();
}
 
Example #10
Source File: MSSQLServerContainerFactory.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
public static MSSQLServerContainer newMSSQLServerContainer(Logger logger) {
    final MSSQLServerContainer mssqlServerContainer = new MSSQLServerContainer();
    mssqlServerContainer.withInitScript("sql/init_mssql.sql");
    mssqlServerContainer.withLogConsumer(new Slf4jLogConsumer(logger));
    return mssqlServerContainer;
}