Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. package com.oodmi.database
  2.  
  3. import com.oodmi.database.service.ExtensionsService
  4. import com.oodmi.database.service.MigrationService
  5. import jdk.nashorn.internal.runtime.regexp.joni.Config.log
  6. import org.apache.tomcat.jdbc.pool.DataSource
  7. import org.junit.After
  8. import org.junit.Before
  9. import org.junit.Test
  10. import org.testcontainers.containers.ContainerFetchException
  11. import org.testcontainers.containers.PostgreSQLContainer
  12. import java.util.*
  13.  
  14. class AppTests(private var postgres: PostgreSQLContainer<*>? = null,
  15. private var sut: MigrationService? = null) {
  16.  
  17. @Before
  18. fun setUp() {
  19. val candidates = Arrays.asList("docker.io/postgres:latest", "postgres:latest")
  20. for (candidate in candidates) {
  21. try {
  22. this.postgres = PostgreSQLContainer<*>(candidate)
  23. postgres!!.start()
  24. val dataSource = DataSource()
  25. dataSource.driverClassName = postgres!!.getDriverClassName()
  26. dataSource.url = postgres!!.getJdbcUrl()
  27. dataSource.username = postgres!!.getUsername()
  28. dataSource.password = postgres!!.getPassword()
  29. dataSource.loginTimeout = 5
  30. sut = MigrationService(dataSource, ExtensionsService(dataSource))
  31. break
  32. } catch (e: ContainerFetchException) {
  33. log.printf("Can't load DB candidate: {}.", e.message)
  34. }
  35.  
  36. }
  37. }
  38.  
  39. @Test
  40. fun migrationSuccessful() {
  41. sut!!.migrate()
  42. }
  43.  
  44. @After
  45. fun tearDown() {
  46. postgres!!.stop()
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement