Skip to content

Commit

Permalink
Merge pull request #14 from reportportal/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
HardNorth authored Jan 11, 2024
2 parents 7bbb2f6 + 6fe5151 commit 418e7f4
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 60 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Unreleased]
### Changed
- Client version updated on [5.2.0](https://github.com/reportportal/client-java/releases/tag/5.2.0), by @HardNorth
### Removed
- HttpCore dependency was removed to avoid conflicts, by @HardNorth

## [5.1.6]
### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Report Portal Java formatting utils for Agents and Loggers

[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/utils-java-formatting.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22utils-java-formatting%22)
[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/utils-java-formatting.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.epam.reportportal/utils-java-formatting)
[![CI Build](https://github.com/reportportal/utils-java-formatting/actions/workflows/ci.yml/badge.svg)](https://github.com/reportportal/utils-java-formatting/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/reportportal/utils-java-formatting/branch/develop/graph/badge.svg?token=D21P4TVVAS)](https://codecov.io/gh/reportportal/utils-java-formatting)
[![Join Slack chat!](https://slack.epmrpp.reportportal.io/badge.svg)](https://slack.epmrpp.reportportal.io/)
Expand Down
2 changes: 1 addition & 1 deletion README_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Report Portal Java formatting utils for Agents and Loggers

[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/utils-java-formatting.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22utils-java-formatting%22)
[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/utils-java-formatting.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.epam.reportportal/utils-java-formatting)
[![CI Build](https://github.com/reportportal/utils-java-formatting/actions/workflows/ci.yml/badge.svg)](https://github.com/reportportal/utils-java-formatting/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/reportportal/utils-java-formatting/branch/develop/graph/badge.svg?token=D21P4TVVAS)](https://codecov.io/gh/reportportal/utils-java-formatting)
[![Join Slack chat!](https://slack.epmrpp.reportportal.io/badge.svg)](https://slack.epmrpp.reportportal.io/)
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
apply plugin: 'java-library'

apply from: "build-quality.gradle"
apply from: 'build-quality.gradle'
apply from: "${project.scripts_url}/${project.scripts_branch}/release-commons.gradle"
apply from: "${project.scripts_url}/${project.scripts_branch}/signing.gradle"
apply from: "${project.scripts_url}/${project.scripts_branch}/jacoco.gradle"
Expand All @@ -37,12 +37,11 @@ repositories {
}

dependencies {
api 'com.epam.reportportal:client-java:5.1.22'
api 'com.epam.reportportal:client-java:5.2.0'
api 'com.google.code.findbugs:jsr305:3.0.2'
api 'com.epam.reportportal:commons-model:5.0.0'

implementation 'org.jsoup:jsoup:1.15.3'
implementation 'org.apache.httpcomponents:httpcore:4.4.15'

testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.2'

Expand All @@ -54,6 +53,7 @@ dependencies {
testImplementation 'org.hamcrest:hamcrest-core:2.2'
testImplementation "org.mockito:mockito-core:${mockito_version}"
testImplementation "org.mockito:mockito-inline:${mockito_version}"
testImplementation 'org.apache.httpcomponents:httpcore:4.4.15'
}

test {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=5.1.7-SNAPSHOT
version=5.2.0-SNAPSHOT
description=Report Portal Java formatting utils for Agents and Loggers
junit5_version=5.6.3
junit5_runner_version=1.6.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import com.epam.reportportal.service.Launch;
import com.epam.reportportal.service.ReportPortal;
import com.epam.reportportal.service.step.StepReporter;
import com.google.common.io.ByteSource;
import org.apache.http.entity.ContentType;
import com.epam.reportportal.utils.files.ByteSource;
import com.epam.reportportal.utils.http.ContentType;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -125,7 +125,7 @@ protected void emitLog(HttpFormatter formatter) {
attachAsBinary(
formatter.formatHead(),
formatter.getBinaryBody(),
ofNullable(formatter.getMimeType()).orElse(ContentType.APPLICATION_OCTET_STREAM.getMimeType())
ofNullable(formatter.getMimeType()).orElse(ContentType.APPLICATION_OCTET_STREAM)
);
break;
case MULTIPART:
Expand Down
55 changes: 30 additions & 25 deletions src/main/java/com/epam/reportportal/formatting/http/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.epam.reportportal.formatting.http.prettiers.HtmlPrettier;
import com.epam.reportportal.formatting.http.prettiers.JsonPrettier;
import com.epam.reportportal.formatting.http.prettiers.XmlPrettier;
import org.apache.http.entity.ContentType;
import com.epam.reportportal.utils.http.ContentType;

import java.util.*;
import java.util.function.Function;
Expand All @@ -40,38 +40,43 @@ public class Constants {
public static final String BODY_HIGHLIGHT = "```";

public static final Set<String> MULTIPART_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
ContentType.MULTIPART_FORM_DATA.getMimeType(),
"multipart/mixed",
"multipart/alternative",
"multipart/digest",
"multipart/parallel"
ContentType.MULTIPART_FORM_DATA,
ContentType.MULTIPART_MIXED,
ContentType.MULTIPART_ALTERNATIVE,
ContentType.MULTIPART_DIGEST,
ContentType.MULTIPART_PARALLEL
)));

public static final Set<String> TEXT_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(ContentType.APPLICATION_JSON.getMimeType(),
ContentType.TEXT_PLAIN.getMimeType(),
ContentType.TEXT_HTML.getMimeType(),
ContentType.TEXT_XML.getMimeType(),
ContentType.APPLICATION_XML.getMimeType(),
ContentType.DEFAULT_TEXT.getMimeType()
)));
public static final Set<String> TEXT_TYPES =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(ContentType.APPLICATION_JSON,
ContentType.TEXT_PLAIN,
ContentType.TEXT_HTML,
ContentType.TEXT_XML,
ContentType.APPLICATION_XML
)));

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

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

public static final Map<String, Function<String, String>> DEFAULT_PRETTIERS = Collections.unmodifiableMap(new HashMap<String, Function<String, String>>() {{
put(ContentType.APPLICATION_XML.getMimeType(), XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_SOAP_XML.getMimeType(), XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_ATOM_XML.getMimeType(), XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_SVG_XML.getMimeType(), XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_XHTML_XML.getMimeType(), XmlPrettier.INSTANCE);
put(ContentType.TEXT_XML.getMimeType(), XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_JSON.getMimeType(), JsonPrettier.INSTANCE);
put("text/json", JsonPrettier.INSTANCE);
put(ContentType.TEXT_HTML.getMimeType(), HtmlPrettier.INSTANCE);
}});
public static final Map<String, Function<String, String>> DEFAULT_PRETTIERS =
Collections.unmodifiableMap(new HashMap<String, Function<String, String>>() {{
put(ContentType.APPLICATION_XML, XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_SOAP_XML, XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_ATOM_XML, XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_SVG_XML, XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_XHTML_XML, XmlPrettier.INSTANCE);
put(ContentType.TEXT_XML, XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_JSON, JsonPrettier.INSTANCE);
put("text/json", JsonPrettier.INSTANCE);
put(ContentType.TEXT_HTML, HtmlPrettier.INSTANCE);
}});

private Constants() {
throw new RuntimeException("No instances should exist for the class!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import com.epam.reportportal.formatting.http.entities.Cookie;
import com.epam.reportportal.formatting.http.entities.Header;
import com.epam.reportportal.formatting.http.entities.Param;
import com.epam.reportportal.utils.http.ContentType;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.http.entity.ContentType;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -49,13 +49,15 @@ private HttpFormatUtils() {
throw new IllegalStateException("Static only class");
}

@Nonnull
public static String getMimeType(@Nullable String contentType) {
return ofNullable(contentType).filter(ct -> !ct.isEmpty())
.map(ct -> ContentType.parse(contentType).getMimeType())
.orElse(ContentType.APPLICATION_OCTET_STREAM.getMimeType());
.map(ct -> ContentType.parse(contentType))
.orElse(ContentType.APPLICATION_OCTET_STREAM);
}

public static String joinParts(String delimiter, String... parts) {
@Nonnull
public static String joinParts(@Nonnull String delimiter, @Nullable String... parts) {
if (parts == null) {
return "";
}
Expand All @@ -66,7 +68,7 @@ public static String joinParts(String delimiter, String... parts) {

@Nonnull
public static <T> String format(@Nullable List<T> entities, @Nonnull Function<T, String> converter,
@Nullable String tag) {
@Nullable String tag) {
String prefix = tag == null ? "" : tag + LINE_DELIMITER;
if (entities == null || entities.isEmpty()) {
return "";
Expand All @@ -79,7 +81,7 @@ public static <T> String format(@Nullable List<T> entities, @Nonnull Function<T,

@Nonnull
public static String formatHeaders(@Nullable List<Header> headers,
@Nullable Function<Header, String> headerConverter) {
@Nullable Function<Header, String> headerConverter) {
return format(headers,
headerConverter == null ? DefaultHttpHeaderConverter.INSTANCE : headerConverter,
HEADERS_TAG
Expand All @@ -88,7 +90,7 @@ public static String formatHeaders(@Nullable List<Header> headers,

@Nonnull
public static String formatCookies(@Nullable List<Cookie> cookies,
@Nullable Function<Cookie, String> cookieConverter) {
@Nullable Function<Cookie, String> cookieConverter) {
return format(cookies,
cookieConverter == null ? DefaultCookieConverter.INSTANCE : cookieConverter,
COOKIES_TAG
Expand All @@ -97,7 +99,7 @@ public static String formatCookies(@Nullable List<Cookie> cookies,

@Nonnull
public static String formatText(@Nullable String header, @Nullable List<Param> params, @Nullable String tag,
@Nullable Function<Param, String> paramConverter) {
@Nullable Function<Param, String> paramConverter) {
if (params == null || params.isEmpty()) {
return header == null ? "" : header;
}
Expand All @@ -113,7 +115,7 @@ public static String formatText(@Nullable String header, @Nullable List<Param> p

@Nonnull
public static String formatText(@Nullable String header, @Nullable String body, @Nullable String tag,
@Nullable Map<String, Function<String, String>> contentPrettiers, String contentType) {
@Nullable Map<String, Function<String, String>> contentPrettiers, String contentType) {
Map<String, Function<String, String>> prettiers = contentPrettiers;
if (contentPrettiers == null) {
prettiers = Collections.emptyMap();
Expand Down Expand Up @@ -161,9 +163,9 @@ public static Stream<Pair<String, String>> toKeyValue(@Nonnull String headerValu

@Nonnull
public static Cookie toCookie(@Nonnull String name, @Nullable String value, @Nullable String comment,
@Nullable String path, @Nullable String domain, @Nullable Long maxAge, @Nullable Boolean secured,
@Nullable Boolean httpOnly, @Nullable Date expiryDate, @Nullable Integer version,
@Nullable String sameSite) {
@Nullable String path, @Nullable String domain, @Nullable Long maxAge, @Nullable Boolean secured,
@Nullable Boolean httpOnly, @Nullable Date expiryDate, @Nullable Integer version,
@Nullable String sameSite) {
Cookie cookie = new Cookie(name);
cookie.setValue(value);
cookie.setComment(comment);
Expand Down Expand Up @@ -276,7 +278,7 @@ public static BodyType getBodyType(@Nullable String contentType, @Nullable Map<S
if (contentType == null || contentType.isEmpty()) {
return BodyType.NONE;
}
String mimeType = ContentType.parse(contentType).getMimeType();
String mimeType = ContentType.parse(contentType);
return ofNullable(typeMap).map(m -> m.getOrDefault(mimeType, BodyType.BINARY)).orElse(BodyType.BINARY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.epam.reportportal.formatting.http.entities.Cookie;
import com.epam.reportportal.formatting.http.entities.Header;
import com.epam.reportportal.formatting.http.entities.Param;
import org.apache.http.entity.ContentType;
import com.epam.reportportal.utils.http.ContentType;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -233,7 +233,7 @@ public Builder addCookie(Cookie cookie) {
}

public Builder addCookie(String name, String value, String comment, String path, String domain, Long maxAge,
Boolean secured, Boolean httpOnly, Date expiryDate, Integer version, String sameSite) {
Boolean secured, Boolean httpOnly, Date expiryDate, Integer version, String sameSite) {
return addCookie(HttpFormatUtils.toCookie(name,
value,
comment,
Expand Down Expand Up @@ -272,21 +272,21 @@ public Builder bodyBytes(String mimeType, byte[] payload) {

public Builder bodyParams(List<Param> formParameters) {
type = BodyType.FORM;
this.mimeType = ContentType.APPLICATION_FORM_URLENCODED.getMimeType();
this.mimeType = ContentType.APPLICATION_FORM_URLENCODED;
body = formParameters;
return this;
}

public Builder bodyParams(Map<String, String> formParameters) {
type = BodyType.FORM;
this.mimeType = ContentType.APPLICATION_FORM_URLENCODED.getMimeType();
this.mimeType = ContentType.APPLICATION_FORM_URLENCODED;
body = HttpFormatUtils.toForm(formParameters);
return this;
}

public Builder bodyParams(String formParameters) {
type = BodyType.FORM;
this.mimeType = ContentType.APPLICATION_FORM_URLENCODED.getMimeType();
this.mimeType = ContentType.APPLICATION_FORM_URLENCODED;
body = HttpFormatUtils.toForm(formParameters);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public Builder addCookie(Cookie cookie) {
}

public Builder addCookie(String name, String value, String comment, String path, String domain, Long maxAge,
Boolean secured, Boolean httpOnly, Date expiryDate, Integer version, String sameSite) {
Boolean secured, Boolean httpOnly, Date expiryDate, Integer version, String sameSite) {
return addCookie(HttpFormatUtils.toCookie(name,
value,
comment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.epam.reportportal.formatting.http.converters;

import com.epam.reportportal.formatting.http.entities.Header;
import com.google.common.net.HttpHeaders;

import javax.annotation.Nullable;
import java.util.Collections;
Expand All @@ -30,7 +29,7 @@

public class SanitizingHttpHeaderConverter implements Function<Header, String> {
public static final Set<String> SENSITIVE_HEADERS = Collections.unmodifiableSet(new HashSet<>(Collections.singletonList(
HttpHeaders.AUTHORIZATION)));
"Authorization")));

public static final Function<Header, String> INSTANCE = new SanitizingHttpHeaderConverter();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public String apply(String uriStr) {
.map(info -> info.split(":", 2))
.map(info -> {
if (info.length > 1) {
return new String[] { info[0], REMOVED_TAG };
return new String[]{info[0], REMOVED_TAG};
}
return info;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.epam.reportportal.formatting.http.prettiers.JsonPrettier;
import com.epam.reportportal.formatting.http.prettiers.Prettier;
import com.epam.reportportal.formatting.http.prettiers.XmlPrettier;
import com.google.common.net.HttpHeaders;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

Expand Down Expand Up @@ -62,10 +61,10 @@ public void testSessionIdHeaderRemove(Cookie input, String expected) {

public static Iterable<Object[]> headerCases() {
return Arrays.asList(
new Object[] { new Header(HttpHeaders.AUTHORIZATION, "Bearer test_token"),
HttpHeaders.AUTHORIZATION + ": " + Constants.REMOVED_TAG },
new Object[] { new Header("Authorization", "Bearer test_token"),
"Authorization: " + Constants.REMOVED_TAG },
new Object[] { null, null },
new Object[] { new Header(HttpHeaders.ACCEPT, "*/*"), HttpHeaders.ACCEPT + ": \\*/\\*" }
new Object[] { new Header("Accept", "*/*"), "Accept: \\*/\\*" }
);
}

Expand Down

0 comments on commit 418e7f4

Please sign in to comment.