Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. // configuration (groovy)
  2.  
  3. import de.flapdoodle.embed.process.runtime.Network
  4. import org.postgresql.ds.PGPoolingDataSource
  5. import org.springframework.context.annotation.Bean
  6. import org.springframework.context.annotation.Configuration
  7. import org.springframework.context.annotation.DependsOn
  8. import org.springframework.context.annotation.Profile
  9. import ru.yandex.qatools.embed.postgresql.PostgresExecutable
  10. import ru.yandex.qatools.embed.postgresql.PostgresProcess
  11. import ru.yandex.qatools.embed.postgresql.PostgresStarter
  12. import ru.yandex.qatools.embed.postgresql.config.AbstractPostgresConfig
  13. import ru.yandex.qatools.embed.postgresql.config.PostgresConfig
  14. import ru.yandex.qatools.embed.postgresql.distribution.Version
  15.  
  16. import javax.sql.DataSource
  17.  
  18. @Profile('test')
  19. @Configuration
  20. class TestDBConfig {
  21.  
  22. final PostgresConfig config = new PostgresConfig(
  23. Version.V9_5_0,
  24. new AbstractPostgresConfig.Net('localhost', Network.freeServerPort),
  25. new AbstractPostgresConfig.Storage('test'),
  26. new AbstractPostgresConfig.Timeout(),
  27. new AbstractPostgresConfig.Credentials('user', 'pass')
  28. )
  29.  
  30. @Bean(destroyMethod = 'stop', name = 'postgresProcess')
  31. PostgresProcess postgresProcess() {
  32. PostgresStarter<PostgresExecutable, PostgresProcess> runtime = PostgresStarter.getDefaultInstance()
  33. PostgresExecutable exec = runtime.prepare(config)
  34. PostgresProcess process = exec.start()
  35. process
  36. }
  37.  
  38. @Bean(destroyMethod = 'close')
  39. @DependsOn('postgresProcess')
  40. DataSource dataSource() {
  41. PGPoolingDataSource ds = new PGPoolingDataSource()
  42. ds.user = config.credentials().username()
  43. ds.password = config.credentials().password()
  44. ds.portNumber = config.net().port()
  45. ds.serverName = config.net().host()
  46. ds.databaseName = config.storage().dbName()
  47. ds
  48. }
  49. }
  50.  
  51. // required dependencies (gradle) - spring dependencies omitted - used spring-boot 1.3.7.RELEASE
  52.  
  53. compile 'org.postgresql:postgresql:9.4.1209'
  54. testCompile 'ru.yandex.qatools.embed:postgresql-embedded:1.15'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement