Skip to content

Commit ac33ab4

Browse files
authored
Merge pull request #21 from reportportal/develop
Release
2 parents f6f7454 + bf8b85c commit ac33ab4

22 files changed

+431
-262
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+
- More `Prettiers` to `Prettifiers` renaming and deprecation of `Prettiers`, by @HardNorth
46

57
## [5.2.6]
68
### Added

src/main/java/com/epam/reportportal/formatting/AbstractHttpFormatter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import java.util.function.Function;
3838

3939
import static com.epam.reportportal.formatting.http.Constants.BODY_TYPE_MAP;
40-
import static com.epam.reportportal.formatting.http.Constants.DEFAULT_PRETTIERS;
40+
import static com.epam.reportportal.formatting.http.Constants.DEFAULT_PRETTIFIERS;
4141
import static java.util.Optional.ofNullable;
4242

4343
/**
@@ -54,7 +54,7 @@ public abstract class AbstractHttpFormatter<SELF extends AbstractHttpFormatter<S
5454
protected final Function<Cookie, String> cookieConverter;
5555
protected final Function<String, String> uriConverter;
5656

57-
private Map<String, Function<String, String>> contentPrettifiers = DEFAULT_PRETTIERS;
57+
private Map<String, Function<String, String>> contentPrettifiers = DEFAULT_PRETTIFIERS;
5858

5959
/**
6060
* @deprecated Use {@link #getContentPrettifiers()} instead

src/main/java/com/epam/reportportal/formatting/http/Constants.java

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
package com.epam.reportportal.formatting.http;
1818

1919
import com.epam.reportportal.formatting.http.entities.BodyType;
20-
import com.epam.reportportal.formatting.http.prettiers.HtmlPrettier;
21-
import com.epam.reportportal.formatting.http.prettiers.JsonPrettier;
22-
import com.epam.reportportal.formatting.http.prettiers.XmlPrettier;
20+
import com.epam.reportportal.formatting.http.prettifiers.HtmlPrettifier;
21+
import com.epam.reportportal.formatting.http.prettifiers.JsonPrettifier;
22+
import com.epam.reportportal.formatting.http.prettifiers.XmlPrettifier;
2323
import com.epam.reportportal.utils.http.ContentType;
2424

2525
import java.util.*;
@@ -47,43 +47,48 @@ public class Constants {
4747
ContentType.MULTIPART_PARALLEL
4848
)));
4949

50-
public static final Set<String> TEXT_TYPES =
51-
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(ContentType.APPLICATION_JSON,
52-
ContentType.TEXT_PLAIN,
53-
ContentType.TEXT_HTML,
54-
ContentType.TEXT_XML,
55-
ContentType.APPLICATION_XML,
56-
ContentType.APPLICATION_SOAP_XML,
57-
ContentType.APPLICATION_ATOM_XML,
58-
// Can't use ContentType.TEXT_JSON, etc. because client-java dependency marked as compileOnly
59-
"text/json",
60-
"application/x.reportportal.launch.v2+json",
61-
"application/x.reportportal.test.v2+json"
62-
)));
50+
public static final Set<String> TEXT_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
51+
ContentType.APPLICATION_JSON,
52+
ContentType.TEXT_PLAIN,
53+
ContentType.TEXT_HTML,
54+
ContentType.TEXT_XML,
55+
ContentType.APPLICATION_XML,
56+
ContentType.APPLICATION_SOAP_XML,
57+
ContentType.APPLICATION_ATOM_XML,
58+
// Can't use ContentType.TEXT_JSON, etc. because client-java dependency marked as compileOnly
59+
"text/json",
60+
"application/x.reportportal.launch.v2+json",
61+
"application/x.reportportal.test.v2+json"
62+
)));
6363

6464
public static final Set<String> FORM_TYPES = Collections.singleton(ContentType.APPLICATION_FORM_URLENCODED);
6565

66-
public static final Map<String, BodyType> BODY_TYPE_MAP = Collections.unmodifiableMap(Stream.of(TEXT_TYPES.stream()
67-
.collect(Collectors.toMap(k -> k, v -> BodyType.TEXT)),
66+
public static final Map<String, BodyType> BODY_TYPE_MAP = Collections.unmodifiableMap(Stream.of(
67+
TEXT_TYPES.stream().collect(Collectors.toMap(k -> k, v -> BodyType.TEXT)),
6868
FORM_TYPES.stream().collect(Collectors.toMap(k -> k, v -> BodyType.FORM)),
6969
MULTIPART_TYPES.stream().collect(Collectors.toMap(k -> k, v -> BodyType.MULTIPART))
7070
).flatMap(m -> m.entrySet().stream()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
7171

72-
public static final Map<String, Function<String, String>> DEFAULT_PRETTIERS =
73-
Collections.unmodifiableMap(new HashMap<String, Function<String, String>>() {{
74-
put(ContentType.APPLICATION_XML, XmlPrettier.INSTANCE);
75-
put(ContentType.APPLICATION_SOAP_XML, XmlPrettier.INSTANCE);
76-
put(ContentType.APPLICATION_ATOM_XML, XmlPrettier.INSTANCE);
77-
put(ContentType.APPLICATION_SVG_XML, XmlPrettier.INSTANCE);
78-
put(ContentType.APPLICATION_XHTML_XML, XmlPrettier.INSTANCE);
79-
put(ContentType.TEXT_XML, XmlPrettier.INSTANCE);
80-
put(ContentType.APPLICATION_JSON, JsonPrettier.INSTANCE);
81-
// Can't use ContentType.TEXT_JSON, etc. because client-java dependency marked as compileOnly
82-
put("text/json", JsonPrettier.INSTANCE);
83-
put("application/x.reportportal.launch.v2+json", JsonPrettier.INSTANCE);
84-
put("application/x.reportportal.test.v2+json", JsonPrettier.INSTANCE);
85-
put(ContentType.TEXT_HTML, HtmlPrettier.INSTANCE);
86-
}});
72+
public static final Map<String, Function<String, String>> DEFAULT_PRETTIFIERS = Collections.unmodifiableMap(new HashMap<String, Function<String, String>>() {{
73+
put(ContentType.APPLICATION_XML, XmlPrettifier.INSTANCE);
74+
put(ContentType.APPLICATION_SOAP_XML, XmlPrettifier.INSTANCE);
75+
put(ContentType.APPLICATION_ATOM_XML, XmlPrettifier.INSTANCE);
76+
put(ContentType.APPLICATION_SVG_XML, XmlPrettifier.INSTANCE);
77+
put(ContentType.APPLICATION_XHTML_XML, XmlPrettifier.INSTANCE);
78+
put(ContentType.TEXT_XML, XmlPrettifier.INSTANCE);
79+
put(ContentType.APPLICATION_JSON, JsonPrettifier.INSTANCE);
80+
// Can't use ContentType.TEXT_JSON, etc. because client-java dependency marked as compileOnly
81+
put("text/json", JsonPrettifier.INSTANCE);
82+
put("application/x.reportportal.launch.v2+json", JsonPrettifier.INSTANCE);
83+
put("application/x.reportportal.test.v2+json", JsonPrettifier.INSTANCE);
84+
put(ContentType.TEXT_HTML, HtmlPrettifier.INSTANCE);
85+
}});
86+
87+
/**
88+
* @deprecated Use {@link #DEFAULT_PRETTIFIERS} instead
89+
*/
90+
@Deprecated
91+
public static final Map<String, Function<String, String>> DEFAULT_PRETTIERS = DEFAULT_PRETTIFIERS;
8792

8893
private Constants() {
8994
throw new RuntimeException("No instances should exist for the class!");

src/main/java/com/epam/reportportal/formatting/http/HttpFormatUtils.java

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,11 @@ public static String joinParts(@Nonnull String delimiter, @Nullable String... pa
6161
if (parts == null) {
6262
return "";
6363
}
64-
return Arrays.stream(parts)
65-
.filter(p -> Objects.nonNull(p) && !p.isEmpty())
66-
.collect(Collectors.joining(delimiter));
64+
return Arrays.stream(parts).filter(p -> Objects.nonNull(p) && !p.isEmpty()).collect(Collectors.joining(delimiter));
6765
}
6866

6967
@Nonnull
70-
public static <T> String format(@Nullable List<T> entities, @Nonnull Function<T, String> converter,
71-
@Nullable String tag) {
68+
public static <T> String format(@Nullable List<T> entities, @Nonnull Function<T, String> converter, @Nullable String tag) {
7269
String prefix = tag == null ? "" : tag + LINE_DELIMITER;
7370
if (entities == null || entities.isEmpty()) {
7471
return "";
@@ -80,53 +77,42 @@ public static <T> String format(@Nullable List<T> entities, @Nonnull Function<T,
8077
}
8178

8279
@Nonnull
83-
public static String formatHeaders(@Nullable List<Header> headers,
84-
@Nullable Function<Header, String> headerConverter) {
85-
return format(headers,
86-
headerConverter == null ? DefaultHttpHeaderConverter.INSTANCE : headerConverter,
87-
HEADERS_TAG
88-
);
80+
public static String formatHeaders(@Nullable List<Header> headers, @Nullable Function<Header, String> headerConverter) {
81+
return format(headers, headerConverter == null ? DefaultHttpHeaderConverter.INSTANCE : headerConverter, HEADERS_TAG);
8982
}
9083

9184
@Nonnull
92-
public static String formatCookies(@Nullable List<Cookie> cookies,
93-
@Nullable Function<Cookie, String> cookieConverter) {
94-
return format(cookies,
95-
cookieConverter == null ? DefaultCookieConverter.INSTANCE : cookieConverter,
96-
COOKIES_TAG
97-
);
85+
public static String formatCookies(@Nullable List<Cookie> cookies, @Nullable Function<Cookie, String> cookieConverter) {
86+
return format(cookies, cookieConverter == null ? DefaultCookieConverter.INSTANCE : cookieConverter, COOKIES_TAG);
9887
}
9988

10089
@Nonnull
10190
public static String formatText(@Nullable String header, @Nullable List<Param> params, @Nullable String tag,
102-
@Nullable Function<Param, String> paramConverter) {
91+
@Nullable Function<Param, String> paramConverter) {
10392
if (params == null || params.isEmpty()) {
10493
return header == null ? "" : header;
10594
}
10695
String prefix = tag == null ? "" : tag + LINE_DELIMITER;
107-
String body = format(params,
108-
paramConverter == null ? DefaultFormParamConverter.INSTANCE : paramConverter,
109-
null
110-
);
96+
String body = format(params, paramConverter == null ? DefaultFormParamConverter.INSTANCE : paramConverter, null);
11197
return (header == null || header.isEmpty() ? "" : header + LINE_DELIMITER + LINE_DELIMITER) + (body.isEmpty() ?
11298
body :
11399
prefix + BODY_HIGHLIGHT + LINE_DELIMITER + body + LINE_DELIMITER + BODY_HIGHLIGHT);
114100
}
115101

116102
@Nonnull
117103
public static String formatText(@Nullable String header, @Nullable String body, @Nullable String tag,
118-
@Nullable Map<String, Function<String, String>> contentPrettiers, String contentType) {
119-
Map<String, Function<String, String>> prettiers = contentPrettiers;
120-
if (contentPrettiers == null) {
121-
prettiers = Collections.emptyMap();
104+
@Nullable Map<String, Function<String, String>> contentPrettifiers, String contentType) {
105+
Map<String, Function<String, String>> prettifiers = contentPrettifiers;
106+
if (contentPrettifiers == null) {
107+
prettifiers = Collections.emptyMap();
122108
}
123109
if (body == null || body.isEmpty()) {
124110
return header == null ? "" : header;
125111
}
126112
return (header == null || header.isEmpty() ? "" : header + LINE_DELIMITER + LINE_DELIMITER) + (tag == null || tag.isEmpty() ?
127113
"" :
128-
tag + LINE_DELIMITER) + BODY_HIGHLIGHT + LINE_DELIMITER + (prettiers.containsKey(contentType) ?
129-
prettiers.get(contentType).apply(body) :
114+
tag + LINE_DELIMITER) + BODY_HIGHLIGHT + LINE_DELIMITER + (prettifiers.containsKey(contentType) ?
115+
prettifiers.get(contentType).apply(body) :
130116
body) + LINE_DELIMITER + BODY_HIGHLIGHT;
131117
}
132118

@@ -162,10 +148,9 @@ public static Stream<Pair<String, String>> toKeyValue(@Nonnull String headerValu
162148
}
163149

164150
@Nonnull
165-
public static Cookie toCookie(@Nonnull String name, @Nullable String value, @Nullable String comment,
166-
@Nullable String path, @Nullable String domain, @Nullable Long maxAge, @Nullable Boolean secured,
167-
@Nullable Boolean httpOnly, @Nullable Date expiryDate, @Nullable Integer version,
168-
@Nullable String sameSite) {
151+
public static Cookie toCookie(@Nonnull String name, @Nullable String value, @Nullable String comment, @Nullable String path,
152+
@Nullable String domain, @Nullable Long maxAge, @Nullable Boolean secured, @Nullable Boolean httpOnly,
153+
@Nullable Date expiryDate, @Nullable Integer version, @Nullable String sameSite) {
169154
Cookie cookie = new Cookie(name);
170155
cookie.setValue(value);
171156
cookie.setComment(comment);
@@ -197,17 +182,16 @@ public static Cookie toCookie(@Nonnull String headerValue) {
197182
// Wed, 06-Sep-2023 11:22:09 GMT
198183
Date expiryDate = ofNullable(cookieMetadata.get("expires")).map(d -> {
199184
try {
200-
return new SimpleDateFormat(DefaultCookieConverter.DEFAULT_COOKIE_DATE_FORMAT).parse(d.replace('-',
201-
' '
202-
));
185+
return new SimpleDateFormat(DefaultCookieConverter.DEFAULT_COOKIE_DATE_FORMAT).parse(d.replace('-', ' '));
203186
} catch (ParseException e) {
204187
return null;
205188
}
206189
}).orElse(null);
207190
Integer version = cookieMetadata.get("version") == null ? null : Integer.valueOf(cookieMetadata.get("version"));
208191
String sameSite = cookieMetadata.get("samesite");
209192

210-
return toCookie(nameValue.getKey(),
193+
return toCookie(
194+
nameValue.getKey(),
211195
nameValue.getValue(),
212196
comment,
213197
path,
@@ -231,8 +215,10 @@ public static boolean isSetCookie(@Nullable String headerName) {
231215

232216
@Nonnull
233217
private static Charset getCharset(@Nullable String contentType) {
234-
return ofNullable(contentType).flatMap(h -> toKeyValue(h).filter(p -> "charset".equalsIgnoreCase(p.getKey()))
235-
.findAny()).map(Pair::getValue).map(Charset::forName).orElse(StandardCharsets.UTF_8);
218+
return ofNullable(contentType).flatMap(h -> toKeyValue(h).filter(p -> "charset".equalsIgnoreCase(p.getKey())).findAny())
219+
.map(Pair::getValue)
220+
.map(Charset::forName)
221+
.orElse(StandardCharsets.UTF_8);
236222
}
237223

238224
@Nonnull

src/main/java/com/epam/reportportal/formatting/http/HttpPartFormatter.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class HttpPartFormatter {
4343
private String fileName;
4444

4545
private Function<Header, String> headerConverter;
46-
private Map<String, Function<String, String>> prettiers;
46+
private Map<String, Function<String, String>> prettifiers;
4747

4848
public HttpPartFormatter(@Nonnull PartType type, @Nonnull String mimeType, @Nonnull Object payload) {
4949
this.type = type;
@@ -71,7 +71,7 @@ public byte[] getBinaryPayload() {
7171
}
7272

7373
public String formatAsText() {
74-
return HttpFormatUtils.formatText(formatHeaders(), getTextPayload(), BODY_PART_TAG, prettiers, mimeType);
74+
return HttpFormatUtils.formatText(formatHeaders(), getTextPayload(), BODY_PART_TAG, prettifiers, mimeType);
7575
}
7676

7777
public String formatForBinaryDataPrefix() {
@@ -128,8 +128,17 @@ public void setHeaderConverter(Function<Header, String> headerConverter) {
128128
this.headerConverter = headerConverter;
129129
}
130130

131-
public void setPrettiers(Map<String, Function<String, String>> prettiers) {
132-
this.prettiers = prettiers;
131+
public void setPrettifiers(Map<String, Function<String, String>> prettifiers) {
132+
this.prettifiers = prettifiers;
133+
}
134+
135+
/**
136+
* @param prettifiers a map with the content type as a key and the prettifier function as a value
137+
* @deprecated Use {@link #setPrettifiers(Map)} instead
138+
*/
139+
@Deprecated
140+
public void setPrettiers(Map<String, Function<String, String>> prettifiers) {
141+
setPrettifiers(prettifiers);
133142
}
134143

135144
public enum PartType {
@@ -148,7 +157,7 @@ public static class Builder {
148157
private String fileName;
149158

150159
private Function<Header, String> headerConverter;
151-
private Map<String, Function<String, String>> prettiers;
160+
private Map<String, Function<String, String>> prettifiers;
152161

153162
/***
154163
*
@@ -198,19 +207,29 @@ public Builder headerConverter(Function<Header, String> converter) {
198207
return this;
199208
}
200209

201-
public Builder prettiers(Map<String, Function<String, String>> formatPrettiers) {
202-
this.prettiers = formatPrettiers;
210+
public Builder prettifiers(Map<String, Function<String, String>> formatPrettifiers) {
211+
this.prettifiers = formatPrettifiers;
203212
return this;
204213
}
205214

215+
/**
216+
* @param formatPrettifiers a map with the content type as a key and the prettifier function as a value
217+
* @return the builder instance
218+
* @deprecated Use {@link #prettifiers(Map)} instead
219+
*/
220+
@Deprecated
221+
public Builder prettiers(Map<String, Function<String, String>> formatPrettifiers) {
222+
return prettifiers(formatPrettifiers);
223+
}
224+
206225
public HttpPartFormatter build() {
207226
HttpPartFormatter formatter = new HttpPartFormatter(type, mimeType, payload);
208227
formatter.setControlName(controlName);
209228
formatter.setHeaders(headers);
210229
formatter.setCharset(charset);
211230
formatter.setFileName(fileName);
212231
formatter.setHeaderConverter(ofNullable(headerConverter).orElse(DefaultHttpHeaderConverter.INSTANCE));
213-
formatter.setPrettiers(ofNullable(prettiers).orElse(Constants.DEFAULT_PRETTIERS));
232+
formatter.setPrettifiers(ofNullable(prettifiers).orElse(Constants.DEFAULT_PRETTIFIERS));
214233
return formatter;
215234
}
216235
}

0 commit comments

Comments
 (0)