Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
release 4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Adven27 committed Jul 24, 2021
1 parent 329d0cb commit 7a72ee1
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 172 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ Java library for a microservice environment emulation
1. Add needed dependencies:

```groovy
testImplementation "io.github.adven27:env-db-postgresql:4.0.0"
testImplementation "io.github.adven27:env-db-mssql:4.0.0"
testImplementation "io.github.adven27:env-db-mysql:4.0.0"
testImplementation "io.github.adven27:env-db-oracle:4.0.0"
testImplementation "io.github.adven27:env-db-oracle-temp:4.0.0"
testImplementation "io.github.adven27:env-db-db2:4.0.0"
testImplementation "io.github.adven27:env-jar-application:4.0.0"
testImplementation "io.github.adven27:env-mq-rabbit:4.0.0"
testImplementation "io.github.adven27:env-mq-ibmmq:4.0.0"
testImplementation "io.github.adven27:env-mq-redis:4.0.0"
testImplementation "io.github.adven27:env-grpc-mock:4.0.0"
testImplementation "io.github.adven27:env-wiremock:4.0.0"
testImplementation "io.github.adven27:env-db-postgresql:4.0.1"
testImplementation "io.github.adven27:env-db-mssql:4.0.1"
testImplementation "io.github.adven27:env-db-mysql:4.0.1"
testImplementation "io.github.adven27:env-db-oracle:4.0.1"
testImplementation "io.github.adven27:env-db-oracle-temp:4.0.1"
testImplementation "io.github.adven27:env-db-db2:4.0.1"
testImplementation "io.github.adven27:env-jar-application:4.0.1"
testImplementation "io.github.adven27:env-mq-rabbit:4.0.1"
testImplementation "io.github.adven27:env-mq-ibmmq:4.0.1"
testImplementation "io.github.adven27:env-mq-redis:4.0.1"
testImplementation "io.github.adven27:env-grpc-mock:4.0.1"
testImplementation "io.github.adven27:env-wiremock:4.0.1"
```

2. Set up systems:
Expand All @@ -40,7 +40,7 @@ class SomeEnvironment : Environment(
"WIREMOCK" to WiremockSystem()
) {
fun rabbit() = find<RabbitContainerSystem>("RABBIT")
fun mock() = find<WiremockSystem>("WIREMOCK").server
fun mock() = find<WiremockSystem>("WIREMOCK")
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
ext.testContainers_version = '1.15.3'
ext.wiremock_version = '2.27.2'
ext.klogging_version = '2.0.10'
ext.libVersion = "4.0.0"
ext.libVersion = "4.0.1"
ext.libGroup = 'io.github.adven27'
repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.adven27.env.core

import io.github.adven27.env.core.Environment.Companion.propagateToSystemProperties
import java.util.function.BiFunction
import java.util.function.Consumer
import java.util.function.Function
Expand All @@ -11,11 +12,12 @@ interface ExternalSystem {
fun start(fixedEnv: Boolean)
fun stop()
fun running(): Boolean
fun config(): Any
fun describe(): String = toString()
fun config(): ExternalSystemConfig
fun describe(): String =
toString() + config().properties.entries.joinToString(separator = "\n\t", prefix = "\n\t") { it.toString() }
}

open class GenericExternalSystem<T, C : Any> @JvmOverloads constructor(
open class GenericExternalSystem<T, C : ExternalSystemConfig> @JvmOverloads constructor(
protected var system: T,
private var config: C,
private val start: BiFunction<Boolean, T, C>,
Expand Down Expand Up @@ -47,3 +49,11 @@ interface EnvironmentStrategy {
override fun fixedEnv(): Boolean = System.getProperty(property, orElse.toString()).toBoolean()
}
}

open class ExternalSystemConfig(val properties: Map<String, String>) {
constructor(vararg properties: Pair<String, String>) : this(properties.toMap())

init {
properties.propagateToSystemProperties()
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.github.adven27.env.db.db2

import io.github.adven27.env.core.Environment.Companion.propagateToSystemProperties
import io.github.adven27.env.core.ExternalSystem
import io.github.adven27.env.core.ExternalSystemConfig
import org.testcontainers.containers.Db2Container
import org.testcontainers.utility.DockerImageName

@Suppress("unused", "LongParameterList")
class Db2ContainerSystem @JvmOverloads constructor(
open class Db2ContainerSystem @JvmOverloads constructor(
dockerImageName: DockerImageName,
private val defaultPort: Int = DB2_PORT,
private var config: Config = Config(),
Expand All @@ -29,26 +29,23 @@ class Db2ContainerSystem @JvmOverloads constructor(

override fun running() = isRunning
override fun config() = config
override fun describe() = super.describe() + "\n\t" + config.asMap().entries.joinToString("\n\t") { it.toString() }

data class Config @JvmOverloads constructor(
var jdbcUrl: String = "jdbc:db2://localhost:$DB2_PORT/test",
var username: String = "db2inst1",
var password: String = "foobar1234",
var driver: String = "com.ibm.db2.jcc.DB2Driver"
) : ExternalSystemConfig(
PROP_URL to jdbcUrl,
PROP_USER to username,
PROP_PASSWORD to password,
PROP_DRIVER to driver
) {
companion object {
const val PROP_URL = "env.db.db2.url"
const val PROP_USER = "env.db.db2.username"
const val PROP_PASSWORD = "env.db.db2.password"
const val PROP_DRIVER = "env.db.db2.driver"
}

init {
asMap().propagateToSystemProperties()
}

fun asMap() =
mapOf(PROP_URL to jdbcUrl, PROP_USER to username, PROP_PASSWORD to password, PROP_DRIVER to driver)
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.github.adven27.env.db.mssql

import io.github.adven27.env.container.asCompatibleSubstituteFor
import io.github.adven27.env.core.Environment.Companion.propagateToSystemProperties
import io.github.adven27.env.core.ExternalSystem
import io.github.adven27.env.core.ExternalSystemConfig
import mu.KLogging
import org.testcontainers.containers.MSSQLServerContainer
import org.testcontainers.utility.DockerImageName

@Suppress("LongParameterList", "unused")
class MsSqlServerContainerSystem @JvmOverloads constructor(
open class MsSqlServerContainerSystem @JvmOverloads constructor(
dockerImageName: DockerImageName = DEFAULT_IMAGE,
private val defaultPort: Int = MS_SQL_SERVER_PORT,
private var config: Config = Config(),
Expand Down Expand Up @@ -37,28 +37,27 @@ class MsSqlServerContainerSystem @JvmOverloads constructor(

override fun running() = isRunning
override fun config() = config
override fun describe() = super.describe() + "\n\t" + config.asMap().entries.joinToString("\n\t") { it.toString() }

data class Config @JvmOverloads constructor(
var jdbcUrl: String = "jdbc:sqlserver://localhost\\Developer:$MS_SQL_SERVER_PORT",
var username: String = "test",
var password: String = "test",
var driver: String = "com.microsoft.sqlserver.jdbc.SQLServerDriver",
) : ExternalSystemConfig(
PROP_URL to jdbcUrl,
PROP_USER to username,
PROP_PASSWORD to password,
PROP_DRIVER to driver
) {
init {
asMap().propagateToSystemProperties()
companion object : KLogging() {
const val PROP_URL = "env.db.sqlserver.url"
const val PROP_USER = "env.db.sqlserver.username"
const val PROP_PASSWORD = "env.db.sqlserver.password"
const val PROP_DRIVER = "env.db.sqlserver.driver"
}

fun asMap() =
mapOf(PROP_URL to jdbcUrl, PROP_USER to username, PROP_PASSWORD to password, PROP_DRIVER to driver)
}

companion object : KLogging() {
const val PROP_URL = "env.db.sqlserver.url"
const val PROP_USER = "env.db.sqlserver.username"
const val PROP_PASSWORD = "env.db.sqlserver.password"
const val PROP_DRIVER = "env.db.sqlserver.driver"

@JvmField
val DEFAULT_IMAGE: DockerImageName =
"mcr.microsoft.com/azure-sql-edge" asCompatibleSubstituteFor "mcr.microsoft.com/mssql/server"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.github.adven27.env.db.mysql

import io.github.adven27.env.container.parseImage
import io.github.adven27.env.core.Environment.Companion.propagateToSystemProperties
import io.github.adven27.env.core.ExternalSystem
import io.github.adven27.env.core.ExternalSystemConfig
import mu.KLogging
import org.testcontainers.containers.MySQLContainer
import org.testcontainers.utility.DockerImageName

@Suppress("LongParameterList")
class MySqlContainerSystem @JvmOverloads constructor(
@Suppress("LongParameterList", "unused")
open class MySqlContainerSystem @JvmOverloads constructor(
dockerImageName: DockerImageName = DEFAULT_IMAGE,
private val defaultPort: Int = MYSQL_PORT,
private var config: Config = Config(),
Expand All @@ -35,30 +35,25 @@ class MySqlContainerSystem @JvmOverloads constructor(
}

override fun running() = isRunning

override fun config() = config

override fun describe() = super.describe() + "\n\t" + config.asMap().entries.joinToString("\n\t") { it.toString() }

data class Config @JvmOverloads constructor(
var jdbcUrl: String = "jdbc:mysql://localhost:$MYSQL_PORT/test?autoReconnect=true&useSSL=false",
var username: String = "test",
var password: String = "test",
var driver: String = "com.mysql.cj.jdbc.Driver"
) : ExternalSystemConfig(
PROP_URL to jdbcUrl,
PROP_USER to username,
PROP_PASSWORD to password,
PROP_DRIVER to driver
) {
companion object {
const val PROP_URL = "env.db.mysql.url"
const val PROP_USER = "env.db.mysql.username"
const val PROP_PASSWORD = "env.db.mysql.password"
const val PROP_DRIVER = "env.db.mysql.driver"
}

init {
asMap().propagateToSystemProperties()
}

fun asMap() =
mapOf(PROP_URL to jdbcUrl, PROP_USER to username, PROP_PASSWORD to password, PROP_DRIVER to driver)
}

companion object : KLogging() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.adven27.env.db.oracle

import io.github.adven27.env.core.Environment.Companion.propagateToSystemProperties
import io.github.adven27.env.core.ExternalSystem
import io.github.adven27.env.core.ExternalSystemConfig
import mu.KLogging
import org.springframework.core.io.DefaultResourceLoader
import org.springframework.core.io.support.EncodedResource
Expand Down Expand Up @@ -79,29 +79,20 @@ open class OracleTemporarySchemaSystem @JvmOverloads constructor(

override fun running() = isRunning
override fun config() = config
override fun describe() =
super.describe() + "\n\t" + config.asMap().entries.joinToString("\n\t") { it.toString() }

data class Config @JvmOverloads constructor(
val url: String = "jdbc:oracle:thin:@host:port:sid",
val username: String = "test",
val password: String = "test",
val driver: String = "oracle.jdbc.OracleDriver"
) {
) : ExternalSystemConfig(PROP_URL to url, PROP_USER to username, PROP_PASSWORD to password, PROP_DRIVER to driver) {
companion object {
private const val PREFIX = "env.db.oracle."
const val PROP_URL = "${PREFIX}url"
const val PROP_USER = "${PREFIX}username"
const val PROP_PASSWORD = "${PREFIX}password"
const val PROP_DRIVER = "${PREFIX}driver"
}

init {
asMap().propagateToSystemProperties()
}

fun asMap() =
mapOf(PROP_URL to url, PROP_USER to username, PROP_PASSWORD to password, PROP_DRIVER to driver)
}

private var isRunning = false
Expand All @@ -114,9 +105,7 @@ open class OracleTemporarySchemaSystem @JvmOverloads constructor(
fun getUsername() = config.username
fun getPassword() = config.password

override fun close() {
stop()
}
override fun close() = stop()

fun withInitScript(initScriptPath: String): OracleTemporarySchemaSystem {
this.initScriptPath = initScriptPath
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.github.adven27.env.db.oracle

import io.github.adven27.env.container.parseImage
import io.github.adven27.env.core.Environment.Companion.propagateToSystemProperties
import io.github.adven27.env.core.ExternalSystem
import io.github.adven27.env.core.ExternalSystemConfig
import mu.KLogging
import org.testcontainers.containers.OracleContainer
import org.testcontainers.utility.DockerImageName

@Suppress("LongParameterList")
class OracleContainerSystem @JvmOverloads constructor(
@Suppress("LongParameterList", "unused")
open class OracleContainerSystem @JvmOverloads constructor(
dockerImageName: DockerImageName = DEFAULT_IMAGE,
private val defaultPort: Int = PORT,
private var config: Config = Config(),
Expand Down Expand Up @@ -37,30 +37,25 @@ class OracleContainerSystem @JvmOverloads constructor(
}

override fun running() = isRunning

override fun config() = config

override fun describe() = super.describe() + "\n\t" + config.asMap().entries.joinToString("\n\t") { it.toString() }

data class Config @JvmOverloads constructor(
var jdbcUrl: String = "jdbc:oracle:thin:system/oracle@localhost:$PORT:xe",
var username: String = "system",
var password: String = "oracle",
var driver: String = "oracle.jdbc.OracleDriver"
) : ExternalSystemConfig(
PROP_URL to jdbcUrl,
PROP_USER to username,
PROP_PASSWORD to password,
PROP_DRIVER to driver
) {
companion object {
const val PROP_URL = "env.db.oracle.url"
const val PROP_USER = "env.db.oracle.username"
const val PROP_PASSWORD = "env.db.oracle.password"
const val PROP_DRIVER = "env.db.oracle.driver"
}

init {
asMap().propagateToSystemProperties()
}

fun asMap() =
mapOf(PROP_URL to jdbcUrl, PROP_USER to username, PROP_PASSWORD to password, PROP_DRIVER to driver)
}

companion object : KLogging() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.github.adven27.env.db.postgresql

import io.github.adven27.env.container.parseImage
import io.github.adven27.env.core.Environment.Companion.propagateToSystemProperties
import io.github.adven27.env.core.ExternalSystem
import io.github.adven27.env.core.ExternalSystemConfig
import mu.KLogging
import org.testcontainers.containers.PostgreSQLContainer
import org.testcontainers.utility.DockerImageName

@Suppress("LongParameterList")
class PostgreSqlContainerSystem @JvmOverloads constructor(
@Suppress("LongParameterList", "unused")
open class PostgreSqlContainerSystem @JvmOverloads constructor(
dockerImageName: DockerImageName = DEFAULT_IMAGE,
private val defaultPort: Int = POSTGRESQL_PORT,
private var config: Config = Config(),
Expand Down Expand Up @@ -36,13 +36,17 @@ class PostgreSqlContainerSystem @JvmOverloads constructor(

override fun running() = isRunning
override fun config() = config
override fun describe() = super.describe() + "\n\t" + config.asMap().entries.joinToString("\n\t") { it.toString() }

data class Config @JvmOverloads constructor(
val jdbcUrl: String = "jdbc:postgresql://localhost:$POSTGRESQL_PORT/postgres?stringtype=unspecified",
val username: String = "test",
val password: String = "test",
val driver: String = "org.postgresql.Driver"
) : ExternalSystemConfig(
PROP_URL to jdbcUrl,
PROP_USER to username,
PROP_PASSWORD to password,
PROP_DRIVER to driver
) {
companion object {
private const val PREFIX = "env.db.postgresql."
Expand All @@ -51,13 +55,6 @@ class PostgreSqlContainerSystem @JvmOverloads constructor(
const val PROP_PASSWORD = "${PREFIX}password"
const val PROP_DRIVER = "${PREFIX}driver"
}

init {
asMap().propagateToSystemProperties()
}

fun asMap() =
mapOf(PROP_URL to jdbcUrl, PROP_USER to username, PROP_PASSWORD to password, PROP_DRIVER to driver)
}

companion object : KLogging() {
Expand Down
Loading

0 comments on commit 7a72ee1

Please sign in to comment.