diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4327e47..ffae5c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,9 @@ -# Copyright 2021 EPAM Systems +# Copyright 2022 EPAM Systems # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -16,31 +16,33 @@ name: CI Build on: push: branches: - - '*' - - '!main' + - '*' + - '!main' paths-ignore: - - README.md - - README_TEMPLATE.md - - CHANGELOG.md + - README.md + - README_TEMPLATE.md + - CHANGELOG.md pull_request: branches: - - main + - main jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v3 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 + - name: Set up JDK 1.8 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '8' - - name: Build with Gradle - run: ./gradlew build + - name: Build with Gradle + run: ./gradlew build - - name: Codecov upload - run: bash <(curl -s https://codecov.io/bash) + - name: Codecov upload + run: bash <(curl -s https://codecov.io/bash) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index de5e26f..e70454d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,9 @@ -# Copyright 2021 EPAM Systems +# Copyright 2022 EPAM Systems # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -18,17 +18,17 @@ on: branches: - main paths-ignore: + - '.github/**' - README.md - README_TEMPLATE.md - - gradle.properties - CHANGELOG.md env: VERSION_FILE: gradle.properties VERSION_EXTRACT_PATTERN: '(?<=version=).+' - REPOSITORY_URL: 'https://maven.pkg.github.com/' CHANGE_LOG_FILE: CHANGELOG.md CHANGE_LOG_TMP_FILE: CHANGELOG_updated.md + REPOSITORY_URL: 'https://maven.pkg.github.com/' README_FILE: README.md README_TEMPLATE_FILE: README_TEMPLATE.md README_VERSION_PLACEHOLDER: $LATEST_VERSION @@ -38,22 +38,23 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Generate versions - uses: HardNorth/github-version-generate@v1.2.0 + uses: HardNorth/github-version-generate@v1 with: version-source: file version-file: ${{ env.VERSION_FILE }} version-file-extraction-pattern: ${{ env.VERSION_EXTRACT_PATTERN }} - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: - java-version: 1.8 + distribution: 'temurin' + java-version: '8' - name: Setup git credentials - uses: oleksiyrudenko/gha-git-credentials@v2 + uses: oleksiyrudenko/gha-git-credentials@v2.1.1 with: name: 'reportportal.io' email: 'support@reportportal.io' @@ -70,8 +71,8 @@ jobs: - name: Update README.md id: readmeUpdate run: | - sed 's/${{env.README_VERSION_PLACEHOLDER}}/${{env.RELEASE_VERSION}}/g' ${{env.README_TEMPLATE_FILE}} > ${{env.README_FILE}} - git add ${{env.README_FILE}} + sed 's/${{ env.README_VERSION_PLACEHOLDER }}/${{ env.RELEASE_VERSION }}/g' ${{ env.README_TEMPLATE_FILE }} > ${{ env.README_FILE }} + git add ${{ env.README_FILE }} git commit -m "Readme update" - name: Update CHANGELOG.md @@ -90,25 +91,21 @@ jobs: - name: Read changelog Entry id: readChangelogEntry - uses: mindsers/changelog-reader-action@v1.3.1 + uses: mindsers/changelog-reader-action@v2 with: version: ${{ env.RELEASE_VERSION }} path: ./${{ env.CHANGE_LOG_FILE }} - name: Create Release id: createRelease - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: ncipollo/release-action@v1 with: - tag_name: ${{ env.RELEASE_VERSION }} - release_name: Release ${{ env.RELEASE_VERSION }} - body: ${{ steps.readChangelogEntry.outputs.log_entry }} - draft: false - prerelease: false + tag: ${{ env.RELEASE_VERSION }} + name: Release ${{ env.RELEASE_VERSION }} + body: ${{ steps.readChangelogEntry.outputs.changes }} - name: Checkout develop branch - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: ref: 'develop' fetch-depth: 0 @@ -119,4 +116,4 @@ jobs: git merge -m 'Merge main branch into develop after a release' origin/main git status | (! grep -Fq 'both modified:') || git status | grep -F 'both modified:' \ | { echo -e 'Unable to merge main into develop, merge conflicts:'; (! grep -Eo '[^ ]+$') } - git push + git push origin develop diff --git a/CHANGELOG.md b/CHANGELOG.md index f7fb51f..0428d1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog ## [Unreleased] +### Fixed +- Common field duplication in child class, by @HardNorth +### Changed +- Client version updated on [5.1.15](https://github.com/reportportal/client-java/releases/tag/5.1.15), by @HardNorth +- Some refactoring, by @HardNorth +- `utils-java-formatting` library version updated on version [5.1.4](https://github.com/reportportal/utils-java-formatting/releases/tag/5.1.4), by @HardNorth ## [5.2.1] ### Fixed diff --git a/README.md b/README.md index 837cfce..1c3c7a5 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![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) [![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://reportportal-slack-auto.herokuapp.com/badge.svg)](https://reportportal-slack-auto.herokuapp.com) +[![Join Slack chat!](https://slack.epmrpp.reportportal.io/badge.svg)](https://slack.epmrpp.reportportal.io/) [![stackoverflow](https://img.shields.io/badge/reportportal-stackoverflow-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/reportportal) [![Build with Love](https://img.shields.io/badge/build%20with-❤%EF%B8%8F%E2%80%8D-lightgrey.svg)](http://reportportal.io?style=flat) diff --git a/README_TEMPLATE.md b/README_TEMPLATE.md index 7b089b3..d9200b8 100644 --- a/README_TEMPLATE.md +++ b/README_TEMPLATE.md @@ -3,7 +3,7 @@ [![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) [![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://reportportal-slack-auto.herokuapp.com/badge.svg)](https://reportportal-slack-auto.herokuapp.com) +[![Join Slack chat!](https://slack.epmrpp.reportportal.io/badge.svg)](https://slack.epmrpp.reportportal.io/) [![stackoverflow](https://img.shields.io/badge/reportportal-stackoverflow-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/reportportal) [![Build with Love](https://img.shields.io/badge/build%20with-❤%EF%B8%8F%E2%80%8D-lightgrey.svg)](http://reportportal.io?style=flat) diff --git a/build.gradle b/build.gradle index a841b24..f8d3453 100644 --- a/build.gradle +++ b/build.gradle @@ -38,13 +38,13 @@ repositories { } dependencies { - api 'com.epam.reportportal:client-java:5.1.11' + api 'com.epam.reportportal:client-java:5.1.15' 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') { exclude module: 'commons-codec' } - api 'com.epam.reportportal:utils-java-formatting:5.1.2' + api 'com.epam.reportportal:utils-java-formatting:5.1.4' implementation 'commons-codec:commons-codec:1.15' testImplementation('com.github.reportportal:agent-java-test-utils:236a68c') diff --git a/src/main/java/com/epam/reportportal/restassured/ReportPortalRestAssuredLoggingFilter.java b/src/main/java/com/epam/reportportal/restassured/ReportPortalRestAssuredLoggingFilter.java index cdec970..1e9b71b 100644 --- a/src/main/java/com/epam/reportportal/restassured/ReportPortalRestAssuredLoggingFilter.java +++ b/src/main/java/com/epam/reportportal/restassured/ReportPortalRestAssuredLoggingFilter.java @@ -39,9 +39,6 @@ import java.util.function.Function; import java.util.function.Predicate; -import static com.epam.reportportal.formatting.http.Constants.BODY_TYPE_MAP; -import static com.epam.reportportal.formatting.http.Constants.DEFAULT_PRETTIERS; - /** * REST Assured Request/Response logging filter for Report Portal. *

@@ -64,10 +61,6 @@ public class ReportPortalRestAssuredLoggingFilter extends AbstractHttpFormatter< private final int order; - private Map> contentPrettiers = DEFAULT_PRETTIERS; - - private Map bodyTypeMap = BODY_TYPE_MAP; - /** * Create an ordered REST Assured filter with the log level and different converters. * @@ -89,8 +82,7 @@ public ReportPortalRestAssuredLoggingFilter(int filterOrder, @Nonnull LogLevel d @Nullable Function partHeaderConvertFunction, @Nullable Function cookieConvertFunction, @Nullable Function uriConverterFunction) { - super( - defaultLogLevel, + super(defaultLogLevel, headerConvertFunction, partHeaderConvertFunction, cookieConvertFunction, diff --git a/src/main/java/com/epam/reportportal/restassured/support/HttpEntityFactory.java b/src/main/java/com/epam/reportportal/restassured/support/HttpEntityFactory.java index 18fb768..8e32a2c 100644 --- a/src/main/java/com/epam/reportportal/restassured/support/HttpEntityFactory.java +++ b/src/main/java/com/epam/reportportal/restassured/support/HttpEntityFactory.java @@ -36,9 +36,9 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; -import java.util.Calendar; -import java.util.Map; +import java.util.*; import java.util.function.Function; +import java.util.stream.Collectors; import static com.epam.reportportal.formatting.http.HttpFormatUtils.getBodyType; import static com.epam.reportportal.formatting.http.HttpFormatUtils.getMimeType; @@ -49,6 +49,56 @@ */ public class HttpEntityFactory { + @Nonnull + private static List toParts(@Nonnull FilterableRequestSpecification request, + @Nonnull Map bodyTypeMap, @Nullable Function partHeaderConverter) { + return ofNullable(request.getMultiPartParams()).map(params -> params.stream().map(it -> { + String partMimeType = ofNullable(it.getMimeType()).orElse(ContentType.APPLICATION_OCTET_STREAM.getMimeType()); + try { + Object body = it.getContent(); + HttpPartFormatter.PartType partType; + if (BodyType.TEXT == getBodyType(partMimeType, bodyTypeMap)) { + partType = HttpPartFormatter.PartType.TEXT; + } else { + partType = HttpPartFormatter.PartType.BINARY; + } + + Object content; + if (body instanceof File) { + TypeAwareByteSource file = Utils.getFile((File) body); + byte[] data = file.read(); + if (partType == HttpPartFormatter.PartType.TEXT) { + content = ofNullable(data).map(d -> { + try { + return new String(d, ofNullable(it.getCharset()).orElse(StandardCharsets.UTF_8.name())); + } catch (UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + }).orElse(""); + } else { + content = data; + } + } else { + content = body; + } + HttpPartFormatter.Builder partBuilder = new HttpPartFormatter.Builder(partType, partMimeType, content); + ofNullable(it.getHeaders()).ifPresent(headers -> headers.forEach((key, value) -> partBuilder.addHeader( + new Header(key, value)))); + partBuilder.controlName(it.getControlName()); + partBuilder.charset(it.getCharset()); + partBuilder.fileName(it.getFileName()); + partBuilder.headerConverter(partHeaderConverter); + return partBuilder.build(); + } catch (IOException e) { + ReportPortal.emitLog("Unable to read file: " + e.getMessage(), + "ERROR", + Calendar.getInstance().getTime() + ); + return null; + } + }).filter(Objects::nonNull).collect(Collectors.toList())).orElse(Collections.emptyList()); + } + @Nonnull public static HttpRequestFormatter createHttpRequestFormatter( @Nonnull FilterableRequestSpecification requestSpecification, @@ -88,54 +138,7 @@ public static HttpRequestFormatter createHttpRequestFormatter( builder.bodyParams(requestSpecification.getFormParams()); break; case MULTIPART: - ofNullable(requestSpecification.getMultiPartParams()).ifPresent(params -> params.forEach(it -> { - String partMimeType = ofNullable(it.getMimeType()).orElse(ContentType.APPLICATION_OCTET_STREAM.getMimeType()); - HttpPartFormatter.Builder partBuilder; - try { - Object body = it.getContent(); - HttpPartFormatter.PartType partType; - if (BodyType.TEXT == getBodyType(partMimeType, bodyTypeMap)) { - partType = HttpPartFormatter.PartType.TEXT; - } else { - partType = HttpPartFormatter.PartType.BINARY; - } - - Object content; - if (body instanceof File) { - TypeAwareByteSource file = Utils.getFile((File) body); - byte[] data = file.read(); - if (partType == HttpPartFormatter.PartType.TEXT) { - content = ofNullable(data).map(d -> { - try { - return new String(d, - ofNullable(it.getCharset()).orElse(StandardCharsets.UTF_8.name()) - ); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException(e); - } - }).orElse(""); - } else { - content = data; - } - } else { - content = body; - } - partBuilder = new HttpPartFormatter.Builder(partType, partMimeType, content); - - ofNullable(it.getHeaders()).ifPresent(headers -> headers.forEach((key, value) -> partBuilder.addHeader( - new Header(key, value)))); - partBuilder.controlName(it.getControlName()); - partBuilder.charset(it.getCharset()); - partBuilder.fileName(it.getFileName()); - partBuilder.headerConverter(partHeaderConverter); - builder.addBodyPart(partBuilder.build()); - } catch (IOException e) { - ReportPortal.emitLog("Unable to read file: " + e.getMessage(), - "ERROR", - Calendar.getInstance().getTime() - ); - } - })); + toParts(requestSpecification, bodyTypeMap, partHeaderConverter).forEach(builder::addBodyPart); break; default: builder.bodyBytes(mimeType, requestSpecification.getBody());