Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #24

Merged
merged 4 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
- `utils-java-formatting` library version updated on version [5.2.0](https://github.com/reportportal/utils-java-formatting/releases/tag/5.2.0), by @HardNorth
- Rest-Assured dependency marked as `implementation` to force users specify their own versions, by @HardNorth

## [5.2.4]
### 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 logger for REST Assured

[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/logger-java-rest-assured.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22logger-java-rest-assured%22)
[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/logger-java-rest-assured.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.epam.reportportal/logger-java-rest-assured)
[![CI Build](https://github.com/reportportal/logger-java-rest-assured/actions/workflows/ci.yml/badge.svg)](https://github.com/reportportal/logger-java-rest-assured/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/reportportal/logger-java-rest-assured/branch/develop/graph/badge.svg?token=W3MTDF607A)](https://codecov.io/gh/reportportal/logger-java-rest-assured)
[![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 logger for REST Assured

[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/logger-java-rest-assured.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22logger-java-rest-assured%22)
[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/logger-java-rest-assured.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.epam.reportportal/logger-java-rest-assured)
[![CI Build](https://github.com/reportportal/logger-java-rest-assured/actions/workflows/ci.yml/badge.svg)](https://github.com/reportportal/logger-java-rest-assured/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/reportportal/logger-java-rest-assured/branch/develop/graph/badge.svg?token=W3MTDF607A)](https://codecov.io/gh/reportportal/logger-java-rest-assured)
[![Join Slack chat!](https://slack.epmrpp.reportportal.io/badge.svg)](https://slack.epmrpp.reportportal.io/)
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ 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'
api ('io.rest-assured:rest-assured:5.1.1') {
api 'com.epam.reportportal:utils-java-formatting:5.2.0'
implementation 'commons-codec:commons-codec:1.15'
implementation ('io.rest-assured:rest-assured:5.1.1') {
exclude module: 'commons-codec'
}
api 'com.epam.reportportal:utils-java-formatting:5.1.6'
implementation 'commons-codec:commons-codec:1.15'

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

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.2.5-SNAPSHOT
version=5.3.0-SNAPSHOT
description=Report Portal logger for REST Assured
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 @@ -52,6 +52,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Consumer;
Expand Down Expand Up @@ -111,8 +112,8 @@ public Response next(FilterableRequestSpecification requestSpecification,
}

public static Iterable<Object[]> requestData() {
return Arrays.asList(new Object[] { JSON_TYPE, "{\"object\": {\"key\": \"value\"}}",
"{\"object\": {\"key\": \"value\"}}", JsonPrettier.INSTANCE, null, null },
return Arrays.asList(new Object[] { JSON_TYPE, "{\"object\": {\"key\": \"value\"}}", "{\"object\": {\"key\": \"value\"}}",
JsonPrettier.INSTANCE, null, null },
new Object[] { "application/xml", "<test><key><value>value</value></key></test>",
"<test><key><value>value</value></key></test>", XmlPrettier.INSTANCE, null, null }
);
Expand All @@ -128,20 +129,14 @@ private void runFilter(FilterableRequestSpecification requestSpecification, Resp

private void runFilter(FilterableRequestSpecification requestSpecification, Response responseObject,
Consumer<MockedStatic<ReportPortal>> mocks) {
runFilter(requestSpecification,
responseObject,
mocks,
new ReportPortalRestAssuredLoggingFilter(42, LogLevel.INFO)
);
runFilter(requestSpecification, responseObject, mocks, new ReportPortalRestAssuredLoggingFilter(42, LogLevel.INFO));
}

private List<String> runFilterTextMessageCapture(FilterableRequestSpecification requestSpecification,
Response responseObject) {
private List<String> runFilterTextMessageCapture(FilterableRequestSpecification requestSpecification, Response responseObject) {
ArgumentCaptor<String> logCapture = ArgumentCaptor.forClass(String.class);
runFilter(requestSpecification,
responseObject,
mock -> mock.when(() -> ReportPortal.emitLog(logCapture.capture(), anyString(), any(Date.class)))
.thenReturn(Boolean.TRUE)
mock -> mock.when(() -> ReportPortal.emitLog(logCapture.capture(), anyString(), any(Date.class))).thenReturn(Boolean.TRUE)
);
return logCapture.getAllValues();
}
Expand All @@ -151,8 +146,7 @@ private List<ReportPortalMessage> runFilterBinaryMessageCapture(FilterableReques
ArgumentCaptor<ReportPortalMessage> logCapture = ArgumentCaptor.forClass(ReportPortalMessage.class);
runFilter(requestSpecification,
responseObject,
mock -> mock.when(() -> ReportPortal.emitLog(logCapture.capture(), anyString(), any(Date.class)))
.thenReturn(Boolean.TRUE)
mock -> mock.when(() -> ReportPortal.emitLog(logCapture.capture(), anyString(), any(Date.class))).thenReturn(Boolean.TRUE)
);
return logCapture.getAllValues();
}
Expand All @@ -175,10 +169,7 @@ private Triple<List<String>, List<String>, List<ReportPortalMessage>> runFilterC
.thenReturn(Boolean.TRUE);
}, filter);
}
return Triple.of(stepCaptor.getAllValues(),
stringArgumentCaptor.getAllValues(),
messageArgumentCaptor.getAllValues()
);
return Triple.of(stepCaptor.getAllValues(), stringArgumentCaptor.getAllValues(), messageArgumentCaptor.getAllValues());
}

@SuppressWarnings("SameParameterValue")
Expand Down Expand Up @@ -238,8 +229,7 @@ public void test_rest_assured_logger_text_body(String mimeType, Object requestBo
String request = logs.get(0);
assertThat(request, equalTo(expectedRequest));

String expectedResponse =
EMPTY_RESPONSE + "\n\n**Body**\n```\n" + prettier.apply((String) responseBody) + "\n```";
String expectedResponse = EMPTY_RESPONSE + "\n\n**Body**\n```\n" + prettier.apply((String) responseBody) + "\n```";
String response = logs.get(1);
assertThat(response, equalTo(expectedResponse));
}
Expand Down Expand Up @@ -322,8 +312,7 @@ public void test_rest_assured_logger_headers_and_cookies(String contentType) {
List<String> logs = runFilterTextMessageCapture(requestSpecification, responseObject);
assertThat(logs, hasSize(2)); // Request + Response

String headerString =
"\n\n**Headers**\n" + HTTP_HEADER + ": " + HTTP_HEADER_VALUE + "\n\n" + formatCookie(cookie);
String headerString = "\n\n**Headers**\n" + HTTP_HEADER + ": " + HTTP_HEADER_VALUE + "\n\n" + formatCookie(cookie);

assertThat(logs.get(0), equalTo(EMPTY_REQUEST + headerString));
assertThat(logs.get(1), equalTo(EMPTY_RESPONSE + headerString));
Expand Down Expand Up @@ -414,19 +403,13 @@ public void test_rest_assured_logger_empty_multipart(List<MultiPartSpecification
assertThat(logs.get(0), equalTo(EMPTY_REQUEST));
}

private MultiPartSpecification getBinaryPart(String mimeType, String filePath, boolean file,
Map<String, String> headers) {
private MultiPartSpecification getBinaryPart(String mimeType, String filePath, boolean file, Map<String, String> headers) {
return new MultiPartSpecification() {
@Override
public Object getContent() {
return file ?
new File(System.getProperty("user.dir") + System.getProperty("file.separator") + String.join(
System.getProperty("file.separator"),
"src",
"test",
"resources",
filePath
)) :
new File(System.getProperty("user.dir") + FileSystems.getDefault().getSeparator()
+ String.join(FileSystems.getDefault().getSeparator(), "src", "test", "resources", filePath)) :
getResource(filePath);
}

Expand Down Expand Up @@ -477,9 +460,7 @@ public void test_rest_assured_logger_image_multipart(boolean isFile) throws IOEx
FilterableRequestSpecification requestSpecification = mockBasicRequest(mimeType);
when(requestSpecification.getMultiPartParams()).thenReturn(Collections.singletonList(part));

Triple<List<String>, List<String>, List<ReportPortalMessage>> logs = runFilterComplexMessageCapture(requestSpecification,
null
);
Triple<List<String>, List<String>, List<ReportPortalMessage>> logs = runFilterComplexMessageCapture(requestSpecification, null);
assertThat(logs.getLeft(), hasSize(1));
assertThat(logs.getMiddle(), hasSize(1));
assertThat(logs.getRight(), hasSize(1));
Expand Down Expand Up @@ -544,18 +525,16 @@ public void test_rest_assured_logger_text_and_image_multipart() throws IOExcepti
getBinaryPart(ContentType.IMAGE_JPEG.getMimeType(), IMAGE, false)
));

Triple<List<String>, List<String>, List<ReportPortalMessage>> logs = runFilterComplexMessageCapture(requestSpecification,
null
);
Triple<List<String>, List<String>, List<ReportPortalMessage>> logs = runFilterComplexMessageCapture(requestSpecification, null);
assertThat(logs.getLeft(), hasSize(1));
assertThat(logs.getMiddle(), hasSize(2));
assertThat(logs.getRight(), hasSize(1));

assertThat(logs.getLeft().get(0), equalTo(EMPTY_REQUEST));

assertThat(logs.getMiddle().get(0),
equalTo(Constants.HEADERS_TAG + "\n" + HttpHeaders.CONTENT_TYPE + ": " + textType + "\n\n"
+ Constants.BODY_PART_TAG + "\n```\n" + message + "\n```")
equalTo(Constants.HEADERS_TAG + "\n" + HttpHeaders.CONTENT_TYPE + ": " + textType + "\n\n" + Constants.BODY_PART_TAG
+ "\n```\n" + message + "\n```")
);
assertThat(logs.getMiddle().get(1), equalTo(NULL_RESPONSE));

Expand Down Expand Up @@ -607,8 +586,7 @@ public void test_rest_assured_logger_invalid_content_type(String mimeType, Strin
public void test_rest_assured_log_filter_type() {
FilterableRequestSpecification requestSpecification = mockBasicRequest(HTML_TYPE);
Response responseObject = mockBasicResponse(HTML_TYPE);
Triple<List<String>, List<String>, List<ReportPortalMessage>> logs = runFilterComplexMessageCapture(
requestSpecification,
Triple<List<String>, List<String>, List<ReportPortalMessage>> logs = runFilterComplexMessageCapture(requestSpecification,
responseObject,
new ReportPortalRestAssuredLoggingFilter(42, LogLevel.INFO).addRequestFilter(r -> true)
);
Expand All @@ -629,18 +607,16 @@ public void test_rest_assured_logger_text_as_file_multipart() {
Collections.singletonMap(HttpHeaders.CONTENT_TYPE, textType)
)));

Triple<List<String>, List<String>, List<ReportPortalMessage>> logs = runFilterComplexMessageCapture(requestSpecification,
null
);
Triple<List<String>, List<String>, List<ReportPortalMessage>> logs = runFilterComplexMessageCapture(requestSpecification, null);
assertThat(logs.getLeft(), hasSize(1));
assertThat(logs.getMiddle(), hasSize(2));
assertThat(logs.getRight(), hasSize(0));

assertThat(logs.getLeft().get(0), equalTo(EMPTY_REQUEST));

assertThat(logs.getMiddle().get(0),
equalTo(Constants.HEADERS_TAG + "\n" + HttpHeaders.CONTENT_TYPE + ": " + textType + "\n\n"
+ Constants.BODY_PART_TAG + "\n```\n" + text + "\n```")
equalTo(Constants.HEADERS_TAG + "\n" + HttpHeaders.CONTENT_TYPE + ": " + textType + "\n\n" + Constants.BODY_PART_TAG
+ "\n```\n" + text + "\n```")
);
assertThat(logs.getMiddle().get(1), equalTo(NULL_RESPONSE));
}
Expand Down