Skip to content

Commit 0dd5b51

Browse files
committed
utils-java-formatting dependency version updated
1 parent ee705b0 commit 0dd5b51

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Changed
5+
- `utils-java-formatting` dependency version updated on [5.2.7](https://github.com/reportportal/utils-java-formatting/releases/tag/5.2.7), by @HardNorth
46

57
## [5.3.8]
68
### Changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ repositories {
3737
}
3838

3939
dependencies {
40-
api 'com.epam.reportportal:utils-java-formatting:5.2.6'
40+
api 'com.epam.reportportal:utils-java-formatting:5.2.7'
4141
compileOnly "com.epam.reportportal:client-java:${client_version}"
4242
implementation 'com.google.code.findbugs:jsr305:3.0.2'
4343
implementation 'commons-codec:commons-codec:1.15'

src/main/java/com/epam/reportportal/restassured/ReportPortalRestAssuredLoggingFilter.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818

1919
import com.epam.reportportal.formatting.AbstractHttpFormatter;
2020
import com.epam.reportportal.formatting.http.converters.DefaultCookieConverter;
21+
import com.epam.reportportal.formatting.http.converters.DefaultFormParamConverter;
2122
import com.epam.reportportal.formatting.http.converters.DefaultHttpHeaderConverter;
2223
import com.epam.reportportal.formatting.http.converters.DefaultUriConverter;
2324
import com.epam.reportportal.formatting.http.entities.Cookie;
2425
import com.epam.reportportal.formatting.http.entities.Header;
26+
import com.epam.reportportal.formatting.http.entities.Param;
2527
import com.epam.reportportal.listeners.LogLevel;
2628
import com.epam.reportportal.restassured.support.HttpEntityFactory;
2729
import com.epam.reportportal.service.ReportPortal;
@@ -67,6 +69,8 @@ public class ReportPortalRestAssuredLoggingFilter extends AbstractHttpFormatter<
6769

6870
private final int order;
6971

72+
protected final Function<Param, String> paramConverter;
73+
7074
/**
7175
* Create an ordered REST Assured filter with the log level and different converters.
7276
*
@@ -82,14 +86,48 @@ public class ReportPortalRestAssuredLoggingFilter extends AbstractHttpFormatter<
8286
* formats Cookies with <code>toString</code> method
8387
* @param uriConverterFunction the same as 'headerConvertFunction' param but for URI, default function returns
8488
* URI "as is"
89+
* @param paramConverter the same as 'headerConvertFunction' param but for Web Form Params, default function returns
90+
* <code>param.getName() + ": " + param.getValue()</code>
8591
*/
8692
public ReportPortalRestAssuredLoggingFilter(int filterOrder, @Nonnull LogLevel defaultLogLevel,
8793
@Nullable Function<Header, String> headerConvertFunction, @Nullable Function<Header, String> partHeaderConvertFunction,
88-
@Nullable Function<Cookie, String> cookieConvertFunction, @Nullable Function<String, String> uriConverterFunction) {
94+
@Nullable Function<Cookie, String> cookieConvertFunction, @Nullable Function<String, String> uriConverterFunction,
95+
@Nullable Function<Param, String> paramConverter) {
8996
super(defaultLogLevel, headerConvertFunction, partHeaderConvertFunction, cookieConvertFunction, uriConverterFunction);
97+
this.paramConverter = paramConverter != null ? paramConverter : DefaultFormParamConverter.INSTANCE;
9098
order = filterOrder;
9199
}
92100

101+
/**
102+
* Create an ordered REST Assured filter with the log level and different converters.z
103+
*
104+
* @param filterOrder if you have different filters which modify requests on fly this parameter allows
105+
* you to control the order when Report Portal logger will be called, and therefore
106+
* log or don't log some data.
107+
* @param defaultLogLevel log level on which REST Assured requests/responses will appear on Report Portal
108+
* @param headerConvertFunction if you want to preprocess your HTTP Headers before they appear on Report Portal
109+
* provide this custom function for the class, default function formats it like
110+
* that: <code>header.getName() + ": " + header.getValue()</code>
111+
* @param partHeaderConvertFunction the same as fot HTTP Headers, but for parts in Multipart request
112+
* @param cookieConvertFunction the same as 'headerConvertFunction' param but for Cookies, default function
113+
* formats Cookies with <code>toString</code> method
114+
* @param uriConverterFunction the same as 'headerConvertFunction' param but for URI, default function returns
115+
* URI "as is"
116+
*/
117+
public ReportPortalRestAssuredLoggingFilter(int filterOrder, @Nonnull LogLevel defaultLogLevel,
118+
@Nullable Function<Header, String> headerConvertFunction, @Nullable Function<Header, String> partHeaderConvertFunction,
119+
@Nullable Function<Cookie, String> cookieConvertFunction, @Nullable Function<String, String> uriConverterFunction) {
120+
this(
121+
filterOrder,
122+
defaultLogLevel,
123+
headerConvertFunction,
124+
partHeaderConvertFunction,
125+
cookieConvertFunction,
126+
uriConverterFunction,
127+
DefaultFormParamConverter.INSTANCE
128+
);
129+
}
130+
93131
/**
94132
* Create an ordered REST Assured filter with the log level and different converters.
95133
*
@@ -178,6 +216,7 @@ public Response filter(FilterableRequestSpecification requestSpec, FilterableRes
178216
uriConverter,
179217
myHeaderConverter,
180218
cookieConverter,
219+
paramConverter,
181220
getContentPrettifiers(),
182221
partHeaderConverter,
183222
getBodyTypeMap()

src/main/java/com/epam/reportportal/restassured/support/HttpEntityFactory.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.epam.reportportal.formatting.http.entities.BodyType;
2323
import com.epam.reportportal.formatting.http.entities.Cookie;
2424
import com.epam.reportportal.formatting.http.entities.Header;
25+
import com.epam.reportportal.formatting.http.entities.Param;
2526
import com.epam.reportportal.message.TypeAwareByteSource;
2627
import com.epam.reportportal.service.ReportPortal;
2728
import com.epam.reportportal.utils.files.Utils;
@@ -99,8 +100,9 @@ private static List<HttpPartFormatter> toParts(@Nonnull FilterableRequestSpecifi
99100
@Nonnull
100101
public static HttpRequestFormatter createHttpRequestFormatter(@Nonnull FilterableRequestSpecification requestSpecification,
101102
@Nullable Function<String, String> uriConverter, @Nullable Function<Header, String> headerConverter,
102-
@Nullable Function<Cookie, String> cookieConverter, @Nullable Map<String, Function<String, String>> prettiers,
103-
@Nullable Function<Header, String> partHeaderConverter, @Nonnull Map<String, BodyType> bodyTypeMap) {
103+
@Nullable Function<Cookie, String> cookieConverter, @Nullable Function<Param, String> paramConverter,
104+
@Nullable Map<String, Function<String, String>> prettifiers, @Nullable Function<Header, String> partHeaderConverter,
105+
@Nonnull Map<String, BodyType> bodyTypeMap) {
104106
HttpRequestFormatter.Builder builder = new HttpRequestFormatter.Builder(
105107
requestSpecification.getMethod(),
106108
requestSpecification.getURI()
@@ -122,7 +124,11 @@ public static HttpRequestFormatter createHttpRequestFormatter(@Nonnull Filterabl
122124
c.getVersion(),
123125
c.getSameSite()
124126
)));
125-
builder.uriConverter(uriConverter).headerConverter(headerConverter).cookieConverter(cookieConverter).prettiers(prettiers);
127+
builder.uriConverter(uriConverter)
128+
.headerConverter(headerConverter)
129+
.cookieConverter(cookieConverter)
130+
.paramConverter(paramConverter)
131+
.prettifiers(prettifiers);
126132
String mimeType = getMimeType(requestSpecification.getContentType());
127133
BodyType bodyType = getBodyType(requestSpecification.getContentType(), bodyTypeMap);
128134
switch (bodyType) {
@@ -144,7 +150,7 @@ public static HttpRequestFormatter createHttpRequestFormatter(@Nonnull Filterabl
144150
@Nonnull
145151
public static HttpResponseFormatter createHttpResponseFormatter(@Nonnull Response response,
146152
@Nullable Function<Header, String> headerConverter, @Nullable Function<Cookie, String> cookieConverter,
147-
@Nullable Map<String, Function<String, String>> prettiers, @Nonnull Map<String, BodyType> bodyTypeMap) {
153+
@Nullable Map<String, Function<String, String>> prettifiers, @Nonnull Map<String, BodyType> bodyTypeMap) {
148154
HttpResponseFormatter.Builder builder = new HttpResponseFormatter.Builder(response.statusCode(), response.getStatusLine());
149155
ofNullable(response.getHeaders()).ifPresent(headers -> headers.forEach(h -> builder.addHeader(h.getName(), h.getValue())));
150156
ofNullable(response.getDetailedCookies()).ifPresent(cookies -> cookies.forEach(c -> builder.addCookie(
@@ -160,7 +166,7 @@ public static HttpResponseFormatter createHttpResponseFormatter(@Nonnull Respons
160166
c.getVersion(),
161167
c.getSameSite()
162168
)));
163-
builder.headerConverter(headerConverter).cookieConverter(cookieConverter).prettiers(prettiers);
169+
builder.headerConverter(headerConverter).cookieConverter(cookieConverter).prettifiers(prettifiers);
164170

165171
String type = getMimeType(response.getContentType());
166172
BodyType bodyType = getBodyType(response.getContentType(), bodyTypeMap);

0 commit comments

Comments
 (0)