Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.oodmi.database
- import com.oodmi.database.service.ExtensionsService
- import com.oodmi.database.service.MigrationService
- import jdk.nashorn.internal.runtime.regexp.joni.Config.log
- import org.apache.tomcat.jdbc.pool.DataSource
- import org.junit.After
- import org.junit.Before
- import org.junit.Test
- import org.testcontainers.containers.ContainerFetchException
- import org.testcontainers.containers.PostgreSQLContainer
- import java.util.*
- class AppTests(private var postgres: PostgreSQLContainer<*>? = null,
- private var sut: MigrationService? = null) {
- @Before
- fun setUp() {
- val candidates = Arrays.asList("docker.io/postgres:latest", "postgres:latest")
- for (candidate in candidates) {
- try {
- this.postgres = PostgreSQLContainer<*>(candidate)
- postgres!!.start()
- val dataSource = DataSource()
- dataSource.driverClassName = postgres!!.getDriverClassName()
- dataSource.url = postgres!!.getJdbcUrl()
- dataSource.username = postgres!!.getUsername()
- dataSource.password = postgres!!.getPassword()
- dataSource.loginTimeout = 5
- sut = MigrationService(dataSource, ExtensionsService(dataSource))
- break
- } catch (e: ContainerFetchException) {
- log.printf("Can't load DB candidate: {}.", e.message)
- }
- }
- }
- @Test
- fun migrationSuccessful() {
- sut!!.migrate()
- }
- @After
- fun tearDown() {
- postgres!!.stop()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement