Improve MsSqlServerR2dbcDockerComposeConnectionDetailsFactory tests

See gh-35144
pull/35185/head
Andy Wilkinson 2 years ago
parent 963da20493
commit 8fd36d04e1

@ -30,4 +30,5 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("com.microsoft.sqlserver:mssql-jdbc")
testRuntimeOnly("io.r2dbc:r2dbc-mssql")
}

@ -16,11 +16,14 @@
package org.springframework.boot.docker.compose.service.connection.sqlserver;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.r2dbc.R2dbcConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.r2dbc.core.DatabaseClient;
import static org.assertj.core.api.Assertions.assertThat;
@ -37,12 +40,18 @@ class MsSqlServerR2dbcDockerComposeConnectionDetailsFactoryIntegrationTests
}
@Test
void runCreatesConnectionDetails() {
void runCreatesConnectionDetailsThatCanBeUsedToAccessDatabase() {
R2dbcConnectionDetails connectionDetails = run(R2dbcConnectionDetails.class);
ConnectionFactoryOptions connectionFactoryOptions = connectionDetails.getConnectionFactoryOptions();
assertThat(connectionFactoryOptions.toString()).contains("driver=mssql", "password=REDACTED", "user=SA");
assertThat(connectionFactoryOptions.getRequiredValue(ConnectionFactoryOptions.PASSWORD))
.isEqualTo("verYs3cret");
Object result = DatabaseClient.create(ConnectionFactories.get(connectionFactoryOptions))
.sql(DatabaseDriver.SQLSERVER.getValidationQuery())
.map((row, metadata) -> row.get(0))
.first()
.block();
assertThat(result).isEqualTo(1);
}
}

Loading…
Cancel
Save