Skip to content

Commit a91823d

Browse files
author
Manuel Stöger
committed
#373: Adding simple solution for having different image for realdata testing
1 parent f6f7957 commit a91823d

File tree

1 file changed

+70
-35
lines changed

1 file changed

+70
-35
lines changed

binocular-backend-new/web/src/test/kotlin/com/inso_world/binocular/web/graphql/integration/realdata/base/BaseGraphQlCompatibilityIT.kt

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,94 @@ package com.inso_world.binocular.web.graphql.integration.realdata.base
22

33
import com.inso_world.binocular.core.delegates.logger
44
import com.inso_world.binocular.core.integration.base.BaseIntegrationTest
5+
import com.inso_world.binocular.infrastructure.arangodb.ArangodbTestConfig
56
import com.inso_world.binocular.web.BinocularWebApplication
67
import com.inso_world.binocular.web.base.AbstractWebIntegrationTest
78
import com.inso_world.binocular.web.graphql.integration.realdata.base.legacy.LegacyHttpGraphQlClient
89
import com.inso_world.binocular.web.graphql.integration.realdata.base.spring.SpringTesterGraphQlClient
10+
import io.testcontainers.arangodb.containers.ArangoContainer
911
import org.springframework.beans.factory.annotation.Autowired
1012
import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureGraphQlTester
1113
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
1214
import org.springframework.boot.test.context.SpringBootTest
15+
import org.springframework.boot.test.util.TestPropertyValues
16+
import org.springframework.context.ApplicationContextInitializer
17+
import org.springframework.context.ConfigurableApplicationContext
18+
import org.springframework.core.env.Profiles
1319
import org.springframework.graphql.test.tester.GraphQlTester
20+
import org.springframework.test.context.ContextConfiguration
21+
import org.testcontainers.utility.DockerImageName
1422

1523
@AutoConfigureGraphQlTester
1624
@AutoConfigureMockMvc
1725
@SpringBootTest(
18-
classes = [BinocularWebApplication::class],
19-
webEnvironment = SpringBootTest.WebEnvironment.MOCK
26+
classes = [BinocularWebApplication::class],
27+
webEnvironment = SpringBootTest.WebEnvironment.MOCK
2028
)
21-
internal abstract class BaseGraphQlCompatibilityIT : AbstractWebIntegrationTest() {
22-
23-
companion object {
24-
private const val DEFAULT_TARGET = "spring"
25-
private const val TARGET_LEGACY = "legacy"
26-
private const val TARGET_SPRING = "spring"
27-
private const val DEFAULT_LEGACY_URL = "http://[::1]:8080/graphQl"
28-
val logger by logger()
29-
}
30-
31-
@Autowired
32-
protected lateinit var tester: GraphQlTester
33-
34-
protected val client: CompatibleGraphQlClient by lazy {
35-
val target = graphqlTarget()
36-
log("Running GraphQL tests in mode: $target")
37-
38-
when (target) {
39-
TARGET_LEGACY -> createLegacyClient()
40-
TARGET_SPRING -> SpringTesterGraphQlClient(tester)
41-
else -> error("Unknown graphql.target: $target (use '$TARGET_LEGACY' or '$TARGET_SPRING')")
29+
@ContextConfiguration(
30+
initializers = [
31+
BaseGraphQlCompatibilityIT.Initializer::class,
32+
]
33+
)
34+
internal abstract class BaseGraphQlCompatibilityIT {
35+
36+
companion object {
37+
private val adbContainer =
38+
ArangoContainer(
39+
DockerImageName.parse("ghcr.io/inso-world/binocular-database:3.12.test-data")
40+
.asCompatibleSubstituteFor("arangodb")
41+
)
42+
.apply { withExposedPorts(8529) }
43+
.apply { withoutAuth() }
44+
.apply { withReuse(true) }
45+
46+
private const val DEFAULT_TARGET = "spring"
47+
private const val TARGET_LEGACY = "legacy"
48+
private const val TARGET_SPRING = "spring"
49+
private const val DEFAULT_LEGACY_URL = "http://[::1]:8080/graphQl"
50+
private val logger by logger()
51+
}
52+
53+
private class Initializer : ApplicationContextInitializer<ConfigurableApplicationContext> {
54+
override fun initialize(ctx: ConfigurableApplicationContext) {
55+
if (!ctx.environment.acceptsProfiles(Profiles.of("arangodb"))) return
56+
adbContainer.start()
57+
58+
TestPropertyValues.of(
59+
"binocular.arangodb.database.name=binocular-binocular",
60+
"binocular.arangodb.database.host=${adbContainer.host}",
61+
"binocular.arangodb.database.port=${adbContainer.firstMappedPort}"
62+
).applyTo(ctx.environment)
63+
}
4264
}
43-
}
4465

45-
private fun createLegacyClient(): CompatibleGraphQlClient {
46-
val url = legacyUrl()
47-
log("Legacy endpoint: $url (override with -Dgraphql.legacy.url)")
48-
return LegacyHttpGraphQlClient(url)
49-
}
66+
@Autowired
67+
protected lateinit var tester: GraphQlTester
68+
69+
protected val client: CompatibleGraphQlClient by lazy {
70+
val target = graphqlTarget()
71+
log("Running GraphQL tests in mode: $target")
72+
73+
when (target) {
74+
TARGET_LEGACY -> createLegacyClient()
75+
TARGET_SPRING -> SpringTesterGraphQlClient(tester)
76+
else -> error("Unknown graphql.target: $target (use '$TARGET_LEGACY' or '$TARGET_SPRING')")
77+
}
78+
}
79+
80+
private fun createLegacyClient(): CompatibleGraphQlClient {
81+
val url = legacyUrl()
82+
log("Legacy endpoint: $url (override with -Dgraphql.legacy.url)")
83+
return LegacyHttpGraphQlClient(url)
84+
}
5085

51-
private fun graphqlTarget(): String =
52-
System.getProperty("graphql.target", DEFAULT_TARGET).lowercase()
86+
private fun graphqlTarget(): String =
87+
System.getProperty("graphql.target", DEFAULT_TARGET).lowercase()
5388

54-
private fun legacyUrl(): String =
55-
System.getProperty("graphql.legacy.url", DEFAULT_LEGACY_URL)
89+
private fun legacyUrl(): String =
90+
System.getProperty("graphql.legacy.url", DEFAULT_LEGACY_URL)
5691

57-
private fun log(message: String) =
58-
logger.info("[GRAPHQL-IT] $message")
92+
private fun log(message: String) =
93+
logger.info("[GRAPHQL-IT] $message")
5994

6095
}

0 commit comments

Comments
 (0)