diff --git a/ci/smoke-tests.yml b/ci/smoke-tests.yml index df13c527..9c7091ec 100644 --- a/ci/smoke-tests.yml +++ b/ci/smoke-tests.yml @@ -113,6 +113,9 @@ groups: - name: cloud-loadbalancing-webflux app_test: true test: false + - name: cloud-openfeign + app_test: true + test: false - name: cloud-stream-kafka app_test: true test: false diff --git a/cloud/cloud-openfeign/build.gradle b/cloud/cloud-openfeign/build.gradle new file mode 100644 index 00000000..dcf69896 --- /dev/null +++ b/cloud/cloud-openfeign/build.gradle @@ -0,0 +1,29 @@ +import org.springframework.boot.gradle.plugin.SpringBootPlugin + +plugins { + id 'java' + id 'org.springframework.boot' + id 'org.springframework.aot.smoke-test' + id 'org.graalvm.buildtools.native' +} + +ext { + set('springCloudVersion', "2022.0.2-SNAPSHOT") +} + +dependencies { + implementation(platform(SpringBootPlugin.BOM_COORDINATES)) + implementation(platform("org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}")) + implementation("org.springframework.cloud:spring-cloud-starter-openfeign") + implementation("org.springframework.cloud:spring-cloud-starter-loadbalancer") + implementation ('org.springframework.boot:spring-boot-starter-web') + + testImplementation("org.springframework.boot:spring-boot-starter-test") + + appTestImplementation(project(":aot-smoke-test-support")) + appTestImplementation("org.awaitility:awaitility:4.2.0") +} + +aotSmokeTest { + webApplication = true +} \ No newline at end of file diff --git a/cloud/cloud-openfeign/docker-compose.yml b/cloud/cloud-openfeign/docker-compose.yml new file mode 100644 index 00000000..06df560a --- /dev/null +++ b/cloud/cloud-openfeign/docker-compose.yml @@ -0,0 +1,6 @@ +version: '3' +services: + test-service: + image: springcloud/test-service:latest + ports: + - "8081" \ No newline at end of file diff --git a/cloud/cloud-openfeign/src/appTest/java/com/example/cloud/openfeign/CloudOpenFeignApplicationAotTests.java b/cloud/cloud-openfeign/src/appTest/java/com/example/cloud/openfeign/CloudOpenFeignApplicationAotTests.java new file mode 100644 index 00000000..0ddb4717 --- /dev/null +++ b/cloud/cloud-openfeign/src/appTest/java/com/example/cloud/openfeign/CloudOpenFeignApplicationAotTests.java @@ -0,0 +1,28 @@ +package com.example.cloud.openfeign; + +import java.time.Duration; + +import org.awaitility.Awaitility; +import org.junit.jupiter.api.Test; + +import org.springframework.aot.smoketest.support.assertj.AssertableOutput; +import org.springframework.aot.smoketest.support.junit.ApplicationTest; + +import static org.assertj.core.api.Assertions.assertThat; + +@ApplicationTest +class CloudOpenFeignApplicationAotTests { + + @Test + void shouldCallTestService(AssertableOutput output) { + Awaitility.await().atMost(Duration.ofSeconds(30)).untilAsserted(() -> { + assertThat(output).hasLineContaining("c.e.c.o.CloudOpenFeignApplication : test"); + assertThat(output).hasLineContaining("c.e.c.o.CloudOpenFeignApplication : test type hints"); + // verify custom config with Logger.Level.FULL loaded + assertThat(output).hasLineContaining("---> POST http://test-service/test HTTP/1.1"); + assertThat(output).hasNoLinesContaining("ERROR"); + }); + + } + +} diff --git a/cloud/cloud-openfeign/src/main/java/com/example/cloud/openfeign/CloudOpenFeignApplication.java b/cloud/cloud-openfeign/src/main/java/com/example/cloud/openfeign/CloudOpenFeignApplication.java new file mode 100644 index 00000000..c943269d --- /dev/null +++ b/cloud/cloud-openfeign/src/main/java/com/example/cloud/openfeign/CloudOpenFeignApplication.java @@ -0,0 +1,95 @@ +package com.example.cloud.openfeign; + +import com.example.cloud.openfeign.config.CustomFeignConfig; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +@SpringBootApplication +@EnableFeignClients(clients = TestServiceClient.class) +public class CloudOpenFeignApplication implements CommandLineRunner { + + private static final Log LOG = LogFactory.getLog(CloudOpenFeignApplication.class); + + @Autowired + private TestServiceClient testServiceClient; + + public static void main(String[] args) { + SpringApplication.run(CloudOpenFeignApplication.class, args); + } + + @Override + public void run(String... args) { + callTestService(); + } + + private void callTestService() { + if (LOG.isInfoEnabled()) { + LOG.info(testServiceClient.test()); + LOG.info(testServiceClient.testTypesForReflection(new TestArgType("test type hints")).getTest()); + } + } + +} + +@FeignClient(value = "test-service", configuration = CustomFeignConfig.class) +interface TestServiceClient { + + @GetMapping("/") + String test(); + + @PostMapping(value = "/test", produces = "application/json", consumes = "application/json") + TestReturnType testTypesForReflection(@RequestBody TestArgType testArg); + +} + +class TestReturnType { + + private String test; + + public TestReturnType(String test) { + this.test = test; + } + + public TestReturnType() { + } + + public String getTest() { + return test; + } + + public void setTest(String test) { + this.test = test; + } + +} + +class TestArgType { + + private String test; + + public TestArgType(String test) { + this.test = test; + } + + public TestArgType() { + } + + public String getTest() { + return test; + } + + public void setTest(String test) { + this.test = test; + } + +} diff --git a/cloud/cloud-openfeign/src/main/java/com/example/cloud/openfeign/config/CustomFeignConfig.java b/cloud/cloud-openfeign/src/main/java/com/example/cloud/openfeign/config/CustomFeignConfig.java new file mode 100644 index 00000000..d239a0d4 --- /dev/null +++ b/cloud/cloud-openfeign/src/main/java/com/example/cloud/openfeign/config/CustomFeignConfig.java @@ -0,0 +1,14 @@ +package com.example.cloud.openfeign.config; + +import feign.Logger; + +import org.springframework.context.annotation.Bean; + +public class CustomFeignConfig { + + @Bean + Logger.Level loggingLevel() { + return Logger.Level.FULL; + } + +} diff --git a/cloud/cloud-openfeign/src/main/resources/application.yml b/cloud/cloud-openfeign/src/main/resources/application.yml new file mode 100644 index 00000000..26d2e143 --- /dev/null +++ b/cloud/cloud-openfeign/src/main/resources/application.yml @@ -0,0 +1,19 @@ +logging: + level: + com.example.cloud.openfeign.TestServiceClient: DEBUG +spring: + application: + name: cloud-openfeign + cloud: + discovery: + client: + simple: + instances: + test-service: + - uri: http://${TEST-SERVICE_HOST:localhost}:${TEST-SERVICE_PORT_8081:8081} + refresh: + enabled: false + loadbalancer: + eager-load: + clients: + - test-service \ No newline at end of file