From 9838ae7e0f445b46f8e4f1505889b596b11a65e3 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Mon, 18 Feb 2019 00:23:58 +0100 Subject: [PATCH 1/3] Fix SpringBootWebApplication auto-configuration annotation The exclude is supposed to be on SpringBootApplication annotation, otherwise IntelliJ Spring plugin errors, and also SpringBootApplication already contains EnableAutoConfiguration. Signed-off-by: Tomas Slusny --- .../net/runelite/http/service/SpringBootWebApplication.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/http-service/src/main/java/net/runelite/http/service/SpringBootWebApplication.java b/http-service/src/main/java/net/runelite/http/service/SpringBootWebApplication.java index bfdac0a254..d0103d89f8 100644 --- a/http-service/src/main/java/net/runelite/http/service/SpringBootWebApplication.java +++ b/http-service/src/main/java/net/runelite/http/service/SpringBootWebApplication.java @@ -44,7 +44,6 @@ import org.slf4j.ILoggerFactory; import org.slf4j.impl.StaticLoggerBinder; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; @@ -58,9 +57,8 @@ import org.sql2o.Sql2o; import org.sql2o.converters.Converter; import org.sql2o.quirks.NoQuirks; -@SpringBootApplication +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) @EnableScheduling -@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) @Slf4j public class SpringBootWebApplication extends SpringBootServletInitializer { From 52a862c43b329b84f64013071f138c695cb8d329 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Mon, 18 Feb 2019 00:26:34 +0100 Subject: [PATCH 2/3] Migrate SpringBootWebApplicationTest to spring profiles - Instead of replacing configuration with dev configuration on classpath, create dev profile and use that - Move common properties to application.yaml Signed-off-by: Tomas Slusny --- .../src/main/resources/application.yaml | 29 +++++++++++++++++-- .../service/SpringBootWebApplicationTest.java | 7 ++--- .../{dev.yaml => application-dev.yaml} | 14 +++++++-- .../src/test/resources/application.yaml | 22 -------------- 4 files changed, 41 insertions(+), 31 deletions(-) rename http-service/src/test/resources/{dev.yaml => application-dev.yaml} (63%) diff --git a/http-service/src/main/resources/application.yaml b/http-service/src/main/resources/application.yaml index 9aa02c58ac..271b190a90 100644 --- a/http-service/src/main/resources/application.yaml +++ b/http-service/src/main/resources/application.yaml @@ -5,8 +5,33 @@ datasource: jndiName: java:comp/env/jdbc/runelite-cache2 runelite-tracker: jndiName: java:comp/env/jdbc/runelite-tracker + # By default Spring tries to register the datasource as an MXBean, -# so if multiple apis are delpoyed on one web container with +# so if multiple apis are deployed on one web container with # shared datasource it tries to register it multiples times and # fails when starting the 2nd api -spring.jmx.enabled: false \ No newline at end of file +spring.jmx.enabled: false + +# Google OAuth client +oauth: + client-id: + client-secret: + +# Minio client storage for cache +minio: + endpoint: http://localhost:9000 + accesskey: AM54M27O4WZK65N6F8IP + secretkey: /PZCxzmsJzwCHYlogcymuprniGCaaLUOET2n6yMP + bucket: runelite + +# Redis client for temporary data storage +redis: + pool.size: 10 + host: http://localhost:6379 + +# Twitter client for feed +runelite: + twitter: + consumerkey: + secretkey: + listid: 968949795153948673 \ No newline at end of file diff --git a/http-service/src/test/java/net/runelite/http/service/SpringBootWebApplicationTest.java b/http-service/src/test/java/net/runelite/http/service/SpringBootWebApplicationTest.java index d2d488e1e6..6adcc0f6f0 100644 --- a/http-service/src/test/java/net/runelite/http/service/SpringBootWebApplicationTest.java +++ b/http-service/src/test/java/net/runelite/http/service/SpringBootWebApplicationTest.java @@ -34,10 +34,9 @@ public class SpringBootWebApplicationTest @Ignore public void run() throws InterruptedException { - String[] args = new String[]{ - "--spring.config.location=classpath:/application.yaml,classpath:/dev.yaml" - }; - SpringApplication.run(SpringBootWebApplication.class, args); + System.setProperty("spring.profiles.active", "dev"); + SpringApplication.run(SpringBootWebApplication.class); + for (;;) { Thread.sleep(100L); diff --git a/http-service/src/test/resources/dev.yaml b/http-service/src/test/resources/application-dev.yaml similarity index 63% rename from http-service/src/test/resources/dev.yaml rename to http-service/src/test/resources/application-dev.yaml index e4967ccee4..b8c5fb91d1 100644 --- a/http-service/src/test/resources/dev.yaml +++ b/http-service/src/test/resources/application-dev.yaml @@ -1,19 +1,27 @@ +# Enable debug logging +debug: true +logging.level.net.runelite: DEBUG + +# Development data sources datasource: runelite: + jndiName: driverClassName: com.mysql.jdbc.Driver type: com.mysql.jdbc.jdbc2.optional.MysqlDataSource - url: jdbc:mysql://192.168.1.2/runelite + url: jdbc:mysql://localhost:3306/runelite username: runelite password: runelite runelite-cache: + jndiName: driverClassName: com.mysql.jdbc.Driver type: com.mysql.jdbc.jdbc2.optional.MysqlDataSource - url: jdbc:mysql://192.168.1.2/cache + url: jdbc:mysql://localhost:3306/runelite-cache username: runelite password: runelite runelite-tracker: + jndiName: driverClassName: com.mysql.jdbc.Driver type: com.mysql.jdbc.jdbc2.optional.MysqlDataSource - url: jdbc:mysql://192.168.1.2/xptracker + url: jdbc:mysql://localhost:3306/runelite-tracker username: runelite password: runelite diff --git a/http-service/src/test/resources/application.yaml b/http-service/src/test/resources/application.yaml index 128e64d8ef..3811b12bf0 100644 --- a/http-service/src/test/resources/application.yaml +++ b/http-service/src/test/resources/application.yaml @@ -1,25 +1,3 @@ -oauth: - client-id: moo - client-secret: cow - -minio: - endpoint: http://10.96.22.171:9000 - accesskey: AM54M27O4WZK65N6F8IP - secretkey: /PZCxzmsJzwCHYlogcymuprniGCaaLUOET2n6yMP - bucket: runelite - -runelite: - twitter: - consumerkey: moo - secretkey: cow - listid: 968949795153948673 - -logging: - level: - net: - runelite: - DEBUG - datasource: runelite: driverClassName: org.h2.Driver From f91412b33e4cda2430ab3072aaa25e0a6b3e24a8 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Mon, 18 Feb 2019 09:07:15 +0000 Subject: [PATCH 3/3] 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