From 15323bddf0477d539b1b9458410b94b22aed11de Mon Sep 17 00:00:00 2001 From: Haroon Khan Date: Tue, 5 Apr 2022 22:02:54 +0100 Subject: [PATCH] [JAVA-10446] Convert Feign-OAuth2 unit test to manual test --- spring-cloud/pom.xml | 2 +- ...nualTest.java => OpenFeignManualTest.java} | 2 +- .../openfeign/OpenFeignOAuth2ManualTest.java | 44 +++++++++++++++++++ .../openfeign/PaymentClientUnitTest.java | 30 ------------- 4 files changed, 46 insertions(+), 32 deletions(-) rename spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/{OpenfeignManualTest.java => OpenFeignManualTest.java} (96%) create mode 100644 spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/OpenFeignOAuth2ManualTest.java delete mode 100644 spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/PaymentClientUnitTest.java diff --git a/spring-cloud/pom.xml b/spring-cloud/pom.xml index a2c4b3509f..9205416cd5 100644 --- a/spring-cloud/pom.xml +++ b/spring-cloud/pom.xml @@ -45,7 +45,7 @@ spring-cloud-ribbon-retry spring-cloud-circuit-breaker spring-cloud-eureka-self-preservation - + spring-cloud-openfeign spring-cloud-netflix-feign spring-cloud-sentinel spring-cloud-dapr diff --git a/spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/OpenfeignManualTest.java b/spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/OpenFeignManualTest.java similarity index 96% rename from spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/OpenfeignManualTest.java rename to spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/OpenFeignManualTest.java index 8ae6883519..4eb014de96 100644 --- a/spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/OpenfeignManualTest.java +++ b/spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/OpenFeignManualTest.java @@ -15,7 +15,7 @@ import static org.junit.Assert.assertNotNull; @RunWith(SpringRunner.class) @SpringBootTest -public class OpenfeignManualTest { +public class OpenFeignManualTest { @Autowired private JSONPlaceHolderService jsonPlaceHolderService; diff --git a/spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/OpenFeignOAuth2ManualTest.java b/spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/OpenFeignOAuth2ManualTest.java new file mode 100644 index 0000000000..8084fd23cd --- /dev/null +++ b/spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/OpenFeignOAuth2ManualTest.java @@ -0,0 +1,44 @@ +package com.baeldung.cloud.openfeign; + +import com.baeldung.cloud.openfeign.client.PaymentClient; +import com.baeldung.cloud.openfeign.model.Payment; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.List; + +import static org.junit.Assert.assertFalse; + +/** + * This test can be used to verify OAuth2 Token functionality with Feign client + * (https://www.baeldung.com/spring-cloud-feign-oauth-token). + * + * The following components should be setup and running, as described in the article, prior to running this test. + * + * Authorization Server - embedded Keycloak server with the correct client and client-secret defined in the master realm. + * This will issue the auth tokens used by Feign client. + * Further details are available at: https://www.baeldung.com/keycloak-embedded-in-spring-boot-app + * + * Resource Server - OAuth resource server requiring valid JWT token (issued by the Authorization Server). + * Further details are available at: https://www.baeldung.com/spring-security-oauth-resource-server + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest +public class OpenFeignOAuth2ManualTest { + + @Autowired + private PaymentClient paymentClient; + + @Test + public void whenGetPayment_thenListPayments() { + + List payments = paymentClient.getPayments(); + + assertFalse(payments.isEmpty()); + } + +} diff --git a/spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/PaymentClientUnitTest.java b/spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/PaymentClientUnitTest.java deleted file mode 100644 index 0372728515..0000000000 --- a/spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/PaymentClientUnitTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.cloud.openfeign; - -import com.baeldung.cloud.openfeign.client.PaymentClient; -import com.baeldung.cloud.openfeign.model.Payment; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.List; - -import static org.junit.Assert.assertFalse; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class PaymentClientUnitTest { - - @Autowired - private PaymentClient paymentClient; - - @Test - public void whenGetPayment_thenListPayments() { - - List payments = paymentClient.getPayments(); - - assertFalse(payments.isEmpty()); - } - -}