From dc2539eed67e1862955a3978d81a6c225cb8d632 Mon Sep 17 00:00:00 2001 From: "Zickermann, Jan" <jan.zickermann@dataport.de> Date: Wed, 24 Jan 2024 14:28:30 +0100 Subject: [PATCH] OZG-4815 OZG-4832 Setup Spring Boot REST --- pom.xml | 21 ++++++ src/main/resources/application.properties | 1 - src/main/resources/application.yaml | 4 ++ .../java/de/ozgcloud/admin/ApiRootITCase.java | 68 +++++++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-) delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/application.yaml create mode 100644 src/test/java/de/ozgcloud/admin/ApiRootITCase.java diff --git a/pom.xml b/pom.xml index 2b0b19fe..3af917d6 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,10 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-rest</artifactId> + </dependency> <!-- Dev --> <dependency> @@ -51,6 +55,23 @@ <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-testcontainers</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>mongodb</artifactId> + <version>1.19.3</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>junit-jupiter</artifactId> + <version>1.19.3</version> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 8b137891..00000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml new file mode 100644 index 00000000..2db35bd1 --- /dev/null +++ b/src/main/resources/application.yaml @@ -0,0 +1,4 @@ +spring: + data: + rest: + basePath: /api \ No newline at end of file diff --git a/src/test/java/de/ozgcloud/admin/ApiRootITCase.java b/src/test/java/de/ozgcloud/admin/ApiRootITCase.java new file mode 100644 index 00000000..5dfe66fd --- /dev/null +++ b/src/test/java/de/ozgcloud/admin/ApiRootITCase.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024. Das Land Schleswig-Holstein vertreten durch das Ministerium für Energiewende, Klimaschutz, Umwelt und Natur + * Zentrales IT-Management + * + * Lizenziert unter der EUPL, Version 1.2 oder - sobald + * diese von der Europäischen Kommission genehmigt wurden - + * Folgeversionen der EUPL ("Lizenz"); + * Sie dürfen dieses Werk ausschließlich gemäß + * dieser Lizenz nutzen. + * Eine Kopie der Lizenz finden Sie hier: + * + * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 + * + * Sofern nicht durch anwendbare Rechtsvorschriften + * gefordert oder in schriftlicher Form vereinbart, wird + * die unter der Lizenz verbreitete Software "so wie sie + * ist", OHNE JEGLICHE GEWÄHRLEISTUNG ODER BEDINGUNGEN - + * ausdrücklich oder stillschweigend - verbreitet. + * Die sprachspezifischen Genehmigungen und Beschränkungen + * unter der Lizenz sind dem Lizenztext zu entnehmen. + */ +package de.ozgcloud.admin; + +import static org.hamcrest.Matchers.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import de.ozgcloud.common.test.ITCase; +import lombok.SneakyThrows; + +/** + * Test that the spring-boot-starter-data-rest dependency is being used and spring.data.rest.basePath == /api + */ +@ITCase +class ApiRootITCase { + + private MockMvc mockMvc; + + @BeforeEach + void setup(WebApplicationContext context) { + mockMvc = MockMvcBuilders.webAppContextSetup(context).build(); + } + + @Test + @SneakyThrows + void shouldHaveRESTApiRootEndpoint() { + mockMvc.perform(get("/api")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/hal+json")) + .andExpect(jsonPath("$._links.profile.href", endsWith("/api/profile"))); + } + + @Test + @SneakyThrows + void shouldHaveRESTApiProfileEndpoint() { + mockMvc.perform(get("/api/profile")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/hal+json")) + .andExpect(jsonPath("$._links.self.href", endsWith("/api/profile"))); + } + +} \ No newline at end of file -- GitLab