1616package io .qameta .allure .restassured ;
1717
1818import com .github .tomakehurst .wiremock .WireMockServer ;
19+ import com .github .tomakehurst .wiremock .client .ResponseDefinitionBuilder ;
1920import com .github .tomakehurst .wiremock .client .WireMock ;
2021import com .github .tomakehurst .wiremock .core .WireMockConfiguration ;
2122import com .google .common .collect .ImmutableList ;
2223import io .qameta .allure .model .Attachment ;
2324import io .qameta .allure .model .TestResult ;
2425import io .qameta .allure .test .AllureResults ;
2526import io .restassured .RestAssured ;
27+ import org .junit .jupiter .api .Test ;
2628import org .junit .jupiter .api .extension .ExtensionContext ;
2729import org .junit .jupiter .params .ParameterizedTest ;
2830import org .junit .jupiter .params .provider .Arguments ;
2931import org .junit .jupiter .params .provider .ArgumentsProvider ;
3032import org .junit .jupiter .params .provider .ArgumentsSource ;
31- import java .util .*;
33+
34+ import java .util .ArrayList ;
35+ import java .util .Collection ;
36+ import java .util .List ;
3237import java .util .stream .Collectors ;
3338import java .util .stream .Stream ;
39+
3440import static io .qameta .allure .test .RunUtils .runWithinTestContext ;
3541import static org .assertj .core .api .Assertions .assertThat ;
3642import static org .junit .jupiter .params .provider .Arguments .arguments ;
@@ -68,6 +74,41 @@ void shouldCreateAttachment(final List<String> attachmentNames, final AllureRest
6874 .isEqualTo (attachmentNames );
6975 }
7076
77+ @ Test
78+ void shouldProperlySetAttachmentNameForSingleFilterInstance () {
79+ final AllureRestAssured filter = new AllureRestAssured ();
80+
81+ final ResponseDefinitionBuilder responseBuilderOne = WireMock .aResponse ()
82+ .withStatus (200 )
83+ .withBody ("some body" );
84+
85+ final ResponseDefinitionBuilder responseBuilderTwo = WireMock .aResponse ()
86+ .withStatus (400 )
87+ .withBody ("some other body" );
88+
89+ RestAssured .replaceFiltersWith (filter );
90+ final AllureResults resultsOne = executeWithStub (responseBuilderOne );
91+
92+ RestAssured .replaceFiltersWith (filter );
93+ final AllureResults resultsTwo = executeWithStub (responseBuilderTwo );
94+
95+ assertThat (resultsOne .getTestResults ()
96+ .stream ()
97+ .map (TestResult ::getAttachments )
98+ .flatMap (Collection ::stream )
99+ .map (Attachment ::getName ))
100+ .hasSize (2 )
101+ .anyMatch (res -> res .equals ("HTTP/1.1 200 OK" ));
102+
103+ assertThat (resultsTwo .getTestResults ()
104+ .stream ()
105+ .map (TestResult ::getAttachments )
106+ .flatMap (Collection ::stream )
107+ .map (Attachment ::getName ))
108+ .hasSize (2 )
109+ .anyMatch (res -> res .equals ("HTTP/1.1 400 Bad Request" ));
110+ }
111+
71112 @ ParameterizedTest
72113 @ ArgumentsSource (AttachmentArgumentProvider .class )
73114 void shouldCatchAttachmentBody (final List <String > attachmentNames , final AllureRestAssured filter ) {
@@ -91,15 +132,20 @@ void shouldCatchAttachmentBody(final List<String> attachmentNames, final AllureR
91132 }
92133
93134 protected final AllureResults execute () {
135+ return executeWithStub (WireMock .aResponse ().withBody ("some body" ));
136+ }
137+
138+ protected final AllureResults executeWithStub (ResponseDefinitionBuilder responseBuilder ) {
94139 final WireMockServer server = new WireMockServer (WireMockConfiguration .options ().dynamicPort ());
140+ final int statusCode = responseBuilder .build ().getStatus ();
95141
96142 return runWithinTestContext (() -> {
97143 server .start ();
98144 WireMock .configureFor (server .port ());
99145
100- WireMock .stubFor (WireMock .get (WireMock .urlEqualTo ("/hello" )).willReturn (WireMock . aResponse (). withBody ( "some body" ) ));
146+ WireMock .stubFor (WireMock .get (WireMock .urlEqualTo ("/hello" )).willReturn (responseBuilder ));
101147 try {
102- RestAssured .when ().get (server .url ("/hello" )).then ().statusCode (200 );
148+ RestAssured .when ().get (server .url ("/hello" )).then ().statusCode (statusCode );
103149 } finally {
104150 server .stop ();
105151 RestAssured .replaceFiltersWith (ImmutableList .of ());
0 commit comments