-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17d5bd9
commit 94c8cb0
Showing
11 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: service-catalog | ||
labels: | ||
app: service-catalog | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: service-catalog | ||
env: | ||
- name: MONGO_USERNAME | ||
value: root | ||
- name: MONGO_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: catalog-mongodb | ||
key: ROOT_PASSWORD | ||
- name: MONGO_SERVICE | ||
value: staging-catalog-mongodb-headless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,6 @@ namespace: staging | |
resources: | ||
- ../base | ||
- ingress.yaml | ||
|
||
patchesStrategicMerge: | ||
- env.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/no/digdir/service_catalog/controller/ServiceController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package no.digdir.service_catalog.controller | ||
|
||
import no.digdir.service_catalog.model.Service | ||
import no.digdir.service_catalog.mongodb.ServiceRepository | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.stereotype.Controller | ||
import org.springframework.web.bind.annotation.CrossOrigin | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
|
||
@Controller | ||
@CrossOrigin | ||
@RequestMapping(value = ["/services"]) | ||
class ServiceController(private val serviceRepository: ServiceRepository) { | ||
|
||
@GetMapping | ||
fun getAllServices(): ResponseEntity<List<Service>> = | ||
ResponseEntity(serviceRepository.findAll(), HttpStatus.OK) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package no.digdir.service_catalog.model | ||
|
||
import org.springframework.data.mongodb.core.mapping.Document | ||
|
||
@Document(collection = "services") | ||
data class Service ( | ||
val id: String, | ||
val title: String | ||
) |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/no/digdir/service_catalog/mongodb/ServiceRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package no.digdir.service_catalog.mongodb | ||
|
||
import no.digdir.service_catalog.model.Service | ||
import org.springframework.data.mongodb.repository.MongoRepository | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
interface ServiceRepository : MongoRepository<Service, String?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/test/kotlin/no/digdir/service_catalog/integration/GetServices.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package no.digdir.service_catalog.integration | ||
|
||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import no.digdir.service_catalog.model.Service | ||
import no.digdir.service_catalog.utils.ApiTestContext | ||
import no.digdir.service_catalog.utils.SERVICES | ||
import no.digdir.service_catalog.utils.apiGet | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Tag | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.test.context.ContextConfiguration | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@ContextConfiguration(initializers = [ApiTestContext.Initializer::class]) | ||
@Tag("integration") | ||
class GetServices: ApiTestContext() { | ||
private val mapper = jacksonObjectMapper() | ||
|
||
@Test | ||
fun `able to get all services`() { | ||
val response = apiGet(port, "/services", null) | ||
Assertions.assertEquals(HttpStatus.OK.value(), response["status"]) | ||
|
||
val result: List<Service> = mapper.readValue(response["body"] as String) | ||
Assertions.assertEquals(SERVICES, result) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/test/kotlin/no/digdir/service_catalog/utils/ApiTestContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,43 @@ | ||
package no.digdir.service_catalog.utils | ||
|
||
import no.digdir.service_catalog.mongodb.ServiceRepository | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.util.TestPropertyValues | ||
import org.springframework.boot.test.web.server.LocalServerPort | ||
import org.springframework.context.ApplicationContextInitializer | ||
import org.springframework.context.ConfigurableApplicationContext | ||
import org.testcontainers.containers.GenericContainer | ||
import org.testcontainers.containers.wait.strategy.Wait | ||
|
||
abstract class ApiTestContext { | ||
@LocalServerPort | ||
var port: Int = 0 | ||
|
||
@Autowired | ||
private lateinit var serviceRepository: ServiceRepository | ||
@BeforeEach | ||
fun resetDatabase() { | ||
serviceRepository.deleteAll() | ||
serviceRepository.saveAll(SERVICES) | ||
} | ||
|
||
internal class Initializer : ApplicationContextInitializer<ConfigurableApplicationContext> { | ||
override fun initialize(configurableApplicationContext: ConfigurableApplicationContext) { | ||
TestPropertyValues.of( | ||
"spring.data.mongodb.uri=mongodb://$MONGO_USER:$MONGO_PASSWORD@localhost:${mongoContainer.getMappedPort(MONGO_PORT)}/$MONGO_DB_NAME?authSource=admin", | ||
).applyTo(configurableApplicationContext.environment) | ||
} | ||
} | ||
|
||
companion object { | ||
val mongoContainer: GenericContainer<*> = GenericContainer("mongo:latest") | ||
.withEnv(MONGO_ENV_VALUES) | ||
.withExposedPorts(MONGO_PORT) | ||
.waitingFor(Wait.forListeningPort()) | ||
|
||
init { | ||
mongoContainer.start() | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/kotlin/no/digdir/service_catalog/utils/TestData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package no.digdir.service_catalog.utils | ||
|
||
import no.digdir.service_catalog.model.Service | ||
import org.testcontainers.shaded.com.google.common.collect.ImmutableMap | ||
|
||
const val MONGO_USER = "testuser" | ||
const val MONGO_PASSWORD = "testpassword" | ||
const val MONGO_PORT = 27017 | ||
const val MONGO_DB_NAME = "serviceCatalog" | ||
|
||
val MONGO_ENV_VALUES: Map<String, String> = ImmutableMap.of( | ||
"MONGO_INITDB_ROOT_USERNAME", MONGO_USER, | ||
"MONGO_INITDB_ROOT_PASSWORD", MONGO_PASSWORD | ||
) | ||
|
||
val SERVICE_0 = Service("0", "title 0") | ||
val SERVICE_1 = Service("1", "title 1") | ||
|
||
val SERVICES = listOf(SERVICE_0, SERVICE_1) |