From 6465b341c076a56ed055acb0e074c490a73cc8a3 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Thu, 13 Jul 2023 22:50:36 +0200 Subject: [PATCH] Introduce dev-services profile to showcase Docker services features. --- server/pom.xml | 27 ++++++++++++ .../restbucks/TestApplication.java | 41 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 server/src/test/java/org/springsource/restbucks/TestApplication.java diff --git a/server/pom.xml b/server/pom.xml index 5acb643f..8ada40cb 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -167,6 +167,16 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma true + + org.springframework.boot + spring-boot-testcontainers + + + + org.testcontainers + postgresql + + @@ -244,6 +254,23 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma + + + dev-services + + + spring-boot:test-run + + + + + org.postgresql + postgresql + + + + + diff --git a/server/src/test/java/org/springsource/restbucks/TestApplication.java b/server/src/test/java/org/springsource/restbucks/TestApplication.java new file mode 100644 index 00000000..16f1cb1b --- /dev/null +++ b/server/src/test/java/org/springsource/restbucks/TestApplication.java @@ -0,0 +1,41 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License 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. + */ +package org.springsource.restbucks; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; +import org.springframework.context.annotation.Bean; +import org.testcontainers.containers.PostgreSQLContainer; + +/** + * @author Oliver Drotbohm + */ +@TestConfiguration +public class TestApplication { + + @Bean + @ServiceConnection + PostgreSQLContainer postgres() { + return new PostgreSQLContainer<>("postgres:latest"); + } + + public static void main(String[] args) { + SpringApplication.from(Restbucks::main) + .with(TestApplication.class) + .run(args); + } +}