Skip to content

Add openfeign module #1180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sbushmelev
Copy link

Add new module that automatically captures Feign client HTTP traffic as Allure attachments for comprehensive API test reporting.

@CLAassistant
Copy link

CLAassistant commented Jul 20, 2025

CLA assistant check
All committers have signed the CLA.

@baev baev added the type:new feature Change that add something new for end users label Jul 21, 2025
Copy link
Member

@baev baev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! 👍

```xml
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-open-feign</artifactId>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allure-openfeign?

@BeforeAll
static void setUp() {
wireMockServer = new WireMockServer(options().dynamicPort());
wireMockServer.start();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tear down?

import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.junit.jupiter.api.Assertions.assertAll;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use AssertJ assertions instead


assertAll(
() -> assertEquals(new HelloWorldRecord("Hello World").getMessage(), helloWorldRecord.get().getMessage()),
() -> assertTrue(attachmentNames.contains("Response"), "Cannot find attachment with name \"Response\""),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use assertTrue, AssertJ provides more convenient ways to check that


static WireMockServer wireMockServer;

@BeforeAll
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's only a few tests, we can use @BeforeEach instead?

}

@Test
void jsonBodyTest() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add tests for the plan body response and no response body

.getJsonHelloWorld());
});

List<String> attachmentNames = allureResults.getTestResults().stream()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check not only the attachment name, but the body as well

@sbushmelev
Copy link
Author

sbushmelev commented Jul 30, 2025

Hello! When writing additional tests, I discovered a nuance. If you need to use the feign.Response entity in an autotest, for example, to get the headers, the feign.codec.Decode#decode method is not called, which makes sense since the attachment is not attached. Using feign.ResponseInterceptor is not possible because the feign.Response that is passed to the feign.ResponseInterceptor#intercept method is designed so that you can only read the response body once. However, since openFeign supports multiple http clients, you can use the following construct:

        HttpClientBuilder builder = HttpClientBuilder.create()
                .addInterceptorFirst(new AllureHttpClientRequest())
                .addInterceptorLast(new AllureHttpClientResponse());

        Example example = Feign.builder()
                .client(new ApacheHttpClient(builder.build()))
                .decoder(new GsonDecoder())
                .encoder(new GsonEncoder())
                .logLevel(Logger.Level.FULL)
                .target(Example.class, "http://example.com/");

I have tested it locally and it works both when the interface method returns feign.Response and when the DTO.If it makes sense, I can write tests for all the http clients that openFeign supports, and update the README with examples of how to use openFeign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme:build type:new feature Change that add something new for end users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants