From f91412b33e4cda2430ab3072aaa25e0a6b3e24a8 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Mon, 18 Feb 2019 09:07:15 +0000 Subject: [PATCH] Migrate Spring unit tests to spring profiles Instead of replacing configuration with test configuration on classpath, create test profile and use that. Signed-off-by: Tomas Slusny --- .../runelite/http/service/config/ConfigControllerTest.java | 2 ++ .../http/service/loottracker/LootTrackerControllerTest.java | 2 ++ .../resources/{application.yaml => application-test.yaml} | 4 ++++ 3 files changed, 8 insertions(+) rename http-service/src/test/resources/{application.yaml => application-test.yaml} (82%) diff --git a/http-service/src/test/java/net/runelite/http/service/config/ConfigControllerTest.java b/http-service/src/test/java/net/runelite/http/service/config/ConfigControllerTest.java index 5ba857ef0a..b91029bec2 100644 --- a/http-service/src/test/java/net/runelite/http/service/config/ConfigControllerTest.java +++ b/http-service/src/test/java/net/runelite/http/service/config/ConfigControllerTest.java @@ -43,6 +43,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; @@ -51,6 +52,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @WebMvcTest(ConfigController.class) @Slf4j +@ActiveProfiles("test") public class ConfigControllerTest { @Autowired diff --git a/http-service/src/test/java/net/runelite/http/service/loottracker/LootTrackerControllerTest.java b/http-service/src/test/java/net/runelite/http/service/loottracker/LootTrackerControllerTest.java index e708de0c29..9151838016 100644 --- a/http-service/src/test/java/net/runelite/http/service/loottracker/LootTrackerControllerTest.java +++ b/http-service/src/test/java/net/runelite/http/service/loottracker/LootTrackerControllerTest.java @@ -49,6 +49,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -57,6 +58,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @WebMvcTest(LootTrackerController.class) @Slf4j +@ActiveProfiles("test") public class LootTrackerControllerTest { @Autowired diff --git a/http-service/src/test/resources/application.yaml b/http-service/src/test/resources/application-test.yaml similarity index 82% rename from http-service/src/test/resources/application.yaml rename to http-service/src/test/resources/application-test.yaml index 3811b12bf0..0532963ade 100644 --- a/http-service/src/test/resources/application.yaml +++ b/http-service/src/test/resources/application-test.yaml @@ -1,13 +1,17 @@ +# Use in-memory database for tests datasource: runelite: + jndiName: driverClassName: org.h2.Driver type: org.h2.jdbcx.JdbcDataSource url: jdbc:h2:mem:runelite runelite-cache: + jndiName: driverClassName: org.h2.Driver type: org.h2.jdbcx.JdbcDataSource url: jdbc:h2:mem:cache runelite-tracker: + jndiName: driverClassName: org.h2.Driver type: org.h2.jdbcx.JdbcDataSource url: jdbc:h2:mem:xptracker