diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63c1f5b..790bddf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,11 +34,14 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Set up JDK 1.8 uses: actions/setup-java@v1 with: java-version: 1.8 + - name: Grant execute permission for gradlew run: chmod +x gradlew + - name: Build with Gradle run: ./gradlew build diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml new file mode 100644 index 0000000..9f124a5 --- /dev/null +++ b/.github/workflows/promote.yml @@ -0,0 +1,117 @@ +# Copyright 2021 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 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Promote + +on: + workflow_dispatch: + inputs: + version: + description: 'Release version' + required: true + +env: + REPOSITORY_URL: 'https://maven.pkg.github.com' + UPSTREAM_REPOSITORY_URL: 'https://oss.sonatype.org' + PACKAGE_SUFFIXES: '-javadoc.jar,-javadoc.jar.asc,-sources.jar,-sources.jar.asc,.jar,.jar.asc,.pom,.pom.asc' + PACKAGE: 'com.epam.reportportal' + + +jobs: + build: + runs-on: ubuntu-latest + + steps: + + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + + - name: Get variables + run: | + echo "ARTIFACT=`echo ${{ github.repository }} | cut -d/ -f2- | awk '{print tolower($0)}'`" >> $GITHUB_ENV + echo "PACKAGE_PATH=`echo ${{ env.PACKAGE }} | sed 's/\./\//g'`" >> $GITHUB_ENV + + - name: Upload package + run: | + IFS=',' read -a files <<< '${{ env.PACKAGE_SUFFIXES }}' + for f in ${files[@]}; do + export URL="${{ env.REPOSITORY_URL }}/${{ github.repository }}/${PACKAGE_PATH}/${ARTIFACT}/${{ github.event.inputs.version }}/${ARTIFACT}-${{ github.event.inputs.version }}${f}" + echo "Downloading artifact: ${URL}" + curl -f -u ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} -s -O -L "${URL}" + done + files=($(ls)) + echo 'Files downloaded:' + echo "${files[@]}" + + echo 'Bundle generation' + export BUNDLE_FILE="bundle.jar" + jar -cvf ${BUNDLE_FILE} "${files[@]}" + + echo 'Bundle upload' + curl -u ${{ secrets.SONATYPE_USER }}:${{ secrets.SONATYPE_PASSWORD }} -L \ + --request POST '${{ env.UPSTREAM_REPOSITORY_URL }}/service/local/staging/bundle_upload' \ + --form "file=@${BUNDLE_FILE}" >response.json + + response_type=`jq type response.json || echo ''` + if [ -z "$response_type" ]; then + echo 'ERROR: Response is not JSON!' 1>&2 + cat response.json 1>&2 + exit 1 + fi + + repo=`jq -r '.repositoryUris[0]' response.json` + if [ -z "$repo" ]; then + echo 'Unable to upload bundle' 1>&2 + cat response.json 1>&2 + exit 1 + fi + + echo "NEXUS_REPOSITORY=${repo}" >> $GITHUB_ENV + + - name: Get repository variables + run: | + echo "NEXUS_REPOSITORY_NAME=`echo ${NEXUS_REPOSITORY} | sed -E 's/(.+)\/([^\/]+)$/\2/'`" >> $GITHUB_ENV + + - name: Promote package + env: + ATTEMPTS: 60 + SLEEP_TIME: 10 + run: | + verified=false + for i in `seq 0 ${ATTEMPTS}`; do + sleep $SLEEP_TIME + curl -f -s -u ${{ secrets.SONATYPE_USER }}:${{ secrets.SONATYPE_PASSWORD }} -L \ + --header 'Accept: application/json' \ + ${{ env.UPSTREAM_REPOSITORY_URL }}/service/local/staging/repository/${NEXUS_REPOSITORY_NAME} >result.json + + is_closed=`jq -r '.type' result.json` + is_transitioning=`jq -r '.transitioning' result.json` + echo "Current repository status: $is_closed; transitioning: $is_transitioning" + + if [[ "$is_closed" == "closed" && "$is_transitioning" == "false" ]]; then + verified=true + break + fi + done + if $verified; then + echo "A bundle was verified, releasing" + curl -f -u ${{ secrets.SONATYPE_USER }}:${{ secrets.SONATYPE_PASSWORD }} -L \ + --header 'Content-Type: application/json' \ + --data-raw "{\"data\":{\"stagedRepositoryIds\":[\"${NEXUS_REPOSITORY_NAME}\"], \"description\":\"Releasing ${{ github.event.inputs.version }}\"}}" \ + --request POST ${{ env.UPSTREAM_REPOSITORY_URL }}/service/local/staging/bulk/promote + else + echo 'Verification failed, please check the bundle' 1>&2 + exit 1 + fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 67bd58b..3c730e6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,7 +27,7 @@ on: env: VERSION_FILE: gradle.properties VERSION_EXTRACT_PATTERN: '(?<=version=).+' - GH_USER_NAME: github.actor + REPOSITORY_URL: 'https://maven.pkg.github.com/' CHANGE_LOG_FILE: CHANGELOG.md CHANGE_LOG_TMP_FILE: CHANGELOG_updated.md README_FILE: README.md @@ -42,7 +42,7 @@ jobs: uses: actions/checkout@v2 - name: Generate versions - uses: HardNorth/github-version-generate@v1.0.2 + uses: HardNorth/github-version-generate@v1.1.1 with: version-source: file version-file: ${{ env.VERSION_FILE }} @@ -61,14 +61,18 @@ jobs: with: name: 'reportportal.io' email: 'support@reportportal.io' - token: ${{ secrets.GH_TOKEN }} + token: ${{ secrets.GITHUB_TOKEN }} - name: Release with Gradle id: release run: | - ./gradlew release -PreleaseMode -Prelease.useAutomaticVersion=true -Prelease.releaseVersion=${{env.RELEASE_VERSION}} \ - -Prelease.newVersion=${{env.NEXT_VERSION}} -PbintrayUser=${{secrets.BINTRAY_USER}} -PbintrayApiKey=${{secrets.BINTRAY_API_KEY}} \ - -PgithubUserName=${{env.GH_USER_NAME}} -PgithubToken=${{secrets.GITHUB_TOKEN}} + ./gradlew release -Prelease.useAutomaticVersion=true -Prelease.releaseVersion=${{ env.RELEASE_VERSION }} \ + -Prelease.newVersion=${{ env.NEXT_VERSION }} -PpublishRepo=${{ env.REPOSITORY_URL }}${{ github.repository }} \ + -PgithubUserName=${{ github.actor }} -PgithubToken=${{ secrets.GITHUB_TOKEN }} \ + -PgpgPassphrase=${{ secrets.GPG_PASSPHRASE }} -PgpgPrivateKey="$(cat <<'EOF' + ${{ secrets.GPG_PRIVATE_KEY }} + EOF + )" - name: Update README.md id: readmeUpdate @@ -102,7 +106,7 @@ jobs: id: createRelease uses: actions/create-release@v1 env: - GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ env.RELEASE_VERSION }} release_name: Release ${{ env.RELEASE_VERSION }} @@ -111,7 +115,7 @@ jobs: prerelease: false - name: Checkout develop branch - if: ${{github.ref}} == 'master' + if: ${{ github.ref }} == 'master' uses: actions/checkout@v2 with: ref: 'develop' @@ -119,7 +123,7 @@ jobs: - name: Merge release branch into develop id: mergeIntoDevelop - if: ${{github.ref}} == 'master' + if: ${{ github.ref }} == 'master' run: | git merge -m 'Merge master branch into develop after a release' origin/master git status | (! grep -Fq 'both modified:') || git status | grep -F 'both modified:' \ diff --git a/CHANGELOG.md b/CHANGELOG.md index e0b221f..256ea9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog ## [Unreleased] +### Changed +- Client version updated on [5.1.0-RC-6](https://github.com/reportportal/client-java/releases/tag/5.1.0-RC-6) +- Version changed on 5.1.0 + +## [5.1.0-ALPHA-1] +### Changed +- Client version updated on [5.1.0-ALPHA-5](https://github.com/reportportal/client-java/releases/tag/5.1.0-ALPHA-5) ## [5.0.0] ### Added diff --git a/README.md b/README.md index 6c5d685..db77ad3 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,14 @@ > after a successful launch start. This information might help us to improve both ReportPortal backend and client sides. It is used by the > ReportPortal team only and is not supposed for sharing with 3rd parties. +[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/agent-java-junit.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22agent-java-junit%22) ![CI Build](https://github.com/reportportal/agent-java-junit/workflows/CI%20Build/badge.svg?branch=develop) -[ ![Download](https://api.bintray.com/packages/epam/reportportal/agent-java-junit/images/download.svg) ](https://bintray.com/epam/reportportal/agent-java-junit/_latestVersion) [![Join Slack chat!](https://reportportal-slack-auto.herokuapp.com/badge.svg)](https://reportportal-slack-auto.herokuapp.com) [![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) #### Overview: How to Add ReportPortal Logging to Your JUnit Java Project +Report Portal supports JUnit 4 tests. The integration is built on top of [JUnit Foundation](https://github.com/sbabcoc/JUnit-Foundation) framework by [Scott Babcock](https://github.com/sbabcoc). 1. [Configuration](#configuration): Create/update the **_reportportal.properties_** configuration file 2. [Logback Framework](#logback-framework): For the Logback framework: @@ -89,18 +90,7 @@ In your project, create or update a file named logback.xml in the src/main/resou 1.8 1.8 - - - - bintray - http://dl.bintray.com/epam/reportportal - - - jitpack.io - https://jitpack.io - - - + ch.qos.logback @@ -189,17 +179,6 @@ In your project, create or update a file named logback.xml in the src/main/resou 1.8 1.8 - - - - bintray - http://dl.bintray.com/epam/reportportal - - - jitpack.io - https://jitpack.io - - @@ -293,9 +272,6 @@ description = 'ReportPortal JUnit 4 example' repositories { mavenLocal() mavenCentral() - jcenter() - maven { url 'https://jitpack.io' } - maven { url "http://dl.bintray.com/epam/reportportal" } } dependencies { @@ -414,22 +390,7 @@ We’ll assume that Report Portal is installed and running on - - bintray - http://dl.bintray.com/epam/reportportal - - - jitpack.io - https://jitpack.io - - -``` - -##### 2.2 Add following dependencies: +##### 2.1 Add following dependencies: *Report Portal agent implementation for JUnit 4* ```xml @@ -440,11 +401,11 @@ We’ll assume that Report Portal is installed and running on test ``` -Note that `agent-java-junit` brings in `JUnit 4.12` and the `JUnit Foundation` library as transitive dependencies, so these don't need to be declared explicitly in your project. +Note that `agent-java-junit` brings in `JUnit` and the `JUnit Foundation` library as transitive dependencies, so these don't need to be declared explicitly in your project. -> Latest version of the agent, could be found [here](https://bintray.com/epam/reportportal/agent-java-junit) +> Latest version of the agent, could be found [here](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22agent-java-junit%22) -##### 2.3 Add Report Portal dedicated logger wrapper +##### 2.2 Add Report Portal dedicated logger wrapper If you prefer using **Logback** logging library, add following dependencies: @@ -456,7 +417,7 @@ If you prefer using **Logback** logging library, add following dependencies: 5.0.3 ``` -> Up to date version could be found [here](https://bintray.com/epam/reportportal/logger-java-logback) +> Up to date version could be found [here](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22logger-java-logback%22) *The logback itself* ```xml @@ -477,7 +438,7 @@ If you prefer using **Log4j** logging library, add following dependencies: 5.0.3 ``` -> Up to date version could be found [here](https://bintray.com/epam/reportportal/logger-java-log4j) +> Up to date version could be found [here](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22logger-java-log4j%22) *The log4j itself* ```xml @@ -697,17 +658,6 @@ in this case - add a `maven dependency plugin` dependency explicitly, like this: myProject 1.0-SNAPSHOT - - - bintray - http://dl.bintray.com/epam/reportportal - - - jitpack.io - https://jitpack.io - - - com.epam.reportportal @@ -819,7 +769,7 @@ You can put the jar directly in the project tree or use the one, that Maven down On MAC OS system the path to maven downloaded junit-foundation.jar would have the following format: ```shell -/Users//.m2/repository/com/nordstrom/tools/junit-foundation/9.4.3/junit-foundation-9.4.3.jar +/Users//.m2/repository/com/nordstrom/tools/junit-foundation/12.5.3/junit-foundation-12.5.3.jar ``` When you are done adding local run configuration, simply go to *Run* -> *Run ''* and that test run results will be sent to Report Portal @@ -844,9 +794,6 @@ targetCompatibility = 1.8 repositories { mavenLocal() mavenCentral() - jcenter() - maven { url 'https://jitpack.io' } - maven { url "http://dl.bintray.com/epam/reportportal" } } dependencies { diff --git a/README_TEMPLATE.md b/README_TEMPLATE.md index 3bdbd8f..9cd74e5 100644 --- a/README_TEMPLATE.md +++ b/README_TEMPLATE.md @@ -4,13 +4,14 @@ > after a successful launch start. This information might help us to improve both ReportPortal backend and client sides. It is used by the > ReportPortal team only and is not supposed for sharing with 3rd parties. +[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/agent-java-junit.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22agent-java-junit%22) ![CI Build](https://github.com/reportportal/agent-java-junit/workflows/CI%20Build/badge.svg?branch=develop) -[ ![Download](https://api.bintray.com/packages/epam/reportportal/agent-java-junit/images/download.svg) ](https://bintray.com/epam/reportportal/agent-java-junit/_latestVersion) [![Join Slack chat!](https://reportportal-slack-auto.herokuapp.com/badge.svg)](https://reportportal-slack-auto.herokuapp.com) [![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) -#### Overview: How to Add ReportPortal Logging to Your JUnit Java Project +### Overview: How to Add ReportPortal Logging to Your JUnit Java Project +Report Portal supports JUnit 4 tests. The integration is built on top of [JUnit Foundation](https://github.com/sbabcoc/JUnit-Foundation) framework by [Scott Babcock](https://github.com/sbabcoc). 1. [Configuration](#configuration): Create/update the **_reportportal.properties_** configuration file 2. [Logback Framework](#logback-framework): For the Logback framework: @@ -89,18 +90,7 @@ In your project, create or update a file named logback.xml in the src/main/resou 1.8 1.8 - - - - bintray - http://dl.bintray.com/epam/reportportal - - - jitpack.io - https://jitpack.io - - - + ch.qos.logback @@ -189,18 +179,7 @@ In your project, create or update a file named logback.xml in the src/main/resou 1.8 1.8 - - - - bintray - http://dl.bintray.com/epam/reportportal - - - jitpack.io - https://jitpack.io - - - + org.apache.logging.log4j @@ -293,9 +272,6 @@ description = 'ReportPortal JUnit 4 example' repositories { mavenLocal() mavenCentral() - jcenter() - maven { url 'https://jitpack.io' } - maven { url "http://dl.bintray.com/epam/reportportal" } } dependencies { @@ -414,22 +390,7 @@ We’ll assume that Report Portal is installed and running on - - bintray - http://dl.bintray.com/epam/reportportal - - - jitpack.io - https://jitpack.io - - -``` - -##### 2.2 Add following dependencies: +##### 2.1 Add following dependencies: *Report Portal agent implementation for JUnit 4* ```xml @@ -440,11 +401,11 @@ We’ll assume that Report Portal is installed and running on test ``` -Note that `agent-java-junit` brings in `JUnit 4.12` and the `JUnit Foundation` library as transitive dependencies, so these don't need to be declared explicitly in your project. +Note that `agent-java-junit` brings in `JUnit` and the `JUnit Foundation` library as transitive dependencies, so these don't need to be declared explicitly in your project. -> Latest version of the agent, could be found [here](https://bintray.com/epam/reportportal/agent-java-junit) +> Latest version of the agent, could be found [here](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22agent-java-junit%22) -##### 2.3 Add Report Portal dedicated logger wrapper +##### 2.2 Add Report Portal dedicated logger wrapper If you prefer using **Logback** logging library, add following dependencies: @@ -456,7 +417,7 @@ If you prefer using **Logback** logging library, add following dependencies: 5.0.3 ``` -> Up to date version could be found [here](https://bintray.com/epam/reportportal/logger-java-logback) +> Up to date version could be found [here](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22logger-java-logback%22) *The logback itself* ```xml @@ -477,7 +438,7 @@ If you prefer using **Log4j** logging library, add following dependencies: 5.0.3 ``` -> Up to date version could be found [here](https://bintray.com/epam/reportportal/logger-java-log4j) +> Up to date version could be found [here](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22logger-java-log4j%22) *The log4j itself* ```xml @@ -697,17 +658,6 @@ in this case - add a `maven dependency plugin` dependency explicitly, like this: myProject 1.0-SNAPSHOT - - - bintray - http://dl.bintray.com/epam/reportportal - - - jitpack.io - https://jitpack.io - - - com.epam.reportportal @@ -819,7 +769,7 @@ You can put the jar directly in the project tree or use the one, that Maven down On MAC OS system the path to maven downloaded junit-foundation.jar would have the following format: ```shell -/Users//.m2/repository/com/nordstrom/tools/junit-foundation/9.4.3/junit-foundation-9.4.3.jar +/Users//.m2/repository/com/nordstrom/tools/junit-foundation/12.5.3/junit-foundation-12.5.3.jar ``` When you are done adding local run configuration, simply go to *Run* -> *Run ''* and that test run results will be sent to Report Portal @@ -844,9 +794,6 @@ targetCompatibility = 1.8 repositories { mavenLocal() mavenCentral() - jcenter() - maven { url 'https://jitpack.io' } - maven { url "http://dl.bintray.com/epam/reportportal" } } dependencies { diff --git a/build.gradle b/build.gradle index 6d8b139..207f463 100644 --- a/build.gradle +++ b/build.gradle @@ -13,63 +13,41 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +apply plugin: 'java-library' -plugins { - id 'java-library' -} - -project.ext.releaseMode = project.hasProperty('releaseMode') - -def branch = releaseMode ? '5.0.0' : 'develop' -apply from: "https://raw.githubusercontent.com/reportportal/gradle-scripts/$branch/build-quality.gradle" -apply from: "https://raw.githubusercontent.com/reportportal/gradle-scripts/$branch/release-commons.gradle" +apply from: "${project.scripts_url}/${project.scripts_branch}/build-quality.gradle" +apply from: "${project.scripts_url}/${project.scripts_branch}/release-commons.gradle" +apply from: "${project.scripts_url}/${project.scripts_branch}/signing.gradle" sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 repositories { - mavenLocal() + mavenCentral() maven { url 'https://jitpack.io' } - maven { url "http://dl.bintray.com/epam/reportportal" } - jcenter() -} - -project.ext.githubUserName = project.hasProperty('githubUserName') ? githubUserName : "" -project.ext.githubToken = project.hasProperty('githubToken') ? githubToken : "" - -publishing { - repositories { - maven { - name = "JUnit 4 GitHub Packages" - url = uri("https://maven.pkg.github.com/reportportal/agent-java-junit") - credentials { - username = githubUserName - password = githubToken - } - } - } } dependencies { - api 'com.epam.reportportal:client-java:5.0.18' + api 'com.epam.reportportal:client-java:5.1.0-RC-6' api 'com.epam.reportportal:commons-model:5.0.0' - api 'com.nordstrom.tools:junit-foundation:12.5.3' + api 'com.nordstrom.tools:junit-foundation:15.3.0' api 'com.google.code.findbugs:jsr305:3.0.2' + implementation 'org.slf4j:slf4j-api:1.7.25' + testImplementation 'com.github.reportportal:agent-java-test-utils:ddcf50ee20' testImplementation 'org.aspectj:aspectjweaver:1.9.2' testImplementation 'org.hamcrest:hamcrest-core:2.2' testImplementation "org.mockito:mockito-core:${project.mockito_version}" + testImplementation "org.mockito:mockito-junit-jupiter:${project.mockito_version}" testImplementation 'ch.qos.logback:logback-classic:1.2.3' testImplementation 'com.epam.reportportal:logger-java-logback:5.0.3' - testImplementation ("org.junit.platform:junit-platform-runner:${project.junit5_launcher_version}") { + testImplementation ("org.junit.platform:junit-platform-runner:${project.junit5_runner_version}") { exclude module: 'junit' } - testImplementation "org.junit.platform:junit-platform-launcher:${project.junit5_launcher_version}" testImplementation "org.junit.jupiter:junit-jupiter-api:${project.junit5_version}" testImplementation "org.junit.jupiter:junit-jupiter-params:${project.junit5_version}" testImplementation "org.junit.jupiter:junit-jupiter-engine:${project.junit5_version}" - testImplementation "org.mockito:mockito-junit-jupiter:${project.mockito_version}" testImplementation 'org.apache.commons:commons-io:1.3.2' testImplementation 'pl.pragmatists:JUnitParams:1.1.1' testImplementation "org.powermock:powermock-module-junit4:${project.powermock_version}" @@ -87,7 +65,7 @@ test { jvmArgs += "-javaagent:${junitFoundation.file}" jvmArgs += "-javaagent:$weaver" } - + environment "AGENT_NO_ANALYTICS", "1" testLogging { events "failed" exceptionFormat "full" @@ -103,7 +81,3 @@ processResources { expand(project.properties) } } - -def releaseDependencies = [bintrayUpload, publish] -releaseDependencies.addAll(afterReleaseBuild.getDependsOn()) -afterReleaseBuild.setDependsOn(releaseDependencies) diff --git a/gradle.properties b/gradle.properties index bdfc15b..ebd7768 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,8 @@ -version=5.0.1-SNAPSHOT +version=5.1.0-RC-1-SNAPSHOT description=ReportPortal JUnit 4 client junit5_version=5.6.3 -junit5_launcher_version=1.6.2 +junit5_runner_version=1.6.3 mockito_version=3.3.3 powermock_version=2.0.9 +scripts_url=https://raw.githubusercontent.com/reportportal/gradle-scripts/ +scripts_branch=develop diff --git a/src/main/java/com/epam/reportportal/junit/ReportPortalListener.java b/src/main/java/com/epam/reportportal/junit/ReportPortalListener.java index 24fbb5c..abff1ab 100644 --- a/src/main/java/com/epam/reportportal/junit/ReportPortalListener.java +++ b/src/main/java/com/epam/reportportal/junit/ReportPortalListener.java @@ -72,7 +72,7 @@ * launch should be unique. (User shouldn't run the same classes twice/or more * times in the one launch) */ -public class ReportPortalListener implements ShutdownListener, RunnerWatcher, RunWatcher, MethodWatcher { +public class ReportPortalListener implements ShutdownListener, RunnerWatcher, RunWatcher, MethodWatcher { private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalListener.class); @@ -80,7 +80,9 @@ public class ReportPortalListener implements ShutdownListener, RunnerWatcher, Ru private static final String START_TIME = "START_TIME"; private static final String IS_RETRY = "IS_RETRY"; private static final String IS_THEORY = "IS_THEORY"; - private static final Map, ItemType> TYPE_MAP = Collections.unmodifiableMap(new HashMap, ItemType>() {{ + private static final Map, ItemType> TYPE_MAP = Collections.unmodifiableMap(new HashMap, ItemType>() { + private static final long serialVersionUID = 5292344734560662610L; + { put(Test.class, ItemType.STEP); put(Before.class, ItemType.BEFORE_METHOD); put(After.class, ItemType.AFTER_METHOD); @@ -342,7 +344,7 @@ protected Date getDateForChild(@Nullable final TestItemTree.TestItemLeaf parentL * * @param testContext {@link AtomicTest} object for test method */ - protected void startTest(@Nonnull final AtomicTest testContext) { + protected void startTest(@Nonnull final AtomicTest testContext) { FrameworkMethod method = testContext.getIdentity(); if (!ofNullable(method.getAnnotation(Theory.class)).isPresent()) { context.setTestStatus(createItemTreeKey(method, getStepParameters(testContext)), ItemStatus.PASSED); @@ -355,7 +357,7 @@ protected void startTest(@Nonnull final AtomicTest testContext) * * @param testContext {@link AtomicTest} object for test method */ - protected void finishTest(@Nonnull final AtomicTest testContext) { + protected void finishTest(@Nonnull final AtomicTest testContext) { FrameworkMethod method = testContext.getIdentity(); TestItemTree.ItemTreeKey key = ofNullable(method.getAnnotation(Theory.class)).map(T -> createItemTreeKey(method)) .orElseGet(() -> createItemTreeKey(method, getStepParameters(testContext))); @@ -487,17 +489,22 @@ protected void reportSkippedStep(@Nonnull final Object runner, @Nonnull final Fr TestItemTree.TestItemLeaf testLeaf = ofNullable(getLeaf(runner)).orElseGet(() -> context.getItemTree() .getTestItems() .get(myParentKey)); - AtomicTest testContext = LifecycleHooks.getAtomicTestOf(runner); - Description description = testContext.getDescription(); - FrameworkMethod method = testContext.getIdentity(); - ofNullable(testLeaf).ifPresent(l -> { - StartTestItemRQ startRq = buildStartStepRq(runner, description, method, callable, skipStartTime); - Maybe id = launch.get().startTestItem(l.getItemId(), startRq); - ofNullable(throwable).ifPresent(t -> sendReportPortalMsg(id, LogLevel.WARN, throwable)); - FinishTestItemRQ finishRq = buildFinishStepRq(method, ItemStatus.SKIPPED); - finishRq.setIssue(Launch.NOT_ISSUE); - launch.get().finishTestItem(id, finishRq); - }); + try { + Object target = LifecycleHooks.getFieldValue(callable, "val$target"); + AtomicTest testContext = LifecycleHooks.getAtomicTestOf(target); + Description description = testContext.getDescription(); + FrameworkMethod method = testContext.getIdentity(); + ofNullable(testLeaf).ifPresent(l -> { + StartTestItemRQ startRq = buildStartStepRq(runner, description, method, callable, skipStartTime); + Maybe id = launch.get().startTestItem(l.getItemId(), startRq); + ofNullable(throwable).ifPresent(t -> sendReportPortalMsg(id, LogLevel.WARN, throwable)); + FinishTestItemRQ finishRq = buildFinishStepRq(method, ItemStatus.SKIPPED); + finishRq.setIssue(Launch.NOT_ISSUE); + launch.get().finishTestItem(id, finishRq); + }); + } catch (IllegalAccessException | NoSuchFieldException | SecurityException e) { + // nothing to do here + } } /** @@ -588,7 +595,7 @@ protected void stopTestMethod(@Nonnull final Object runner, @Nonnull final Frame * @param testContext {@link AtomicTest} object for test method * @param thrown a Throwable thrown by method */ - protected void setTestFailure(@Nonnull final AtomicTest testContext, @Nullable final Throwable thrown) { + protected void setTestFailure(@Nonnull final AtomicTest testContext, @Nullable final Throwable thrown) { FrameworkMethod method = testContext.getIdentity(); TestItemTree.ItemTreeKey key = ofNullable(method.getAnnotation(Theory.class)).map(a -> createItemTreeKey(testContext.getIdentity())) .orElseGet(() -> createItemTreeKey(testContext.getIdentity(), getStepParameters(testContext))); @@ -601,25 +608,25 @@ protected void setTestFailure(@Nonnull final AtomicTest testCon * * @param testContext {@link AtomicTest} object for test method */ - protected void handleTestSkip(@Nonnull final AtomicTest testContext) { + protected void handleTestSkip(@Nonnull final AtomicTest testContext) { List parameters = getStepParameters(testContext); TestItemTree.ItemTreeKey key = createItemTreeKey(testContext.getIdentity(), parameters); context.setTestStatus(key, ItemStatus.SKIPPED); Object runner = testContext.getRunner(); FrameworkMethod method = testContext.getIdentity(); - Object target = getTargetForRunner(runner); - ReflectiveCallable callable = LifecycleHooks.encloseCallable(method.getMethod(), target); TestItemTree.ItemTreeKey myKey = createItemTreeKey(method, parameters); TestItemTree.TestItemLeaf myLeaf = ofNullable(retrieveLeaf(runner).getChildItems().get(myKey)).orElse(null); if (myLeaf == null) { // a test method wasn't started, most likely an ignored test: start and stop a test item with 'skipped' status + ReflectiveCallable callable = LifecycleHooks.encloseCallable(method.getMethod(), null); + startTest(testContext); startTestMethod(runner, method, callable); stopTestMethod(runner, method, callable, ItemStatus.SKIPPED, null); } else { // a test method started FinishTestItemRQ rq; - if (testContext.getDescription().getAnnotation(RetriedTest.class) != null) { + if (RetriedTest.isRetriedTest(testContext.getDescription())) { // a retry, send an item update with retry flag rq = buildFinishStepRq(method, myLeaf.getStatus()); rq.setRetry(true); @@ -628,6 +635,7 @@ protected void handleTestSkip(@Nonnull final AtomicTest testCon rq = buildFinishStepRq(method, ItemStatus.SKIPPED); myLeaf.setStatus(ItemStatus.SKIPPED); } + ReflectiveCallable callable = LifecycleHooks.getCallableOf(testContext.getDescription()); stopTestMethod(runner, method, callable, rq); } } @@ -638,7 +646,7 @@ protected void handleTestSkip(@Nonnull final AtomicTest testCon * @param testContext {@link AtomicTest} object for test method * @param thrown a Throwable thrown by method */ - protected void setTestSkip(@Nonnull final AtomicTest testContext, @Nullable final Throwable thrown) { + protected void setTestSkip(@Nonnull final AtomicTest testContext, @Nullable final Throwable thrown) { TestItemTree.ItemTreeKey key = createItemTreeKey(testContext.getIdentity(), getStepParameters(testContext)); context.setTestStatus(key, ItemStatus.SKIPPED); context.setTestThrowable(key, thrown); @@ -857,10 +865,10 @@ protected TestCaseIdEntry getTestCaseId(@Nullable final Object runner, @Nonn * @return Test/Step Parameters being sent to Report Portal or 'null' if empty or not exist */ @Nullable - protected List getStepParameters(@Nonnull final AtomicTest test) { + protected List getStepParameters(@Nonnull final AtomicTest test) { Object runner = test.getRunner(); FrameworkMethod identity = test.getIdentity(); - return getStepParameters(identity, runner, LifecycleHooks.encloseCallable(identity.getMethod(), getTargetForRunner(runner))); + return getStepParameters(identity, runner, LifecycleHooks.getCallableOf(test.getDescription())); } /** @@ -891,7 +899,7 @@ protected List getMethodParameters(@Nonnull final FrameworkMe @Nonnull final ReflectiveCallable callable) { List result = new ArrayList<>(); if (!(method.isStatic())) { - Object target = getTargetForRunner(runner); + Object target = getTargetFor(runner, method); if (target instanceof ArtifactParams) { //noinspection Guava com.google.common.base.Optional> params = ((ArtifactParams) target).getParameters(); @@ -914,7 +922,7 @@ protected List getMethodParameters(@Nonnull final FrameworkMe } catch (NoSuchFieldException e) { LOGGER.warn("Unable to get parameters for parameterized runner", e); } - } else { + } else if (callable != null) { try { Object[] params = (Object[]) Accessible.on(callable).field("val$params").getValue(); result.addAll(ParameterUtils.getParameters(method.getMethod(), Arrays.asList(params))); @@ -932,11 +940,13 @@ protected List getMethodParameters(@Nonnull final FrameworkMe * NOTE: This shim enables subclasses of this handler to supply custom instances. * * @param runner JUnit class runner + * @param method JUnit framework method context * @return JUnit test class instance for specified runner */ @Nullable - protected Object getTargetForRunner(@Nonnull final Object runner) { - return LifecycleHooks.getTargetForRunner(runner); + protected Object getTargetFor(@Nonnull final Object runner, @Nonnull final FrameworkMethod method) { + Description description = LifecycleHooks.describeChild(runner, method); + return LifecycleHooks.getTargetOf(description); } /** @@ -1052,7 +1062,7 @@ public void runFinished(Object runner) { * {@inheritDoc} */ @Override - public void testStarted(AtomicTest atomicTest) { + public void testStarted(AtomicTest atomicTest) { startTest(atomicTest); } @@ -1060,7 +1070,7 @@ public void testStarted(AtomicTest atomicTest) { * {@inheritDoc} */ @Override - public void testFinished(AtomicTest atomicTest) { + public void testFinished(AtomicTest atomicTest) { finishTest(atomicTest); } @@ -1068,7 +1078,7 @@ public void testFinished(AtomicTest atomicTest) { * {@inheritDoc} */ @Override - public void testFailure(AtomicTest atomicTest, Throwable thrown) { + public void testFailure(AtomicTest atomicTest, Throwable thrown) { setTestFailure(atomicTest, thrown); } @@ -1076,7 +1086,7 @@ public void testFailure(AtomicTest atomicTest, Throwable thrown * {@inheritDoc} */ @Override - public void testAssumptionFailure(AtomicTest atomicTest, AssumptionViolatedException thrown) { + public void testAssumptionFailure(AtomicTest atomicTest, AssumptionViolatedException thrown) { setTestSkip(atomicTest, thrown); } @@ -1084,7 +1094,7 @@ public void testAssumptionFailure(AtomicTest atomicTest, Assump * {@inheritDoc} */ @Override - public void testIgnored(AtomicTest atomicTest) { + public void testIgnored(AtomicTest atomicTest) { handleTestSkip(atomicTest); } diff --git a/src/main/java/com/epam/reportportal/junit/utils/ItemTreeUtils.java b/src/main/java/com/epam/reportportal/junit/utils/ItemTreeUtils.java index 68b876e..0df051c 100644 --- a/src/main/java/com/epam/reportportal/junit/utils/ItemTreeUtils.java +++ b/src/main/java/com/epam/reportportal/junit/utils/ItemTreeUtils.java @@ -63,7 +63,7 @@ public static TestItemTree.ItemTreeKey createItemTreeKey(@Nonnull FrameworkMetho } @Nonnull - public static TestItemTree.ItemTreeKey createItemTreeKey(@Nonnull AtomicTest test) { + public static TestItemTree.ItemTreeKey createItemTreeKey(@Nonnull AtomicTest test) { return TestItemTree.ItemTreeKey.of(test.getDescription().getDisplayName()); } diff --git a/src/test/java/com/epam/reportportal/junit/assumption/AssumptionSkipTest.java b/src/test/java/com/epam/reportportal/junit/assumption/AssumptionSkipTest.java index a3ef730..25ac3b2 100644 --- a/src/test/java/com/epam/reportportal/junit/assumption/AssumptionSkipTest.java +++ b/src/test/java/com/epam/reportportal/junit/assumption/AssumptionSkipTest.java @@ -21,12 +21,12 @@ import com.epam.reportportal.junit.utils.TestUtils; import com.epam.reportportal.listeners.ItemStatus; import com.epam.reportportal.listeners.LogLevel; -import com.epam.reportportal.restendpoint.http.MultiPartRequest; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; +import okhttp3.MultipartBody; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -36,6 +36,7 @@ import java.util.stream.Collectors; import static com.epam.reportportal.junit.utils.TestUtils.PROCESSING_TIMEOUT; +import static com.epam.reportportal.junit.utils.TestUtils.toSaveLogRQ; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.mockito.Mockito.*; @@ -61,20 +62,13 @@ public void verify_assumption_violated_test_logs_message_and_marked_as_skipped() ArgumentCaptor captor = ArgumentCaptor.forClass(FinishTestItemRQ.class); verify(client, timeout(PROCESSING_TIMEOUT)).finishTestItem(same(methodId), captor.capture()); - ArgumentCaptor logCaptor = ArgumentCaptor.forClass(MultiPartRequest.class); + ArgumentCaptor> logCaptor = ArgumentCaptor.forClass(List.class); verify(client, timeout(PROCESSING_TIMEOUT).atLeastOnce()).log(logCaptor.capture()); FinishTestItemRQ item = captor.getAllValues().get(0); assertThat(item.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.SKIPPED.name()))); - List expectedErrorList = logCaptor.getAllValues() - .stream() - .flatMap(l -> l.getSerializedRQs().stream()) - .map(MultiPartRequest.MultiPartSerialized::getRequest) - .filter(l -> l instanceof List) - .flatMap(l -> ((List) l).stream()) - .filter(l -> l instanceof SaveLogRQ) - .map(l -> (SaveLogRQ) l) + List expectedErrorList = toSaveLogRQ(logCaptor.getAllValues()).stream() .filter(l -> LogLevel.WARN.name().equals(l.getLevel())) .filter(l -> l.getMessage() != null && l.getMessage().contains(AssumptionViolatedTest.VIOLATION_MESSAGE)) .collect(Collectors.toList()); diff --git a/src/test/java/com/epam/reportportal/junit/assumption/ParameterizedAssumptionSkipTest.java b/src/test/java/com/epam/reportportal/junit/assumption/ParameterizedAssumptionSkipTest.java index 1ebeabc..ee5d2b5 100644 --- a/src/test/java/com/epam/reportportal/junit/assumption/ParameterizedAssumptionSkipTest.java +++ b/src/test/java/com/epam/reportportal/junit/assumption/ParameterizedAssumptionSkipTest.java @@ -21,12 +21,12 @@ import com.epam.reportportal.junit.utils.TestUtils; import com.epam.reportportal.listeners.ItemStatus; import com.epam.reportportal.listeners.LogLevel; -import com.epam.reportportal.restendpoint.http.MultiPartRequest; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; +import okhttp3.MultipartBody; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -37,6 +37,7 @@ import java.util.stream.Stream; import static com.epam.reportportal.junit.utils.TestUtils.PROCESSING_TIMEOUT; +import static com.epam.reportportal.junit.utils.TestUtils.toSaveLogRQ; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.mockito.Mockito.*; @@ -63,7 +64,7 @@ public void verify_assumption_violated_parameterized_test_logs_message_and_marke ArgumentCaptor captor = ArgumentCaptor.forClass(FinishTestItemRQ.class); verify(client, timeout(PROCESSING_TIMEOUT)).finishTestItem(same(methodIds.get(0)), captor.capture()); verify(client, timeout(PROCESSING_TIMEOUT)).finishTestItem(same(methodIds.get(1)), captor.capture()); - ArgumentCaptor logCaptor = ArgumentCaptor.forClass(MultiPartRequest.class); + ArgumentCaptor> logCaptor = ArgumentCaptor.forClass(List.class); verify(client, timeout(PROCESSING_TIMEOUT).atLeastOnce()).log(logCaptor.capture()); FinishTestItemRQ item = captor.getAllValues().get(0); @@ -72,14 +73,7 @@ public void verify_assumption_violated_parameterized_test_logs_message_and_marke item = captor.getAllValues().get(1); assertThat(item.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.SKIPPED.name()))); - List expectedErrorList = logCaptor.getAllValues() - .stream() - .flatMap(l -> l.getSerializedRQs().stream()) - .map(MultiPartRequest.MultiPartSerialized::getRequest) - .filter(l -> l instanceof List) - .flatMap(l -> ((List) l).stream()) - .filter(l -> l instanceof SaveLogRQ) - .map(l -> (SaveLogRQ) l) + List expectedErrorList = toSaveLogRQ(logCaptor.getAllValues()).stream() .filter(l -> LogLevel.WARN.name().equals(l.getLevel())) .filter(l -> l.getMessage() != null && l.getMessage().contains(AssumptionParameterTest.VIOLATION_MESSAGE)) .collect(Collectors.toList()); diff --git a/src/test/java/com/epam/reportportal/junit/exception/ExpectedExceptionFailedTest.java b/src/test/java/com/epam/reportportal/junit/exception/ExpectedExceptionFailedTest.java index 0d937b7..314ec2c 100644 --- a/src/test/java/com/epam/reportportal/junit/exception/ExpectedExceptionFailedTest.java +++ b/src/test/java/com/epam/reportportal/junit/exception/ExpectedExceptionFailedTest.java @@ -20,12 +20,12 @@ import com.epam.reportportal.junit.features.exception.ExpectedExceptionNotThrownTest; import com.epam.reportportal.junit.utils.TestUtils; import com.epam.reportportal.listeners.ItemStatus; -import com.epam.reportportal.restendpoint.http.MultiPartRequest; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; +import okhttp3.MultipartBody; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -36,6 +36,7 @@ import java.util.stream.Collectors; import static com.epam.reportportal.junit.utils.TestUtils.PROCESSING_TIMEOUT; +import static com.epam.reportportal.junit.utils.TestUtils.toSaveLogRQ; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; @@ -73,17 +74,10 @@ public void verify_expected_exception_was_not_thrown() { assertThat(items.get(0).getStatus(), equalTo(ItemStatus.PASSED.name())); assertThat(items.get(1).getStatus(), equalTo(ItemStatus.FAILED.name())); - ArgumentCaptor logRqCaptor = ArgumentCaptor.forClass(MultiPartRequest.class); + ArgumentCaptor> logRqCaptor = ArgumentCaptor.forClass(List.class); verify(client, timeout(PROCESSING_TIMEOUT).atLeastOnce()).log(logRqCaptor.capture()); - List logs = logRqCaptor.getAllValues(); - List expectedErrorList = logs.stream() - .flatMap(l -> l.getSerializedRQs().stream()) - .map(MultiPartRequest.MultiPartSerialized::getRequest) - .filter(l -> l instanceof List) - .flatMap(l -> ((List) l).stream()) - .filter(l -> l instanceof SaveLogRQ) - .map(l -> (SaveLogRQ) l) + List expectedErrorList = toSaveLogRQ(logRqCaptor.getAllValues()).stream() .filter(l -> l.getMessage() != null && l.getMessage().startsWith(EXPECTED_ERROR)) .collect(Collectors.toList()); assertThat(expectedErrorList, hasSize(1)); diff --git a/src/test/java/com/epam/reportportal/junit/features/parameters/JUnitParamsNullValueTest.java b/src/test/java/com/epam/reportportal/junit/features/parameters/JUnitParamsNullValueTest.java index 0ec9b29..151fd9d 100644 --- a/src/test/java/com/epam/reportportal/junit/features/parameters/JUnitParamsNullValueTest.java +++ b/src/test/java/com/epam/reportportal/junit/features/parameters/JUnitParamsNullValueTest.java @@ -59,9 +59,8 @@ public Description getDescription() { @Override public Optional> getParameters() { - Object runner = LifecycleHooks.getRunnerForTarget(this); - AtomicTest test = LifecycleHooks.getAtomicTestOf(runner); - ReflectiveCallable callable = LifecycleHooks.getCallableOf(runner, test.getIdentity()); + AtomicTest test = LifecycleHooks.getAtomicTestOf(this); + ReflectiveCallable callable = LifecycleHooks.getCallableOf(test.getDescription()); try { Object[] params = LifecycleHooks.getFieldValue(callable, "val$params"); String param = (String) params[0]; diff --git a/src/test/java/com/epam/reportportal/junit/features/parameters/JUnitParamsSimpleTest.java b/src/test/java/com/epam/reportportal/junit/features/parameters/JUnitParamsSimpleTest.java index 9b802d2..671b3bc 100644 --- a/src/test/java/com/epam/reportportal/junit/features/parameters/JUnitParamsSimpleTest.java +++ b/src/test/java/com/epam/reportportal/junit/features/parameters/JUnitParamsSimpleTest.java @@ -55,9 +55,8 @@ public Description getDescription() { @Override public Optional> getParameters() { - Object runner = LifecycleHooks.getRunnerForTarget(this); - AtomicTest test = LifecycleHooks.getAtomicTestOf(runner); - ReflectiveCallable callable = LifecycleHooks.getCallableOf(runner, test.getIdentity()); + AtomicTest test = LifecycleHooks.getAtomicTestOf(this); + ReflectiveCallable callable = LifecycleHooks.getCallableOf(test.getDescription()); try { Object[] params = LifecycleHooks.getFieldValue(callable, "val$params"); String param = (String) params[0]; diff --git a/src/test/java/com/epam/reportportal/junit/features/parameters/JUnitParamsTwoParamsTest.java b/src/test/java/com/epam/reportportal/junit/features/parameters/JUnitParamsTwoParamsTest.java index 9399a5b..0ea1b3a 100644 --- a/src/test/java/com/epam/reportportal/junit/features/parameters/JUnitParamsTwoParamsTest.java +++ b/src/test/java/com/epam/reportportal/junit/features/parameters/JUnitParamsTwoParamsTest.java @@ -55,9 +55,8 @@ public Description getDescription() { @Override public Optional> getParameters() { - Object runner = LifecycleHooks.getRunnerForTarget(this); - AtomicTest test = LifecycleHooks.getAtomicTestOf(runner); - ReflectiveCallable callable = LifecycleHooks.getCallableOf(runner, test.getIdentity()); + AtomicTest test = LifecycleHooks.getAtomicTestOf(this); + ReflectiveCallable callable = LifecycleHooks.getCallableOf(test.getDescription()); try { Object[] params = LifecycleHooks.getFieldValue(callable, "val$params"); return Param.mapOf(Param.param("param1", params[0]), Param.param("param2", params[1])); diff --git a/src/test/java/com/epam/reportportal/junit/features/retry/BasicRetryPassedTest.java b/src/test/java/com/epam/reportportal/junit/features/retry/BasicRetryPassedTest.java index e3a7958..9f2358c 100644 --- a/src/test/java/com/epam/reportportal/junit/features/retry/BasicRetryPassedTest.java +++ b/src/test/java/com/epam/reportportal/junit/features/retry/BasicRetryPassedTest.java @@ -22,7 +22,7 @@ public class BasicRetryPassedTest { public static final int FAILURE_NUMBER = 1; - public final AtomicInteger RETRY_COUNT = new AtomicInteger(0); + public static final AtomicInteger RETRY_COUNT = new AtomicInteger(0); @Test public void testRetry() { diff --git a/src/test/java/com/epam/reportportal/junit/features/retry/StandardParametersRetryTest.java b/src/test/java/com/epam/reportportal/junit/features/retry/StandardParametersRetryTest.java index 2c180aa..ac3e06b 100644 --- a/src/test/java/com/epam/reportportal/junit/features/retry/StandardParametersRetryTest.java +++ b/src/test/java/com/epam/reportportal/junit/features/retry/StandardParametersRetryTest.java @@ -34,7 +34,7 @@ public class StandardParametersRetryTest implements ArtifactParams { public static final int FAILURE_NUMBER = 1; public static final String FAILURE_PARAMETER = "one"; - public final AtomicInteger RETRY_COUNT = new AtomicInteger(0); + public static final AtomicInteger RETRY_COUNT = new AtomicInteger(0); @Rule public final AtomIdentity identity = new AtomIdentity(this); diff --git a/src/test/java/com/epam/reportportal/junit/theory/TheoryFailedTest.java b/src/test/java/com/epam/reportportal/junit/theory/TheoryFailedTest.java index 21b0377..bc5390e 100644 --- a/src/test/java/com/epam/reportportal/junit/theory/TheoryFailedTest.java +++ b/src/test/java/com/epam/reportportal/junit/theory/TheoryFailedTest.java @@ -21,13 +21,13 @@ import com.epam.reportportal.junit.utils.TestUtils; import com.epam.reportportal.listeners.ItemStatus; import com.epam.reportportal.listeners.ItemType; -import com.epam.reportportal.restendpoint.http.MultiPartRequest; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; +import okhttp3.MultipartBody; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -76,17 +76,12 @@ public void verify_simple_theory_test_failed() { FinishTestItemRQ finishRq = finishCaptor.getValue(); assertThat(finishRq.getStatus(), equalTo(ItemStatus.FAILED.name())); - ArgumentCaptor logRqCaptor = ArgumentCaptor.forClass(MultiPartRequest.class); + ArgumentCaptor> logRqCaptor = ArgumentCaptor.forClass(List.class); verify(client, timeout(PROCESSING_TIMEOUT).atLeastOnce()).log(logRqCaptor.capture()); - List logs = logRqCaptor.getAllValues(); - List expectedErrorList = logs.stream() - .flatMap(l -> l.getSerializedRQs().stream()) - .map(MultiPartRequest.MultiPartSerialized::getRequest) - .filter(l -> l instanceof List) - .flatMap(l -> ((List) l).stream()) - .filter(l -> l instanceof SaveLogRQ) - .map(l -> (SaveLogRQ) l) + List> logs = logRqCaptor.getAllValues(); + List expectedErrorList = TestUtils.toSaveLogRQ(logs) + .stream() .filter(l -> l.getMessage() != null && l.getMessage().startsWith(EXPECTED_ERROR)) .collect(Collectors.toList()); assertThat(expectedErrorList, hasSize(1)); diff --git a/src/test/java/com/epam/reportportal/junit/utils/TestUtils.java b/src/test/java/com/epam/reportportal/junit/utils/TestUtils.java index af7a4f6..8e06653 100644 --- a/src/test/java/com/epam/reportportal/junit/utils/TestUtils.java +++ b/src/test/java/com/epam/reportportal/junit/utils/TestUtils.java @@ -17,16 +17,20 @@ package com.epam.reportportal.junit.utils; import com.epam.reportportal.listeners.ListenerParameters; -import com.epam.reportportal.restendpoint.http.MultiPartRequest; import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; +import com.epam.reportportal.utils.http.HttpRequestUtils; import com.epam.ta.reportportal.ws.model.BatchSaveOperatingRS; +import com.epam.ta.reportportal.ws.model.Constants; import com.epam.ta.reportportal.ws.model.EntryCreatedAsyncRS; import com.epam.ta.reportportal.ws.model.OperationCompletionRS; import com.epam.ta.reportportal.ws.model.item.ItemCreatedRS; import com.epam.ta.reportportal.ws.model.launch.StartLaunchRS; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; +import com.fasterxml.jackson.core.type.TypeReference; import io.reactivex.Maybe; +import okhttp3.MultipartBody; +import okio.Buffer; import org.apache.commons.lang3.tuple.Pair; import org.junit.runner.JUnitCore; import org.junit.runner.Result; @@ -34,6 +38,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.io.IOException; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -117,18 +122,15 @@ public static > void mockLaunch(@Nonnull final Repo when(client.finishLaunch(eq(launch), any())).thenReturn(createMaybe(new OperationCompletionRS())); } + @SuppressWarnings("unchecked") public static void mockBatchLogging(final ReportPortalClient client) { - when(client.log(any(MultiPartRequest.class))).thenReturn(createMaybe(new BatchSaveOperatingRS())); + when(client.log(any(List.class))).thenReturn(createMaybe(new BatchSaveOperatingRS())); } public static void mockSingleLogging(final ReportPortalClient client) { when(client.log(any(SaveLogRQ.class))).thenReturn(createMaybe(new EntryCreatedAsyncRS())); } - public static void mockNestedSteps(final ReportPortalClient client, final Pair parentNestedPair) { - mockNestedSteps(client, Collections.singletonList(parentNestedPair)); - } - @SuppressWarnings("unchecked") public static void mockNestedSteps(final ReportPortalClient client, final List> parentNestedPairs) { Map> responseOrders = parentNestedPairs.stream() @@ -148,6 +150,33 @@ public static void mockNestedSteps(final ReportPortalClient client, final List

>) invocation -> createMaybe(new OperationCompletionRS()))); } + public static List toSaveLogRQ(List> rqs) { + return rqs.stream() + .flatMap(List::stream) + .filter(p -> ofNullable(p.headers()).map(headers -> headers.get("Content-Disposition")) + .map(h -> h.contains(Constants.LOG_REQUEST_JSON_PART)) + .orElse(false)) + .map(MultipartBody.Part::body) + .map(b -> { + Buffer buf = new Buffer(); + try { + b.writeTo(buf); + } catch (IOException ignore) { + } + return buf.readByteArray(); + }) + .map(b -> { + try { + return HttpRequestUtils.MAPPER.readValue(b, new TypeReference>() { + }); + } catch (IOException e) { + return Collections.emptyList(); + } + }) + .flatMap(Collection::stream) + .collect(Collectors.toList()); + } + public static ListenerParameters standardParameters() { ListenerParameters result = new ListenerParameters(); result.setClientJoin(false);