26
26
import com .epam .reportportal .service .Launch ;
27
27
import com .epam .reportportal .service .ReportPortal ;
28
28
import com .epam .reportportal .service .step .StepReporter ;
29
+ import com .epam .reportportal .util .test .CommonUtils ;
29
30
import com .epam .reportportal .utils .files .Utils ;
30
31
import io .restassured .config .LogConfig ;
31
32
import io .restassured .config .RestAssuredConfig ;
@@ -108,31 +109,31 @@ public Response send(RequestSender requestSender) {
108
109
109
110
@ Override
110
111
public Response next (FilterableRequestSpecification requestSpecification ,
111
- FilterableResponseSpecification responseSpecification ) {
112
+ FilterableResponseSpecification responseSpecification ) {
112
113
return response ;
113
114
}
114
115
};
115
116
}
116
117
117
118
public static Iterable <Object []> requestData () {
118
119
return Arrays .asList (
119
- new Object [] { JSON_TYPE , "{\" object\" : {\" key\" : \" value\" }}" , "{\" object\" : {\" key\" : \" value\" }}" , JsonPrettier . INSTANCE ,
120
- null , null },
121
- new Object [] { "application/xml" , "<test><key><value>value</value></key></test>" ,
122
- "<test><key><value>value</value></key></test>" , XmlPrettier .INSTANCE , null , null }
120
+ new Object []{ JSON_TYPE , "{\" object\" : {\" key\" : \" value\" }}" , "{\" object\" : {\" key\" : \" value\" }}" ,
121
+ JsonPrettier . INSTANCE , null , null },
122
+ new Object []{ "application/xml" , "<test><key><value>value</value></key></test>" ,
123
+ "<test><key><value>value</value></key></test>" , XmlPrettier .INSTANCE , null , null }
123
124
);
124
125
}
125
126
126
127
private void runFilter (FilterableRequestSpecification requestSpecification , Response responseObject ,
127
- Consumer <MockedStatic <ReportPortal >> mocks , OrderedFilter filter ) {
128
+ Consumer <MockedStatic <ReportPortal >> mocks , OrderedFilter filter ) {
128
129
try (MockedStatic <ReportPortal > utilities = Mockito .mockStatic (ReportPortal .class )) {
129
130
mocks .accept (utilities );
130
131
filter .filter (requestSpecification , null , getFilterContext (responseObject ));
131
132
}
132
133
}
133
134
134
135
private void runFilter (FilterableRequestSpecification requestSpecification , Response responseObject ,
135
- Consumer <MockedStatic <ReportPortal >> mocks ) {
136
+ Consumer <MockedStatic <ReportPortal >> mocks ) {
136
137
runFilter (requestSpecification , responseObject , mocks , new ReportPortalRestAssuredLoggingFilter (42 , LogLevel .INFO ));
137
138
}
138
139
@@ -147,7 +148,7 @@ private List<String> runFilterTextMessageCapture(FilterableRequestSpecification
147
148
}
148
149
149
150
private List <ReportPortalMessage > runFilterBinaryMessageCapture (FilterableRequestSpecification requestSpecification ,
150
- Response responseObject ) {
151
+ Response responseObject ) {
151
152
ArgumentCaptor <ReportPortalMessage > logCapture = ArgumentCaptor .forClass (ReportPortalMessage .class );
152
153
runFilter (
153
154
requestSpecification ,
@@ -167,7 +168,7 @@ private Triple<List<String>, List<String>, List<ReportPortalMessage>> runFilterC
167
168
StepReporter reporter = mock (StepReporter .class );
168
169
utilities .when (Launch ::currentLaunch ).thenReturn (launch );
169
170
when (launch .getStepReporter ()).thenReturn (reporter );
170
- doNothing (). when (reporter ) .sendStep (any (ItemStatus .class ), stepCaptor .capture ());
171
+ when (reporter .sendStep (any (ItemStatus .class ), stepCaptor .capture ())). thenReturn ( CommonUtils . createMaybeUuid ());
171
172
runFilter (
172
173
requestSpecification , responseObject , mock -> {
173
174
mock .when (() -> ReportPortal .emitLog (stringArgumentCaptor .capture (), anyString (), any (Date .class )))
@@ -222,7 +223,7 @@ public void test_rest_assured_logger_null_values() {
222
223
@ MethodSource ("requestData" )
223
224
@ SuppressWarnings ("rawtypes" )
224
225
public void test_rest_assured_logger_text_body (String mimeType , Object requestBody , Object responseBody ,
225
- Function <String , String > prettier ) {
226
+ Function <String , String > prettier ) {
226
227
FilterableRequestSpecification requestSpecification = mockBasicRequest (mimeType );
227
228
when (requestSpecification .getBody ()).thenReturn (requestBody );
228
229
@@ -244,7 +245,7 @@ public void test_rest_assured_logger_text_body(String mimeType, Object requestBo
244
245
}
245
246
246
247
public static Iterable <Object []> testTypes () {
247
- return Arrays .asList (new Object [] { HTML_TYPE }, new Object [] { null });
248
+ return Arrays .asList (new Object []{ HTML_TYPE }, new Object []{ null });
248
249
}
249
250
250
251
@ ParameterizedTest
@@ -361,7 +362,7 @@ private byte[] getResource(String imagePath) {
361
362
private static final String WILDCARD_TYPE = "*/*" ;
362
363
363
364
@ ParameterizedTest
364
- @ ValueSource (strings = { IMAGE_TYPE , WILDCARD_TYPE })
365
+ @ ValueSource (strings = {IMAGE_TYPE , WILDCARD_TYPE })
365
366
@ SuppressWarnings ("rawtypes" )
366
367
public void test_rest_assured_logger_image_body (String mimeType ) throws IOException {
367
368
FilterableRequestSpecification requestSpecification = mockBasicRequest (mimeType );
@@ -461,7 +462,7 @@ private MultiPartSpecification getBinaryPart(String mimeType, String filePath, b
461
462
}
462
463
463
464
@ ParameterizedTest
464
- @ ValueSource (booleans = { true , false })
465
+ @ ValueSource (booleans = {true , false })
465
466
public void test_rest_assured_logger_image_multipart (boolean isFile ) throws IOException {
466
467
byte [] image = getResource (IMAGE );
467
468
String imageType = ContentType .IMAGE_JPEG .getMimeType ();
@@ -557,13 +558,13 @@ public void test_rest_assured_logger_text_and_image_multipart() throws IOExcepti
557
558
558
559
public static Iterable <Object []> invalidContentTypes () {
559
560
return Arrays .asList (
560
- new Object [] { "" , ContentType .APPLICATION_OCTET_STREAM .getMimeType () },
561
- new Object [] { null , ContentType .APPLICATION_OCTET_STREAM .getMimeType () },
562
- new Object [] { "*/*" , "*/*" },
563
- new Object [] { "something invalid" , "something invalid" },
564
- new Object [] { "/" , "/" },
565
- new Object [] { "#*'\\ `%^!@/\" $;" , "#*'\\ `%^!@/\" $" },
566
- new Object [] { "a/a;F#%235f\\ =f324$%^&" , "a/a" }
561
+ new Object []{ "" , ContentType .APPLICATION_OCTET_STREAM .getMimeType ()},
562
+ new Object []{ null , ContentType .APPLICATION_OCTET_STREAM .getMimeType ()},
563
+ new Object []{ "*/*" , "*/*" },
564
+ new Object []{ "something invalid" , "something invalid" },
565
+ new Object []{ "/" , "/" },
566
+ new Object []{ "#*'\\ `%^!@/\" $;" , "#*'\\ `%^!@/\" $" },
567
+ new Object []{ "a/a;F#%235f\\ =f324$%^&" , "a/a" }
567
568
);
568
569
}
569
570
@@ -641,18 +642,24 @@ public void test_rest_assured_logger_text_as_file_multipart() {
641
642
@ Test
642
643
public void test_rest_assured_header_filter () {
643
644
FilterableRequestSpecification requestSpecification = mockBasicRequest (HTML_TYPE );
644
- RestAssuredConfig config = RestAssuredConfig .config ().logConfig (LogConfig .logConfig ().blacklistHeader ("Authorization" ));
645
+ RestAssuredConfig config = RestAssuredConfig .config ().logConfig (
646
+ LogConfig .logConfig ().blacklistHeader ("Authorization" ).blacklistHeader ("Set-Cookie" ));
645
647
when (requestSpecification .getConfig ()).thenReturn (config );
646
- Headers headers = new Headers (new Header (HttpHeaders .AUTHORIZATION , "Bearer some_token" ));
647
- when (requestSpecification .getHeaders ()).thenReturn (headers );
648
+ Headers requestHeaders = new Headers (new Header (HttpHeaders .AUTHORIZATION , "Bearer some_token" ),
649
+ new Header ("Cookies" , "request_cookie" ));
650
+ when (requestSpecification .getHeaders ()).thenReturn (requestHeaders );
648
651
Response responseObject = mockBasicResponse (HTML_TYPE );
652
+ Headers responseHeaders = new Headers (new Header ("Set-Cookie" , "response_cookie" ));
653
+ when (responseObject .getHeaders ()).thenReturn (responseHeaders );
649
654
650
655
List <String > logs = runFilterTextMessageCapture (requestSpecification , responseObject );
651
656
assertThat (logs , hasSize (2 )); // Request + Response
652
657
653
- String headerString = "\n \n **Headers**\n " + HttpHeaders .AUTHORIZATION + ": " + REMOVED_TAG ;
658
+ String requestHeaderString = "\n \n **Headers**\n " + HttpHeaders .AUTHORIZATION + ": " + REMOVED_TAG +
659
+ "\n Cookies: request_cookie" ;
660
+ assertThat (logs .get (0 ), equalTo (EMPTY_REQUEST + requestHeaderString ));
654
661
655
- assertThat ( logs . get ( 0 ), equalTo ( EMPTY_REQUEST + headerString )) ;
656
- assertThat (logs .get (1 ), equalTo (EMPTY_RESPONSE ));
662
+ String responseHeaderString = " \n \n **Headers** \n Set-Cookie: " + REMOVED_TAG ;
663
+ assertThat (logs .get (1 ), equalTo (EMPTY_RESPONSE + responseHeaderString ));
657
664
}
658
665
}
0 commit comments