diff --git a/build.gradle.kts b/build.gradle.kts index f0447d0..2bc2548 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ plugins { group = "au.kilemon" // Make sure version matches version defined in MessageQueueApplication -version = "0.3.2" +version = "0.3.3" java.sourceCompatibility = JavaVersion.VERSION_17 repositories { @@ -30,9 +30,6 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-data-redis:${springVersion}") // JPA dependency implementation("org.springframework.boot:spring-boot-starter-data-jpa:${springVersion}") - // No SQL drivers - // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-mongodb - implementation("org.springframework.boot:spring-boot-starter-data-mongodb:${springVersion}") // https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webmvc-ui implementation("org.springdoc:springdoc-openapi-starter-webmvc-api:${springDocVersion}") @@ -51,6 +48,12 @@ dependencies { implementation("com.mysql:mysql-connector-j:8.4.0") // https://mvnrepository.com/artifact/org.postgresql/postgresql implementation("org.postgresql:postgresql:42.7.3") + // https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc + implementation("com.microsoft.sqlserver:mssql-jdbc:12.6.3.jre11") + + // No SQL drivers + // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-mongodb + implementation("org.springframework.boot:spring-boot-starter-data-mongodb:${springVersion}") // JWT token // https://mvnrepository.com/artifact/com.auth0/java-jwt diff --git a/src/main/kotlin/au/kilemon/messagequeue/MessageQueueApplication.kt b/src/main/kotlin/au/kilemon/messagequeue/MessageQueueApplication.kt index 64bdbfb..8a0c595 100644 --- a/src/main/kotlin/au/kilemon/messagequeue/MessageQueueApplication.kt +++ b/src/main/kotlin/au/kilemon/messagequeue/MessageQueueApplication.kt @@ -17,7 +17,7 @@ open class MessageQueueApplication /** * Application version number, make sure this matches what is defined in `build.gradle.kts`. */ - const val VERSION: String = "0.3.2" + const val VERSION: String = "0.3.3" } } diff --git a/src/test/kotlin/au/kilemon/messagequeue/queue/sql/MicrosoftSqlMultiQueueTest.kt b/src/test/kotlin/au/kilemon/messagequeue/queue/sql/MicrosoftSqlMultiQueueTest.kt new file mode 100644 index 0000000..e8d0095 --- /dev/null +++ b/src/test/kotlin/au/kilemon/messagequeue/queue/sql/MicrosoftSqlMultiQueueTest.kt @@ -0,0 +1,93 @@ +package au.kilemon.messagequeue.queue.sql + +import au.kilemon.messagequeue.configuration.QueueConfiguration +import au.kilemon.messagequeue.logging.LoggingConfiguration +import au.kilemon.messagequeue.queue.MultiQueueTest +import au.kilemon.messagequeue.queue.sql.MicrosoftSqlMultiQueueTest.Companion.MS_SQL_CONTAINER +import org.junit.jupiter.api.AfterAll +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.BeforeEach +import org.springframework.boot.test.util.TestPropertyValues +import org.springframework.context.ApplicationContextInitializer +import org.springframework.context.ConfigurableApplicationContext +import org.springframework.context.annotation.Import +import org.springframework.test.context.ContextConfiguration +import org.testcontainers.containers.GenericContainer +import org.testcontainers.utility.DockerImageName + +/** + * A test class for the [MS_SQL_CONTAINER] to ensure the [SqlMultiQueue] works as expected with this underlying data storage DB. + * + * @author github.com/Kilemonn + */ +@ContextConfiguration(initializers = [MicrosoftSqlMultiQueueTest.Initializer::class]) +@Import( *[QueueConfiguration::class, LoggingConfiguration::class, MultiQueueTest.MultiQueueTestConfiguration::class] ) +class MicrosoftSqlMultiQueueTest: SqlMultiQueueTest() +{ + companion object + { + lateinit var database: GenericContainer<*> + + private const val MS_SQL_CONTAINER = "mcr.microsoft.com/mssql/server:2022-CU13-ubuntu-22.04" + private const val MS_CONTAINER_PORT = 1433 + + /** + * Stop the container at the end of all the tests. + */ + @AfterAll + @JvmStatic + fun afterClass() + { + database.stop() + } + } + + /** + * The test initialiser for [MicrosoftSqlMultiQueueTest] to initialise the container and test properties. + * + * @author github.com/Kilemonn + */ + internal class Initializer : ApplicationContextInitializer + { + /** + * Force start the container, so we can place its host and dynamic ports into the system properties. + * + * Set the environment variables before any of the beans are initialised. + */ + override fun initialize(configurableApplicationContext: ConfigurableApplicationContext) + { + val password = "This154Strong" // container has password requirements + val username = "sa" + val envMap = HashMap() + envMap["MSSQL_SA_PASSWORD"] = password + envMap["ACCEPT_EULA"] = "Y" + + database = GenericContainer(DockerImageName.parse(MS_SQL_CONTAINER)) + .withExposedPorts(MS_CONTAINER_PORT).withReuse(false).withEnv(envMap) + database.start() + + // "jdbc:sqlserver://localhost:1433;databaseName=dbname;encrypt=false" + val endpoint = "jdbc:sqlserver://${database.host}:${database.getMappedPort(MS_CONTAINER_PORT)};encrypt=true;trustServerCertificate=true" + + TestPropertyValues.of( + "spring.datasource.url=$endpoint", + "spring.datasource.username=$username", + "spring.datasource.password=$password", + + // We have to explicitly set the dialect here since without it spring is unable to determine + // the dialect to use when we run all tests. + "spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServerDialect" + ).applyTo(configurableApplicationContext.environment) + } + } + + /** + * Check the container is running before each test as it's required for the methods to access the [SqlMultiQueue]. + */ + @BeforeEach + fun beforeEach() + { + Assertions.assertTrue(database.isRunning) + multiQueue.clear() + } +} \ No newline at end of file