Skip to content

Commit

Permalink
Migrate to dummy-synq for integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anotheroneofthese committed Aug 5, 2024
1 parent 31211e8 commit 594bbab
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
6 changes: 6 additions & 0 deletions docker/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ services:
command: start-dev --import-realm
volumes:
- ./keycloak/import:/opt/keycloak/data/import

dummy-synq:
image: harbor.nb.no/mlt/dummy-synq:main
restart: always
ports:
- 8181:8181
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ spring:
# Set a dummycatalog base path to SynQ for testing purposes
synq:
path:
base: http://dummycatalog.nb.no/synq/resources
base: http://localhost:8181/synq/resources

---

Expand Down
6 changes: 4 additions & 2 deletions src/test/kotlin/no/nb/mlt/wls/TestcontainerInitializer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ package no.nb.mlt.wls
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.MongoDBContainer
import org.testcontainers.lifecycle.Startables
import org.testcontainers.utility.DockerImageName

class TestcontainerInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> {
companion object {
val MongoContainer = MongoDBContainer(DockerImageName.parse("mongo:4.4.22"))
val DummySynqContainer = GenericContainer(DockerImageName.parse("harbor.nb.no/mlt/dummy-synq:main"))

init {
Startables.deepStart(MongoContainer).join()
Startables.deepStart(MongoContainer, DummySynqContainer).join()
}
}

override fun initialize(applicationContext: ConfigurableApplicationContext) {
TestPropertyValues.of("spring.data.mongodb.uri=" + MongoContainer.replicaSetUrl).applyTo(applicationContext)
// Temporary solution while we are working on implementing a test container for SynQ
TestPropertyValues.of("synq.path.base=http://dummycatalog.nb.no/synq/resources").applyTo(applicationContext)
TestPropertyValues.of("synq.path.base=http://localhost:8181/synq/resources").applyTo(applicationContext)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package no.nb.mlt.wls.product.controller

import com.ninjasquad.springmockk.MockkBean
import io.mockk.every
import io.mockk.junit5.MockKExtension
import no.nb.mlt.wls.EnableTestcontainers
Expand All @@ -26,14 +25,12 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDO
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.security.test.context.support.WithMockUser
import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.csrf
import org.springframework.test.web.reactive.server.WebTestClient
import org.springframework.test.web.reactive.server.expectBody
import org.springframework.web.client.HttpClientErrorException
import org.springframework.web.server.ServerErrorException
import java.net.URI

@EnableTestcontainers
@TestInstance(PER_CLASS)
Expand All @@ -42,11 +39,9 @@ import java.net.URI
@EnableMongoRepositories("no.nb.mlt.wls")
@SpringBootTest(webEnvironment = RANDOM_PORT)
class ProductControllerTest(
@Autowired val repository: ProductRepository
@Autowired val repository: ProductRepository,
@Autowired val synqProductService: SynqProductService
) {
@MockkBean
private lateinit var synqProductService: SynqProductService

private lateinit var webTestClient: WebTestClient

@BeforeEach
Expand All @@ -64,10 +59,6 @@ class ProductControllerTest(
@Test
@WithMockUser
fun `createProduct with valid payload creates product`() {
every {
synqProductService.createProduct(any())
} returns ResponseEntity.created(URI.create("")).build()

webTestClient
.mutateWith(csrf())
.post()
Expand Down Expand Up @@ -124,10 +115,6 @@ class ProductControllerTest(
@Test
@WithMockUser
fun `createProduct where SynQ says it's a duplicate returns OK`() {
every {
synqProductService.createProduct(any())
} returns ResponseEntity.ok().build()

webTestClient
.mutateWith(csrf())
.post()
Expand Down

0 comments on commit 594bbab

Please sign in to comment.