Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Gate-Pool): Add Bpdm pool and gate containers to test env #208

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

package com.catenax.bpdm.bridge.dummy

import com.catenax.bpdm.bridge.dummy.util.BpdmGateContextInitializer
import com.catenax.bpdm.bridge.dummy.util.BpdmPoolContextInitializer
import com.catenax.bpdm.bridge.dummy.util.OpenSearchContextInitializer
import com.catenax.bpdm.bridge.dummy.util.PostgreSQLContextInitializer
import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest
Expand All @@ -27,11 +30,12 @@ import org.springframework.test.context.ContextConfiguration

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class])
@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class, OpenSearchContextInitializer::class, BpdmPoolContextInitializer::class, BpdmGateContextInitializer::class])
class ApplicationTests {

@Test
fun contextLoads() {

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package com.catenax.bpdm.bridge.dummy.util


import com.catenax.bpdm.bridge.dummy.util.BpdmPoolContextInitializer.Companion.bpdmPoolContainer
import com.catenax.bpdm.bridge.dummy.util.OpenSearchContextInitializer.Companion.openSearchContainer
import com.catenax.bpdm.bridge.dummy.util.PostgreSQLContextInitializer.Companion.postgreSQLContainer
import org.springframework.boot.test.util.TestPropertyValues
import org.springframework.context.ApplicationContextInitializer
import org.springframework.context.ConfigurableApplicationContext
import org.testcontainers.containers.GenericContainer
import org.testcontainers.lifecycle.Startable

/**
* When used on a spring boot test, starts a singleton postgres db container that is shared between all integration tests.
*/


class BpdmGateContextInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> {

companion object {
const val BPDM_PORT = 8081

private val bpdmGateContainer: GenericContainer<*> =
GenericContainer("ghcr.io/catenax-ng/tx-bpdm/gate:4.0.0-alpha.4")
.dependsOn(listOf<Startable>(postgreSQLContainer, openSearchContainer, bpdmPoolContainer))
.withNetwork(postgreSQLContainer.getNetwork())
.withExposedPorts(BPDM_PORT)


}


override fun initialize(applicationContext: ConfigurableApplicationContext) {
val postgresNetworkAlias = applicationContext.environment.getProperty("bpdm.datasource.alias")
val bpdmPoolAlias = applicationContext.environment.getProperty("bpdm.pool.alias")
val dataBase = postgreSQLContainer.getDatabaseName()
bpdmGateContainer.withEnv(
"spring.datasource.url", "jdbc:postgresql://${postgresNetworkAlias}:5432/${dataBase}?loggerLevel=OFF"
)
.withEnv("bpdm.pool.base-url", "http://$bpdmPoolAlias:8080/api/catena")

.withEnv(
"spring.datasource.username", postgreSQLContainer.username
)
.withEnv(
"spring.datasource.password", postgreSQLContainer.password
).start()


TestPropertyValues.of(
"bpdm.gate.base-url=http://localhost:${bpdmGateContainer.getMappedPort(BPDM_PORT)}",
).applyTo(applicationContext.environment)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package com.catenax.bpdm.bridge.dummy.util


import com.catenax.bpdm.bridge.dummy.util.OpenSearchContextInitializer.Companion.openSearchContainer
import com.catenax.bpdm.bridge.dummy.util.PostgreSQLContextInitializer.Companion.postgreSQLContainer
import org.springframework.boot.test.util.TestPropertyValues
import org.springframework.context.ApplicationContextInitializer
import org.springframework.context.ConfigurableApplicationContext
import org.testcontainers.containers.GenericContainer
import org.testcontainers.lifecycle.Startable

/**
* When used on a spring boot test, starts a singleton postgres db container that is shared between all integration tests.
*/


class BpdmPoolContextInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> {

companion object {
const val BPDM_PORT = 8080

val bpdmPoolContainer: GenericContainer<*> =
GenericContainer("ghcr.io/catenax-ng/tx-bpdm/pool:4.0.0-alpha.4")
.dependsOn(listOf<Startable>(postgreSQLContainer, openSearchContainer))
.withNetwork(postgreSQLContainer.getNetwork())
.withExposedPorts(BPDM_PORT)


}


override fun initialize(applicationContext: ConfigurableApplicationContext) {
val postgresNetworkAlias = applicationContext.environment.getProperty("bpdm.datasource.alias")
val openSearchNetworkAlias = applicationContext.environment.getProperty("bpdm.opensearch.alias")
val dataBase = postgreSQLContainer.getDatabaseName()
val bpdmAlias = applicationContext.environment.getProperty("bpdm.pool.alias")
bpdmPoolContainer.withNetworkAliases(bpdmAlias)

bpdmPoolContainer.withEnv(
"spring.datasource.url", "jdbc:postgresql://${postgresNetworkAlias}:5432/${dataBase}?loggerLevel=OFF"
)
.withEnv("bpdm.opensearch.host", openSearchNetworkAlias)
.withEnv(
"pdm.opensearch.port",
OpenSearchContextInitializer.OPENSEARCH_PORT.toString()
)
.withEnv("bpdm.opensearch.scheme", "http")
.withEnv(
"spring.datasource.username", postgreSQLContainer.username
)
.withEnv(
"spring.datasource.password", postgreSQLContainer.password
).start()

TestPropertyValues.of(
"bpdm.pool.base-url=http://localhost:${bpdmPoolContainer.getMappedPort(8080)}",
).applyTo(applicationContext.environment)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package com.catenax.bpdm.bridge.dummy.util


import com.catenax.bpdm.bridge.dummy.util.PostgreSQLContextInitializer.Companion.postgreSQLContainer
import com.github.dockerjava.api.model.Ulimit
import org.springframework.boot.test.util.TestPropertyValues
import org.springframework.context.ApplicationContextInitializer
import org.springframework.context.ConfigurableApplicationContext
import org.testcontainers.containers.GenericContainer
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy
import org.testcontainers.lifecycle.Startable

/**
* When used on a spring boot test, starts a singleton opensearch container that is shared between all integration tests.
*/

class OpenSearchContextInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> {
companion object {
const val OPENSEARCH_PORT = 9200
val openSearchContainer: GenericContainer<*> = GenericContainer("opensearchproject/opensearch:2.1.0")
.withExposedPorts(OPENSEARCH_PORT)
.waitingFor(HttpWaitStrategy()
.forPort(OPENSEARCH_PORT)
.forStatusCodeMatching { response -> response == 200 || response == 401 }
)
// based on sample docker-compose for development from https://opensearch.org/docs/latest/opensearch/install/docker
.withEnv("cluster.name", "cdqbridge")
.withEnv("node.name", "bpdm-opensearch")
.withEnv("bootstrap.memory_lock", "true")
.withEnv("OPENSEARCH_JAVA_OPTS", "-Xms512m -Xmx512m")
.withEnv("DISABLE_INSTALL_DEMO_CONFIG", "true")
.withEnv("DISABLE_SECURITY_PLUGIN", "true")
.withEnv("discovery.type", "single-node")
.withCreateContainerCmdModifier { cmd ->
cmd.hostConfig!!.withUlimits(arrayOf(Ulimit("nofile", 65536L, 65536L), Ulimit("memlock", -1L, -1L)))
}
.withNetwork(postgreSQLContainer.getNetwork())
.dependsOn(listOf<Startable>(postgreSQLContainer))
}

override fun initialize(applicationContext: ConfigurableApplicationContext) {
val openSearchAlias = applicationContext.environment.getProperty("bpdm.opensearch.alias")
openSearchContainer.withNetworkAliases(openSearchAlias)
openSearchContainer.start()
TestPropertyValues.of(
"bpdm.opensearch.host=${openSearchContainer.host}",
"bpdm.opensearch.port=${openSearchContainer.getMappedPort(OPENSEARCH_PORT)}",
"bpdm.opensearch.scheme=http",
"bpdm.opensearch.enabled=true",
).applyTo(applicationContext.environment)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,31 @@ package com.catenax.bpdm.bridge.dummy.util
import org.springframework.boot.test.util.TestPropertyValues
import org.springframework.context.ApplicationContextInitializer
import org.springframework.context.ConfigurableApplicationContext
import org.testcontainers.containers.Network
import org.testcontainers.containers.PostgreSQLContainer

/**
* When used on a spring boot test, starts a singleton postgres db container that is shared between all integration tests.
*/
class PostgreSQLContextInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> {
companion object {

val postgreSQLContainer = PostgreSQLContainer("postgres:13.2")
.withAccessToHost(true)
.withNetwork(Network.SHARED)


}

override fun initialize(applicationContext: ConfigurableApplicationContext) {
val postgresAlias = applicationContext.environment.getProperty("bpdm.datasource.alias")
postgreSQLContainer.withNetworkAliases(postgresAlias)

postgreSQLContainer.start()
TestPropertyValues.of(
"spring.datasource.url=${postgreSQLContainer.jdbcUrl}",
"spring.datasource.username=${postgreSQLContainer.username}",
"spring.datasource.password=${postgreSQLContainer.password}"
"spring.datasource.password=${postgreSQLContainer.password}",
).applyTo(applicationContext.environment)
}
}
25 changes: 25 additions & 0 deletions bpdm-bridge-dummy/src/test/resources/application-test.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
################################################################################
# Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# SPDX-License-Identifier: Apache-2.0
################################################################################
bpdm.opensearch.enabled=false
bpdm.opensearch.refresh-on-write=true
bpdm.opensearch.alias=bpdm-opensearch
bpdm.datasource.alias=bpdm-postgres
bpdm.pool.alias=bpdm-pool
logging.level.root=INFO
spring.datasource.hikari.maximum-pool-size=2