From 597c3850e3abfd97806b81460f53b602bb5ffd84 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 18 Apr 2024 13:55:02 +0100 Subject: [PATCH] fix tests --- pom.xml | 5 +++++ .../backend/config/TestMongoConfig.java | 21 +++++++++++++++++++ .../backend/tests/MojangControllerTests.java | 4 +++- .../backend/tests/PlayerControllerTests.java | 4 +++- .../backend/tests/ServerControllerTests.java | 4 +++- 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/test/java/xyz/mcutils/backend/config/TestMongoConfig.java diff --git a/pom.xml b/pom.xml index 1079375..98ca33b 100644 --- a/pom.xml +++ b/pom.xml @@ -170,6 +170,11 @@ 1.4.3 test + + de.flapdoodle.embed + de.flapdoodle.embed.mongo + test + \ No newline at end of file diff --git a/src/test/java/xyz/mcutils/backend/config/TestMongoConfig.java b/src/test/java/xyz/mcutils/backend/config/TestMongoConfig.java new file mode 100644 index 0000000..473a3cf --- /dev/null +++ b/src/test/java/xyz/mcutils/backend/config/TestMongoConfig.java @@ -0,0 +1,21 @@ +package xyz.mcutils.backend.config; + +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import lombok.NonNull; +import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; +import org.springframework.boot.test.context.TestConfiguration; +import redis.embedded.RedisServer; + +import java.io.IOException; + +/** + * Test configuration for + * a mock Redis server. + * + * @author Braydon + */ +@TestConfiguration @DataMongoTest +public class TestMongoConfig { + +} \ No newline at end of file diff --git a/src/test/java/xyz/mcutils/backend/tests/MojangControllerTests.java b/src/test/java/xyz/mcutils/backend/tests/MojangControllerTests.java index 5db6d0f..44fbbaa 100644 --- a/src/test/java/xyz/mcutils/backend/tests/MojangControllerTests.java +++ b/src/test/java/xyz/mcutils/backend/tests/MojangControllerTests.java @@ -3,16 +3,18 @@ package xyz.mcutils.backend.tests; import cc.fascinated.config.TestRedisConfig; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; +import xyz.mcutils.backend.config.TestMongoConfig; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @AutoConfigureMockMvc -@SpringBootTest(classes = TestRedisConfig.class) +@SpringBootTest(classes = {TestRedisConfig.class, TestMongoConfig.class}) class MojangControllerTests { @Autowired diff --git a/src/test/java/xyz/mcutils/backend/tests/PlayerControllerTests.java b/src/test/java/xyz/mcutils/backend/tests/PlayerControllerTests.java index 4726593..195f7fd 100644 --- a/src/test/java/xyz/mcutils/backend/tests/PlayerControllerTests.java +++ b/src/test/java/xyz/mcutils/backend/tests/PlayerControllerTests.java @@ -3,10 +3,12 @@ package xyz.mcutils.backend.tests; import cc.fascinated.config.TestRedisConfig; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; +import xyz.mcutils.backend.config.TestMongoConfig; import xyz.mcutils.backend.model.skin.ISkinPart; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -14,7 +16,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @AutoConfigureMockMvc -@SpringBootTest(classes = TestRedisConfig.class) +@SpringBootTest(classes = {TestRedisConfig.class, TestMongoConfig.class}) class PlayerControllerTests { private final String testPlayerUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48"; diff --git a/src/test/java/xyz/mcutils/backend/tests/ServerControllerTests.java b/src/test/java/xyz/mcutils/backend/tests/ServerControllerTests.java index 1fa3227..761785a 100644 --- a/src/test/java/xyz/mcutils/backend/tests/ServerControllerTests.java +++ b/src/test/java/xyz/mcutils/backend/tests/ServerControllerTests.java @@ -3,17 +3,19 @@ package xyz.mcutils.backend.tests; import cc.fascinated.config.TestRedisConfig; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; +import xyz.mcutils.backend.config.TestMongoConfig; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @AutoConfigureMockMvc -@SpringBootTest(classes = TestRedisConfig.class) +@SpringBootTest(classes = {TestRedisConfig.class, TestMongoConfig.class}) class ServerControllerTests { private final String testServer = "play.hypixel.net";