From a3efdb93fa10a3a6850a6edcdda3aba46124e71c Mon Sep 17 00:00:00 2001 From: jarno Date: Sat, 12 Oct 2024 23:20:22 +0200 Subject: [PATCH] FIX: now tests run --- .github/workflows/test.yml | 5 +++++ docker-compose.yml | 8 ++++++- .../wiemanapi/WiemanApiApplicationTests.java | 9 ++++---- .../wiemanapi/config/TestSecurityConfig.java | 22 +++++++++++++++++++ .../presentation/ProfileControllerTest.java | 4 +++- src/test/resources/application.properties | 3 ++- 6 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 src/test/java/com/wiemanboy/wiemanapi/config/TestSecurityConfig.java diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 22355b5..084e283 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,3 +25,8 @@ jobs: - name: Run tests run: mvn test + env: + AUTH0_CLIENT_ID: ${{ secrets.AUTH0_CLIENT_ID }} + AUTH0_CLIENT_SECRET: ${{ secrets.AUTH0_CLIENT_SECRET }} + "okta.oauth2.issuer": https://${{ secrets.OKTA_OAUTH2_ISSUER }}/ + "okta.oauth2.audience": ${{ secrets.OKTA_OAUTH2_AUDIENCE }} diff --git a/docker-compose.yml b/docker-compose.yml index aa9c11b..854f20d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,13 @@ services: MONGO_USER: admin MONGO_PASSWORD: admin MONGO_DB: dev_db - SPRING_DATA_MONGODB_URI: mongodb://admin:admin@mongo:27017/dev_db + MONGO_HOST: mongo + MONGO_PORT: 27017 + MONGO_AUTH_DB: admin + AUTH0_BASE_URL: ${AUTH0_BASE_URL} + AUTH0_CLIENT_ID: ${AUTH0_CLIENT_ID} + AUTH0_CLIENT_SECRET: ${AUTH0_CLIENT_SECRET} + AUTH0_AUDIENCE: ${AUTH0_AUDIENCE} mongo: image: mongo:latest diff --git a/src/test/java/com/wiemanboy/wiemanapi/WiemanApiApplicationTests.java b/src/test/java/com/wiemanboy/wiemanapi/WiemanApiApplicationTests.java index 6a99508..39c1474 100644 --- a/src/test/java/com/wiemanboy/wiemanapi/WiemanApiApplicationTests.java +++ b/src/test/java/com/wiemanboy/wiemanapi/WiemanApiApplicationTests.java @@ -1,13 +1,14 @@ package com.wiemanboy.wiemanapi; +import com.wiemanboy.wiemanapi.config.TestSecurityConfig; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest +@SpringBootTest(classes = {TestSecurityConfig.class, WiemanApiApplication.class}) class WiemanApiApplicationTests { - @Test - void contextLoads() { - } + @Test + void contextLoads() { + } } diff --git a/src/test/java/com/wiemanboy/wiemanapi/config/TestSecurityConfig.java b/src/test/java/com/wiemanboy/wiemanapi/config/TestSecurityConfig.java new file mode 100644 index 0000000..5c05d78 --- /dev/null +++ b/src/test/java/com/wiemanboy/wiemanapi/config/TestSecurityConfig.java @@ -0,0 +1,22 @@ +package com.wiemanboy.wiemanapi.config; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; +import org.springframework.security.oauth2.jwt.JwtDecoder; + +import static org.mockito.Mockito.mock; + +@TestConfiguration +public class TestSecurityConfig { + + @Bean + public JwtDecoder jwtDecoder() { + return mock(JwtDecoder.class); // Mock JwtDecoder + } + + @Bean + public ClientRegistrationRepository clientRegistrationRepository() { + return mock(ClientRegistrationRepository.class); // Mock ClientRegistrationRepository + } +} diff --git a/src/test/java/com/wiemanboy/wiemanapi/presentation/ProfileControllerTest.java b/src/test/java/com/wiemanboy/wiemanapi/presentation/ProfileControllerTest.java index c455a3b..610a279 100644 --- a/src/test/java/com/wiemanboy/wiemanapi/presentation/ProfileControllerTest.java +++ b/src/test/java/com/wiemanboy/wiemanapi/presentation/ProfileControllerTest.java @@ -1,6 +1,8 @@ package com.wiemanboy.wiemanapi.presentation; +import com.wiemanboy.wiemanapi.WiemanApiApplication; import com.wiemanboy.wiemanapi.builders.ProfileBuilder; +import com.wiemanboy.wiemanapi.config.TestSecurityConfig; import com.wiemanboy.wiemanapi.data.ProfileRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -16,7 +18,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@SpringBootTest +@SpringBootTest(classes = {TestSecurityConfig.class, WiemanApiApplication.class}) @AutoConfigureMockMvc public class ProfileControllerTest { diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 80c6377..e16eb8e 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -1 +1,2 @@ -debug=true \ No newline at end of file +debug=true +spring.main.allow-bean-definition-overriding=true \ No newline at end of file