From 863b04e9e84734ec9a440d34b42ddd203b8e74cd Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 11 Dec 2023 13:39:56 +0300 Subject: [PATCH 01/76] Update CI build workflow --- .github/workflows/ci.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3262a3..20f3334 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,9 @@ -# Copyright 2020 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, @@ -17,7 +17,7 @@ on: push: branches: - '*' - - '!master' + - '!main' paths-ignore: - README.md - README_TEMPLATE.md @@ -25,8 +25,7 @@ on: pull_request: branches: - - master - - develop + - main jobs: build: From 5b13d5dd9702a905325f3dbe65e95605da26626d Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 11 Dec 2023 13:53:13 +0300 Subject: [PATCH 02/76] Update build scripts --- build-quality.gradle | 43 +++++++++++++++++++++++++++++++++++++++++++ build.gradle | 37 ++++++++++++++++++------------------- gradle.properties | 5 +++-- 3 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 build-quality.gradle diff --git a/build-quality.gradle b/build-quality.gradle new file mode 100644 index 0000000..d3c4c51 --- /dev/null +++ b/build-quality.gradle @@ -0,0 +1,43 @@ +/* + * Copyright 2019 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. + */ +buildscript { + repositories { + maven { + url 'https://plugins.gradle.org/m2/' + } + } + dependencies { + classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:4.8.0' + } +} + +apply plugin: com.github.spotbugs.snom.SpotBugsPlugin + +spotbugs { + toolVersion = '3.1.12' + effort = 'max' + reportLevel = 'high' +} + +spotbugsMain { + sourceDirs = files(sourceSets.main.allSource.srcDirs) + classDirs = files(sourceSets.main.output) + auxClassPaths = files(sourceSets.main.compileClasspath) + reports { + html.enabled(true) + xml.enabled(false) + } +} diff --git a/build.gradle b/build.gradle index b0af09e..2fb3569 100644 --- a/build.gradle +++ b/build.gradle @@ -15,16 +15,24 @@ */ apply plugin: 'java-library' -apply plugin: 'maven-publish' -// Blocking issue for gradle version >=7.0:https://github.com/reportportal/gradle-scripts/issues/37 -//apply from: "${project.scripts_url}/${project.scripts_branch}/release-commons.gradle" -//apply from: "${project.scripts_url}/${project.scripts_branch}/build-quality.gradle" -//apply from: "${project.scripts_url}/${project.scripts_branch}/signing.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" +project.ext.limits = [ + 'instruction': 70, + 'branch' : 53, + 'line' : 75, + 'complexity' : 60, + 'method' : 65, + 'class' : 83 +] sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 + compileJava.options.encoding = 'UTF-8' compileTestJava.options.encoding = 'UTF-8' @@ -42,13 +50,6 @@ dependencies { testImplementation "org.mockito:mockito-junit-jupiter:${project.mockito_version}" } -tasks.withType(Test) { - jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED', - '--add-opens', 'java.base/java.lang.reflect=ALL-UNNAMED', - '--add-opens', 'java.base/java.util=ALL-UNNAMED', - '--add-opens', 'java.base/java.util.concurrent=ALL-UNNAMED'] -} - test { outputs.upToDateWhen { return false } maxParallelForks(5) @@ -56,6 +57,10 @@ test { doFirst { def weaver = configurations.testRuntimeClasspath.find { it.name.contains("aspectjweaver") } jvmArgs += "-javaagent:$weaver" + jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED', + '--add-opens', 'java.base/java.lang.reflect=ALL-UNNAMED', + '--add-opens', 'java.base/java.util=ALL-UNNAMED', + '--add-opens', 'java.base/java.util.concurrent=ALL-UNNAMED'] } environment "AGENT_NO_ANALYTICS", "1" testLogging { @@ -74,10 +79,4 @@ processResources { } } -publishing { - publications { - mavenJava(MavenPublication) { - from components.java - } - } -} +build.dependsOn jacocoTestReport diff --git a/gradle.properties b/gradle.properties index 0b562d8..4cd65d4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,8 @@ gradle_version=8.2 reportportal_client_java_version=5.1.16 reportportal_logback_version=5.1.3 karate_version=[1.3.1, ) -junit_version=5.10.0-M1 +junit_version=5.10.1 mockito_version=5.4.0 scripts_url=https://raw.githubusercontent.com/reportportal/gradle-scripts -scripts_branch=master \ No newline at end of file +scripts_branch=develop +excludeTests= From 44a1210c28e38ee521acc7e8cb02277ba76d98d4 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 11 Dec 2023 17:42:46 +0300 Subject: [PATCH 03/76] Add the first integration test --- build.gradle | 1 + .../karate/KarateReportPortalRunner.java | 2 +- .../karate/ReportPortalPublisherTest.java | 2 +- .../karate/coderef/ScenarioCodeRefTest.java | 15 +++++++++++++++ .../{ => karate}/utils/ReflectUtils.java | 4 ++-- .../reportportal/karate/utils/TestUtils.java | 16 ++++++++++++++++ src/test/resources/feature/simple.feature | 5 +++++ 7 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java rename src/test/java/com/epam/reportportal/{ => karate}/utils/ReflectUtils.java (90%) create mode 100644 src/test/java/com/epam/reportportal/karate/utils/TestUtils.java create mode 100644 src/test/resources/feature/simple.feature diff --git a/build.gradle b/build.gradle index 2fb3569..38c8160 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,7 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter-engine:${project.junit_version}" testImplementation "org.mockito:mockito-core:${project.mockito_version}" testImplementation "org.mockito:mockito-junit-jupiter:${project.mockito_version}" + testImplementation 'org.hamcrest:hamcrest-core:2.2' } test { diff --git a/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java b/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java index fb81065..dbc99cf 100644 --- a/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java +++ b/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java @@ -7,7 +7,7 @@ import java.util.*; import java.util.stream.Collectors; -public class KarateReportPortalRunner extends Suite { +public class KarateReportPortalRunner { public static > Builder path(String... paths) { Builder builder = new Builder<>(); diff --git a/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java b/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java index dbe1a68..54f5819 100644 --- a/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java +++ b/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java @@ -2,7 +2,7 @@ import com.epam.reportportal.listeners.ListenerParameters; import com.epam.reportportal.service.Launch; -import com.epam.reportportal.utils.ReflectUtils; +import com.epam.reportportal.karate.utils.ReflectUtils; import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java new file mode 100644 index 0000000..9587efe --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java @@ -0,0 +1,15 @@ +package com.epam.reportportal.karate.coderef; + +import com.epam.reportportal.karate.utils.TestUtils; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +public class ScenarioCodeRefTest { + @Test + public void test_scenario_code_reference() { + var results = TestUtils.run("classpath:feature/simple.feature"); + assertThat(results.getFailCount(), equalTo(0)); + } +} diff --git a/src/test/java/com/epam/reportportal/utils/ReflectUtils.java b/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java similarity index 90% rename from src/test/java/com/epam/reportportal/utils/ReflectUtils.java rename to src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java index f1d20cf..54d6d9e 100644 --- a/src/test/java/com/epam/reportportal/utils/ReflectUtils.java +++ b/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java @@ -1,4 +1,4 @@ -package com.epam.reportportal.utils; +package com.epam.reportportal.karate.utils; import java.lang.reflect.Field; @@ -16,4 +16,4 @@ public static void setField(Object object, Field fld, Object value) { throw new RuntimeException("Failed to set " + fieldName + " of object", e); } } -} \ No newline at end of file +} diff --git a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java new file mode 100644 index 0000000..e77569e --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java @@ -0,0 +1,16 @@ +package com.epam.reportportal.karate.utils; + +import com.epam.reportportal.karate.KarateReportPortalRunner; +import com.intuit.karate.Results; + +public class TestUtils { + private TestUtils() { + } + + public static Results run(String... paths) { + return KarateReportPortalRunner + .path(paths) + .outputCucumberJson(false) + .parallel(1); + } +} diff --git a/src/test/resources/feature/simple.feature b/src/test/resources/feature/simple.feature new file mode 100644 index 0000000..3c8457b --- /dev/null +++ b/src/test/resources/feature/simple.feature @@ -0,0 +1,5 @@ +Feature: the very basic test to run by Karate + Scenario: Verify response code + Given url 'https://example.com/' + When method GET + Then status 200 From 8538603f2b6af0128adc70a6be62610de367fde4 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 12 Dec 2023 14:34:54 +0300 Subject: [PATCH 04/76] Dependency update --- build.gradle | 6 ++++-- gradle.properties | 4 +--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 38c8160..7f3aa5d 100644 --- a/build.gradle +++ b/build.gradle @@ -41,9 +41,11 @@ repositories { } dependencies { - api "com.epam.reportportal:client-java:${project.reportportal_client_java_version}" - api "com.epam.reportportal:logger-java-logback:${project.reportportal_logback_version}" + api 'com.epam.reportportal:client-java:5.1.24' api "com.intuit.karate:karate-core:${project.karate_version}" + implementation 'org.slf4j:slf4j-api:2.0.7' + + testImplementation 'com.epam.reportportal:logger-java-logback:5.1.6' testImplementation "org.junit.jupiter:junit-jupiter-api:${project.junit_version}" testImplementation "org.junit.jupiter:junit-jupiter-engine:${project.junit_version}" testImplementation "org.mockito:mockito-core:${project.mockito_version}" diff --git a/gradle.properties b/gradle.properties index 4cd65d4..b3dc51a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,7 @@ name=agent-java-karate version=1.0.6 -description=EPAM Report portal. Karate test framework [1.3.1, ) adapter +description=EPAM ReportPortal. Karate test framework [1.3.1, ) adapter gradle_version=8.2 -reportportal_client_java_version=5.1.16 -reportportal_logback_version=5.1.3 karate_version=[1.3.1, ) junit_version=5.10.1 mockito_version=5.4.0 From c7221bae5b9382493f1c2a4737244f84c858dd91 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 12 Dec 2023 15:49:48 +0300 Subject: [PATCH 05/76] The first Code Reference test, ReportPortal format apply, ignore target folder --- .gitignore | 1 + build.gradle | 1 + .../karate/KarateReportPortalRunner.java | 65 +- .../karate/ReportPortalPublisher.java | 664 +++++++++--------- .../karate/enums/ItemLogLevelEnum.java | 22 +- .../karate/enums/ItemStatusEnum.java | 28 +- .../epam/reportportal/karate/KarateTest.java | 24 +- .../karate/ReportPortalPublisherTest.java | 94 +-- .../karate/coderef/ScenarioCodeRefTest.java | 57 +- .../karate/utils/ReflectUtils.java | 22 +- .../reportportal/karate/utils/TestUtils.java | 158 ++++- src/test/resources/feature/Test.feature | 1 + src/test/resources/feature/simple.feature | 1 + src/test/resources/logback.xml | 6 +- 14 files changed, 680 insertions(+), 464 deletions(-) diff --git a/.gitignore b/.gitignore index beed998..39b8c7c 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ hs_err_pid* .gradle/ build/ test-output/ +target/ # IntelliJ Idea files .idea/ diff --git a/build.gradle b/build.gradle index 7f3aa5d..1ae5bc7 100644 --- a/build.gradle +++ b/build.gradle @@ -46,6 +46,7 @@ dependencies { implementation 'org.slf4j:slf4j-api:2.0.7' testImplementation 'com.epam.reportportal:logger-java-logback:5.1.6' + testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.2' testImplementation "org.junit.jupiter:junit-jupiter-api:${project.junit_version}" testImplementation "org.junit.jupiter:junit-jupiter-engine:${project.junit_version}" testImplementation "org.mockito:mockito-core:${project.mockito_version}" diff --git a/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java b/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java index dbc99cf..221bb01 100644 --- a/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java +++ b/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java @@ -1,35 +1,42 @@ - package com.epam.reportportal.karate; -import com.intuit.karate.*; -import com.intuit.karate.core.*; - -import java.util.*; -import java.util.stream.Collectors; +import com.epam.reportportal.service.ReportPortal; +import com.intuit.karate.Results; +import com.intuit.karate.Runner; public class KarateReportPortalRunner { - public static > Builder path(String... paths) { - Builder builder = new Builder<>(); - return builder.path(paths); - } - - public static class Builder> extends Runner.Builder { - ReportPortalPublisher reporter = new ReportPortalPublisher(); - - public Builder() { - super(); - } - - @Override - public Results parallel(int threadCount) { - reporter.startLaunch(); - Results results = super.parallel(threadCount); - List featureResults = results.getFeatureResults().collect(Collectors.toList()); - featureResults.forEach(f -> reporter.startFeature(f)); - featureResults.forEach(f -> reporter.finishFeature(f)); - reporter.finishLaunch(); - return results; - } - } + public static > Builder path(String... paths) { + Builder builder = new Builder<>(); + return builder.path(paths); + } + + public static class Builder> extends Runner.Builder { + private ReportPortal rp; + + public Builder() { + super(); + } + + public Builder withReportPortal(ReportPortal reportPortal) { + rp = reportPortal; + return this; + } + + @Override + public Results parallel(int threadCount) { + if (rp == null) { + rp = ReportPortal.builder().build(); + } + ReportPortalPublisher reporter = new ReportPortalPublisher(rp); + reporter.startLaunch(); + Results results = super.parallel(threadCount); + results.getFeatureResults().forEach(f -> { + reporter.startFeature(f); + reporter.finishFeature(f); + }); + reporter.finishLaunch(); + return results; + } + } } diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index c0e0d1f..27265e0 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -1,7 +1,7 @@ package com.epam.reportportal.karate; -import com.epam.reportportal.karate.enums.ItemStatusEnum; import com.epam.reportportal.karate.enums.ItemLogLevelEnum; +import com.epam.reportportal.karate.enums.ItemStatusEnum; import com.epam.reportportal.listeners.ListenerParameters; import com.epam.reportportal.service.Launch; import com.epam.reportportal.service.ReportPortal; @@ -17,7 +17,10 @@ import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; -import java.util.*; +import java.util.Calendar; +import java.util.Date; +import java.util.HashSet; +import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; @@ -25,336 +28,329 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class ReportPortalPublisher { - private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalPublisher.class); - - private static final ReportPortal REPORT_PORTAL = ReportPortal.builder().build(); - private final ConcurrentHashMap> featureIdMap = new ConcurrentHashMap<>(); - private final ConcurrentHashMap> scenarioIdMap = new ConcurrentHashMap<>(); - private final ConcurrentHashMap, Long> stepStartTimeMap = new ConcurrentHashMap<>(); - private Maybe stepId; - - private final MemoizingSupplier launch; - - private Thread shutDownHook; - - private static Thread getShutdownHook(final Supplier launch) { - return new Thread(() -> { - FinishExecutionRQ rq = new FinishExecutionRQ(); - rq.setEndTime(Calendar.getInstance().getTime()); - launch.get().finish(rq); - }); - } - - public ReportPortalPublisher() { - this.launch = new MemoizingSupplier<>(() -> { - ReportPortal rp = getReporter(); - ListenerParameters params = rp.getParameters(); - StartLaunchRQ rq = buildStartLaunchRq(params); - rq.setStartTime(Calendar.getInstance().getTime()); - Launch newLaunch = rp.newLaunch(rq); - shutDownHook = getShutdownHook(() -> newLaunch); - Runtime.getRuntime().addShutdownHook(shutDownHook); - return newLaunch; - }); - } - - public ReportPortalPublisher(Supplier launchSupplier) { - launch = new MemoizingSupplier<>(launchSupplier); - shutDownHook = getShutdownHook(launch); - Runtime.getRuntime().addShutdownHook(shutDownHook); - } - - /** - * Customize start launch event/request - * @param parameters Launch configuration parameters - * @return request to ReportPortal - */ - protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) { - StartLaunchRQ rq = new StartLaunchRQ(); - rq.setName(parameters.getLaunchName()); - rq.setStartTime(Calendar.getInstance().getTime()); - rq.setMode(parameters.getLaunchRunningMode()); - rq.setAttributes(new HashSet<>(parameters.getAttributes())); - if (!isNullOrEmpty(parameters.getDescription())) { - rq.setDescription(parameters.getDescription()); - } - rq.setStartTime(Calendar.getInstance().getTime()); - rq.setRerun(parameters.isRerun()); - if (isNotBlank(parameters.getRerunOf())) { - rq.setRerunOf(parameters.getRerunOf()); - } - return rq; - } - - /** - * Starts launch instance - */ - public void startLaunch() { - launch.get().start(); - } - - /** - * @return ReportPortal client instance - */ - protected ReportPortal getReporter() { - return REPORT_PORTAL; - } - - /** - * Finish launch - */ - public void finishLaunch() { - FinishExecutionRQ rq = new FinishExecutionRQ(); - rq.setEndTime(Calendar.getInstance().getTime()); - ListenerParameters parameters = launch.get().getParameters(); - LOGGER.info("LAUNCH URL: {}/ui/#{}/launches/all/{}", parameters.getBaseUrl(), parameters.getProjectName(), - System.getProperty("rp.launch.id")); - launch.get().finish(rq); - Runtime.getRuntime().removeShutdownHook(shutDownHook); - } - - /** - * Customize start test item event/request - * @param name item's name - * @param startTime item's start time in Date format - * @param type item's type (e.g. feature, scenario, step, etc.) - * @return request to ReportPortal - */ - protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, - @Nonnull Date startTime, - @Nonnull String type) { - StartTestItemRQ rq = new StartTestItemRQ(); - rq.setName(name); - rq.setStartTime(startTime); - rq.setType(type); - return rq; - } - - /** - * Customize start test item event/request - * @param name item's name - * @param startTime item's start time - * @param type item's type (e.g. feature, scenario, step, etc.) - * @param hasStats enables nested items - * @return request to ReportPortal - */ - @SuppressWarnings("SameParameterValue") - protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, - @Nonnull Date startTime, - @Nonnull String type, - boolean hasStats) { - StartTestItemRQ rq = buildStartTestItemRq(name, startTime, type); - rq.setHasStats(hasStats); - return rq; - } - - /** - * Customize start test item event/request - * - * @param endTime item's end time - * @param status item's status - * @return request to ReportPortal - */ - protected FinishTestItemRQ buildFinishTestItemRq(@Nonnull Date endTime, - @Nonnull String status) { - FinishTestItemRQ rq = new FinishTestItemRQ(); - rq.setEndTime(endTime); - rq.setStatus(status); - return rq; - } - - /** - * Start sending feature data to ReportPortal - * - * @param featureResult feature result - */ - public void startFeature(FeatureResult featureResult) { - StartTestItemRQ rq = buildStartTestItemRq(String.valueOf(featureResult.toCucumberJson().get("name")), - Calendar.getInstance().getTime(), - "STORY"); - Maybe featureId = launch.get().startTestItem(rq); - featureIdMap.put(featureResult.getCallNameForReport(), featureId); - } - - /** - * Finish sending feature data to ReportPortal - * - * @param featureResult feature result - */ - public void finishFeature(FeatureResult featureResult) { - if (!featureIdMap.containsKey(featureResult.getCallNameForReport())) { - LOGGER.error("ERROR: Trying to finish unspecified feature."); - } - - for (ScenarioResult scenarioResult : featureResult.getScenarioResults()) { - startScenario(scenarioResult, featureResult); - List stepResults = scenarioResult.getStepResults(); - - for (StepResult stepResult : stepResults) { - startStep(stepResult, scenarioResult); - sendStepResults(stepResult); - finishStep(stepResult); - } - - stepStartTimeMap.clear(); - finishScenario(scenarioResult); - } - - FinishTestItemRQ rq = buildFinishTestItemRq(Calendar.getInstance().getTime(), - featureResult.isFailed() ? ItemStatusEnum.FAILED.toString() : ItemStatusEnum.PASSED.toString()); - launch.get().finishTestItem(featureIdMap.remove(featureResult.getCallNameForReport()), rq); - } - - /** - * Start sending scenario data to ReportPortal - * - * @param scenarioResult scenario result - * @param featureResult feature result - */ - public void startScenario(ScenarioResult scenarioResult, FeatureResult featureResult) { - StartTestItemRQ rq = buildStartTestItemRq(scenarioResult.getScenario().getName(), - Calendar.getInstance().getTime(), - "STEP"); - Maybe scenarioId = launch.get().startTestItem(featureIdMap.get(featureResult.getCallNameForReport()), rq); - scenarioIdMap.put(scenarioResult.getScenario().getName(), scenarioId); - } - - /** - * Finish sending scenario data to ReportPortal - * - * @param scenarioResult scenario result - */ - public void finishScenario(ScenarioResult scenarioResult) { - if (!scenarioIdMap.containsKey(scenarioResult.getScenario().getName())) { - LOGGER.error("ERROR: Trying to finish unspecified scenario."); - } - - FinishTestItemRQ rq = buildFinishTestItemRq(Calendar.getInstance().getTime(), - scenarioResult.getFailureMessageForDisplay() == null ? ItemStatusEnum.PASSED.toString() : ItemStatusEnum.FAILED.toString()); - Maybe removedScenarioId = scenarioIdMap.remove(scenarioResult.getScenario().getName()); - launch.get().finishTestItem(removedScenarioId, rq); - } - - /** - * Start sending step data to ReportPortal - * - * @param stepResult step result - * @param scenarioResult scenario result - */ - public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { - String stepName = stepResult.getStep().getPrefix() + " " + stepResult.getStep().getText(); - StartTestItemRQ rq = buildStartTestItemRq(stepName, getStepStartTime(stepStartTimeMap, stepId), "STEP", false); - stepId = launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), rq); - stepStartTimeMap.put(stepId, rq.getStartTime().getTime()); - } - - /** - * Finish sending scenario data to ReportPortal - * - * @param stepResult step result - */ - public void finishStep(StepResult stepResult) { - if (stepId == null) { - LOGGER.error("ERROR: Trying to finish unspecified step."); - return; - } - - FinishTestItemRQ rq = buildFinishTestItemRq(Calendar.getInstance().getTime(), - getStepStatus(stepResult.getResult().getStatus())); - launch.get().finishTestItem(stepId, rq); - } - - - /** - * Send step execution results to ReportPortal - * - * @param stepResult step execution results - */ - public void sendStepResults(StepResult stepResult) { - Result result = stepResult.getResult(); - String logLevel = getLogLevel(result.getStatus()); - Step step = stepResult.getStep(); - - if (step.getDocString() != null) { - sendLog("\n-----------------DOC_STRING-----------------\n" + step.getDocString(), logLevel); - } - - if (stepResult.getStepLog() != null - && !stepResult.getStepLog().isEmpty() - && !stepResult.getStepLog().equals(" ")) { - sendLog(stepResult.getStepLog(), logLevel); - } - } - - /** - * Send step logs and/or execution results to ReportPortal - * - * @param message log message to send - * @param level log level - */ - public void sendLog(final String message, final String level) { - ReportPortal.emitLog(itemId -> { - SaveLogRQ rq = new SaveLogRQ(); - rq.setMessage(message); - rq.setItemUuid(itemId); - rq.setLevel(level); - rq.setLogTime(Calendar.getInstance().getTime()); - return rq; - }); - } - - private String getStepStatus(String status) { - switch (status) { - case "failed": - return ItemStatusEnum.FAILED.toString(); - case "passed": - return ItemStatusEnum.PASSED.toString(); - case "skipped": - return ItemStatusEnum.SKIPPED.toString(); - case "stopped": - return ItemStatusEnum.STOPPED.toString(); - case "interrupted": - return ItemStatusEnum.RESETED.toString(); - case "cancelled": - return ItemStatusEnum.CANCELLED.toString(); - default: - LOGGER.warn("Unknown step status received! Set it as SKIPPED"); - return ItemStatusEnum.SKIPPED.toString(); - } - } - - private String getLogLevel(String status) { - switch (status) { - case "failed": - return ItemLogLevelEnum.ERROR.toString(); - case "stopped": - case "interrupted": - case "cancelled": - return ItemLogLevelEnum.WARN.toString(); - default: - return ItemLogLevelEnum.INFO.toString(); - } - } - - /** - * Get step start time to keep the steps order - * in case previous step startTime == current step startTime or previous step startTime > current step startTime. - * - * @param stepStartTimeMap ConcurrentHashMap of steps within a scenario. - * @param stepId step ID. - * @return step new startTime in Date format. - */ - private Date getStepStartTime(ConcurrentHashMap, Long> stepStartTimeMap, Maybe stepId) { - long currentStepStartTime = Calendar.getInstance().getTime().getTime(); - - if (!stepStartTimeMap.keySet().isEmpty()) { - long lastStepStartTime = stepStartTimeMap.get(stepId); - - if (lastStepStartTime >= currentStepStartTime) { - currentStepStartTime += (lastStepStartTime - currentStepStartTime) + 1; - } - } - - return new Date(currentStepStartTime); - } + private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalPublisher.class); + private final ConcurrentHashMap> featureIdMap = new ConcurrentHashMap<>(); + private final ConcurrentHashMap> scenarioIdMap = new ConcurrentHashMap<>(); + private final ConcurrentHashMap, Long> stepStartTimeMap = new ConcurrentHashMap<>(); + private Maybe stepId; + + private final MemoizingSupplier launch; + + private Thread shutDownHook; + + private static Thread getShutdownHook(final Supplier launch) { + return new Thread(() -> { + FinishExecutionRQ rq = new FinishExecutionRQ(); + rq.setEndTime(Calendar.getInstance().getTime()); + launch.get().finish(rq); + }); + } + + /** + * Customize start launch event/request + * + * @param parameters Launch configuration parameters + * @return request to ReportPortal + */ + protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) { + StartLaunchRQ rq = new StartLaunchRQ(); + rq.setName(parameters.getLaunchName()); + rq.setStartTime(Calendar.getInstance().getTime()); + rq.setMode(parameters.getLaunchRunningMode()); + rq.setAttributes(new HashSet<>(parameters.getAttributes())); + if (!isNullOrEmpty(parameters.getDescription())) { + rq.setDescription(parameters.getDescription()); + } + rq.setStartTime(Calendar.getInstance().getTime()); + rq.setRerun(parameters.isRerun()); + if (isNotBlank(parameters.getRerunOf())) { + rq.setRerunOf(parameters.getRerunOf()); + } + return rq; + } + + public ReportPortalPublisher(ReportPortal reportPortal) { + launch = new MemoizingSupplier<>(() -> { + ListenerParameters params = reportPortal.getParameters(); + StartLaunchRQ rq = buildStartLaunchRq(params); + rq.setStartTime(Calendar.getInstance().getTime()); + Launch newLaunch = reportPortal.newLaunch(rq); + shutDownHook = getShutdownHook(() -> newLaunch); + Runtime.getRuntime().addShutdownHook(shutDownHook); + return newLaunch; + }); + } + + public ReportPortalPublisher(Supplier launchSupplier) { + launch = new MemoizingSupplier<>(launchSupplier); + shutDownHook = getShutdownHook(launch); + Runtime.getRuntime().addShutdownHook(shutDownHook); + } + + /** + * Starts launch instance + */ + public void startLaunch() { + launch.get().start(); + } + + /** + * Finish launch + */ + public void finishLaunch() { + FinishExecutionRQ rq = new FinishExecutionRQ(); + rq.setEndTime(Calendar.getInstance().getTime()); + ListenerParameters parameters = launch.get().getParameters(); + LOGGER.info("LAUNCH URL: {}/ui/#{}/launches/all/{}", parameters.getBaseUrl(), parameters.getProjectName(), + System.getProperty("rp.launch.id")); + launch.get().finish(rq); + Runtime.getRuntime().removeShutdownHook(shutDownHook); + } + + /** + * Customize start test item event/request + * + * @param name item's name + * @param startTime item's start time in Date format + * @param type item's type (e.g. feature, scenario, step, etc.) + * @return request to ReportPortal + */ + protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, + @Nonnull Date startTime, + @Nonnull String type) { + StartTestItemRQ rq = new StartTestItemRQ(); + rq.setName(name); + rq.setStartTime(startTime); + rq.setType(type); + return rq; + } + + /** + * Customize start test item event/request + * + * @param name item's name + * @param startTime item's start time + * @param type item's type (e.g. feature, scenario, step, etc.) + * @param hasStats enables nested items + * @return request to ReportPortal + */ + @SuppressWarnings("SameParameterValue") + protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, + @Nonnull Date startTime, + @Nonnull String type, + boolean hasStats) { + StartTestItemRQ rq = buildStartTestItemRq(name, startTime, type); + rq.setHasStats(hasStats); + return rq; + } + + /** + * Customize start test item event/request + * + * @param endTime item's end time + * @param status item's status + * @return request to ReportPortal + */ + protected FinishTestItemRQ buildFinishTestItemRq(@Nonnull Date endTime, + @Nonnull String status) { + FinishTestItemRQ rq = new FinishTestItemRQ(); + rq.setEndTime(endTime); + rq.setStatus(status); + return rq; + } + + /** + * Start sending feature data to ReportPortal + * + * @param featureResult feature result + */ + public void startFeature(FeatureResult featureResult) { + StartTestItemRQ rq = buildStartTestItemRq(String.valueOf(featureResult.toCucumberJson().get("name")), + Calendar.getInstance().getTime(), + "STORY"); + Maybe featureId = launch.get().startTestItem(rq); + featureIdMap.put(featureResult.getCallNameForReport(), featureId); + } + + /** + * Finish sending feature data to ReportPortal + * + * @param featureResult feature result + */ + public void finishFeature(FeatureResult featureResult) { + if (!featureIdMap.containsKey(featureResult.getCallNameForReport())) { + LOGGER.error("ERROR: Trying to finish unspecified feature."); + } + + for (ScenarioResult scenarioResult : featureResult.getScenarioResults()) { + startScenario(scenarioResult, featureResult); + List stepResults = scenarioResult.getStepResults(); + + for (StepResult stepResult : stepResults) { + startStep(stepResult, scenarioResult); + sendStepResults(stepResult); + finishStep(stepResult); + } + + stepStartTimeMap.clear(); + finishScenario(scenarioResult); + } + + FinishTestItemRQ rq = buildFinishTestItemRq(Calendar.getInstance().getTime(), + featureResult.isFailed() ? ItemStatusEnum.FAILED.toString() : ItemStatusEnum.PASSED.toString()); + launch.get().finishTestItem(featureIdMap.remove(featureResult.getCallNameForReport()), rq); + } + + /** + * Start sending scenario data to ReportPortal + * + * @param scenarioResult scenario result + * @param featureResult feature result + */ + public void startScenario(ScenarioResult scenarioResult, FeatureResult featureResult) { + StartTestItemRQ rq = buildStartTestItemRq(scenarioResult.getScenario().getName(), + Calendar.getInstance().getTime(), + "STEP"); + Maybe scenarioId = launch.get().startTestItem(featureIdMap.get(featureResult.getCallNameForReport()), rq); + scenarioIdMap.put(scenarioResult.getScenario().getName(), scenarioId); + } + + /** + * Finish sending scenario data to ReportPortal + * + * @param scenarioResult scenario result + */ + public void finishScenario(ScenarioResult scenarioResult) { + if (!scenarioIdMap.containsKey(scenarioResult.getScenario().getName())) { + LOGGER.error("ERROR: Trying to finish unspecified scenario."); + } + + FinishTestItemRQ rq = buildFinishTestItemRq(Calendar.getInstance().getTime(), + scenarioResult.getFailureMessageForDisplay() == null ? ItemStatusEnum.PASSED.toString() : ItemStatusEnum.FAILED.toString()); + Maybe removedScenarioId = scenarioIdMap.remove(scenarioResult.getScenario().getName()); + launch.get().finishTestItem(removedScenarioId, rq); + } + + /** + * Start sending step data to ReportPortal + * + * @param stepResult step result + * @param scenarioResult scenario result + */ + public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { + String stepName = stepResult.getStep().getPrefix() + " " + stepResult.getStep().getText(); + StartTestItemRQ rq = buildStartTestItemRq(stepName, getStepStartTime(stepStartTimeMap, stepId), "STEP", false); + stepId = launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), rq); + stepStartTimeMap.put(stepId, rq.getStartTime().getTime()); + } + + /** + * Finish sending scenario data to ReportPortal + * + * @param stepResult step result + */ + public void finishStep(StepResult stepResult) { + if (stepId == null) { + LOGGER.error("ERROR: Trying to finish unspecified step."); + return; + } + + FinishTestItemRQ rq = buildFinishTestItemRq(Calendar.getInstance().getTime(), + getStepStatus(stepResult.getResult().getStatus())); + launch.get().finishTestItem(stepId, rq); + } + + + /** + * Send step execution results to ReportPortal + * + * @param stepResult step execution results + */ + public void sendStepResults(StepResult stepResult) { + Result result = stepResult.getResult(); + String logLevel = getLogLevel(result.getStatus()); + Step step = stepResult.getStep(); + + if (step.getDocString() != null) { + sendLog("\n-----------------DOC_STRING-----------------\n" + step.getDocString(), logLevel); + } + + if (stepResult.getStepLog() != null + && !stepResult.getStepLog().isEmpty() + && !stepResult.getStepLog().equals(" ")) { + sendLog(stepResult.getStepLog(), logLevel); + } + } + + /** + * Send step logs and/or execution results to ReportPortal + * + * @param message log message to send + * @param level log level + */ + public void sendLog(final String message, final String level) { + ReportPortal.emitLog(itemId -> { + SaveLogRQ rq = new SaveLogRQ(); + rq.setMessage(message); + rq.setItemUuid(itemId); + rq.setLevel(level); + rq.setLogTime(Calendar.getInstance().getTime()); + return rq; + }); + } + + private String getStepStatus(String status) { + switch (status) { + case "failed": + return ItemStatusEnum.FAILED.toString(); + case "passed": + return ItemStatusEnum.PASSED.toString(); + case "skipped": + return ItemStatusEnum.SKIPPED.toString(); + case "stopped": + return ItemStatusEnum.STOPPED.toString(); + case "interrupted": + return ItemStatusEnum.RESETED.toString(); + case "cancelled": + return ItemStatusEnum.CANCELLED.toString(); + default: + LOGGER.warn("Unknown step status received! Set it as SKIPPED"); + return ItemStatusEnum.SKIPPED.toString(); + } + } + + private String getLogLevel(String status) { + switch (status) { + case "failed": + return ItemLogLevelEnum.ERROR.toString(); + case "stopped": + case "interrupted": + case "cancelled": + return ItemLogLevelEnum.WARN.toString(); + default: + return ItemLogLevelEnum.INFO.toString(); + } + } + + /** + * Get step start time to keep the steps order + * in case previous step startTime == current step startTime or previous step startTime > current step startTime. + * + * @param stepStartTimeMap ConcurrentHashMap of steps within a scenario. + * @param stepId step ID. + * @return step new startTime in Date format. + */ + private Date getStepStartTime(ConcurrentHashMap, Long> stepStartTimeMap, Maybe stepId) { + long currentStepStartTime = Calendar.getInstance().getTime().getTime(); + + if (!stepStartTimeMap.keySet().isEmpty()) { + long lastStepStartTime = stepStartTimeMap.get(stepId); + + if (lastStepStartTime >= currentStepStartTime) { + currentStepStartTime += (lastStepStartTime - currentStepStartTime) + 1; + } + } + + return new Date(currentStepStartTime); + } } diff --git a/src/main/java/com/epam/reportportal/karate/enums/ItemLogLevelEnum.java b/src/main/java/com/epam/reportportal/karate/enums/ItemLogLevelEnum.java index f3f63df..49d9b87 100644 --- a/src/main/java/com/epam/reportportal/karate/enums/ItemLogLevelEnum.java +++ b/src/main/java/com/epam/reportportal/karate/enums/ItemLogLevelEnum.java @@ -1,18 +1,18 @@ package com.epam.reportportal.karate.enums; public enum ItemLogLevelEnum { - INFO("INFO"), - WARN("WARN"), - ERROR("ERROR"); + INFO("INFO"), + WARN("WARN"), + ERROR("ERROR"); - private final String name; + private final String name; - ItemLogLevelEnum(String name) { - this.name = name; - } + ItemLogLevelEnum(String name) { + this.name = name; + } - @Override - public String toString() { - return this.name; - } + @Override + public String toString() { + return this.name; + } } diff --git a/src/main/java/com/epam/reportportal/karate/enums/ItemStatusEnum.java b/src/main/java/com/epam/reportportal/karate/enums/ItemStatusEnum.java index 620e670..3f90dc4 100644 --- a/src/main/java/com/epam/reportportal/karate/enums/ItemStatusEnum.java +++ b/src/main/java/com/epam/reportportal/karate/enums/ItemStatusEnum.java @@ -1,21 +1,21 @@ package com.epam.reportportal.karate.enums; public enum ItemStatusEnum { - PASSED("PASSED"), - FAILED("FAILED"), - SKIPPED("SKIPPED"), - STOPPED("STOPPED"), - RESETED("RESETED"), - CANCELLED("CANCELLED"); + PASSED("PASSED"), + FAILED("FAILED"), + SKIPPED("SKIPPED"), + STOPPED("STOPPED"), + RESETED("RESETED"), + CANCELLED("CANCELLED"); - private final String name; + private final String name; - ItemStatusEnum(String name) { - this.name = name; - } + ItemStatusEnum(String name) { + this.name = name; + } - @Override - public String toString() { - return this.name; - } + @Override + public String toString() { + return this.name; + } } diff --git a/src/test/java/com/epam/reportportal/karate/KarateTest.java b/src/test/java/com/epam/reportportal/karate/KarateTest.java index fd3e58a..957c3fe 100644 --- a/src/test/java/com/epam/reportportal/karate/KarateTest.java +++ b/src/test/java/com/epam/reportportal/karate/KarateTest.java @@ -7,16 +7,16 @@ import static org.junit.jupiter.api.Assertions.assertTrue; class KarateTest { - @Test - void testParallel() { - Results results = KarateReportPortalRunner - .path("classpath:feature") - .outputCucumberJson(true) - .tags("~@ignore","@To_run") - .parallel(2); - assertEquals(0, results.getFailCount()); - assertEquals(0, results.getErrors().size()); - assertTrue(results.getSuite().parallel); - assertEquals(2, results.getScenariosTotal()); - } + @Test + void testParallel() { + Results results = KarateReportPortalRunner + .path("classpath:feature") + .outputCucumberJson(true) + .tags("~@ignore", "@To_run") + .parallel(2); + assertEquals(0, results.getFailCount()); + assertEquals(0, results.getErrors().size()); + assertTrue(results.getSuite().parallel); + assertEquals(2, results.getScenariosTotal()); + } } \ No newline at end of file diff --git a/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java b/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java index 54f5819..bee1f1a 100644 --- a/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java +++ b/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java @@ -1,8 +1,8 @@ package com.epam.reportportal.karate; +import com.epam.reportportal.karate.utils.ReflectUtils; import com.epam.reportportal.listeners.ListenerParameters; import com.epam.reportportal.service.Launch; -import com.epam.reportportal.karate.utils.ReflectUtils; import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; @@ -20,56 +20,56 @@ @ExtendWith(MockitoExtension.class) public class ReportPortalPublisherTest { - private ReportPortalPublisher reportPortalPublisher; - @Mock - Launch launchMock; + private ReportPortalPublisher reportPortalPublisher; + @Mock + Launch launchMock; - @BeforeEach - public void setUp() { - reportPortalPublisher = new ReportPortalPublisher(() -> launchMock); - } + @BeforeEach + public void setUp() { + reportPortalPublisher = new ReportPortalPublisher(() -> launchMock); + } - @Test - public void shouldStartLaunch() { - reportPortalPublisher.startLaunch(); - verify(launchMock, times(1)).start(); - } + @Test + public void shouldStartLaunch() { + reportPortalPublisher.startLaunch(); + verify(launchMock, times(1)).start(); + } - @Test - public void shouldFinishLaunch() { - when(launchMock.getParameters()).thenReturn(getListenerParameters()); - reportPortalPublisher.finishLaunch(); - verify(launchMock, times(1)).finish(any(FinishExecutionRQ.class)); - } + @Test + public void shouldFinishLaunch() { + when(launchMock.getParameters()).thenReturn(getListenerParameters()); + reportPortalPublisher.finishLaunch(); + verify(launchMock, times(1)).finish(any(FinishExecutionRQ.class)); + } - @SuppressWarnings("unchecked") - @Test - public void shouldStartFeature() { - FeatureResult featureResult = mock(FeatureResult.class); - when(featureResult.getCallNameForReport()).thenReturn("featureName"); - when(launchMock.startTestItem(any(StartTestItemRQ.class))).thenReturn(mock(Maybe.class)); - reportPortalPublisher.startFeature(featureResult); - verify(launchMock, times(1)).startTestItem(any(StartTestItemRQ.class)); - } + @SuppressWarnings("unchecked") + @Test + public void shouldStartFeature() { + FeatureResult featureResult = mock(FeatureResult.class); + when(featureResult.getCallNameForReport()).thenReturn("featureName"); + when(launchMock.startTestItem(any(StartTestItemRQ.class))).thenReturn(mock(Maybe.class)); + reportPortalPublisher.startFeature(featureResult); + verify(launchMock, times(1)).startTestItem(any(StartTestItemRQ.class)); + } - @SuppressWarnings("unchecked") - @Test - public void shouldFinishFeature() throws NoSuchFieldException { - FeatureResult featureResult = mock(FeatureResult.class); - when(featureResult.getCallNameForReport()).thenReturn("featureName"); - ConcurrentHashMap> featureIdMap = new ConcurrentHashMap<>(); - featureIdMap.put("featureName", mock(Maybe.class)); - ReflectUtils.setField(reportPortalPublisher, ReportPortalPublisher.class.getDeclaredField("featureIdMap"), featureIdMap); - reportPortalPublisher.finishFeature(featureResult); - verify(launchMock, times(1)).finishTestItem(any(Maybe.class), any(FinishTestItemRQ.class)); - } + @SuppressWarnings("unchecked") + @Test + public void shouldFinishFeature() throws NoSuchFieldException { + FeatureResult featureResult = mock(FeatureResult.class); + when(featureResult.getCallNameForReport()).thenReturn("featureName"); + ConcurrentHashMap> featureIdMap = new ConcurrentHashMap<>(); + featureIdMap.put("featureName", mock(Maybe.class)); + ReflectUtils.setField(reportPortalPublisher, ReportPortalPublisher.class.getDeclaredField("featureIdMap"), featureIdMap); + reportPortalPublisher.finishFeature(featureResult); + verify(launchMock, times(1)).finishTestItem(any(Maybe.class), any(FinishTestItemRQ.class)); + } - private ListenerParameters getListenerParameters() { - ListenerParameters parameters = new ListenerParameters(); - parameters.setLaunchName("launch"); - parameters.setBaseUrl("url"); - parameters.setProjectName("project"); - System.setProperty("rp.launch.id", "launchId"); - return parameters; - } + private ListenerParameters getListenerParameters() { + ListenerParameters parameters = new ListenerParameters(); + parameters.setLaunchName("launch"); + parameters.setBaseUrl("url"); + parameters.setProjectName("project"); + System.setProperty("rp.launch.id", "launchId"); + return parameters; + } } diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java index 9587efe..9829266 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java @@ -1,15 +1,68 @@ package com.epam.reportportal.karate.coderef; import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.listeners.ItemType; +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.StartTestItemRQ; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; public class ScenarioCodeRefTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); + + private static final String SIMPLE_CODE_REFERENCE = "feature/simple.feature/[SCENARIO:Verify response code]"; + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + @Test public void test_scenario_code_reference() { - var results = TestUtils.run("classpath:feature/simple.feature"); + var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); + + List items = captor.getAllValues(); + assertThat(items, hasSize(5)); + + StartTestItemRQ featureRq = items.get(0); + StartTestItemRQ scenarioRq = items.get(1); + + assertThat(featureRq.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); + + assertThat(scenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(scenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(SIMPLE_CODE_REFERENCE))); + + List stepRqs = items.subList(2, items.size()); + IntStream.range(0, stepRqs.size()).forEach(i -> { + StartTestItemRQ step = stepRqs.get(i); + assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(step.isHasStats(), equalTo(Boolean.FALSE)); + }); } } diff --git a/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java b/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java index 54d6d9e..f1a1488 100644 --- a/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java +++ b/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java @@ -4,16 +4,16 @@ public class ReflectUtils { - private ReflectUtils() { - } + private ReflectUtils() { + } - public static void setField(Object object, Field fld, Object value) { - try { - fld.setAccessible(true); - fld.set(object, value); - } catch (IllegalAccessException e) { - String fieldName = fld.getName(); - throw new RuntimeException("Failed to set " + fieldName + " of object", e); - } - } + public static void setField(Object object, Field fld, Object value) { + try { + fld.setAccessible(true); + fld.set(object, value); + } catch (IllegalAccessException e) { + String fieldName = fld.getName(); + throw new RuntimeException("Failed to set " + fieldName + " of object", e); + } + } } diff --git a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java index e77569e..ab33a9b 100644 --- a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java +++ b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java @@ -1,16 +1,172 @@ package com.epam.reportportal.karate.utils; import com.epam.reportportal.karate.KarateReportPortalRunner; +import com.epam.reportportal.listeners.ListenerParameters; +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.BatchSaveOperatingRS; +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.intuit.karate.Results; +import io.reactivex.Maybe; +import org.apache.commons.lang3.tuple.Pair; +import org.mockito.stubbing.Answer; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.stream.Collectors; + +import static com.epam.reportportal.util.test.CommonUtils.generateUniqueId; +import static java.util.Optional.ofNullable; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.when; public class TestUtils { + public static final String ROOT_SUITE_PREFIX = "root_"; + private TestUtils() { } - public static Results run(String... paths) { + public static ExecutorService testExecutor() { + return Executors.newSingleThreadExecutor(r -> { + Thread t = new Thread(r); + t.setDaemon(true); + return t; + }); + } + + public static Results runAsReport(ReportPortal reportPortal, String... paths) { return KarateReportPortalRunner .path(paths) + .withReportPortal(reportPortal) .outputCucumberJson(false) .parallel(1); } + + public static ListenerParameters standardParameters() { + ListenerParameters result = new ListenerParameters(); + result.setClientJoin(false); + result.setLaunchName("My-test-launch" + generateUniqueId()); + result.setProjectName("test-project"); + result.setEnable(true); + result.setCallbackReportingEnabled(true); + result.setBaseUrl("http://localhost:8080"); + return result; + } + + public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid, + @Nullable final String storyUuid, @Nonnull String testClassUuid, + @Nonnull String stepUuid) { + mockLaunch(client, launchUuid, storyUuid, testClassUuid, Collections.singleton(stepUuid)); + } + + public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid, + @Nullable final String storyUuid, @Nonnull String testClassUuid, + @Nonnull Collection stepList) { + mockLaunch(client, launchUuid, storyUuid, Collections.singletonList(Pair.of(testClassUuid, stepList))); + } + + public static > void mockLaunch( + @Nonnull final ReportPortalClient client, @Nullable final String launchUuid, + @Nullable final String storyUuid, @Nonnull final Collection> testSteps) { + String launch = ofNullable(launchUuid).orElse(CommonUtils.namedId("launch_")); + when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launch, 1L))); + when(client.finishLaunch(eq(launch), any())).thenReturn(Maybe.just(new OperationCompletionRS())); + + mockFeature(client, storyUuid, testSteps); + } + + public static > void mockFeature( + @Nonnull final ReportPortalClient client, @Nullable final String storyUuid, + @Nonnull final Collection> testSteps) { + String rootItemId = ofNullable(storyUuid).orElseGet(() -> CommonUtils.namedId(ROOT_SUITE_PREFIX)); + mockFeatures(client, Collections.singletonList(Pair.of(rootItemId, testSteps))); + } + + @SuppressWarnings("unchecked") + public static > void mockFeatures( + @Nonnull final ReportPortalClient client, + @Nonnull final List>>> stories) { + if (stories.isEmpty()) { + return; + } + String firstStory = stories.get(0).getKey(); + Maybe first = Maybe.just(new ItemCreatedRS(firstStory, firstStory)); + Maybe[] other = (Maybe[]) stories.subList(1, stories.size()) + .stream() + .map(Pair::getKey) + .map(s -> Maybe.just(new ItemCreatedRS(s, s))) + .toArray(Maybe[]::new); + when(client.startTestItem(any())).thenReturn(first, other); + + stories.forEach(i -> { + Maybe rootFinishMaybe = Maybe.just(new OperationCompletionRS()); + when(client.finishTestItem(same(i.getKey()), any())).thenReturn(rootFinishMaybe); + mockScenario(client, i.getKey(), i.getValue()); + }); + } + + @SuppressWarnings("unchecked") + public static > void mockScenario( + @Nonnull final ReportPortalClient client, @Nonnull final String storyUuid, + @Nonnull final Collection> testSteps) { + List> testResponses = testSteps.stream() + .map(Pair::getKey) + .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) + .collect(Collectors.toList()); + + Maybe first = testResponses.get(0); + Maybe[] other = testResponses.subList(1, testResponses.size()).toArray(new Maybe[0]); + when(client.startTestItem(same(storyUuid), any())).thenReturn(first, other); + + testSteps.forEach(test -> { + String testClassUuid = test.getKey(); + List> stepResponses = test.getValue() + .stream() + .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) + .collect(Collectors.toList()); + when(client.finishTestItem(same(testClassUuid), any())).thenReturn(Maybe.just(new OperationCompletionRS())); + if (!stepResponses.isEmpty()) { + Maybe myFirst = stepResponses.get(0); + Maybe[] myOther = stepResponses.subList(1, stepResponses.size()).toArray(new Maybe[0]); + when(client.startTestItem(same(testClassUuid), any())).thenReturn(myFirst, myOther); + new HashSet<>(test.getValue()).forEach(testMethodUuid -> when( + client.finishTestItem(same(testMethodUuid), + any() + )).thenReturn(Maybe.just(new OperationCompletionRS()))); + } + }); + } + + @SuppressWarnings("unchecked") + public static void mockBatchLogging(final ReportPortalClient client) { + when(client.log(any(List.class))).thenReturn(Maybe.just(new BatchSaveOperatingRS())); + } + + 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() + .collect(Collectors.groupingBy(Pair::getKey, Collectors.mapping(Pair::getValue, Collectors.toList()))); + responseOrders.forEach((k, v) -> { + List> responses = v.stream() + .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) + .collect(Collectors.toList()); + + Maybe first = responses.get(0); + Maybe[] other = responses.subList(1, responses.size()).toArray(new Maybe[0]); + when(client.startTestItem(eq(k), any())).thenReturn(first, other); + }); + parentNestedPairs.forEach(p -> when(client.finishTestItem(same(p.getValue()), + any() + )).thenAnswer((Answer>) invocation -> Maybe.just(new OperationCompletionRS()))); + } } diff --git a/src/test/resources/feature/Test.feature b/src/test/resources/feature/Test.feature index 28ecaf4..e3ff8c8 100644 --- a/src/test/resources/feature/Test.feature +++ b/src/test/resources/feature/Test.feature @@ -1,4 +1,5 @@ Feature: Quote generator + @To_run Scenario: Fetch random quote 1 Given url 'http://jsonplaceholder.typicode.com/posts' diff --git a/src/test/resources/feature/simple.feature b/src/test/resources/feature/simple.feature index 3c8457b..1079edb 100644 --- a/src/test/resources/feature/simple.feature +++ b/src/test/resources/feature/simple.feature @@ -1,4 +1,5 @@ Feature: the very basic test to run by Karate + Scenario: Verify response code Given url 'https://example.com/' When method GET diff --git a/src/test/resources/logback.xml b/src/test/resources/logback.xml index 6a3f276..017378b 100644 --- a/src/test/resources/logback.xml +++ b/src/test/resources/logback.xml @@ -31,7 +31,7 @@ - + @@ -40,8 +40,8 @@ - - + + From 941db52d42504f8bb65f84bf24f14cfb119cb4ab Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 12 Dec 2023 15:56:51 +0300 Subject: [PATCH 06/76] Do not output Cucumber to avoid failures in CI --- src/test/java/com/epam/reportportal/karate/KarateTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/epam/reportportal/karate/KarateTest.java b/src/test/java/com/epam/reportportal/karate/KarateTest.java index 957c3fe..5b488d4 100644 --- a/src/test/java/com/epam/reportportal/karate/KarateTest.java +++ b/src/test/java/com/epam/reportportal/karate/KarateTest.java @@ -11,7 +11,7 @@ class KarateTest { void testParallel() { Results results = KarateReportPortalRunner .path("classpath:feature") - .outputCucumberJson(true) + .outputCucumberJson(false) .tags("~@ignore", "@To_run") .parallel(2); assertEquals(0, results.getFailCount()); From cd07d38597f78c48d37cd17a3eb661f443ba5171 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 12 Dec 2023 16:31:17 +0300 Subject: [PATCH 07/76] Revert last change --- src/test/java/com/epam/reportportal/karate/KarateTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/epam/reportportal/karate/KarateTest.java b/src/test/java/com/epam/reportportal/karate/KarateTest.java index 5b488d4..957c3fe 100644 --- a/src/test/java/com/epam/reportportal/karate/KarateTest.java +++ b/src/test/java/com/epam/reportportal/karate/KarateTest.java @@ -11,7 +11,7 @@ class KarateTest { void testParallel() { Results results = KarateReportPortalRunner .path("classpath:feature") - .outputCucumberJson(false) + .outputCucumberJson(true) .tags("~@ignore", "@To_run") .parallel(2); assertEquals(0, results.getFailCount()); From c5054170b18f7e823c9562e1f1e36640745d8748 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 12 Dec 2023 17:07:15 +0300 Subject: [PATCH 08/76] A try to fix tests --- build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/build.gradle b/build.gradle index 1ae5bc7..6a0ccf7 100644 --- a/build.gradle +++ b/build.gradle @@ -56,7 +56,6 @@ dependencies { test { outputs.upToDateWhen { return false } - maxParallelForks(5) useJUnitPlatform() doFirst { def weaver = configurations.testRuntimeClasspath.find { it.name.contains("aspectjweaver") } From 11dbf977dc4819b987933a7cc4041d944ead1ae2 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 12 Dec 2023 18:32:42 +0300 Subject: [PATCH 09/76] Add code reference for simple scenarios --- .../karate/ReportPortalPublisher.java | 54 ++++++++++++++----- .../karate/coderef/ScenarioCodeRefTest.java | 2 +- src/test/resources/feature/simple.feature | 8 +-- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 27265e0..4fc72d6 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -2,6 +2,7 @@ import com.epam.reportportal.karate.enums.ItemLogLevelEnum; import com.epam.reportportal.karate.enums.ItemStatusEnum; +import com.epam.reportportal.listeners.ItemType; import com.epam.reportportal.listeners.ListenerParameters; import com.epam.reportportal.service.Launch; import com.epam.reportportal.service.ReportPortal; @@ -28,6 +29,8 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class ReportPortalPublisher { + public static final String SCENARIO_CODE_REFERENCE_PATTERN = "%s/[SCENARIO:%s]"; + private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalPublisher.class); private final ConcurrentHashMap> featureIdMap = new ConcurrentHashMap<>(); private final ConcurrentHashMap> scenarioIdMap = new ConcurrentHashMap<>(); @@ -91,6 +94,7 @@ public ReportPortalPublisher(Supplier launchSupplier) { * Starts launch instance */ public void startLaunch() { + //noinspection ReactiveStreamsUnusedPublisher launch.get().start(); } @@ -101,12 +105,21 @@ public void finishLaunch() { FinishExecutionRQ rq = new FinishExecutionRQ(); rq.setEndTime(Calendar.getInstance().getTime()); ListenerParameters parameters = launch.get().getParameters(); - LOGGER.info("LAUNCH URL: {}/ui/#{}/launches/all/{}", parameters.getBaseUrl(), parameters.getProjectName(), + LOGGER.info("Launch URL: {}/ui/#{}/launches/all/{}", parameters.getBaseUrl(), parameters.getProjectName(), System.getProperty("rp.launch.id")); launch.get().finish(rq); Runtime.getRuntime().removeShutdownHook(shutDownHook); } + protected String getCodeRef(Scenario scenario) { + if(scenario.getExampleIndex() < 0) { + return String.format(SCENARIO_CODE_REFERENCE_PATTERN, scenario.getFeature().getResource().getRelativePath(), + scenario.getName()); + } else { + return null; + } + } + /** * Customize start test item event/request * @@ -115,13 +128,12 @@ public void finishLaunch() { * @param type item's type (e.g. feature, scenario, step, etc.) * @return request to ReportPortal */ - protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, - @Nonnull Date startTime, - @Nonnull String type) { + protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Date startTime, + @Nonnull ItemType type) { StartTestItemRQ rq = new StartTestItemRQ(); rq.setName(name); rq.setStartTime(startTime); - rq.setType(type); + rq.setType(type.name()); return rq; } @@ -135,15 +147,27 @@ protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, * @return request to ReportPortal */ @SuppressWarnings("SameParameterValue") - protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, - @Nonnull Date startTime, - @Nonnull String type, - boolean hasStats) { + protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Date startTime, + @Nonnull ItemType type, boolean hasStats) { StartTestItemRQ rq = buildStartTestItemRq(name, startTime, type); rq.setHasStats(hasStats); return rq; } + /** + * Build ReportPortal request for start Scenario event + * + * @param scenarioResult Karate's ScenarioResult instance + * @return request to ReportPortal + */ + protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioResult scenarioResult) { + StartTestItemRQ rq = buildStartTestItemRq(scenarioResult.getScenario().getName(), + Calendar.getInstance().getTime(), + ItemType.STEP); + rq.setCodeRef(getCodeRef(scenarioResult.getScenario())); + return rq; + } + /** * Customize start test item event/request * @@ -167,7 +191,7 @@ protected FinishTestItemRQ buildFinishTestItemRq(@Nonnull Date endTime, public void startFeature(FeatureResult featureResult) { StartTestItemRQ rq = buildStartTestItemRq(String.valueOf(featureResult.toCucumberJson().get("name")), Calendar.getInstance().getTime(), - "STORY"); + ItemType.STORY); Maybe featureId = launch.get().startTestItem(rq); featureIdMap.put(featureResult.getCallNameForReport(), featureId); } @@ -198,6 +222,7 @@ public void finishFeature(FeatureResult featureResult) { FinishTestItemRQ rq = buildFinishTestItemRq(Calendar.getInstance().getTime(), featureResult.isFailed() ? ItemStatusEnum.FAILED.toString() : ItemStatusEnum.PASSED.toString()); + //noinspection ReactiveStreamsUnusedPublisher launch.get().finishTestItem(featureIdMap.remove(featureResult.getCallNameForReport()), rq); } @@ -208,9 +233,8 @@ public void finishFeature(FeatureResult featureResult) { * @param featureResult feature result */ public void startScenario(ScenarioResult scenarioResult, FeatureResult featureResult) { - StartTestItemRQ rq = buildStartTestItemRq(scenarioResult.getScenario().getName(), - Calendar.getInstance().getTime(), - "STEP"); + StartTestItemRQ rq = buildStartScenarioRq(scenarioResult); + Maybe scenarioId = launch.get().startTestItem(featureIdMap.get(featureResult.getCallNameForReport()), rq); scenarioIdMap.put(scenarioResult.getScenario().getName(), scenarioId); } @@ -228,6 +252,7 @@ public void finishScenario(ScenarioResult scenarioResult) { FinishTestItemRQ rq = buildFinishTestItemRq(Calendar.getInstance().getTime(), scenarioResult.getFailureMessageForDisplay() == null ? ItemStatusEnum.PASSED.toString() : ItemStatusEnum.FAILED.toString()); Maybe removedScenarioId = scenarioIdMap.remove(scenarioResult.getScenario().getName()); + //noinspection ReactiveStreamsUnusedPublisher launch.get().finishTestItem(removedScenarioId, rq); } @@ -239,7 +264,7 @@ public void finishScenario(ScenarioResult scenarioResult) { */ public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { String stepName = stepResult.getStep().getPrefix() + " " + stepResult.getStep().getText(); - StartTestItemRQ rq = buildStartTestItemRq(stepName, getStepStartTime(stepStartTimeMap, stepId), "STEP", false); + StartTestItemRQ rq = buildStartTestItemRq(stepName, getStepStartTime(stepStartTimeMap, stepId), ItemType.STEP, false); stepId = launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), rq); stepStartTimeMap.put(stepId, rq.getStartTime().getTime()); } @@ -257,6 +282,7 @@ public void finishStep(StepResult stepResult) { FinishTestItemRQ rq = buildFinishTestItemRq(Calendar.getInstance().getTime(), getStepStatus(stepResult.getResult().getStatus())); + //noinspection ReactiveStreamsUnusedPublisher launch.get().finishTestItem(stepId, rq); } diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java index 9829266..887237c 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java @@ -26,7 +26,7 @@ public class ScenarioCodeRefTest { private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); - private static final String SIMPLE_CODE_REFERENCE = "feature/simple.feature/[SCENARIO:Verify response code]"; + private static final String SIMPLE_CODE_REFERENCE = "feature/simple.feature/[SCENARIO:Verify math]"; private final ReportPortalClient client = mock(ReportPortalClient.class); private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); diff --git a/src/test/resources/feature/simple.feature b/src/test/resources/feature/simple.feature index 1079edb..c5b56a0 100644 --- a/src/test/resources/feature/simple.feature +++ b/src/test/resources/feature/simple.feature @@ -1,6 +1,6 @@ Feature: the very basic test to run by Karate - Scenario: Verify response code - Given url 'https://example.com/' - When method GET - Then status 200 + Scenario: Verify math + Given def four = 4 + When def acualFour = 2 * 2 + Then assert acualFour == four From 5e874bc03ff547e1d7850cbf9da1bd1151f6bb88 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 14 Dec 2023 18:14:15 +0300 Subject: [PATCH 10/76] Add code reference for Examples scenarios --- .../epam/reportportal/karate/KarateUtils.java | 48 +++++++++++ .../karate/ReportPortalPublisher.java | 4 +- .../karate/coderef/ExamplesCodeRefTest.java | 80 +++++++++++++++++++ .../reportportal/karate/utils/TestUtils.java | 48 +++++------ src/test/resources/feature/examples.feature | 10 +++ 5 files changed, 165 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/epam/reportportal/karate/KarateUtils.java create mode 100644 src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java create mode 100644 src/test/resources/feature/examples.feature diff --git a/src/main/java/com/epam/reportportal/karate/KarateUtils.java b/src/main/java/com/epam/reportportal/karate/KarateUtils.java new file mode 100644 index 0000000..db4ce6d --- /dev/null +++ b/src/main/java/com/epam/reportportal/karate/KarateUtils.java @@ -0,0 +1,48 @@ +/* + * 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. + */ +package com.epam.reportportal.karate; + +import javax.annotation.Nonnull; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Set of useful utils related to Karate -> ReportPortal integration + */ +public class KarateUtils { + + private KarateUtils() { + throw new AssertionError("No instances should exist for the class!"); + } + + private static final String PARAMETER_ITEMS_START = "["; + private static final String PARAMETER_ITEMS_END = "]"; + private static final String PARAMETER_ITEMS_DELIMITER = ";"; + private static final String KEY_VALUE_SEPARATOR = ":"; + + /** + * Create a String from a parameter Map to be used as a test key and title + * + * @param example a map of parameters: name->value + * @return a formatted string of parameters + */ + public static String formatExampleKey(@Nonnull final Map example) { + return example.entrySet() + .stream() + .map(e -> e.getKey() + KEY_VALUE_SEPARATOR + e.getValue().toString()) + .collect(Collectors.joining(PARAMETER_ITEMS_DELIMITER, PARAMETER_ITEMS_START, PARAMETER_ITEMS_END)); + } +} diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 4fc72d6..416029f 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -30,6 +30,7 @@ public class ReportPortalPublisher { public static final String SCENARIO_CODE_REFERENCE_PATTERN = "%s/[SCENARIO:%s]"; + public static final String EXAMPLE_CODE_REFERENCE_PATTERN = "%s/[EXAMPLE:%s%s]"; private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalPublisher.class); private final ConcurrentHashMap> featureIdMap = new ConcurrentHashMap<>(); @@ -116,7 +117,8 @@ protected String getCodeRef(Scenario scenario) { return String.format(SCENARIO_CODE_REFERENCE_PATTERN, scenario.getFeature().getResource().getRelativePath(), scenario.getName()); } else { - return null; + return String.format(EXAMPLE_CODE_REFERENCE_PATTERN, scenario.getFeature().getResource().getRelativePath(), + scenario.getName(), KarateUtils.formatExampleKey(scenario.getExampleData())); } } diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java new file mode 100644 index 0000000..f36b00d --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java @@ -0,0 +1,80 @@ +package com.epam.reportportal.karate.coderef; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.listeners.ItemType; +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.StartTestItemRQ; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class ExamplesCodeRefTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) + .collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); + + private static final String EXAMPLE_CODE_REFERENCE_PATTERN = "feature/examples.feature/[EXAMPLE:Verify different maths[%s]]"; + private static final String FIRST_EXAMPLE_CODE_REFERENCE = String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "vara:2;varb:2;result:4"); + private static final String SECOND_EXAMPLE_CODE_REFERENCE = String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "vara:1;varb:2;result:3"); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_examples_code_reference() { + var results = TestUtils.runAsReport(rp, "classpath:feature/examples.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(2)).startTestItem(same(featureId), captor.capture()); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), captor.capture()); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), captor.capture()); + + List items = captor.getAllValues(); + assertThat(items, hasSize(7)); + + StartTestItemRQ featureRq = items.get(0); + + assertThat(featureRq.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); + + StartTestItemRQ firstScenarioRq = items.get(1); + assertThat(firstScenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(firstScenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_CODE_REFERENCE))); + + StartTestItemRQ secondScenarioRq = items.get(2); + assertThat(secondScenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(secondScenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_CODE_REFERENCE))); + + List stepRqs = items.subList(3, items.size()); + IntStream.range(0, stepRqs.size()).forEach(i -> { + StartTestItemRQ step = stepRqs.get(i); + assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(step.isHasStats(), equalTo(Boolean.FALSE)); + }); + } +} diff --git a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java index ab33a9b..3fbc449 100644 --- a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java +++ b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java @@ -60,51 +60,51 @@ public static ListenerParameters standardParameters() { } public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid, - @Nullable final String storyUuid, @Nonnull String testClassUuid, + @Nullable final String featureUuid, @Nonnull String scenarioUuid, @Nonnull String stepUuid) { - mockLaunch(client, launchUuid, storyUuid, testClassUuid, Collections.singleton(stepUuid)); + mockLaunch(client, launchUuid, featureUuid, scenarioUuid, Collections.singleton(stepUuid)); } public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid, - @Nullable final String storyUuid, @Nonnull String testClassUuid, + @Nullable final String featureUuid, @Nonnull String scenarioUuid, @Nonnull Collection stepList) { - mockLaunch(client, launchUuid, storyUuid, Collections.singletonList(Pair.of(testClassUuid, stepList))); + mockLaunch(client, launchUuid, featureUuid, Collections.singletonList(Pair.of(scenarioUuid, stepList))); } public static > void mockLaunch( @Nonnull final ReportPortalClient client, @Nullable final String launchUuid, - @Nullable final String storyUuid, @Nonnull final Collection> testSteps) { + @Nullable final String featureUuid, @Nonnull final Collection> scenarioSteps) { String launch = ofNullable(launchUuid).orElse(CommonUtils.namedId("launch_")); when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launch, 1L))); when(client.finishLaunch(eq(launch), any())).thenReturn(Maybe.just(new OperationCompletionRS())); - mockFeature(client, storyUuid, testSteps); + mockFeature(client, featureUuid, scenarioSteps); } public static > void mockFeature( - @Nonnull final ReportPortalClient client, @Nullable final String storyUuid, - @Nonnull final Collection> testSteps) { - String rootItemId = ofNullable(storyUuid).orElseGet(() -> CommonUtils.namedId(ROOT_SUITE_PREFIX)); - mockFeatures(client, Collections.singletonList(Pair.of(rootItemId, testSteps))); + @Nonnull final ReportPortalClient client, @Nullable final String featureUuid, + @Nonnull final Collection> scenarioSteps) { + String rootItemId = ofNullable(featureUuid).orElseGet(() -> CommonUtils.namedId(ROOT_SUITE_PREFIX)); + mockFeatures(client, Collections.singletonList(Pair.of(rootItemId, scenarioSteps))); } @SuppressWarnings("unchecked") public static > void mockFeatures( @Nonnull final ReportPortalClient client, - @Nonnull final List>>> stories) { - if (stories.isEmpty()) { + @Nonnull final List>>> features) { + if (features.isEmpty()) { return; } - String firstStory = stories.get(0).getKey(); - Maybe first = Maybe.just(new ItemCreatedRS(firstStory, firstStory)); - Maybe[] other = (Maybe[]) stories.subList(1, stories.size()) + String firstFeature = features.get(0).getKey(); + Maybe first = Maybe.just(new ItemCreatedRS(firstFeature, firstFeature)); + Maybe[] other = (Maybe[]) features.subList(1, features.size()) .stream() .map(Pair::getKey) .map(s -> Maybe.just(new ItemCreatedRS(s, s))) .toArray(Maybe[]::new); when(client.startTestItem(any())).thenReturn(first, other); - stories.forEach(i -> { + features.forEach(i -> { Maybe rootFinishMaybe = Maybe.just(new OperationCompletionRS()); when(client.finishTestItem(same(i.getKey()), any())).thenReturn(rootFinishMaybe); mockScenario(client, i.getKey(), i.getValue()); @@ -113,28 +113,28 @@ public static > void mockFeatures( @SuppressWarnings("unchecked") public static > void mockScenario( - @Nonnull final ReportPortalClient client, @Nonnull final String storyUuid, - @Nonnull final Collection> testSteps) { - List> testResponses = testSteps.stream() + @Nonnull final ReportPortalClient client, @Nonnull final String featureUuid, + @Nonnull final Collection> scenarioSteps) { + List> testResponses = scenarioSteps.stream() .map(Pair::getKey) .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) .collect(Collectors.toList()); Maybe first = testResponses.get(0); Maybe[] other = testResponses.subList(1, testResponses.size()).toArray(new Maybe[0]); - when(client.startTestItem(same(storyUuid), any())).thenReturn(first, other); + when(client.startTestItem(same(featureUuid), any())).thenReturn(first, other); - testSteps.forEach(test -> { - String testClassUuid = test.getKey(); + scenarioSteps.forEach(test -> { + String scenarioUuid = test.getKey(); List> stepResponses = test.getValue() .stream() .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) .collect(Collectors.toList()); - when(client.finishTestItem(same(testClassUuid), any())).thenReturn(Maybe.just(new OperationCompletionRS())); + when(client.finishTestItem(same(scenarioUuid), any())).thenReturn(Maybe.just(new OperationCompletionRS())); if (!stepResponses.isEmpty()) { Maybe myFirst = stepResponses.get(0); Maybe[] myOther = stepResponses.subList(1, stepResponses.size()).toArray(new Maybe[0]); - when(client.startTestItem(same(testClassUuid), any())).thenReturn(myFirst, myOther); + when(client.startTestItem(same(scenarioUuid), any())).thenReturn(myFirst, myOther); new HashSet<>(test.getValue()).forEach(testMethodUuid -> when( client.finishTestItem(same(testMethodUuid), any() diff --git a/src/test/resources/feature/examples.feature b/src/test/resources/feature/examples.feature new file mode 100644 index 0000000..19617fc --- /dev/null +++ b/src/test/resources/feature/examples.feature @@ -0,0 +1,10 @@ +Feature: math tests with examples + + Scenario Outline: Verify different maths + Given def mathResult = vara + varb + Then assert mathResult == result + + Examples: + | vara! | varb! | result! | + | 2 | 2 | 4 | + | 1 | 2 | 3 | From 18247076fe8b8edf3dd001562db3dd29ac8d2887 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 14 Dec 2023 18:15:18 +0300 Subject: [PATCH 11/76] Format fixes --- .../reportportal/karate/coderef/ExamplesCodeRefTest.java | 9 ++++++--- .../reportportal/karate/coderef/ScenarioCodeRefTest.java | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java index f36b00d..40e9a2a 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java @@ -31,9 +31,12 @@ public class ExamplesCodeRefTest { .limit(2).collect(Collectors.toList()))) .collect(Collectors.toList()); - private static final String EXAMPLE_CODE_REFERENCE_PATTERN = "feature/examples.feature/[EXAMPLE:Verify different maths[%s]]"; - private static final String FIRST_EXAMPLE_CODE_REFERENCE = String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "vara:2;varb:2;result:4"); - private static final String SECOND_EXAMPLE_CODE_REFERENCE = String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "vara:1;varb:2;result:3"); + private static final String EXAMPLE_CODE_REFERENCE_PATTERN = + "feature/examples.feature/[EXAMPLE:Verify different maths[%s]]"; + private static final String FIRST_EXAMPLE_CODE_REFERENCE = + String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "vara:2;varb:2;result:4"); + private static final String SECOND_EXAMPLE_CODE_REFERENCE = + String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "vara:1;varb:2;result:3"); private final ReportPortalClient client = mock(ReportPortalClient.class); private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java index 887237c..b7b047a 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java @@ -24,7 +24,8 @@ public class ScenarioCodeRefTest { private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); private static final String SIMPLE_CODE_REFERENCE = "feature/simple.feature/[SCENARIO:Verify math]"; From 94136429ac65042655219dc8ad2e3d7f73f4767a Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 14 Dec 2023 18:20:25 +0300 Subject: [PATCH 12/76] Code reference generation: sort by example key to unify code reference --- src/main/java/com/epam/reportportal/karate/KarateUtils.java | 1 + .../epam/reportportal/karate/coderef/ExamplesCodeRefTest.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/epam/reportportal/karate/KarateUtils.java b/src/main/java/com/epam/reportportal/karate/KarateUtils.java index db4ce6d..b557b25 100644 --- a/src/main/java/com/epam/reportportal/karate/KarateUtils.java +++ b/src/main/java/com/epam/reportportal/karate/KarateUtils.java @@ -42,6 +42,7 @@ private KarateUtils() { public static String formatExampleKey(@Nonnull final Map example) { return example.entrySet() .stream() + .sorted(Map.Entry.comparingByKey()) .map(e -> e.getKey() + KEY_VALUE_SEPARATOR + e.getValue().toString()) .collect(Collectors.joining(PARAMETER_ITEMS_DELIMITER, PARAMETER_ITEMS_START, PARAMETER_ITEMS_END)); } diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java index 40e9a2a..e941a90 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java @@ -34,9 +34,9 @@ public class ExamplesCodeRefTest { private static final String EXAMPLE_CODE_REFERENCE_PATTERN = "feature/examples.feature/[EXAMPLE:Verify different maths[%s]]"; private static final String FIRST_EXAMPLE_CODE_REFERENCE = - String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "vara:2;varb:2;result:4"); + String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "result:4;vara:2;varb:2"); private static final String SECOND_EXAMPLE_CODE_REFERENCE = - String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "vara:1;varb:2;result:3"); + String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "result:3;vara:1;varb:2"); private final ReportPortalClient client = mock(ReportPortalClient.class); private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); From b2587fe880bd66cef25ab8450405b88585d292e0 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 15 Dec 2023 15:26:58 +0300 Subject: [PATCH 13/76] Add Test Case ID --- .../karate/ReportPortalPublisher.java | 30 +++++++- .../karate/id/ExamplesTestCaseIdTest.java | 68 +++++++++++++++++++ .../karate/id/ScenarioTestCaseIdTest.java | 55 +++++++++++++++ 3 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java create mode 100644 src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 416029f..aa24f34 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -6,7 +6,9 @@ import com.epam.reportportal.listeners.ListenerParameters; import com.epam.reportportal.service.Launch; import com.epam.reportportal.service.ReportPortal; +import com.epam.reportportal.service.item.TestCaseIdEntry; import com.epam.reportportal.utils.MemoizingSupplier; +import com.epam.reportportal.utils.TestCaseIdUtils; import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; @@ -18,6 +20,7 @@ import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.Calendar; import java.util.Date; import java.util.HashSet; @@ -26,6 +29,7 @@ import java.util.function.Supplier; import static com.google.common.base.Strings.isNullOrEmpty; +import static java.util.Optional.ofNullable; import static org.apache.commons.lang3.StringUtils.isNotBlank; public class ReportPortalPublisher { @@ -112,8 +116,15 @@ public void finishLaunch() { Runtime.getRuntime().removeShutdownHook(shutDownHook); } - protected String getCodeRef(Scenario scenario) { - if(scenario.getExampleIndex() < 0) { + /** + * Returns code reference for feature files by URI and Scenario reference + * + * @param scenario Karate's Scenario object instance + * @return a code reference + */ + @Nonnull + protected String getCodeRef(@Nonnull Scenario scenario) { + if (scenario.getExampleIndex() < 0) { return String.format(SCENARIO_CODE_REFERENCE_PATTERN, scenario.getFeature().getResource().getRelativePath(), scenario.getName()); } else { @@ -122,6 +133,17 @@ protected String getCodeRef(Scenario scenario) { } } + /** + * Return a Test Case ID for a Scenario in a Feature file + * + * @param scenario Karate's Scenario object instance + * @return Test Case ID entity or null if it's not possible to calculate + */ + @Nullable + protected TestCaseIdEntry getTestCaseId(@Nonnull Scenario scenario) { + return TestCaseIdUtils.getTestCaseId(getCodeRef(scenario), null); + } + /** * Customize start test item event/request * @@ -166,7 +188,9 @@ protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioResult scenarioR StartTestItemRQ rq = buildStartTestItemRq(scenarioResult.getScenario().getName(), Calendar.getInstance().getTime(), ItemType.STEP); - rq.setCodeRef(getCodeRef(scenarioResult.getScenario())); + Scenario scenario = scenarioResult.getScenario(); + rq.setCodeRef(getCodeRef(scenario)); + rq.setTestCaseId(ofNullable(getTestCaseId(scenario)).map(TestCaseIdEntry::getId).orElse(null)); return rq; } diff --git a/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java b/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java new file mode 100644 index 0000000..1ca7ff6 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java @@ -0,0 +1,68 @@ +package com.epam.reportportal.karate.id; + +import com.epam.reportportal.karate.utils.TestUtils; +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.StartTestItemRQ; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class ExamplesTestCaseIdTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) + .collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); + + private static final String EXAMPLE_TEST_CASE_ID_PATTERN = + "feature/examples.feature/[EXAMPLE:Verify different maths[%s]]"; + private static final String FIRST_EXAMPLE_TEST_CASE_ID = + String.format(EXAMPLE_TEST_CASE_ID_PATTERN, "result:4;vara:2;varb:2"); + private static final String SECOND_EXAMPLE_TEST_CASE_ID = + String.format(EXAMPLE_TEST_CASE_ID_PATTERN, "result:3;vara:1;varb:2"); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_examples_test_case_id() { + var results = TestUtils.runAsReport(rp, "classpath:feature/examples.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(2)).startTestItem(same(featureId), captor.capture()); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), captor.capture()); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), captor.capture()); + + List items = captor.getAllValues(); + assertThat(items, hasSize(7)); + + StartTestItemRQ firstScenarioRq = items.get(1); + assertThat(firstScenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_TEST_CASE_ID))); + + StartTestItemRQ secondScenarioRq = items.get(2); + assertThat(secondScenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_TEST_CASE_ID))); + } +} diff --git a/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java b/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java new file mode 100644 index 0000000..38dd509 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java @@ -0,0 +1,55 @@ +package com.epam.reportportal.karate.id; + +import com.epam.reportportal.karate.utils.TestUtils; +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.StartTestItemRQ; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class ScenarioTestCaseIdTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private static final String SIMPLE_TEST_CASE_ID = "feature/simple.feature/[SCENARIO:Verify math]"; + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_test_case_id() { + var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); + + List items = captor.getAllValues(); + assertThat(items, hasSize(5)); + + StartTestItemRQ scenarioRq = items.get(1); + assertThat(scenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(SIMPLE_TEST_CASE_ID))); + } +} From 43b08e44d389168d9ca81473e59c28d6b02bffb2 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Sat, 16 Dec 2023 16:01:54 +0300 Subject: [PATCH 14/76] Attribute handling --- build.gradle | 2 +- .../karate/ReportPortalPublisher.java | 67 ++++++++++++--- ...arateUtils.java => ReportPortalUtils.java} | 6 +- .../attributes/DifferentAttributesTest.java | 85 +++++++++++++++++++ .../karate/attributes/NoAttributesTest.java | 72 ++++++++++++++++ src/test/resources/feature/tags.feature | 8 ++ 6 files changed, 224 insertions(+), 16 deletions(-) rename src/main/java/com/epam/reportportal/karate/{KarateUtils.java => ReportPortalUtils.java} (94%) create mode 100644 src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java create mode 100644 src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java create mode 100644 src/test/resources/feature/tags.feature diff --git a/build.gradle b/build.gradle index 6a0ccf7..929d455 100644 --- a/build.gradle +++ b/build.gradle @@ -41,7 +41,7 @@ repositories { } dependencies { - api 'com.epam.reportportal:client-java:5.1.24' + api 'com.epam.reportportal:client-java:5.1.25' api "com.intuit.karate:karate-core:${project.karate_version}" implementation 'org.slf4j:slf4j-api:2.0.7' diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index aa24f34..b9e9c60 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -1,3 +1,19 @@ +/* + * Copyright 2023 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 + * + * 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, + * 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. + */ + package com.epam.reportportal.karate; import com.epam.reportportal.karate.enums.ItemLogLevelEnum; @@ -7,11 +23,13 @@ import com.epam.reportportal.service.Launch; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.item.TestCaseIdEntry; +import com.epam.reportportal.utils.AttributeParser; import com.epam.reportportal.utils.MemoizingSupplier; import com.epam.reportportal.utils.TestCaseIdUtils; import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; import com.intuit.karate.core.*; @@ -21,12 +39,11 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Calendar; -import java.util.Date; -import java.util.HashSet; -import java.util.List; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static com.google.common.base.Strings.isNullOrEmpty; import static java.util.Optional.ofNullable; @@ -129,7 +146,7 @@ protected String getCodeRef(@Nonnull Scenario scenario) { scenario.getName()); } else { return String.format(EXAMPLE_CODE_REFERENCE_PATTERN, scenario.getFeature().getResource().getRelativePath(), - scenario.getName(), KarateUtils.formatExampleKey(scenario.getExampleData())); + scenario.getName(), ReportPortalUtils.formatExampleKey(scenario.getExampleData())); } } @@ -152,6 +169,7 @@ protected TestCaseIdEntry getTestCaseId(@Nonnull Scenario scenario) { * @param type item's type (e.g. feature, scenario, step, etc.) * @return request to ReportPortal */ + @Nonnull protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Date startTime, @Nonnull ItemType type) { StartTestItemRQ rq = new StartTestItemRQ(); @@ -170,7 +188,6 @@ protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Da * @param hasStats enables nested items * @return request to ReportPortal */ - @SuppressWarnings("SameParameterValue") protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Date startTime, @Nonnull ItemType type, boolean hasStats) { StartTestItemRQ rq = buildStartTestItemRq(name, startTime, type); @@ -178,10 +195,37 @@ protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Da return rq; } + @Nullable + private Set toAttributes(@Nullable List tags) { + Set attributes = ofNullable(tags).orElse(Collections.emptyList()).stream().flatMap(tag -> { + if (tag.getValues().isEmpty()) { + return Stream.of(new ItemAttributesRQ(null, tag.getName())); + } + return AttributeParser.createItemAttributes(tag.getName(), tag.getValues().toArray(new String[0])).stream(); + }).collect(Collectors.toSet()); + return attributes.isEmpty() ? null : attributes; + } + + /** + * Build ReportPortal request for start Feature event. + * + * @param featureResult Karate's FeatureResult object instance + * @return request to ReportPortal + */ + @Nonnull + protected StartTestItemRQ buildStartFeatureRq(@Nonnull FeatureResult featureResult) { + StartTestItemRQ rq = buildStartTestItemRq(String.valueOf(featureResult.toCucumberJson().get("name")), + Calendar.getInstance().getTime(), + ItemType.STORY); + Feature feature = featureResult.getFeature(); + rq.setAttributes(toAttributes(feature.getTags())); + return rq; + } + /** * Build ReportPortal request for start Scenario event * - * @param scenarioResult Karate's ScenarioResult instance + * @param scenarioResult Karate's ScenarioResult object instance * @return request to ReportPortal */ protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioResult scenarioResult) { @@ -191,6 +235,7 @@ protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioResult scenarioR Scenario scenario = scenarioResult.getScenario(); rq.setCodeRef(getCodeRef(scenario)); rq.setTestCaseId(ofNullable(getTestCaseId(scenario)).map(TestCaseIdEntry::getId).orElse(null)); + rq.setAttributes(toAttributes(scenario.getTags())); return rq; } @@ -210,14 +255,12 @@ protected FinishTestItemRQ buildFinishTestItemRq(@Nonnull Date endTime, } /** - * Start sending feature data to ReportPortal + * Start sending feature data to ReportPortal. * * @param featureResult feature result */ - public void startFeature(FeatureResult featureResult) { - StartTestItemRQ rq = buildStartTestItemRq(String.valueOf(featureResult.toCucumberJson().get("name")), - Calendar.getInstance().getTime(), - ItemType.STORY); + public void startFeature(@Nonnull FeatureResult featureResult) { + StartTestItemRQ rq = buildStartFeatureRq(featureResult); Maybe featureId = launch.get().startTestItem(rq); featureIdMap.put(featureResult.getCallNameForReport(), featureId); } diff --git a/src/main/java/com/epam/reportportal/karate/KarateUtils.java b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java similarity index 94% rename from src/main/java/com/epam/reportportal/karate/KarateUtils.java rename to src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java index b557b25..475e0f8 100644 --- a/src/main/java/com/epam/reportportal/karate/KarateUtils.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 EPAM Systems + * Copyright 2023 EPAM Systems * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,9 +22,9 @@ /** * Set of useful utils related to Karate -> ReportPortal integration */ -public class KarateUtils { +public class ReportPortalUtils { - private KarateUtils() { + private ReportPortalUtils() { throw new AssertionError("No instances should exist for the class!"); } diff --git a/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java new file mode 100644 index 0000000..6dec4d0 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java @@ -0,0 +1,85 @@ +/* + * Copyright 2023 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 + * + * 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, + * 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. + */ + +package com.epam.reportportal.karate.attributes; + +import com.epam.reportportal.karate.utils.TestUtils; +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.StartTestItemRQ; +import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class DifferentAttributesTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_different_attributes() { + var results = TestUtils.runAsReport(rp, "classpath:feature/tags.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); + + List items = captor.getAllValues(); + assertThat(items, hasSize(5)); + + StartTestItemRQ featureRq = items.get(0); + StartTestItemRQ scenarioRq = items.get(1); + + assertThat(featureRq.getAttributes(), hasSize(1)); + ItemAttributesRQ featureAttribute = featureRq.getAttributes().iterator().next(); + assertThat(featureAttribute.getKey(), nullValue()); + assertThat(featureAttribute.getValue(), equalTo("tag_test")); + + assertThat(scenarioRq.getAttributes(), hasSize(4)); + Set> scenarioAttributes = scenarioRq + .getAttributes().stream().map(a -> Pair.of(a.getKey(), a.getValue())).collect(Collectors.toSet()); + assertThat(scenarioAttributes, hasItem(Pair.of(null, "math"))); + assertThat(scenarioAttributes, hasItem(Pair.of("scope", "smoke"))); + assertThat(scenarioAttributes, hasItem(Pair.of("environment", "dev"))); + assertThat(scenarioAttributes, hasItem(Pair.of("environment", "qa"))); + } +} diff --git a/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java new file mode 100644 index 0000000..dd6a4ce --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java @@ -0,0 +1,72 @@ +/* + * Copyright 2023 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 + * + * 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, + * 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. + */ + +package com.epam.reportportal.karate.attributes; + +import com.epam.reportportal.karate.utils.TestUtils; +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.StartTestItemRQ; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class NoAttributesTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_different_attributes() { + var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); + + List items = captor.getAllValues(); + assertThat(items, hasSize(5)); + + StartTestItemRQ featureRq = items.get(0); + StartTestItemRQ scenarioRq = items.get(1); + + assertThat(featureRq.getAttributes(), nullValue()); + assertThat(scenarioRq.getAttributes(), nullValue()); + } +} diff --git a/src/test/resources/feature/tags.feature b/src/test/resources/feature/tags.feature new file mode 100644 index 0000000..876caf9 --- /dev/null +++ b/src/test/resources/feature/tags.feature @@ -0,0 +1,8 @@ +@tag_test +Feature: the very basic to test different tags + + @math @scope=smoke @environment=dev,qa + Scenario: Verify math + Given def four = 4 + When def acualFour = 2 * 2 + Then assert acualFour == four From 20880dc9dbba9c22193f73354f698ed07e09fec9 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Sat, 16 Dec 2023 16:08:12 +0300 Subject: [PATCH 15/76] Fix tests --- .../epam/reportportal/karate/ReportPortalPublisherTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java b/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java index bee1f1a..dcdcccd 100644 --- a/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java +++ b/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java @@ -6,6 +6,7 @@ import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.core.Feature; import com.intuit.karate.core.FeatureResult; import io.reactivex.Maybe; import org.junit.jupiter.api.BeforeEach; @@ -46,6 +47,8 @@ public void shouldFinishLaunch() { @Test public void shouldStartFeature() { FeatureResult featureResult = mock(FeatureResult.class); + Feature feature = mock(Feature.class); + when(featureResult.getFeature()).thenReturn(feature); when(featureResult.getCallNameForReport()).thenReturn("featureName"); when(launchMock.startTestItem(any(StartTestItemRQ.class))).thenReturn(mock(Maybe.class)); reportPortalPublisher.startFeature(featureResult); From 96cc9b639a5132ae837b920b6f0346fdfd616348 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 18 Dec 2023 14:23:07 +0300 Subject: [PATCH 16/76] System attributes reporting add --- .../karate/ReportPortalPublisher.java | 11 +++ .../karate/ReportPortalUtils.java | 11 ++- .../attributes/SystemAttributesTest.java | 78 +++++++++++++++++++ 3 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index b9e9c60..0271a38 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -26,6 +26,7 @@ import com.epam.reportportal.utils.AttributeParser; import com.epam.reportportal.utils.MemoizingSupplier; import com.epam.reportportal.utils.TestCaseIdUtils; +import com.epam.reportportal.utils.properties.SystemAttributesExtractor; import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; @@ -45,6 +46,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.epam.reportportal.karate.ReportPortalUtils.AGENT_PROPERTIES_FILE; import static com.google.common.base.Strings.isNullOrEmpty; import static java.util.Optional.ofNullable; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -91,6 +93,15 @@ protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) { if (isNotBlank(parameters.getRerunOf())) { rq.setRerunOf(parameters.getRerunOf()); } + if (null != parameters.getSkippedAnIssue()) { + ItemAttributesRQ skippedIssueAttribute = new ItemAttributesRQ(); + skippedIssueAttribute.setKey(ReportPortalUtils.SKIPPED_ISSUE_KEY); + skippedIssueAttribute.setValue(parameters.getSkippedAnIssue().toString()); + skippedIssueAttribute.setSystem(true); + rq.getAttributes().add(skippedIssueAttribute); + } + rq.getAttributes().addAll(SystemAttributesExtractor.extract(AGENT_PROPERTIES_FILE, + ReportPortalUtils.class.getClassLoader())); return rq; } diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java index 475e0f8..37c9b11 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java @@ -24,15 +24,18 @@ */ public class ReportPortalUtils { - private ReportPortalUtils() { - throw new AssertionError("No instances should exist for the class!"); - } - private static final String PARAMETER_ITEMS_START = "["; private static final String PARAMETER_ITEMS_END = "]"; private static final String PARAMETER_ITEMS_DELIMITER = ";"; private static final String KEY_VALUE_SEPARATOR = ":"; + public static final String AGENT_PROPERTIES_FILE = "agent.properties"; + public static final String SKIPPED_ISSUE_KEY = "skippedIssue"; + + private ReportPortalUtils() { + throw new AssertionError("No instances should exist for the class!"); + } + /** * Create a String from a parameter Map to be used as a test key and title * diff --git a/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java new file mode 100644 index 0000000..7ea6812 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java @@ -0,0 +1,78 @@ +/* + * Copyright 2023 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. + */ + +package com.epam.reportportal.karate.attributes; + +import com.epam.reportportal.karate.utils.TestUtils; +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.attribute.ItemAttributesRQ; +import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static com.epam.reportportal.karate.utils.TestUtils.mockBatchLogging; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class SystemAttributesTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void verify_start_launch_request_contains_system_attributes() { + var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); + + StartLaunchRQ launchStart = startCaptor.getValue(); + + Set attributes = launchStart.getAttributes(); + assertThat(attributes, allOf(notNullValue(), hasSize(greaterThan(0)))); + Set attributesStr = attributes.stream() + .filter(ItemAttributesRQ::isSystem) + .map(e -> e.getKey() + ":" + e.getValue()) + .collect(Collectors.toSet()); + assertThat(attributesStr, hasSize(4)); + assertThat(attributesStr, hasItem("skippedIssue:true")); + assertThat(attributesStr, hasItem("agent:karate-test-agent|test-1.0")); + assertThat(attributesStr, hasItem(startsWith("os:"))); + assertThat(attributesStr, hasItem(startsWith("jvm:"))); + } +} From 276becd07f116a5b3d5d3fa6fca194a5580eeb7e Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 18 Dec 2023 16:30:12 +0300 Subject: [PATCH 17/76] Refactor item start method --- .../karate/ReportPortalPublisher.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 0271a38..9112272 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -88,7 +88,6 @@ protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) { if (!isNullOrEmpty(parameters.getDescription())) { rq.setDescription(parameters.getDescription()); } - rq.setStartTime(Calendar.getInstance().getTime()); rq.setRerun(parameters.isRerun()); if (isNotBlank(parameters.getRerunOf())) { rq.setRerunOf(parameters.getRerunOf()); @@ -109,7 +108,6 @@ public ReportPortalPublisher(ReportPortal reportPortal) { launch = new MemoizingSupplier<>(() -> { ListenerParameters params = reportPortal.getParameters(); StartLaunchRQ rq = buildStartLaunchRq(params); - rq.setStartTime(Calendar.getInstance().getTime()); Launch newLaunch = reportPortal.newLaunch(rq); shutDownHook = getShutdownHook(() -> newLaunch); Runtime.getRuntime().addShutdownHook(shutDownHook); @@ -191,18 +189,15 @@ protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Da } /** - * Customize start test item event/request + * Customize start step test item event/request * * @param name item's name * @param startTime item's start time - * @param type item's type (e.g. feature, scenario, step, etc.) - * @param hasStats enables nested items * @return request to ReportPortal */ - protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Date startTime, - @Nonnull ItemType type, boolean hasStats) { - StartTestItemRQ rq = buildStartTestItemRq(name, startTime, type); - rq.setHasStats(hasStats); + protected StartTestItemRQ buildStartStepRq(@Nonnull String name, @Nonnull Date startTime) { + StartTestItemRQ rq = buildStartTestItemRq(name, startTime, ItemType.STEP); + rq.setHasStats(false); return rq; } @@ -344,7 +339,7 @@ public void finishScenario(ScenarioResult scenarioResult) { */ public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { String stepName = stepResult.getStep().getPrefix() + " " + stepResult.getStep().getText(); - StartTestItemRQ rq = buildStartTestItemRq(stepName, getStepStartTime(stepStartTimeMap, stepId), ItemType.STEP, false); + StartTestItemRQ rq = buildStartStepRq(stepName, getStepStartTime(stepStartTimeMap, stepId)); stepId = launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), rq); stepStartTimeMap.put(stepId, rq.getStartTime().getTime()); } From fbb4433f9097e3be8d68e84cbd04befde3176290 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 18 Dec 2023 16:30:23 +0300 Subject: [PATCH 18/76] Add more tests --- .../attributes/LaunchAttributesTest.java | 82 +++++++++++++++++++ .../launch/LaunchRequiredFieldsTest.java | 69 ++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java create mode 100644 src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java diff --git a/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java new file mode 100644 index 0000000..ee59bad --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java @@ -0,0 +1,82 @@ +/* + * Copyright 2023 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. + */ + +package com.epam.reportportal.karate.attributes; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.listeners.ListenerParameters; +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.attribute.ItemAttributesRQ; +import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class LaunchAttributesTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private ReportPortal rp; + + @BeforeEach + public void setupMock() { + ListenerParameters parameters = standardParameters(); + parameters.setAttributes(new HashSet<>(Arrays.asList(new ItemAttributesRQ("key", "value"), + new ItemAttributesRQ(null, "value")))); + rp = ReportPortal.create(client, parameters, testExecutor()); + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void verify_start_launch_request_contains_launch_attributes() { + var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); + + StartLaunchRQ launchStart = startCaptor.getValue(); + + Set attributes = launchStart.getAttributes(); + assertThat(attributes, allOf(notNullValue(), hasSize(greaterThan(0)))); + Set attributesStr = attributes.stream() + .filter(a -> !a.isSystem()) + .map(e -> e.getKey() + ":" + e.getValue()) + .collect(Collectors.toSet()); + assertThat(attributesStr, hasSize(2)); + assertThat(attributesStr, hasItem("key:value")); + assertThat(attributesStr, hasItem("null:value")); + } +} diff --git a/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java b/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java new file mode 100644 index 0000000..7d4cd6a --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2023 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. + */ + +package com.epam.reportportal.karate.launch; + +import com.epam.reportportal.karate.utils.TestUtils; +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.launch.StartLaunchRQ; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class LaunchRequiredFieldsTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void verify_start_launch_request_contains_required_fields() { + var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); + + StartLaunchRQ launchStart = startCaptor.getValue(); + assertThat(launchStart.getName(), startsWith("My-test-launch")); + assertThat(launchStart.getStartTime(), notNullValue()); + assertThat(System.currentTimeMillis() - launchStart.getStartTime().getTime(), + not(greaterThan(TimeUnit.SECONDS.toMillis(10)))); + + } +} From 7d0e6d1b35f9c1ed358e5375af811e0cbdf733f2 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 18 Dec 2023 17:19:15 +0300 Subject: [PATCH 19/76] Add scenario parameters reporting --- .../karate/ReportPortalPublisher.java | 36 +++++++--- .../ExamplesScenarioParametersTest.java | 72 +++++++++++++++++++ 2 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 9112272..8fa568b 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -25,10 +25,12 @@ import com.epam.reportportal.service.item.TestCaseIdEntry; import com.epam.reportportal.utils.AttributeParser; import com.epam.reportportal.utils.MemoizingSupplier; +import com.epam.reportportal.utils.ParameterUtils; import com.epam.reportportal.utils.TestCaseIdUtils; import com.epam.reportportal.utils.properties.SystemAttributesExtractor; import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; +import com.epam.ta.reportportal.ws.model.ParameterResource; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; @@ -41,7 +43,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -56,9 +57,9 @@ public class ReportPortalPublisher { public static final String EXAMPLE_CODE_REFERENCE_PATTERN = "%s/[EXAMPLE:%s%s]"; private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalPublisher.class); - private final ConcurrentHashMap> featureIdMap = new ConcurrentHashMap<>(); - private final ConcurrentHashMap> scenarioIdMap = new ConcurrentHashMap<>(); - private final ConcurrentHashMap, Long> stepStartTimeMap = new ConcurrentHashMap<>(); + private final Map> featureIdMap = new HashMap<>(); + private final Map> scenarioIdMap = new HashMap<>(); + private final Map, Long> stepStartTimeMap = new HashMap<>(); private Maybe stepId; private final MemoizingSupplier launch; @@ -191,12 +192,12 @@ protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Da /** * Customize start step test item event/request * - * @param name item's name - * @param startTime item's start time + * @param step Karate's Step class instance * @return request to ReportPortal */ - protected StartTestItemRQ buildStartStepRq(@Nonnull String name, @Nonnull Date startTime) { - StartTestItemRQ rq = buildStartTestItemRq(name, startTime, ItemType.STEP); + protected StartTestItemRQ buildStartStepRq(@Nonnull Step step) { + String stepName = step.getPrefix() + " " + step.getText(); + StartTestItemRQ rq = buildStartTestItemRq(stepName, getStepStartTime(stepStartTimeMap, stepId), ItemType.STEP); rq.setHasStats(false); return rq; } @@ -228,6 +229,19 @@ protected StartTestItemRQ buildStartFeatureRq(@Nonnull FeatureResult featureResu return rq; } + @Nullable + private List getParameters(@Nonnull Scenario scenario) { + if (scenario.getExampleIndex() < 0) { + return null; + } + return scenario.getExampleData().entrySet().stream().map(e -> { + ParameterResource parameterResource = new ParameterResource(); + parameterResource.setKey(e.getKey()); + parameterResource.setValue(ofNullable(e.getValue()).map(Object::toString).orElse(ParameterUtils.NULL_VALUE)); + return parameterResource; + }).collect(Collectors.toList()); + } + /** * Build ReportPortal request for start Scenario event * @@ -242,6 +256,7 @@ protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioResult scenarioR rq.setCodeRef(getCodeRef(scenario)); rq.setTestCaseId(ofNullable(getTestCaseId(scenario)).map(TestCaseIdEntry::getId).orElse(null)); rq.setAttributes(toAttributes(scenario.getTags())); + rq.setParameters(getParameters(scenario)); return rq; } @@ -338,8 +353,7 @@ public void finishScenario(ScenarioResult scenarioResult) { * @param scenarioResult scenario result */ public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { - String stepName = stepResult.getStep().getPrefix() + " " + stepResult.getStep().getText(); - StartTestItemRQ rq = buildStartStepRq(stepName, getStepStartTime(stepStartTimeMap, stepId)); + StartTestItemRQ rq = buildStartStepRq(stepResult.getStep()); stepId = launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), rq); stepStartTimeMap.put(stepId, rq.getStartTime().getTime()); } @@ -441,7 +455,7 @@ private String getLogLevel(String status) { * @param stepId step ID. * @return step new startTime in Date format. */ - private Date getStepStartTime(ConcurrentHashMap, Long> stepStartTimeMap, Maybe stepId) { + private Date getStepStartTime(Map, Long> stepStartTimeMap, Maybe stepId) { long currentStepStartTime = Calendar.getInstance().getTime().getTime(); if (!stepStartTimeMap.keySet().isEmpty()) { diff --git a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java new file mode 100644 index 0000000..2324133 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java @@ -0,0 +1,72 @@ +package com.epam.reportportal.karate.parameters; + +import com.epam.reportportal.karate.utils.TestUtils; +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.ParameterResource; +import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class ExamplesScenarioParametersTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) + .collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_examples_scenario_parameters() { + var results = TestUtils.runAsReport(rp, "classpath:feature/examples.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(2)).startTestItem(same(featureId), captor.capture()); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), captor.capture()); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), captor.capture()); + + List items = captor.getAllValues(); + assertThat(items, hasSize(7)); + + StartTestItemRQ firstScenarioRq = items.get(1); + StartTestItemRQ secondScenarioRq = items.get(2); + List firstParameters = firstScenarioRq.getParameters(); + List secondParameters = secondScenarioRq.getParameters(); + assertThat(firstParameters, hasSize(3)); + assertThat(secondParameters, hasSize(3)); + + assertThat( + firstParameters.stream().map(p -> p.getKey() + ":" + p.getValue()).collect(Collectors.toSet()), + allOf(hasItem("vara:2"), hasItem("varb:2"), hasItem("result:4")) + ); + assertThat( + secondParameters.stream().map(p -> p.getKey() + ":" + p.getValue()).collect(Collectors.toSet()), + allOf(hasItem("vara:1"), hasItem("varb:2"), hasItem("result:3")) + ); + } +} From 2fcfdd4c39540b68e60e45eb7033d3bdaacd1bbc Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 19 Dec 2023 17:17:50 +0300 Subject: [PATCH 20/76] Update property format --- src/test/resources/reportportal.properties | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/resources/reportportal.properties b/src/test/resources/reportportal.properties index 2b4544b..2fa4d22 100644 --- a/src/test/resources/reportportal.properties +++ b/src/test/resources/reportportal.properties @@ -1,7 +1,7 @@ -#rp.endpoint= -#rp.uuid= -#rp.launch= -#rp.project= +# rp.endpoint= +# rp.api.key= +# rp.launch= +# rp.project= ## OPTIONAL PARAMETERS # rp.reporting.async=true From 18f33c3436c570c51601bddff9e9d0f59b6669f1 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 19 Dec 2023 20:48:56 +0300 Subject: [PATCH 21/76] Add parameter handling for steps --- build.gradle | 3 +- .../karate/ReportPortalPublisher.java | 49 ++++++++--- .../ExamplesStepParametersTest.java | 81 +++++++++++++++++++ .../karate/parameters/NoParametersTest.java | 58 +++++++++++++ 4 files changed, 181 insertions(+), 10 deletions(-) create mode 100644 src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java create mode 100644 src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java diff --git a/build.gradle b/build.gradle index 929d455..f0b263f 100644 --- a/build.gradle +++ b/build.gradle @@ -37,11 +37,12 @@ compileJava.options.encoding = 'UTF-8' compileTestJava.options.encoding = 'UTF-8' repositories { + mavenLocal() mavenCentral() } dependencies { - api 'com.epam.reportportal:client-java:5.1.25' + api 'com.epam.reportportal:client-java:5.1.26' api "com.intuit.karate:karate-core:${project.karate_version}" implementation 'org.slf4j:slf4j-api:2.0.7' diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 8fa568b..aec3ba7 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -20,6 +20,7 @@ import com.epam.reportportal.karate.enums.ItemStatusEnum; import com.epam.reportportal.listeners.ItemType; import com.epam.reportportal.listeners.ListenerParameters; +import com.epam.reportportal.listeners.LogLevel; import com.epam.reportportal.service.Launch; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.item.TestCaseIdEntry; @@ -44,6 +45,7 @@ import javax.annotation.Nullable; import java.util.*; import java.util.function.Supplier; +import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -55,6 +57,8 @@ public class ReportPortalPublisher { public static final String SCENARIO_CODE_REFERENCE_PATTERN = "%s/[SCENARIO:%s]"; public static final String EXAMPLE_CODE_REFERENCE_PATTERN = "%s/[EXAMPLE:%s%s]"; + public static final String VARIABLE_PATTERN = + "(?:(?<=#\\()%1$s(?=\\)))|(?:(?<=[\\s=+-/*<>(]|^)%1$s(?=[\\s=+-/*<>)]|(?:\\r?\\n)|$))"; private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalPublisher.class); private final Map> featureIdMap = new HashMap<>(); @@ -151,12 +155,12 @@ public void finishLaunch() { */ @Nonnull protected String getCodeRef(@Nonnull Scenario scenario) { - if (scenario.getExampleIndex() < 0) { - return String.format(SCENARIO_CODE_REFERENCE_PATTERN, scenario.getFeature().getResource().getRelativePath(), - scenario.getName()); - } else { + if (scenario.isOutlineExample()) { return String.format(EXAMPLE_CODE_REFERENCE_PATTERN, scenario.getFeature().getResource().getRelativePath(), scenario.getName(), ReportPortalUtils.formatExampleKey(scenario.getExampleData())); + } else { + return String.format(SCENARIO_CODE_REFERENCE_PATTERN, scenario.getFeature().getResource().getRelativePath(), + scenario.getName()); } } @@ -192,13 +196,30 @@ protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Da /** * Customize start step test item event/request * - * @param step Karate's Step class instance + * @param step Karate's Step class instance + * @param scenario Karate's Scenario class instance * @return request to ReportPortal */ - protected StartTestItemRQ buildStartStepRq(@Nonnull Step step) { + protected StartTestItemRQ buildStartStepRq(@Nonnull Step step, Scenario scenario) { String stepName = step.getPrefix() + " " + step.getText(); StartTestItemRQ rq = buildStartTestItemRq(stepName, getStepStartTime(stepStartTimeMap, stepId), ItemType.STEP); rq.setHasStats(false); + if (step.isOutline()) { + List parameters = scenario + .getExampleData() + .entrySet() + .stream() + .filter(e -> Pattern.compile(String.format(VARIABLE_PATTERN, e.getKey())).matcher(step.getText()).find()) + .map(e -> { + ParameterResource param = new ParameterResource(); + param.setKey(e.getKey()); + var value = ofNullable(e.getValue()).map(Object::toString).orElse(ParameterUtils.NULL_VALUE); + param.setValue(value); + return param; + }) + .collect(Collectors.toList()); + rq.setParameters(parameters); + } return rq; } @@ -353,9 +374,19 @@ public void finishScenario(ScenarioResult scenarioResult) { * @param scenarioResult scenario result */ public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { - StartTestItemRQ rq = buildStartStepRq(stepResult.getStep()); - stepId = launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), rq); - stepStartTimeMap.put(stepId, rq.getStartTime().getTime()); + StartTestItemRQ stepRq = buildStartStepRq(stepResult.getStep(), scenarioResult.getScenario()); + stepId = launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), stepRq); + stepStartTimeMap.put(stepId, stepRq.getStartTime().getTime()); + ofNullable(stepRq.getParameters()) + .filter(params -> !params.isEmpty()) + .ifPresent(params -> ReportPortal.emitLog(stepId, id -> { + SaveLogRQ logRq = new SaveLogRQ(); + logRq.setLogTime(Calendar.getInstance().getTime()); + logRq.setItemUuid(id); + logRq.setLevel(LogLevel.INFO.name()); + logRq.setMessage("Parameters:\n\n" + ParameterUtils.formatParametersAsTable(params)); + return logRq; + })); } /** diff --git a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java new file mode 100644 index 0000000..1378c89 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java @@ -0,0 +1,81 @@ +package com.epam.reportportal.karate.parameters; + +import com.epam.reportportal.karate.utils.TestUtils; +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.ParameterResource; +import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static java.util.stream.Stream.ofNullable; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class ExamplesStepParametersTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) + .collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } + + private static Set toParameterStringList(List parameters) { + return ofNullable(parameters) + .flatMap(Collection::stream) + .map(p -> p.getKey() + ":" + p.getValue()) + .collect(Collectors.toSet()); + } + + @Test + public void test_examples_parameters_for_steps() { + var results = TestUtils.runAsReport(rp, "classpath:feature/examples.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(2)).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor firstExampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstExampleCaptor.capture()); + ArgumentCaptor secondExampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondExampleCaptor.capture()); + + List firstSteps = firstExampleCaptor.getAllValues(); + Set parameterStrings = toParameterStringList(firstSteps.get(0).getParameters()); + assertThat(parameterStrings, hasSize(2)); + assertThat(parameterStrings, allOf(hasItem("vara:2"), hasItem("varb:2"))); + parameterStrings = toParameterStringList(firstSteps.get(1).getParameters()); + assertThat(parameterStrings, hasSize(1)); + assertThat(parameterStrings, hasItem("result:4")); + + List secondSteps = secondExampleCaptor.getAllValues(); + parameterStrings = toParameterStringList(secondSteps.get(0).getParameters()); + assertThat(parameterStrings, hasSize(2)); + assertThat(parameterStrings, allOf(hasItem("vara:1"), hasItem("varb:2"))); + parameterStrings = toParameterStringList(secondSteps.get(1).getParameters()); + assertThat(parameterStrings, hasSize(1)); + assertThat(parameterStrings, hasItem("result:3")); + } +} diff --git a/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java new file mode 100644 index 0000000..fa931ad --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java @@ -0,0 +1,58 @@ +package com.epam.reportportal.karate.parameters; + +import com.epam.reportportal.karate.utils.TestUtils; +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.StartTestItemRQ; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class NoParametersTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_no_parameters_reporting() { + var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); + + List items = captor.getAllValues(); + assertThat(items, hasSize(5)); + + StartTestItemRQ featureRq = items.get(0); + StartTestItemRQ scenarioRq = items.get(1); + + assertThat(featureRq.getParameters(), nullValue()); + assertThat(scenarioRq.getParameters(), nullValue()); + + items.subList(2, items.size()).forEach(step -> assertThat(step.getParameters(), nullValue())); + } +} From 27c370c12bbaf8dd6b57e41dc219a0d3e337f7a2 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 20 Dec 2023 13:42:04 +0300 Subject: [PATCH 22/76] Add parameter log message verification --- .../ExamplesStepParametersTest.java | 23 ++++++++++++- .../reportportal/karate/utils/TestUtils.java | 33 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java index 1378c89..7e3d76f 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java @@ -1,11 +1,14 @@ package com.epam.reportportal.karate.parameters; import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.listeners.LogLevel; 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.ParameterResource; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; +import okhttp3.MultipartBody; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -13,6 +16,7 @@ import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -21,6 +25,7 @@ import static java.util.stream.Stream.ofNullable; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.startsWith; import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; @@ -50,12 +55,13 @@ private static Set toParameterStringList(List paramet } @Test + @SuppressWarnings({"unchecked", "rawtypes"}) public void test_examples_parameters_for_steps() { var results = TestUtils.runAsReport(rp, "classpath:feature/examples.feature"); assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); + verify(client).startTestItem(captor.capture()); verify(client, times(2)).startTestItem(same(featureId), captor.capture()); ArgumentCaptor firstExampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstExampleCaptor.capture()); @@ -77,5 +83,20 @@ public void test_examples_parameters_for_steps() { parameterStrings = toParameterStringList(secondSteps.get(1).getParameters()); assertThat(parameterStrings, hasSize(1)); assertThat(parameterStrings, hasItem("result:3")); + + ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); + verify(client, atLeastOnce()).log(logCaptor.capture()); + Map logs = logCaptor + .getAllValues(). + stream() + .flatMap(rq -> extractJsonParts((List) rq).stream()) + .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel())) + .collect(Collectors.toMap(SaveLogRQ::getItemUuid, v -> v)); + + List stepIdList = stepIds.stream().flatMap(e -> e.getValue().stream()).collect(Collectors.toList()); + assertThat(logs.keySet(), hasSize(stepIdList.size())); + stepIdList.forEach(id -> assertThat(logs, hasKey(id))); + assertThat(logs.values().stream().map(SaveLogRQ::getMessage).collect(Collectors.toList()), + everyItem(startsWith("Parameters:"))); } } diff --git a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java index 3fbc449..cbb07c4 100644 --- a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java +++ b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java @@ -5,17 +5,24 @@ import com.epam.reportportal.service.ReportPortal; 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.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 com.intuit.karate.Results; import io.reactivex.Maybe; +import okhttp3.MultipartBody; +import okio.Buffer; import org.apache.commons.lang3.tuple.Pair; import org.mockito.stubbing.Answer; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.io.IOException; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -169,4 +176,30 @@ public static void mockNestedSteps(final ReportPortalClient client, final List

>) invocation -> Maybe.just(new OperationCompletionRS()))); } + + public static List extractJsonParts(List parts) { + return parts.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()); + } } From e5bfcceb5b3cc795e7dfc01f91d68880ad068279 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 20 Dec 2023 17:35:06 +0300 Subject: [PATCH 23/76] Table parameters handling --- .../karate/ReportPortalPublisher.java | 143 ++++++++++-------- .../karate/enums/ItemLogLevelEnum.java | 18 --- .../karate/enums/ItemStatusEnum.java | 21 --- .../ExamplesStepParametersTest.java | 2 +- .../parameters/TableParametersTest.java | 67 ++++++++ src/test/resources/feature/table.feature | 9 ++ 6 files changed, 158 insertions(+), 102 deletions(-) delete mode 100644 src/main/java/com/epam/reportportal/karate/enums/ItemLogLevelEnum.java delete mode 100644 src/main/java/com/epam/reportportal/karate/enums/ItemStatusEnum.java create mode 100644 src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java create mode 100644 src/test/resources/feature/table.feature diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index aec3ba7..7b1a7d5 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -16,8 +16,7 @@ package com.epam.reportportal.karate; -import com.epam.reportportal.karate.enums.ItemLogLevelEnum; -import com.epam.reportportal.karate.enums.ItemStatusEnum; +import com.epam.reportportal.listeners.ItemStatus; import com.epam.reportportal.listeners.ItemType; import com.epam.reportportal.listeners.ListenerParameters; import com.epam.reportportal.listeners.LogLevel; @@ -26,7 +25,6 @@ import com.epam.reportportal.service.item.TestCaseIdEntry; import com.epam.reportportal.utils.AttributeParser; import com.epam.reportportal.utils.MemoizingSupplier; -import com.epam.reportportal.utils.ParameterUtils; import com.epam.reportportal.utils.TestCaseIdUtils; import com.epam.reportportal.utils.properties.SystemAttributesExtractor; import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; @@ -50,6 +48,9 @@ import java.util.stream.Stream; import static com.epam.reportportal.karate.ReportPortalUtils.AGENT_PROPERTIES_FILE; +import static com.epam.reportportal.utils.ParameterUtils.NULL_VALUE; +import static com.epam.reportportal.utils.ParameterUtils.formatParametersAsTable; +import static com.epam.reportportal.utils.markdown.MarkdownUtils.formatDataTable; import static com.google.common.base.Strings.isNullOrEmpty; import static java.util.Optional.ofNullable; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -193,36 +194,6 @@ protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Da return rq; } - /** - * Customize start step test item event/request - * - * @param step Karate's Step class instance - * @param scenario Karate's Scenario class instance - * @return request to ReportPortal - */ - protected StartTestItemRQ buildStartStepRq(@Nonnull Step step, Scenario scenario) { - String stepName = step.getPrefix() + " " + step.getText(); - StartTestItemRQ rq = buildStartTestItemRq(stepName, getStepStartTime(stepStartTimeMap, stepId), ItemType.STEP); - rq.setHasStats(false); - if (step.isOutline()) { - List parameters = scenario - .getExampleData() - .entrySet() - .stream() - .filter(e -> Pattern.compile(String.format(VARIABLE_PATTERN, e.getKey())).matcher(step.getText()).find()) - .map(e -> { - ParameterResource param = new ParameterResource(); - param.setKey(e.getKey()); - var value = ofNullable(e.getValue()).map(Object::toString).orElse(ParameterUtils.NULL_VALUE); - param.setValue(value); - return param; - }) - .collect(Collectors.toList()); - rq.setParameters(parameters); - } - return rq; - } - @Nullable private Set toAttributes(@Nullable List tags) { Set attributes = ofNullable(tags).orElse(Collections.emptyList()).stream().flatMap(tag -> { @@ -258,7 +229,7 @@ private List getParameters(@Nonnull Scenario scenario) { return scenario.getExampleData().entrySet().stream().map(e -> { ParameterResource parameterResource = new ParameterResource(); parameterResource.setKey(e.getKey()); - parameterResource.setValue(ofNullable(e.getValue()).map(Object::toString).orElse(ParameterUtils.NULL_VALUE)); + parameterResource.setValue(ofNullable(e.getValue()).map(Object::toString).orElse(NULL_VALUE)); return parameterResource; }).collect(Collectors.toList()); } @@ -289,10 +260,10 @@ protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioResult scenarioR * @return request to ReportPortal */ protected FinishTestItemRQ buildFinishTestItemRq(@Nonnull Date endTime, - @Nonnull String status) { + @Nonnull ItemStatus status) { FinishTestItemRQ rq = new FinishTestItemRQ(); rq.setEndTime(endTime); - rq.setStatus(status); + rq.setStatus(status.name()); return rq; } @@ -332,7 +303,7 @@ public void finishFeature(FeatureResult featureResult) { } FinishTestItemRQ rq = buildFinishTestItemRq(Calendar.getInstance().getTime(), - featureResult.isFailed() ? ItemStatusEnum.FAILED.toString() : ItemStatusEnum.PASSED.toString()); + featureResult.isFailed() ? ItemStatus.FAILED : ItemStatus.PASSED); //noinspection ReactiveStreamsUnusedPublisher launch.get().finishTestItem(featureIdMap.remove(featureResult.getCallNameForReport()), rq); } @@ -361,12 +332,45 @@ public void finishScenario(ScenarioResult scenarioResult) { } FinishTestItemRQ rq = buildFinishTestItemRq(Calendar.getInstance().getTime(), - scenarioResult.getFailureMessageForDisplay() == null ? ItemStatusEnum.PASSED.toString() : ItemStatusEnum.FAILED.toString()); + scenarioResult.getFailureMessageForDisplay() == null ? ItemStatus.PASSED : ItemStatus.FAILED); Maybe removedScenarioId = scenarioIdMap.remove(scenarioResult.getScenario().getName()); //noinspection ReactiveStreamsUnusedPublisher launch.get().finishTestItem(removedScenarioId, rq); } + /** + * Customize start step test item event/request + * + * @param stepResult Karate's StepResult class instance + * @param scenarioResult Karate's ScenarioResult class instance + * @return request to ReportPortal + */ + @Nonnull + protected StartTestItemRQ buildStartStepRq(@Nonnull StepResult stepResult, @Nonnull ScenarioResult scenarioResult) { + Step step = stepResult.getStep(); + String stepName = step.getPrefix() + " " + step.getText(); + StartTestItemRQ rq = buildStartTestItemRq(stepName, getStepStartTime(stepStartTimeMap, stepId), ItemType.STEP); + rq.setHasStats(false); + if (step.isOutline()) { + Scenario scenario = scenarioResult.getScenario(); + List parameters = scenario + .getExampleData() + .entrySet() + .stream() + .filter(e -> Pattern.compile(String.format(VARIABLE_PATTERN, e.getKey())).matcher(step.getText()).find()) + .map(e -> { + ParameterResource param = new ParameterResource(); + param.setKey(e.getKey()); + var value = ofNullable(e.getValue()).map(Object::toString).orElse(NULL_VALUE); + param.setValue(value); + return param; + }) + .collect(Collectors.toList()); + rq.setParameters(parameters); + } + return rq; + } + /** * Start sending step data to ReportPortal * @@ -374,19 +378,16 @@ public void finishScenario(ScenarioResult scenarioResult) { * @param scenarioResult scenario result */ public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { - StartTestItemRQ stepRq = buildStartStepRq(stepResult.getStep(), scenarioResult.getScenario()); + StartTestItemRQ stepRq = buildStartStepRq(stepResult, scenarioResult); stepId = launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), stepRq); stepStartTimeMap.put(stepId, stepRq.getStartTime().getTime()); ofNullable(stepRq.getParameters()) .filter(params -> !params.isEmpty()) - .ifPresent(params -> ReportPortal.emitLog(stepId, id -> { - SaveLogRQ logRq = new SaveLogRQ(); - logRq.setLogTime(Calendar.getInstance().getTime()); - logRq.setItemUuid(id); - logRq.setLevel(LogLevel.INFO.name()); - logRq.setMessage("Parameters:\n\n" + ParameterUtils.formatParametersAsTable(params)); - return logRq; - })); + .ifPresent(params -> + sendLog(stepId, "Parameters:\n\n" + formatParametersAsTable(params), LogLevel.INFO)); + ofNullable(stepResult.getStep().getTable()) + .ifPresent(table -> + sendLog(stepId, "Table:\n\n" + formatDataTable(table.getRows()), LogLevel.INFO)); } /** @@ -414,7 +415,7 @@ public void finishStep(StepResult stepResult) { */ public void sendStepResults(StepResult stepResult) { Result result = stepResult.getResult(); - String logLevel = getLogLevel(result.getStatus()); + LogLevel logLevel = getLogLevel(result.getStatus()); Step step = stepResult.getStep(); if (step.getDocString() != null) { @@ -434,47 +435,65 @@ public void sendStepResults(StepResult stepResult) { * @param message log message to send * @param level log level */ - public void sendLog(final String message, final String level) { + public void sendLog(final String message, LogLevel level) { ReportPortal.emitLog(itemId -> { SaveLogRQ rq = new SaveLogRQ(); rq.setMessage(message); rq.setItemUuid(itemId); - rq.setLevel(level); + rq.setLevel(level.name()); + rq.setLogTime(Calendar.getInstance().getTime()); + return rq; + }); + } + + /** + * Send step logs and/or execution results to ReportPortal + * + * @param itemId item ID future + * @param message log message to send + * @param level log level + */ + public void sendLog(Maybe itemId, String message, LogLevel level) { + ReportPortal.emitLog(itemId, id -> { + SaveLogRQ rq = new SaveLogRQ(); + rq.setMessage(message); + rq.setItemUuid(id); + rq.setLevel(level.name()); rq.setLogTime(Calendar.getInstance().getTime()); return rq; }); } - private String getStepStatus(String status) { + private ItemStatus getStepStatus(String status) { switch (status) { case "failed": - return ItemStatusEnum.FAILED.toString(); + return ItemStatus.FAILED; case "passed": - return ItemStatusEnum.PASSED.toString(); + return ItemStatus.PASSED; case "skipped": - return ItemStatusEnum.SKIPPED.toString(); + return ItemStatus.SKIPPED; case "stopped": - return ItemStatusEnum.STOPPED.toString(); + return ItemStatus.STOPPED; case "interrupted": - return ItemStatusEnum.RESETED.toString(); + return ItemStatus.INTERRUPTED; case "cancelled": - return ItemStatusEnum.CANCELLED.toString(); + return ItemStatus.CANCELLED; default: LOGGER.warn("Unknown step status received! Set it as SKIPPED"); - return ItemStatusEnum.SKIPPED.toString(); + return ItemStatus.SKIPPED; } } - private String getLogLevel(String status) { + private LogLevel getLogLevel(String status) { switch (status) { case "failed": - return ItemLogLevelEnum.ERROR.toString(); + return LogLevel.ERROR; case "stopped": case "interrupted": case "cancelled": - return ItemLogLevelEnum.WARN.toString(); + return LogLevel.WARN; default: - return ItemLogLevelEnum.INFO.toString(); + return LogLevel.INFO; } } diff --git a/src/main/java/com/epam/reportportal/karate/enums/ItemLogLevelEnum.java b/src/main/java/com/epam/reportportal/karate/enums/ItemLogLevelEnum.java deleted file mode 100644 index 49d9b87..0000000 --- a/src/main/java/com/epam/reportportal/karate/enums/ItemLogLevelEnum.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.epam.reportportal.karate.enums; - -public enum ItemLogLevelEnum { - INFO("INFO"), - WARN("WARN"), - ERROR("ERROR"); - - private final String name; - - ItemLogLevelEnum(String name) { - this.name = name; - } - - @Override - public String toString() { - return this.name; - } -} diff --git a/src/main/java/com/epam/reportportal/karate/enums/ItemStatusEnum.java b/src/main/java/com/epam/reportportal/karate/enums/ItemStatusEnum.java deleted file mode 100644 index 3f90dc4..0000000 --- a/src/main/java/com/epam/reportportal/karate/enums/ItemStatusEnum.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.epam.reportportal.karate.enums; - -public enum ItemStatusEnum { - PASSED("PASSED"), - FAILED("FAILED"), - SKIPPED("SKIPPED"), - STOPPED("STOPPED"), - RESETED("RESETED"), - CANCELLED("CANCELLED"); - - private final String name; - - ItemStatusEnum(String name) { - this.name = name; - } - - @Override - public String toString() { - return this.name; - } -} diff --git a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java index 7e3d76f..d9185e9 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java @@ -97,6 +97,6 @@ public void test_examples_parameters_for_steps() { assertThat(logs.keySet(), hasSize(stepIdList.size())); stepIdList.forEach(id -> assertThat(logs, hasKey(id))); assertThat(logs.values().stream().map(SaveLogRQ::getMessage).collect(Collectors.toList()), - everyItem(startsWith("Parameters:"))); + everyItem(startsWith("Parameters:\n\n"))); } } diff --git a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java new file mode 100644 index 0000000..a108ebd --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java @@ -0,0 +1,67 @@ +package com.epam.reportportal.karate.parameters; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.listeners.LogLevel; +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.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; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.startsWith; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class TableParametersTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(4).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + @SuppressWarnings({"unchecked", "rawtypes"}) + public void test_table_parameters_reporting() { + var results = TestUtils.runAsReport(rp, "classpath:feature/table.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(4)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); + verify(client, atLeastOnce()).log(logCaptor.capture()); + + List items = captor.getAllValues(); + assertThat(items, hasSize(2)); + + Map logs = logCaptor + .getAllValues(). + stream() + .flatMap(rq -> extractJsonParts((List) rq).stream()) + .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel())) + .collect(Collectors.toMap(SaveLogRQ::getItemUuid, v -> v)); + assertThat(logs.get(stepIds.get(2)).getMessage(), startsWith("Table:\n\n")); + } +} diff --git a/src/test/resources/feature/table.feature b/src/test/resources/feature/table.feature new file mode 100644 index 0000000..db2e93e --- /dev/null +++ b/src/test/resources/feature/table.feature @@ -0,0 +1,9 @@ +Feature: test with parameter table + Scenario: Verify parameter table + Given def one = 'hello' + And def two = { baz: 'world' } + And table json + | foo | bar | + | one | { baz: 1 } | + | two.baz | ['baz', 'ban'] | + Then match json == [{ foo: 'hello', bar: { baz: 1 } }, { foo: 'world', bar: ['baz', 'ban'] }] From 74d31474d83c9fd782dce73840498c5aced885ae Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 21 Dec 2023 14:15:40 +0300 Subject: [PATCH 24/76] Background steps handling --- .../karate/ReportPortalPublisher.java | 4 ++ .../karate/background/BackgroundTest.java | 57 +++++++++++++++++++ src/test/resources/feature/background.feature | 8 +++ 3 files changed, 69 insertions(+) create mode 100644 src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java create mode 100644 src/test/resources/feature/background.feature diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 7b1a7d5..9b561f8 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -56,6 +56,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class ReportPortalPublisher { + public static final String BACKGROUND_PREFIX = "BACKGROUND: "; public static final String SCENARIO_CODE_REFERENCE_PATTERN = "%s/[SCENARIO:%s]"; public static final String EXAMPLE_CODE_REFERENCE_PATTERN = "%s/[EXAMPLE:%s%s]"; public static final String VARIABLE_PATTERN = @@ -349,6 +350,9 @@ public void finishScenario(ScenarioResult scenarioResult) { protected StartTestItemRQ buildStartStepRq(@Nonnull StepResult stepResult, @Nonnull ScenarioResult scenarioResult) { Step step = stepResult.getStep(); String stepName = step.getPrefix() + " " + step.getText(); + if (step.isBackground()) { + stepName = BACKGROUND_PREFIX + stepName; + } StartTestItemRQ rq = buildStartTestItemRq(stepName, getStepStartTime(stepStartTimeMap, stepId), ItemType.STEP); rq.setHasStats(false); if (step.isOutline()) { diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java new file mode 100644 index 0000000..6978600 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java @@ -0,0 +1,57 @@ +package com.epam.reportportal.karate.background; + +import com.epam.reportportal.karate.utils.TestUtils; +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.StartTestItemRQ; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class BackgroundTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_background_steps() { + var results = TestUtils.runAsReport(rp, "classpath:feature/background.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + + List items = captor.getAllValues(); + assertThat(items, hasSize(2)); + List steps = stepCaptor.getAllValues(); + assertThat(steps, hasSize(3)); + + assertThat(steps.get(0).getName(), equalTo("BACKGROUND: Given def four = 4")); + } +} diff --git a/src/test/resources/feature/background.feature b/src/test/resources/feature/background.feature new file mode 100644 index 0000000..90069cd --- /dev/null +++ b/src/test/resources/feature/background.feature @@ -0,0 +1,8 @@ +Feature: the test to show item description reporting + + Background: Set variable + Given def four = 4 + + Scenario: Verify math + When def acualFour = 2 * 2 + Then assert acualFour == four From 61861a546fc6d0cf390047e8fbf2d10aa65d005a Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 21 Dec 2023 14:54:01 +0300 Subject: [PATCH 25/76] Test fixes --- .../reportportal/karate/background/BackgroundTest.java | 10 ++++++---- src/test/resources/feature/background.feature | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java index 6978600..958b86a 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java @@ -10,13 +10,13 @@ import org.mockito.ArgumentCaptor; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import static com.epam.reportportal.karate.utils.TestUtils.*; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.*; import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; @@ -26,7 +26,6 @@ public class BackgroundTest { private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); @@ -52,6 +51,9 @@ public void test_background_steps() { List steps = stepCaptor.getAllValues(); assertThat(steps, hasSize(3)); - assertThat(steps.get(0).getName(), equalTo("BACKGROUND: Given def four = 4")); + Set stepNames = steps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet()); + + assertThat(stepNames, allOf(hasItem("BACKGROUND: Given def four = 4"), hasItem("When def actualFour = 2 * 2"), + hasItem("Then assert actualFour == four"))); } } diff --git a/src/test/resources/feature/background.feature b/src/test/resources/feature/background.feature index 90069cd..84f951a 100644 --- a/src/test/resources/feature/background.feature +++ b/src/test/resources/feature/background.feature @@ -4,5 +4,5 @@ Feature: the test to show item description reporting Given def four = 4 Scenario: Verify math - When def acualFour = 2 * 2 - Then assert acualFour == four + When def actualFour = 2 * 2 + Then assert actualFour == four From 226962f7aa7b534a2f0fc82dc0ab2577a4db7f4f Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 21 Dec 2023 14:54:23 +0300 Subject: [PATCH 26/76] Fix typing --- src/test/resources/feature/simple.feature | 4 ++-- src/test/resources/feature/tags.feature | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/resources/feature/simple.feature b/src/test/resources/feature/simple.feature index c5b56a0..f177f74 100644 --- a/src/test/resources/feature/simple.feature +++ b/src/test/resources/feature/simple.feature @@ -2,5 +2,5 @@ Feature: the very basic test to run by Karate Scenario: Verify math Given def four = 4 - When def acualFour = 2 * 2 - Then assert acualFour == four + When def actualFour = 2 * 2 + Then assert actualFour == four diff --git a/src/test/resources/feature/tags.feature b/src/test/resources/feature/tags.feature index 876caf9..4bf25f2 100644 --- a/src/test/resources/feature/tags.feature +++ b/src/test/resources/feature/tags.feature @@ -4,5 +4,5 @@ Feature: the very basic to test different tags @math @scope=smoke @environment=dev,qa Scenario: Verify math Given def four = 4 - When def acualFour = 2 * 2 - Then assert acualFour == four + When def actualFour = 2 * 2 + Then assert actualFour == four From a7c5bdaa97e25d8a2a8410e90a4f50f87ab66d3e Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 21 Dec 2023 17:31:00 +0300 Subject: [PATCH 27/76] Background logic update --- .../karate/ReportPortalPublisher.java | 28 +++++++++++++++---- .../karate/background/BackgroundTest.java | 25 ++++++++++++++--- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 9b561f8..15bdb23 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -56,7 +56,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class ReportPortalPublisher { - public static final String BACKGROUND_PREFIX = "BACKGROUND: "; public static final String SCENARIO_CODE_REFERENCE_PATTERN = "%s/[SCENARIO:%s]"; public static final String EXAMPLE_CODE_REFERENCE_PATTERN = "%s/[EXAMPLE:%s%s]"; public static final String VARIABLE_PATTERN = @@ -66,6 +65,7 @@ public class ReportPortalPublisher { private final Map> featureIdMap = new HashMap<>(); private final Map> scenarioIdMap = new HashMap<>(); private final Map, Long> stepStartTimeMap = new HashMap<>(); + private Maybe backgroundId; private Maybe stepId; private final MemoizingSupplier launch; @@ -307,6 +307,7 @@ public void finishFeature(FeatureResult featureResult) { featureResult.isFailed() ? ItemStatus.FAILED : ItemStatus.PASSED); //noinspection ReactiveStreamsUnusedPublisher launch.get().finishTestItem(featureIdMap.remove(featureResult.getCallNameForReport()), rq); + backgroundId = null; } /** @@ -339,6 +340,14 @@ public void finishScenario(ScenarioResult scenarioResult) { launch.get().finishTestItem(removedScenarioId, rq); } + @Nonnull + @SuppressWarnings("unused") + protected StartTestItemRQ buildStartBackgroundRq(@Nonnull StepResult stepResult, @Nonnull ScenarioResult scenarioResult) { + StartTestItemRQ rq = buildStartTestItemRq(Background.KEYWORD, Calendar.getInstance().getTime(), ItemType.STEP); + rq.setHasStats(false); + return rq; + } + /** * Customize start step test item event/request * @@ -350,9 +359,6 @@ public void finishScenario(ScenarioResult scenarioResult) { protected StartTestItemRQ buildStartStepRq(@Nonnull StepResult stepResult, @Nonnull ScenarioResult scenarioResult) { Step step = stepResult.getStep(); String stepName = step.getPrefix() + " " + step.getText(); - if (step.isBackground()) { - stepName = BACKGROUND_PREFIX + stepName; - } StartTestItemRQ rq = buildStartTestItemRq(stepName, getStepStartTime(stepStartTimeMap, stepId), ItemType.STEP); rq.setHasStats(false); if (step.isOutline()) { @@ -382,8 +388,20 @@ protected StartTestItemRQ buildStartStepRq(@Nonnull StepResult stepResult, @Nonn * @param scenarioResult scenario result */ public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { + if (stepResult.getStep().isBackground()) { + backgroundId = ofNullable(backgroundId).orElseGet(() -> { + StartTestItemRQ backgroundRq = buildStartBackgroundRq(stepResult, scenarioResult); + return launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), backgroundRq); + }); + } else { + backgroundId = null; + } StartTestItemRQ stepRq = buildStartStepRq(stepResult, scenarioResult); - stepId = launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), stepRq); + stepId = launch.get() + .startTestItem( + backgroundId != null ? backgroundId : scenarioIdMap.get(scenarioResult.getScenario().getName()), + stepRq + ); stepStartTimeMap.put(stepId, stepRq.getStartTime().getTime()); ofNullable(stepRq.getParameters()) .filter(params -> !params.isEmpty()) diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java index 958b86a..784b086 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java @@ -1,16 +1,18 @@ package com.epam.reportportal.karate.background; import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.listeners.ItemType; 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.StartTestItemRQ; +import com.intuit.karate.core.Background; +import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import java.util.List; -import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -18,6 +20,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.mockito.ArgumentMatchers.same; +import static org.mockito.ArgumentMatchers.startsWith; import static org.mockito.Mockito.*; public class BackgroundTest { @@ -25,6 +28,8 @@ public class BackgroundTest { private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) .limit(3).collect(Collectors.toList()); + private final List> nestedStepIds = stepIds.stream() + .map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))).collect(Collectors.toList()); private final ReportPortalClient client = mock(ReportPortalClient.class); private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); @@ -32,6 +37,7 @@ public class BackgroundTest { @BeforeEach public void setupMock() { mockLaunch(client, null, featureId, scenarioId, stepIds); + mockNestedSteps(client, nestedStepIds); mockBatchLogging(client); } @@ -45,15 +51,26 @@ public void test_background_steps() { verify(client, times(1)).startTestItem(same(featureId), captor.capture()); ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); List items = captor.getAllValues(); assertThat(items, hasSize(2)); List steps = stepCaptor.getAllValues(); assertThat(steps, hasSize(3)); - Set stepNames = steps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet()); + List backgroundSteps = steps.stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); + assertThat(backgroundSteps, hasSize(1)); + StartTestItemRQ backgroundStep = backgroundSteps.get(0); + assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate + assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); + assertThat(backgroundStep.getStartTime(), notNullValue()); + assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); - assertThat(stepNames, allOf(hasItem("BACKGROUND: Given def four = 4"), hasItem("When def actualFour = 2 * 2"), - hasItem("Then assert actualFour == four"))); + List nestedSteps = nestedStepCaptor.getAllValues(); + assertThat(nestedSteps, hasSize(1)); + StartTestItemRQ nestedStep = nestedSteps.get(0); + assertThat(nestedStep.getName(), equalTo("Given def four = 4")); } } From b5e86bb69b076c21d70ce713ff87100488ac830c Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 21 Dec 2023 18:07:27 +0300 Subject: [PATCH 28/76] Another background test --- .../karate/ReportPortalPublisher.java | 2 +- .../karate/background/BackgroundTest.java | 1 + .../background/BackgroundTwoStepsTest.java | 81 +++++++++++++++++++ .../feature/background_two_steps.feature | 8 ++ 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java create mode 100644 src/test/resources/feature/background_two_steps.feature diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 15bdb23..b710363 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -307,7 +307,6 @@ public void finishFeature(FeatureResult featureResult) { featureResult.isFailed() ? ItemStatus.FAILED : ItemStatus.PASSED); //noinspection ReactiveStreamsUnusedPublisher launch.get().finishTestItem(featureIdMap.remove(featureResult.getCallNameForReport()), rq); - backgroundId = null; } /** @@ -338,6 +337,7 @@ public void finishScenario(ScenarioResult scenarioResult) { Maybe removedScenarioId = scenarioIdMap.remove(scenarioResult.getScenario().getName()); //noinspection ReactiveStreamsUnusedPublisher launch.get().finishTestItem(removedScenarioId, rq); + backgroundId = null; } @Nonnull diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java index 784b086..785c3be 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java @@ -72,5 +72,6 @@ public void test_background_steps() { assertThat(nestedSteps, hasSize(1)); StartTestItemRQ nestedStep = nestedSteps.get(0); assertThat(nestedStep.getName(), equalTo("Given def four = 4")); + assertThat(nestedStep.isHasStats(), equalTo(Boolean.FALSE)); } } diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java new file mode 100644 index 0000000..4659a40 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java @@ -0,0 +1,81 @@ +package com.epam.reportportal.karate.background; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.listeners.ItemType; +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.StartTestItemRQ; +import com.intuit.karate.core.Background; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.ArgumentMatchers.startsWith; +import static org.mockito.Mockito.*; + +public class BackgroundTwoStepsTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2).collect(Collectors.toList()); + private final List> nestedStepIds = Stream.concat( + stepIds.stream().map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))), + stepIds.stream().map(id -> Pair.of(id, CommonUtils.namedId("nested_step_")))).collect(Collectors.toList() + ); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockNestedSteps(client, nestedStepIds); + mockBatchLogging(client); + } + + @Test + public void test_background_steps() { + var results = TestUtils.runAsReport(rp, "classpath:feature/background_two_steps.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); + + List items = captor.getAllValues(); + assertThat(items, hasSize(2)); + List steps = stepCaptor.getAllValues(); + assertThat(steps, hasSize(2)); + + List backgroundSteps = steps.stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); + assertThat(backgroundSteps, hasSize(1)); + StartTestItemRQ backgroundStep = backgroundSteps.get(0); + assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate + assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); + assertThat(backgroundStep.getStartTime(), notNullValue()); + assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); + + List nestedSteps = nestedStepCaptor.getAllValues(); + assertThat(nestedSteps, hasSize(2)); + nestedSteps.forEach(step -> assertThat(step.isHasStats(), equalTo(Boolean.FALSE))); + Set nestedStepNames = nestedSteps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet()); + + assertThat(nestedStepNames, allOf(hasItem("Given def vara = 2"), hasItem("And def varb = 2"))); + } +} diff --git a/src/test/resources/feature/background_two_steps.feature b/src/test/resources/feature/background_two_steps.feature new file mode 100644 index 0000000..70c4f06 --- /dev/null +++ b/src/test/resources/feature/background_two_steps.feature @@ -0,0 +1,8 @@ +Feature: test background with two steps reporting + + Background: Set variable + Given def vara = 2 + And def varb = 2 + + Scenario: Verify math + Then assert vara * varb == 4 From 49a76fe0c808d242e5328a9a213dd02c34c8e441 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 21 Dec 2023 18:30:30 +0300 Subject: [PATCH 29/76] Fix Table test --- .../karate/parameters/TableParametersTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java index a108ebd..2978094 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java @@ -56,12 +56,13 @@ public void test_table_parameters_reporting() { List items = captor.getAllValues(); assertThat(items, hasSize(2)); - Map logs = logCaptor + List logs = logCaptor .getAllValues(). stream() .flatMap(rq -> extractJsonParts((List) rq).stream()) .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel())) - .collect(Collectors.toMap(SaveLogRQ::getItemUuid, v -> v)); - assertThat(logs.get(stepIds.get(2)).getMessage(), startsWith("Table:\n\n")); + .collect(Collectors.toList()); + assertThat(logs, hasSize(1)); + assertThat(logs.get(0).getMessage(), startsWith("Table:\n\n")); } } From 9bcdda6694a3d4e5e1837b5fdd56a57871bc92bd Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 21 Dec 2023 18:31:47 +0300 Subject: [PATCH 30/76] Fix Table test --- .../epam/reportportal/karate/parameters/TableParametersTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java index 2978094..de95fc0 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java @@ -64,5 +64,6 @@ public void test_table_parameters_reporting() { .collect(Collectors.toList()); assertThat(logs, hasSize(1)); assertThat(logs.get(0).getMessage(), startsWith("Table:\n\n")); + assertThat(logs.get(0).getItemUuid(), startsWith("step_")); } } From 03935006b0abcb8f2b785c8579bfda902643950c Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 21 Dec 2023 18:33:17 +0300 Subject: [PATCH 31/76] Fix description --- src/test/resources/feature/background.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/feature/background.feature b/src/test/resources/feature/background.feature index 84f951a..44b742d 100644 --- a/src/test/resources/feature/background.feature +++ b/src/test/resources/feature/background.feature @@ -1,4 +1,4 @@ -Feature: the test to show item description reporting +Feature: test background reporting Background: Set variable Given def four = 4 From d51985cd2f93f2b2095708f0d7395ec354239196 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 22 Dec 2023 12:48:18 +0300 Subject: [PATCH 32/76] Add another test --- .../background/BackgroundExamplesTest.java | 97 +++++++++++++++++++ .../feature/background_examples.feature | 13 +++ 2 files changed, 110 insertions(+) create mode 100644 src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java create mode 100644 src/test/resources/feature/background_examples.feature diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java new file mode 100644 index 0000000..e29f9ab --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java @@ -0,0 +1,97 @@ +package com.epam.reportportal.karate.background; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.listeners.ItemType; +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.StartTestItemRQ; +import com.intuit.karate.core.Background; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.ArgumentMatchers.startsWith; +import static org.mockito.Mockito.*; + +public class BackgroundExamplesTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")) + .limit(2).collect(Collectors.toList()); + + private final List>> scenarioSteps = scenarioIds + .stream().map(s -> + Pair.of(s, Stream.generate(() -> + CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()))) + .collect(Collectors.toList()); + private final List> nestedStepIds = scenarioSteps + .stream() + .flatMap(s -> s.getValue().stream()) + .map(s -> Pair.of(s, CommonUtils.namedId("nested_step_"))) + .collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioSteps); + mockNestedSteps(client, nestedStepIds); + mockBatchLogging(client); + } + + @Test + public void test_background_steps() { + var results = TestUtils.runAsReport(rp, "classpath:feature/background_examples.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client, times(2)).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioIds.get(0)), firstStepCaptor.capture()); + ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioIds.get(1)), secondStepCaptor.capture()); + ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); + + List items = captor.getAllValues(); + assertThat(items, hasSize(3)); + List firstSteps = firstStepCaptor.getAllValues(); + assertThat(firstSteps, hasSize(3)); + List secondSteps = secondStepCaptor.getAllValues(); + assertThat(firstSteps, hasSize(3)); + + List firstBackgroundSteps = firstSteps.stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); + assertThat(firstBackgroundSteps, hasSize(1)); + List secondBackgroundSteps = secondSteps.stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); + assertThat(secondBackgroundSteps, hasSize(1)); + + Stream.concat(firstBackgroundSteps.stream(), secondBackgroundSteps.stream()).forEach(backgroundStep ->{ + assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate + assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); + assertThat(backgroundStep.getStartTime(), notNullValue()); + assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); + }); + + List nestedSteps = nestedStepCaptor.getAllValues(); + assertThat(nestedSteps, hasSize(2)); + nestedSteps.forEach(step -> assertThat(step.isHasStats(), equalTo(Boolean.FALSE))); + Set nestedStepNames = nestedSteps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet()); + + assertThat(nestedStepNames, hasSize(1)); + assertThat(nestedStepNames, hasItem("Given def varb = 2")); + } +} diff --git a/src/test/resources/feature/background_examples.feature b/src/test/resources/feature/background_examples.feature new file mode 100644 index 0000000..b65a603 --- /dev/null +++ b/src/test/resources/feature/background_examples.feature @@ -0,0 +1,13 @@ +Feature: test background with Scenario Outline reporting + + Background: Set varb + Given def varb = 2 + + Scenario Outline: Verify different maths + Given def mathResult = vara + varb + Then assert mathResult == result + + Examples: + | vara! | result! | + | 2 | 4 | + | 1 | 3 | From c3cefa1b14bac9eab79df147920c028bf0130849 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 22 Dec 2023 13:03:53 +0300 Subject: [PATCH 33/76] Add Launch description test --- .../description/LaunchDescriptionTest.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java diff --git a/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java new file mode 100644 index 0000000..91819f9 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java @@ -0,0 +1,70 @@ +/* + * Copyright 2023 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. + */ + +package com.epam.reportportal.karate.description; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.listeners.ListenerParameters; +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.launch.StartLaunchRQ; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class LaunchDescriptionTest { + private static final String TEST_DESCRIPTION = "My test description"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private ReportPortal rp; + + @BeforeEach + public void setupMock() { + ListenerParameters parameters = standardParameters(); + parameters.setDescription(TEST_DESCRIPTION); + rp = ReportPortal.create(client, parameters, testExecutor()); + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void verify_start_launch_request_contains_launch_description() { + var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); + + StartLaunchRQ launchStart = startCaptor.getValue(); + + assertThat(launchStart.getDescription(), equalTo(TEST_DESCRIPTION)); + } +} From 423396805342ee1903aae540375ddca9bb347aec Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 22 Dec 2023 13:09:49 +0300 Subject: [PATCH 34/76] Small fix --- .../com/epam/reportportal/karate/ReportPortalPublisher.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index b710363..6ba7525 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -51,7 +51,6 @@ import static com.epam.reportportal.utils.ParameterUtils.NULL_VALUE; import static com.epam.reportportal.utils.ParameterUtils.formatParametersAsTable; import static com.epam.reportportal.utils.markdown.MarkdownUtils.formatDataTable; -import static com.google.common.base.Strings.isNullOrEmpty; import static java.util.Optional.ofNullable; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -92,7 +91,7 @@ protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) { rq.setStartTime(Calendar.getInstance().getTime()); rq.setMode(parameters.getLaunchRunningMode()); rq.setAttributes(new HashSet<>(parameters.getAttributes())); - if (!isNullOrEmpty(parameters.getDescription())) { + if (!isNotBlank(parameters.getDescription())) { rq.setDescription(parameters.getDescription()); } rq.setRerun(parameters.isRerun()); From 07c551bf977bc14721346c0eadba2a30ade216de Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 22 Dec 2023 13:52:16 +0300 Subject: [PATCH 35/76] Small fix --- .../com/epam/reportportal/karate/ReportPortalPublisher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 6ba7525..074ee59 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -91,7 +91,7 @@ protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) { rq.setStartTime(Calendar.getInstance().getTime()); rq.setMode(parameters.getLaunchRunningMode()); rq.setAttributes(new HashSet<>(parameters.getAttributes())); - if (!isNotBlank(parameters.getDescription())) { + if (isNotBlank(parameters.getDescription())) { rq.setDescription(parameters.getDescription()); } rq.setRerun(parameters.isRerun()); From b69374ec77f8f15af55785f02ce27afca8f05cd1 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 26 Dec 2023 00:06:23 +0300 Subject: [PATCH 36/76] Add test --- .../description/NoLaunchDescriptionTest.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java diff --git a/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java new file mode 100644 index 0000000..e552cbd --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java @@ -0,0 +1,80 @@ +/* + * Copyright 2023 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. + */ + +package com.epam.reportportal.karate.description; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.listeners.ListenerParameters; +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.launch.StartLaunchRQ; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.ArgumentCaptor; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.nullValue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +public class NoLaunchDescriptionTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + public static List dataValues() { + return Arrays.asList( + null, + "", + " " + ); + } + + @ParameterizedTest + @MethodSource("dataValues") + public void verify_start_launch_request_contains_no_launch_description(String description) { + ListenerParameters parameters = standardParameters(); + parameters.setDescription(description); + ReportPortal rp = ReportPortal.create(client, parameters, testExecutor()); + var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); + + StartLaunchRQ launchStart = startCaptor.getValue(); + + assertThat(launchStart.getDescription(), nullValue()); + } +} From 2aa86fd2827743883d442b4c12579edd16332e16 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 26 Dec 2023 00:07:01 +0300 Subject: [PATCH 37/76] Add junit-jupiter-params dependency --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index f0b263f..3620a20 100644 --- a/build.gradle +++ b/build.gradle @@ -50,6 +50,7 @@ dependencies { testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.2' testImplementation "org.junit.jupiter:junit-jupiter-api:${project.junit_version}" testImplementation "org.junit.jupiter:junit-jupiter-engine:${project.junit_version}" + testImplementation "org.junit.jupiter:junit-jupiter-params:${project.junit_version}" testImplementation "org.mockito:mockito-core:${project.mockito_version}" testImplementation "org.mockito:mockito-junit-jupiter:${project.mockito_version}" testImplementation 'org.hamcrest:hamcrest-core:2.2' From 3a07901430c134f412bec4dd261edad2f23a7011 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 26 Dec 2023 01:19:37 +0300 Subject: [PATCH 38/76] Description and item name tests and fixes --- .../karate/ReportPortalPublisher.java | 90 ++++++++++--------- .../attributes/SystemAttributesTest.java | 1 - .../background/BackgroundExamplesTest.java | 2 +- .../karate/background/BackgroundTest.java | 2 +- .../karate/coderef/ScenarioCodeRefTest.java | 22 ++--- .../karate/description/NoDescriptionTest.java | 58 ++++++++++++ .../description/SimpleDescriptionTest.java | 68 ++++++++++++++ .../karate/name/SimpleItemNameTest.java | 65 ++++++++++++++ .../ExamplesStepParametersTest.java | 2 +- .../parameters/TableParametersTest.java | 3 +- .../resources/feature/description.feature | 16 ++++ 11 files changed, 270 insertions(+), 59 deletions(-) create mode 100644 src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java create mode 100644 src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java create mode 100644 src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java create mode 100644 src/test/resources/feature/description.feature diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 074ee59..9d077c8 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -59,6 +59,7 @@ public class ReportPortalPublisher { public static final String EXAMPLE_CODE_REFERENCE_PATTERN = "%s/[EXAMPLE:%s%s]"; public static final String VARIABLE_PATTERN = "(?:(?<=#\\()%1$s(?=\\)))|(?:(?<=[\\s=+-/*<>(]|^)%1$s(?=[\\s=+-/*<>)]|(?:\\r?\\n)|$))"; + public static final String MARKDOWN_DELIMITER_PATTERN = "%s\n\n---\n\n%s"; private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalPublisher.class); private final Map> featureIdMap = new HashMap<>(); @@ -213,43 +214,28 @@ private Set toAttributes(@Nullable List tags) { */ @Nonnull protected StartTestItemRQ buildStartFeatureRq(@Nonnull FeatureResult featureResult) { - StartTestItemRQ rq = buildStartTestItemRq(String.valueOf(featureResult.toCucumberJson().get("name")), - Calendar.getInstance().getTime(), - ItemType.STORY); Feature feature = featureResult.getFeature(); + StartTestItemRQ rq = buildStartTestItemRq(feature.getName(), Calendar.getInstance().getTime(), ItemType.STORY); rq.setAttributes(toAttributes(feature.getTags())); - return rq; - } - - @Nullable - private List getParameters(@Nonnull Scenario scenario) { - if (scenario.getExampleIndex() < 0) { - return null; + String featurePath = feature.getResource().getUri().toString(); + String description = feature.getDescription(); + if (isNotBlank(description)) { + rq.setDescription(String.format(MARKDOWN_DELIMITER_PATTERN, featurePath, description)); + } else { + rq.setDescription(featurePath); } - return scenario.getExampleData().entrySet().stream().map(e -> { - ParameterResource parameterResource = new ParameterResource(); - parameterResource.setKey(e.getKey()); - parameterResource.setValue(ofNullable(e.getValue()).map(Object::toString).orElse(NULL_VALUE)); - return parameterResource; - }).collect(Collectors.toList()); + return rq; } /** - * Build ReportPortal request for start Scenario event + * Start sending feature data to ReportPortal. * - * @param scenarioResult Karate's ScenarioResult object instance - * @return request to ReportPortal + * @param featureResult feature result */ - protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioResult scenarioResult) { - StartTestItemRQ rq = buildStartTestItemRq(scenarioResult.getScenario().getName(), - Calendar.getInstance().getTime(), - ItemType.STEP); - Scenario scenario = scenarioResult.getScenario(); - rq.setCodeRef(getCodeRef(scenario)); - rq.setTestCaseId(ofNullable(getTestCaseId(scenario)).map(TestCaseIdEntry::getId).orElse(null)); - rq.setAttributes(toAttributes(scenario.getTags())); - rq.setParameters(getParameters(scenario)); - return rq; + public void startFeature(@Nonnull FeatureResult featureResult) { + StartTestItemRQ rq = buildStartFeatureRq(featureResult); + Maybe featureId = launch.get().startTestItem(rq); + featureIdMap.put(featureResult.getCallNameForReport(), featureId); } /** @@ -267,17 +253,6 @@ protected FinishTestItemRQ buildFinishTestItemRq(@Nonnull Date endTime, return rq; } - /** - * Start sending feature data to ReportPortal. - * - * @param featureResult feature result - */ - public void startFeature(@Nonnull FeatureResult featureResult) { - StartTestItemRQ rq = buildStartFeatureRq(featureResult); - Maybe featureId = launch.get().startTestItem(rq); - featureIdMap.put(featureResult.getCallNameForReport(), featureId); - } - /** * Finish sending feature data to ReportPortal * @@ -308,6 +283,41 @@ public void finishFeature(FeatureResult featureResult) { launch.get().finishTestItem(featureIdMap.remove(featureResult.getCallNameForReport()), rq); } + @Nullable + private List getParameters(@Nonnull Scenario scenario) { + if (scenario.getExampleIndex() < 0) { + return null; + } + return scenario.getExampleData().entrySet().stream().map(e -> { + ParameterResource parameterResource = new ParameterResource(); + parameterResource.setKey(e.getKey()); + parameterResource.setValue(ofNullable(e.getValue()).map(Object::toString).orElse(NULL_VALUE)); + return parameterResource; + }).collect(Collectors.toList()); + } + + /** + * Build ReportPortal request for start Scenario event + * + * @param scenarioResult Karate's ScenarioResult object instance + * @return request to ReportPortal + */ + protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioResult scenarioResult) { + StartTestItemRQ rq = buildStartTestItemRq(scenarioResult.getScenario().getName(), + Calendar.getInstance().getTime(), + ItemType.STEP); + Scenario scenario = scenarioResult.getScenario(); + rq.setCodeRef(getCodeRef(scenario)); + rq.setTestCaseId(ofNullable(getTestCaseId(scenario)).map(TestCaseIdEntry::getId).orElse(null)); + rq.setAttributes(toAttributes(scenario.getTags())); + rq.setParameters(getParameters(scenario)); + String description = scenario.getDescription(); + if (isNotBlank(description)) { + rq.setDescription(description); + } + return rq; + } + /** * Start sending scenario data to ReportPortal * diff --git a/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java index 7ea6812..a5cb85e 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java @@ -32,7 +32,6 @@ import java.util.stream.Stream; import static com.epam.reportportal.karate.utils.TestUtils.*; -import static com.epam.reportportal.karate.utils.TestUtils.mockBatchLogging; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.mockito.Mockito.mock; diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java index e29f9ab..bdf0b09 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java @@ -79,7 +79,7 @@ public void test_background_steps() { .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); assertThat(secondBackgroundSteps, hasSize(1)); - Stream.concat(firstBackgroundSteps.stream(), secondBackgroundSteps.stream()).forEach(backgroundStep ->{ + Stream.concat(firstBackgroundSteps.stream(), secondBackgroundSteps.stream()).forEach(backgroundStep -> { assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); assertThat(backgroundStep.getStartTime(), notNullValue()); diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java index 785c3be..fa81516 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java @@ -48,7 +48,7 @@ public void test_background_steps() { ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client).startTestItem(captor.capture()); - verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + verify(client).startTestItem(same(featureId), captor.capture()); ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java index b7b047a..fe0c31e 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java @@ -12,7 +12,6 @@ import java.util.List; import java.util.stream.Collectors; -import java.util.stream.IntStream; import java.util.stream.Stream; import static com.epam.reportportal.karate.utils.TestUtils.*; @@ -43,25 +42,22 @@ public void test_scenario_code_reference() { var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(1)).startTestItem(same(featureId), captor.capture()); - verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(5)); - - StartTestItemRQ featureRq = items.get(0); - StartTestItemRQ scenarioRq = items.get(1); + StartTestItemRQ featureRq = featureCaptor.getValue(); + StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); assertThat(featureRq.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); assertThat(scenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); assertThat(scenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(SIMPLE_CODE_REFERENCE))); - List stepRqs = items.subList(2, items.size()); - IntStream.range(0, stepRqs.size()).forEach(i -> { - StartTestItemRQ step = stepRqs.get(i); + stepCaptor.getAllValues().forEach(step -> { assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); assertThat(step.isHasStats(), equalTo(Boolean.FALSE)); }); diff --git a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java new file mode 100644 index 0000000..05b4b97 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java @@ -0,0 +1,58 @@ +package com.epam.reportportal.karate.description; + +import com.epam.reportportal.karate.utils.TestUtils; +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.StartTestItemRQ; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class NoDescriptionTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_description_for_all_possible_items() { + var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + + StartTestItemRQ featureStart = featureCaptor.getValue(); + assertThat(featureStart.getDescription(), endsWith("feature/simple.feature")); + + StartTestItemRQ scenarioStart = scenarioCaptor.getValue(); + assertThat(scenarioStart.getDescription(), nullValue()); + + stepCaptor.getAllValues().forEach(step -> assertThat(step.getDescription(), nullValue())); + } +} diff --git a/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java new file mode 100644 index 0000000..d88c135 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java @@ -0,0 +1,68 @@ +package com.epam.reportportal.karate.description; + +import com.epam.reportportal.karate.utils.TestUtils; +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.StartTestItemRQ; +import com.intuit.karate.core.Background; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class SimpleDescriptionTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + private final List> nestedStepIds = stepIds.stream() + .map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockNestedSteps(client, nestedStepIds); + mockBatchLogging(client); + } + + @Test + public void test_description_for_all_possible_items() { + var results = TestUtils.runAsReport(rp, "classpath:feature/description.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + + StartTestItemRQ featureStart = featureCaptor.getValue(); + assertThat(featureStart.getDescription(), endsWith("feature/description.feature\n\n---\n\nThis is my Feature description.")); + + StartTestItemRQ scenarioStart = scenarioCaptor.getValue(); + assertThat(scenarioStart.getDescription(), equalTo("This is my Scenario description.")); + + List backgroundSteps = stepCaptor.getAllValues().stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); + assertThat(backgroundSteps, hasSize(1)); + StartTestItemRQ backgroundStep = backgroundSteps.get(0); + assertThat("No support of Background description in Karate yet. But this is a part of Gherkin standard.", + backgroundStep.getDescription(), nullValue()); + } +} diff --git a/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java b/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java new file mode 100644 index 0000000..a12ee62 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java @@ -0,0 +1,65 @@ +package com.epam.reportportal.karate.name; + +import com.epam.reportportal.karate.utils.TestUtils; +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.StartTestItemRQ; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class SimpleItemNameTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_scenario_code_reference() { + var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + + StartTestItemRQ featureRq = featureCaptor.getValue(); + StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); + + assertThat(featureRq.getName(), allOf(notNullValue(), equalTo("the very basic test to run by Karate"))); + + assertThat(scenarioRq.getName(), allOf(notNullValue(), equalTo("Verify math"))); + + List stepRqs = stepCaptor.getAllValues(); + String[] stepNames = new String[]{"Given def four = 4", "When def actualFour = 2 * 2", + "Then assert actualFour == four"}; + IntStream.range(0, stepRqs.size()).forEach(i -> { + StartTestItemRQ step = stepRqs.get(i); + assertThat(step.getName(), allOf(notNullValue(), equalTo(stepNames[i]))); + }); + } +} diff --git a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java index d9185e9..5281922 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java @@ -24,8 +24,8 @@ import static com.epam.reportportal.karate.utils.TestUtils.*; import static java.util.stream.Stream.ofNullable; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.startsWith; +import static org.hamcrest.Matchers.*; import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; diff --git a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java index de95fc0..7ed7a89 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java @@ -13,14 +13,13 @@ import org.mockito.ArgumentCaptor; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; import static com.epam.reportportal.karate.utils.TestUtils.*; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.startsWith; +import static org.hamcrest.Matchers.*; import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; diff --git a/src/test/resources/feature/description.feature b/src/test/resources/feature/description.feature new file mode 100644 index 0000000..818e8da --- /dev/null +++ b/src/test/resources/feature/description.feature @@ -0,0 +1,16 @@ +Feature: the test to show item description reporting + + This is my Feature description. + + Background: Set variable + + This is my Background description. + + Given def four = 4 + + Scenario: Verify math + + This is my Scenario description. + + When def actualFour = 2 * 2 + Then assert actualFour == four From a03caa2d58a2cde76acb54fb17771a6c438654dc Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 26 Dec 2023 01:26:02 +0300 Subject: [PATCH 39/76] Fix test --- .../reportportal/karate/ReportPortalPublisherTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java b/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java index dcdcccd..39ee91b 100644 --- a/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java +++ b/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java @@ -8,6 +8,7 @@ import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import com.intuit.karate.core.Feature; import com.intuit.karate.core.FeatureResult; +import com.intuit.karate.resource.Resource; import io.reactivex.Maybe; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -15,6 +16,8 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import java.net.URI; +import java.net.URISyntaxException; import java.util.concurrent.ConcurrentHashMap; import static org.mockito.Mockito.*; @@ -45,11 +48,14 @@ public void shouldFinishLaunch() { @SuppressWarnings("unchecked") @Test - public void shouldStartFeature() { + public void shouldStartFeature() throws URISyntaxException { FeatureResult featureResult = mock(FeatureResult.class); Feature feature = mock(Feature.class); + Resource resource = mock(Resource.class); when(featureResult.getFeature()).thenReturn(feature); when(featureResult.getCallNameForReport()).thenReturn("featureName"); + when(feature.getResource()).thenReturn(resource); + when(resource.getUri()).thenReturn(new URI("file:///feature/simple.feature")); when(launchMock.startTestItem(any(StartTestItemRQ.class))).thenReturn(mock(Maybe.class)); reportPortalPublisher.startFeature(featureResult); verify(launchMock, times(1)).startTestItem(any(StartTestItemRQ.class)); From e5bdda66a1765c7afa8613eb40686335ab22b5e2 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 26 Dec 2023 13:20:37 +0300 Subject: [PATCH 40/76] Refactoring --- .../karate/coderef/ExamplesCodeRefTest.java | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java index e941a90..961de3a 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java @@ -13,7 +13,6 @@ import java.util.List; import java.util.stream.Collectors; -import java.util.stream.IntStream; import java.util.stream.Stream; import static com.epam.reportportal.karate.utils.TestUtils.*; @@ -52,32 +51,31 @@ public void test_examples_code_reference() { var results = TestUtils.runAsReport(rp, "classpath:feature/examples.feature"); assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(2)).startTestItem(same(featureId), captor.capture()); - verify(client, times(2)).startTestItem(same(exampleIds.get(0)), captor.capture()); - verify(client, times(2)).startTestItem(same(exampleIds.get(1)), captor.capture()); - - List items = captor.getAllValues(); - assertThat(items, hasSize(7)); - - StartTestItemRQ featureRq = items.get(0); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); + ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); + StartTestItemRQ featureRq = featureCaptor.getValue(); assertThat(featureRq.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); - StartTestItemRQ firstScenarioRq = items.get(1); + List scenarios = scenarioCaptor.getAllValues(); + StartTestItemRQ firstScenarioRq = scenarios.get(0); assertThat(firstScenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); assertThat(firstScenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_CODE_REFERENCE))); - StartTestItemRQ secondScenarioRq = items.get(2); + StartTestItemRQ secondScenarioRq = scenarios.get(1); assertThat(secondScenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); assertThat(secondScenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_CODE_REFERENCE))); - List stepRqs = items.subList(3, items.size()); - IntStream.range(0, stepRqs.size()).forEach(i -> { - StartTestItemRQ step = stepRqs.get(i); - assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); - assertThat(step.isHasStats(), equalTo(Boolean.FALSE)); - }); + Stream.concat(firstStepCaptor.getAllValues().stream(), secondStepCaptor.getAllValues().stream()) + .forEach(step -> { + assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(step.isHasStats(), equalTo(Boolean.FALSE)); + }); } } From e8b2c7fb5bdb72a902ae94560785529234adec3e Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 26 Dec 2023 13:42:51 +0300 Subject: [PATCH 41/76] Add parameter description to examples --- .../karate/ReportPortalPublisher.java | 29 +++++-- .../NoDescriptionExamplesTest.java | 75 +++++++++++++++++++ 2 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 9d077c8..c12dcc7 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -25,6 +25,7 @@ import com.epam.reportportal.service.item.TestCaseIdEntry; import com.epam.reportportal.utils.AttributeParser; import com.epam.reportportal.utils.MemoizingSupplier; +import com.epam.reportportal.utils.ParameterUtils; import com.epam.reportportal.utils.TestCaseIdUtils; import com.epam.reportportal.utils.properties.SystemAttributesExtractor; import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; @@ -60,6 +61,7 @@ public class ReportPortalPublisher { public static final String VARIABLE_PATTERN = "(?:(?<=#\\()%1$s(?=\\)))|(?:(?<=[\\s=+-/*<>(]|^)%1$s(?=[\\s=+-/*<>)]|(?:\\r?\\n)|$))"; public static final String MARKDOWN_DELIMITER_PATTERN = "%s\n\n---\n\n%s"; + public static final String PARAMETERS_PATTERN = "Parameters:\n\n%s"; private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalPublisher.class); private final Map> featureIdMap = new HashMap<>(); @@ -310,10 +312,24 @@ protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioResult scenarioR rq.setCodeRef(getCodeRef(scenario)); rq.setTestCaseId(ofNullable(getTestCaseId(scenario)).map(TestCaseIdEntry::getId).orElse(null)); rq.setAttributes(toAttributes(scenario.getTags())); - rq.setParameters(getParameters(scenario)); + List parameters = getParameters(scenario); + boolean hasParameters = ofNullable(parameters).filter(p -> !p.isEmpty()).isPresent(); + if (hasParameters) { + rq.setParameters(parameters); + } + String description = scenario.getDescription(); if (isNotBlank(description)) { - rq.setDescription(description); + if (hasParameters) { + rq.setDescription( + String.format(MARKDOWN_DELIMITER_PATTERN, + String.format(PARAMETERS_PATTERN, ParameterUtils.formatParametersAsTable(parameters)), + description)); + } else { + rq.setDescription(description); + } + } else if (hasParameters) { + rq.setDescription(String.format(PARAMETERS_PATTERN, ParameterUtils.formatParametersAsTable(parameters))); } return rq; } @@ -376,7 +392,8 @@ protected StartTestItemRQ buildStartStepRq(@Nonnull StepResult stepResult, @Nonn .getExampleData() .entrySet() .stream() - .filter(e -> Pattern.compile(String.format(VARIABLE_PATTERN, e.getKey())).matcher(step.getText()).find()) + .filter(e -> Pattern.compile(String.format(VARIABLE_PATTERN, e.getKey())) + .matcher(step.getText()).find()) .map(e -> { ParameterResource param = new ParameterResource(); param.setKey(e.getKey()); @@ -400,7 +417,8 @@ public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { if (stepResult.getStep().isBackground()) { backgroundId = ofNullable(backgroundId).orElseGet(() -> { StartTestItemRQ backgroundRq = buildStartBackgroundRq(stepResult, scenarioResult); - return launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), backgroundRq); + return launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), + backgroundRq); }); } else { backgroundId = null; @@ -415,7 +433,8 @@ public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { ofNullable(stepRq.getParameters()) .filter(params -> !params.isEmpty()) .ifPresent(params -> - sendLog(stepId, "Parameters:\n\n" + formatParametersAsTable(params), LogLevel.INFO)); + sendLog(stepId, String.format(PARAMETERS_PATTERN, formatParametersAsTable(params)), + LogLevel.INFO)); ofNullable(stepResult.getStep().getTable()) .ifPresent(table -> sendLog(stepId, "Table:\n\n" + formatDataTable(table.getRows()), LogLevel.INFO)); diff --git a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java new file mode 100644 index 0000000..9dfca6a --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java @@ -0,0 +1,75 @@ +package com.epam.reportportal.karate.description; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.service.ReportPortal; +import com.epam.reportportal.service.ReportPortalClient; +import com.epam.reportportal.util.test.CommonUtils; +import com.epam.reportportal.utils.markdown.MarkdownUtils; +import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class NoDescriptionExamplesTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) + .collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); + + private static final String EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN = + "Parameters:\n\n" + + MarkdownUtils.TABLE_INDENT + + "| vara | varb | result |\n" + + MarkdownUtils.TABLE_INDENT + + "|------|------|--------|\n" + + MarkdownUtils.TABLE_INDENT; + private static final String FIRST_EXAMPLE_DESCRIPTION = EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN + + "|  2   |  2   |   4    |"; + private static final String SECOND_EXAMPLE_DESCRIPTION = EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN + + "|  1   |  2   |   3    |"; + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_examples_no_description() { + var results = TestUtils.runAsReport(rp, "classpath:feature/examples.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); + ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); + + List scenarios = scenarioCaptor.getAllValues(); + StartTestItemRQ firstScenarioRq = scenarios.get(0); + assertThat(firstScenarioRq.getDescription(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_DESCRIPTION))); + + StartTestItemRQ secondScenarioRq = scenarios.get(1); + assertThat(secondScenarioRq.getDescription(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_DESCRIPTION))); + } +} From ff12c0e57ba9506313cca7e93bae86687ef9a490 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 26 Dec 2023 15:31:09 +0300 Subject: [PATCH 42/76] Add examples description tests --- .../description/DescriptionExamplesTest.java | 72 +++++++++++++++++++ .../NoDescriptionExamplesTest.java | 4 +- .../feature/description_examples.feature | 13 ++++ 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java create mode 100644 src/test/resources/feature/description_examples.feature diff --git a/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java b/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java new file mode 100644 index 0000000..3484b36 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java @@ -0,0 +1,72 @@ +package com.epam.reportportal.karate.description; + +import com.epam.reportportal.karate.ReportPortalPublisher; +import com.epam.reportportal.karate.utils.TestUtils; +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.StartTestItemRQ; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.ArgumentMatchers.same; +import static org.mockito.Mockito.*; + +public class DescriptionExamplesTest { + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) + .collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); + + public static final String FIRST_EXAMPLE_DESCRIPTION = String.format( + ReportPortalPublisher.MARKDOWN_DELIMITER_PATTERN, + NoDescriptionExamplesTest.FIRST_EXAMPLE_DESCRIPTION, + "This is my Scenario description."); + public static final String SECOND_EXAMPLE_DESCRIPTION = String.format( + ReportPortalPublisher.MARKDOWN_DELIMITER_PATTERN, + NoDescriptionExamplesTest.SECOND_EXAMPLE_DESCRIPTION, + "This is my Scenario description."); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_examples_description() { + var results = TestUtils.runAsReport(rp, "classpath:feature/description_examples.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); + ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); + + List scenarios = scenarioCaptor.getAllValues(); + StartTestItemRQ firstScenarioRq = scenarios.get(0); + assertThat(firstScenarioRq.getDescription(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_DESCRIPTION))); + + StartTestItemRQ secondScenarioRq = scenarios.get(1); + assertThat(secondScenarioRq.getDescription(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_DESCRIPTION))); + } +} diff --git a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java index 9dfca6a..d8a896b 100644 --- a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java @@ -37,9 +37,9 @@ public class NoDescriptionExamplesTest { + MarkdownUtils.TABLE_INDENT + "|------|------|--------|\n" + MarkdownUtils.TABLE_INDENT; - private static final String FIRST_EXAMPLE_DESCRIPTION = EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN + public static final String FIRST_EXAMPLE_DESCRIPTION = EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN + "|  2   |  2   |   4    |"; - private static final String SECOND_EXAMPLE_DESCRIPTION = EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN + public static final String SECOND_EXAMPLE_DESCRIPTION = EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN + "|  1   |  2   |   3    |"; private final ReportPortalClient client = mock(ReportPortalClient.class); diff --git a/src/test/resources/feature/description_examples.feature b/src/test/resources/feature/description_examples.feature new file mode 100644 index 0000000..0915494 --- /dev/null +++ b/src/test/resources/feature/description_examples.feature @@ -0,0 +1,13 @@ +Feature: math tests with examples + + Scenario Outline: Verify different maths + + This is my Scenario description. + + Given def mathResult = vara + varb + Then assert mathResult == result + + Examples: + | vara! | varb! | result! | + | 2 | 2 | 4 | + | 1 | 2 | 3 | From e9a1f6171d3332097c05ab638c88f1ca012e7085 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 26 Dec 2023 16:15:09 +0300 Subject: [PATCH 43/76] Refactoring --- .../karate/description/DescriptionExamplesTest.java | 4 ++-- .../karate/description/SimpleDescriptionTest.java | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java b/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java index 3484b36..671eda4 100644 --- a/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java @@ -33,11 +33,11 @@ public class DescriptionExamplesTest { public static final String FIRST_EXAMPLE_DESCRIPTION = String.format( ReportPortalPublisher.MARKDOWN_DELIMITER_PATTERN, NoDescriptionExamplesTest.FIRST_EXAMPLE_DESCRIPTION, - "This is my Scenario description."); + SimpleDescriptionTest.SCENARIO_DESCRIPTION); public static final String SECOND_EXAMPLE_DESCRIPTION = String.format( ReportPortalPublisher.MARKDOWN_DELIMITER_PATTERN, NoDescriptionExamplesTest.SECOND_EXAMPLE_DESCRIPTION, - "This is my Scenario description."); + SimpleDescriptionTest.SCENARIO_DESCRIPTION); private final ReportPortalClient client = mock(ReportPortalClient.class); private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); diff --git a/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java index d88c135..94186ce 100644 --- a/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java @@ -30,6 +30,8 @@ public class SimpleDescriptionTest { private final List> nestedStepIds = stepIds.stream() .map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))).collect(Collectors.toList()); + public static final String SCENARIO_DESCRIPTION = "This is my Scenario description."; + private final ReportPortalClient client = mock(ReportPortalClient.class); private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); @@ -56,7 +58,7 @@ public void test_description_for_all_possible_items() { assertThat(featureStart.getDescription(), endsWith("feature/description.feature\n\n---\n\nThis is my Feature description.")); StartTestItemRQ scenarioStart = scenarioCaptor.getValue(); - assertThat(scenarioStart.getDescription(), equalTo("This is my Scenario description.")); + assertThat(scenarioStart.getDescription(), equalTo(SCENARIO_DESCRIPTION)); List backgroundSteps = stepCaptor.getAllValues().stream() .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); From 2a1296594d15608381d6ddd657a721a14e0afe51 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 26 Dec 2023 18:24:44 +0300 Subject: [PATCH 44/76] Add test --- .../karate/status/SimpleAllPassedTest.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java diff --git a/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java b/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java new file mode 100644 index 0000000..93e4543 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java @@ -0,0 +1,86 @@ +/* + * Copyright 2023 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 + * + * 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, + * 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. + */ + +package com.epam.reportportal.karate.status; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.listeners.ItemStatus; +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 org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.Mockito.*; + +public class SimpleAllPassedTest { + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_simple_all_passed() { + var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(client).finishTestItem(same(featureId), featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(client).finishTestItem(same(scenarioId), scenarioCaptor.capture()); + List> stepCaptors = + Stream.generate(() -> ArgumentCaptor.forClass(FinishTestItemRQ.class)).limit(stepIds.size()).collect(Collectors.toList()); + IntStream.range(0, stepIds.size()).forEach(i -> verify(client).finishTestItem(same(stepIds.get(i)), stepCaptors.get(i).capture())); + + FinishTestItemRQ featureRq = featureCaptor.getValue(); + FinishTestItemRQ scenarioRq = scenarioCaptor.getValue(); + + assertThat(featureRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); + assertThat(featureRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(featureRq.getEndTime(), notNullValue()); + + assertThat(scenarioRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); + assertThat(scenarioRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(scenarioRq.getEndTime(), notNullValue()); + + stepCaptors.forEach(stepCaptor -> { + FinishTestItemRQ step = stepCaptor.getValue(); + assertThat(step.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); + assertThat(step.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(step.getEndTime(), notNullValue()); + }); + } +} \ No newline at end of file From 0bd88f09857efe980a2680443b0e7c53d9d8eb52 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 27 Dec 2023 12:52:55 +0300 Subject: [PATCH 45/76] Add test --- .../status/SimpleOneStepFailedTest.java | 88 +++++++++++++++++++ .../resources/feature/simple_failed.feature | 6 ++ 2 files changed, 94 insertions(+) create mode 100644 src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java create mode 100644 src/test/resources/feature/simple_failed.feature diff --git a/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java b/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java new file mode 100644 index 0000000..f66675f --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java @@ -0,0 +1,88 @@ +/* + * Copyright 2023 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 + * + * 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, + * 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. + */ + +package com.epam.reportportal.karate.status; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.listeners.ItemStatus; +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.FinishExecutionRQ; +import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.Mockito.*; + +public class SimpleOneStepFailedTest { + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_simple_one_step_failed() { + var results = TestUtils.runAsReport(rp, "classpath:feature/simple_failed.feature"); + assertThat(results.getFailCount(), equalTo(1)); + + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(client).finishTestItem(same(featureId), featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(client).finishTestItem(same(scenarioId), scenarioCaptor.capture()); + List> stepCaptors = + Stream.generate(() -> ArgumentCaptor.forClass(FinishTestItemRQ.class)).limit(stepIds.size()).collect(Collectors.toList()); + IntStream.range(0, stepIds.size()).forEach(i -> verify(client).finishTestItem(same(stepIds.get(i)), stepCaptors.get(i).capture())); + + FinishTestItemRQ featureRq = featureCaptor.getValue(); + FinishTestItemRQ scenarioRq = scenarioCaptor.getValue(); + + assertThat(featureRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.FAILED.name()))); + assertThat(featureRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(featureRq.getEndTime(), notNullValue()); + + assertThat(scenarioRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.FAILED.name()))); + assertThat(scenarioRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(scenarioRq.getEndTime(), notNullValue()); + + List steps = stepCaptors.stream().map(ArgumentCaptor::getValue).collect(Collectors.toList()); + steps.forEach(step -> { + assertThat(step.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(step.getEndTime(), notNullValue()); + }); + List statuses = steps.stream().map(FinishExecutionRQ::getStatus).collect(Collectors.toList()); + assertThat(statuses, containsInAnyOrder("PASSED", "PASSED", "FAILED")); + } +} diff --git a/src/test/resources/feature/simple_failed.feature b/src/test/resources/feature/simple_failed.feature new file mode 100644 index 0000000..c72116d --- /dev/null +++ b/src/test/resources/feature/simple_failed.feature @@ -0,0 +1,6 @@ +Feature: the very basic test to run by Karate + + Scenario: Verify math + Given def four = 4 + When def actualFour = 2 * 2 + Then assert actualFour != four From 7703c4909bd1e4db1ae50eb46435c6c5d4f53dfe Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 27 Dec 2023 13:03:13 +0300 Subject: [PATCH 46/76] Fix test --- .../karate/name/SimpleItemNameTest.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java b/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java index a12ee62..982fcea 100644 --- a/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java +++ b/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java @@ -11,7 +11,6 @@ import java.util.List; import java.util.stream.Collectors; -import java.util.stream.IntStream; import java.util.stream.Stream; import static com.epam.reportportal.karate.utils.TestUtils.*; @@ -26,6 +25,9 @@ public class SimpleItemNameTest { private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) .limit(3).collect(Collectors.toList()); + private static final String[] STEP_NAMES = new String[]{"Given def four = 4", "When def actualFour = 2 * 2", + "Then assert actualFour == four"}; + private final ReportPortalClient client = mock(ReportPortalClient.class); private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); @@ -36,7 +38,7 @@ public void setupMock() { } @Test - public void test_scenario_code_reference() { + public void test_item_names_simple() { var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); assertThat(results.getFailCount(), equalTo(0)); @@ -54,12 +56,8 @@ public void test_scenario_code_reference() { assertThat(scenarioRq.getName(), allOf(notNullValue(), equalTo("Verify math"))); - List stepRqs = stepCaptor.getAllValues(); - String[] stepNames = new String[]{"Given def four = 4", "When def actualFour = 2 * 2", - "Then assert actualFour == four"}; - IntStream.range(0, stepRqs.size()).forEach(i -> { - StartTestItemRQ step = stepRqs.get(i); - assertThat(step.getName(), allOf(notNullValue(), equalTo(stepNames[i]))); - }); + List stepNames = stepCaptor.getAllValues().stream().map(StartTestItemRQ::getName) + .collect(Collectors.toList()); + assertThat(stepNames, containsInAnyOrder(STEP_NAMES)); } } From b1622e9de555c514510624c5d28e978f1f13455c Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 27 Dec 2023 14:02:38 +0300 Subject: [PATCH 47/76] Update step logging --- .../karate/ReportPortalPublisher.java | 56 ++++++------------- 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index c12dcc7..e3d0835 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -61,6 +61,7 @@ public class ReportPortalPublisher { public static final String VARIABLE_PATTERN = "(?:(?<=#\\()%1$s(?=\\)))|(?:(?<=[\\s=+-/*<>(]|^)%1$s(?=[\\s=+-/*<>)]|(?:\\r?\\n)|$))"; public static final String MARKDOWN_DELIMITER_PATTERN = "%s\n\n---\n\n%s"; + public static final String MARKDOWN_CODE_PATTERN = "```\n%s\n```"; public static final String PARAMETERS_PATTERN = "Parameters:\n\n%s"; private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalPublisher.class); @@ -457,43 +458,33 @@ public void finishStep(StepResult stepResult) { launch.get().finishTestItem(stepId, rq); } - /** * Send step execution results to ReportPortal * * @param stepResult step execution results */ public void sendStepResults(StepResult stepResult) { - Result result = stepResult.getResult(); - LogLevel logLevel = getLogLevel(result.getStatus()); Step step = stepResult.getStep(); - - if (step.getDocString() != null) { - sendLog("\n-----------------DOC_STRING-----------------\n" + step.getDocString(), logLevel); + String docString = step.getDocString(); + if (isNotBlank(docString)) { + sendLog(stepId, "Docstring: \n\n" + String.format(MARKDOWN_CODE_PATTERN, step.getDocString()), + LogLevel.INFO); } - if (stepResult.getStepLog() != null - && !stepResult.getStepLog().isEmpty() - && !stepResult.getStepLog().equals(" ")) { - sendLog(stepResult.getStepLog(), logLevel); + Result result = stepResult.getResult(); + String stepLog = stepResult.getStepLog(); + if (isNotBlank(stepLog)) { + sendLog(stepId, stepLog, LogLevel.INFO); } - } + if (result.isFailed()) { + String fullErrorMessage = step.getPrefix() + " " + step.getText(); + String errorMessage = result.getErrorMessage(); + if (isNotBlank(errorMessage)) { + fullErrorMessage = fullErrorMessage + "\n" + errorMessage; - /** - * Send step logs and/or execution results to ReportPortal - * - * @param message log message to send - * @param level log level - */ - public void sendLog(final String message, LogLevel level) { - ReportPortal.emitLog(itemId -> { - SaveLogRQ rq = new SaveLogRQ(); - rq.setMessage(message); - rq.setItemUuid(itemId); - rq.setLevel(level.name()); - rq.setLogTime(Calendar.getInstance().getTime()); - return rq; - }); + } + sendLog(stepId, fullErrorMessage, LogLevel.ERROR); + } } /** @@ -534,19 +525,6 @@ private ItemStatus getStepStatus(String status) { } } - private LogLevel getLogLevel(String status) { - switch (status) { - case "failed": - return LogLevel.ERROR; - case "stopped": - case "interrupted": - case "cancelled": - return LogLevel.WARN; - default: - return LogLevel.INFO; - } - } - /** * Get step start time to keep the steps order * in case previous step startTime == current step startTime or previous step startTime > current step startTime. From 5cdc3364eb0795723d1410f0ee606fe48efc2ac9 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 27 Dec 2023 16:12:20 +0300 Subject: [PATCH 48/76] Add test --- .../logging/SimpleFailureLoggingTest.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java diff --git a/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java b/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java new file mode 100644 index 0000000..bcc3337 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java @@ -0,0 +1,78 @@ +/* + * Copyright 2023 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 + * + * 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, + * 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. + */ + +package com.epam.reportportal.karate.logging; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.listeners.LogLevel; +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.log.SaveLogRQ; +import okhttp3.MultipartBody; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.Mockito.*; + +public class SimpleFailureLoggingTest { + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + @SuppressWarnings({"unchecked", "rawtypes"}) + public void test_simple_one_step_failed_error_log() { + var results = TestUtils.runAsReport(rp, "classpath:feature/simple_failed.feature"); + assertThat(results.getFailCount(), equalTo(1)); + + ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); + verify(client, atLeastOnce()).log(logCaptor.capture()); + List logs = logCaptor + .getAllValues(). + stream() + .flatMap(rq -> extractJsonParts((List) rq).stream()) + .filter(rq -> LogLevel.ERROR.name().equals(rq.getLevel())) + .collect(Collectors.toList()); + + assertThat(logs, hasSize(1)); + SaveLogRQ log = logs.get(0); + assertThat(log.getItemUuid(), oneOf(stepIds.toArray(new String[0]))); + assertThat(log.getLaunchUuid(), equalTo(launchUuid)); + assertThat(log.getMessage(), equalTo("Then assert actualFour != four\n" + + "did not evaluate to 'true': actualFour != four\n" + + "classpath:feature/simple_failed.feature:6")); + } +} From 838e9f3024b750d8f1424d7c930bd117ec1fa9ae Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 27 Dec 2023 17:33:39 +0300 Subject: [PATCH 49/76] Add another test --- .../karate/ReportPortalPublisher.java | 2 +- .../logging/HttpRequestLoggingTest.java | 80 +++++++++++++++++++ .../resources/feature/http_request.feature | 16 ++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java create mode 100644 src/test/resources/feature/http_request.feature diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index e3d0835..e0fddae 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -467,7 +467,7 @@ public void sendStepResults(StepResult stepResult) { Step step = stepResult.getStep(); String docString = step.getDocString(); if (isNotBlank(docString)) { - sendLog(stepId, "Docstring: \n\n" + String.format(MARKDOWN_CODE_PATTERN, step.getDocString()), + sendLog(stepId, "Docstring:\n\n" + String.format(MARKDOWN_CODE_PATTERN, step.getDocString()), LogLevel.INFO); } diff --git a/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java b/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java new file mode 100644 index 0000000..17a88f9 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java @@ -0,0 +1,80 @@ +/* + * Copyright 2023 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 + * + * 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, + * 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. + */ + +package com.epam.reportportal.karate.logging; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.listeners.LogLevel; +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.log.SaveLogRQ; +import okhttp3.MultipartBody; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.Mockito.*; + +public class HttpRequestLoggingTest { + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(6).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + @SuppressWarnings({"unchecked", "rawtypes"}) + public void test_http_request_logging() { + var results = TestUtils.runAsReport(rp, "classpath:feature/http_request.feature"); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); + verify(client, atLeastOnce()).log(logCaptor.capture()); + List logs = logCaptor + .getAllValues(). + stream() + .flatMap(rq -> extractJsonParts((List) rq).stream()) + .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel())) + .collect(Collectors.toList()); + + assertThat(logs, hasSize(2)); + List messages = logs.stream().map(SaveLogRQ::getMessage).collect(Collectors.toList()); + assertThat(messages, containsInAnyOrder( + equalTo("Docstring:\n\n```\n{\n" + + " username: 'user',\n" + + " password: 'password',\n" + + " grant_type: 'password'\n" + + "}\n```"), + containsString("{\"username\":\"user\",\"password\":\"password\",\"grant_type\":\"password\"}"))); + } +} diff --git a/src/test/resources/feature/http_request.feature b/src/test/resources/feature/http_request.feature new file mode 100644 index 0000000..b958f45 --- /dev/null +++ b/src/test/resources/feature/http_request.feature @@ -0,0 +1,16 @@ +Feature: verify basic HTTP request + + Scenario: Verify HTTP request + Given url 'https://example.com' + And header Content-Type = 'application/json' + And path 'api/test' + And request + """ + { + username: 'user', + password: 'password', + grant_type: 'password' + } + """ + When method post + Then status 404 From 1d106029eb190683fe357ac7fa8bdf9828f98e17 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 27 Dec 2023 18:01:41 +0300 Subject: [PATCH 50/76] Add ReportPortal runtime hook publisher --- .../reportportal/karate/ReportPortalHook.java | 87 +++++++++++++++++++ .../reportportal/karate/utils/TestUtils.java | 10 +++ 2 files changed, 97 insertions(+) create mode 100644 src/main/java/com/epam/reportportal/karate/ReportPortalHook.java diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java new file mode 100644 index 0000000..4efd140 --- /dev/null +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java @@ -0,0 +1,87 @@ +/* + * Copyright 2023 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 + * + * 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, + * 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. + */ + +package com.epam.reportportal.karate; + +import com.epam.reportportal.service.ReportPortal; +import com.intuit.karate.RuntimeHook; +import com.intuit.karate.Suite; +import com.intuit.karate.core.FeatureRuntime; +import com.intuit.karate.core.ScenarioRuntime; +import com.intuit.karate.core.Step; +import com.intuit.karate.core.StepResult; +import com.intuit.karate.http.HttpRequest; +import com.intuit.karate.http.Response; + +public class ReportPortalHook implements RuntimeHook { + public ReportPortalHook(ReportPortal reportPortal) { + + } + + public ReportPortalHook() { + this(ReportPortal.builder().build()); + } + + @Override + public boolean beforeScenario(ScenarioRuntime sr) { + return RuntimeHook.super.beforeScenario(sr); + } + + @Override + public void afterScenario(ScenarioRuntime sr) { + RuntimeHook.super.afterScenario(sr); + } + + @Override + public boolean beforeFeature(FeatureRuntime fr) { + return RuntimeHook.super.beforeFeature(fr); + } + + @Override + public void afterFeature(FeatureRuntime fr) { + RuntimeHook.super.afterFeature(fr); + } + + @Override + public void beforeSuite(Suite suite) { + RuntimeHook.super.beforeSuite(suite); + } + + @Override + public void afterSuite(Suite suite) { + RuntimeHook.super.afterSuite(suite); + } + + @Override + public boolean beforeStep(Step step, ScenarioRuntime sr) { + return RuntimeHook.super.beforeStep(step, sr); + } + + @Override + public void afterStep(StepResult result, ScenarioRuntime sr) { + RuntimeHook.super.afterStep(result, sr); + } + + @Override + public void beforeHttpCall(HttpRequest request, ScenarioRuntime sr) { + RuntimeHook.super.beforeHttpCall(request, sr); + } + + @Override + public void afterHttpCall(HttpRequest request, Response response, ScenarioRuntime sr) { + RuntimeHook.super.afterHttpCall(request, response, sr); + } +} diff --git a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java index cbb07c4..fced60f 100644 --- a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java +++ b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java @@ -1,6 +1,7 @@ package com.epam.reportportal.karate.utils; import com.epam.reportportal.karate.KarateReportPortalRunner; +import com.epam.reportportal.karate.ReportPortalHook; import com.epam.reportportal.listeners.ListenerParameters; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.ReportPortalClient; @@ -14,6 +15,7 @@ import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; import com.fasterxml.jackson.core.type.TypeReference; import com.intuit.karate.Results; +import com.intuit.karate.Runner; import io.reactivex.Maybe; import okhttp3.MultipartBody; import okio.Buffer; @@ -55,6 +57,14 @@ public static Results runAsReport(ReportPortal reportPortal, String... paths) { .parallel(1); } + public static Results runAsHook(ReportPortal reportPortal, String... paths) { + return Runner + .path(paths) + .hook(new ReportPortalHook(reportPortal)) + .outputCucumberJson(false) + .parallel(1); + } + public static ListenerParameters standardParameters() { ListenerParameters result = new ListenerParameters(); result.setClientJoin(false); From a846ae87ae4a32a5442ce8b4023598d07255db8b Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 2 Jan 2024 20:27:06 +0300 Subject: [PATCH 51/76] Refactoring, move common code to util class --- .../karate/ReportPortalPublisher.java | 418 +++++++----------- .../karate/ReportPortalUtils.java | 345 ++++++++++++++- .../description/DescriptionExamplesTest.java | 6 +- 3 files changed, 495 insertions(+), 274 deletions(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index e0fddae..709df32 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -17,22 +17,14 @@ package com.epam.reportportal.karate; import com.epam.reportportal.listeners.ItemStatus; -import com.epam.reportportal.listeners.ItemType; import com.epam.reportportal.listeners.ListenerParameters; import com.epam.reportportal.listeners.LogLevel; import com.epam.reportportal.service.Launch; import com.epam.reportportal.service.ReportPortal; -import com.epam.reportportal.service.item.TestCaseIdEntry; -import com.epam.reportportal.utils.AttributeParser; import com.epam.reportportal.utils.MemoizingSupplier; -import com.epam.reportportal.utils.ParameterUtils; -import com.epam.reportportal.utils.TestCaseIdUtils; -import com.epam.reportportal.utils.properties.SystemAttributesExtractor; import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; -import com.epam.ta.reportportal.ws.model.ParameterResource; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; -import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; import com.intuit.karate.core.*; @@ -44,25 +36,15 @@ import javax.annotation.Nullable; import java.util.*; import java.util.function.Supplier; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import static com.epam.reportportal.karate.ReportPortalUtils.AGENT_PROPERTIES_FILE; -import static com.epam.reportportal.utils.ParameterUtils.NULL_VALUE; +import static com.epam.reportportal.karate.ReportPortalUtils.*; import static com.epam.reportportal.utils.ParameterUtils.formatParametersAsTable; import static com.epam.reportportal.utils.markdown.MarkdownUtils.formatDataTable; import static java.util.Optional.ofNullable; import static org.apache.commons.lang3.StringUtils.isNotBlank; public class ReportPortalPublisher { - public static final String SCENARIO_CODE_REFERENCE_PATTERN = "%s/[SCENARIO:%s]"; - public static final String EXAMPLE_CODE_REFERENCE_PATTERN = "%s/[EXAMPLE:%s%s]"; - public static final String VARIABLE_PATTERN = - "(?:(?<=#\\()%1$s(?=\\)))|(?:(?<=[\\s=+-/*<>(]|^)%1$s(?=[\\s=+-/*<>)]|(?:\\r?\\n)|$))"; - public static final String MARKDOWN_DELIMITER_PATTERN = "%s\n\n---\n\n%s"; public static final String MARKDOWN_CODE_PATTERN = "```\n%s\n```"; - public static final String PARAMETERS_PATTERN = "Parameters:\n\n%s"; private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalPublisher.class); private final Map> featureIdMap = new HashMap<>(); @@ -71,18 +53,10 @@ public class ReportPortalPublisher { private Maybe backgroundId; private Maybe stepId; - private final MemoizingSupplier launch; + protected final MemoizingSupplier launch; private Thread shutDownHook; - private static Thread getShutdownHook(final Supplier launch) { - return new Thread(() -> { - FinishExecutionRQ rq = new FinishExecutionRQ(); - rq.setEndTime(Calendar.getInstance().getTime()); - launch.get().finish(rq); - }); - } - /** * Customize start launch event/request * @@ -90,28 +64,7 @@ private static Thread getShutdownHook(final Supplier launch) { * @return request to ReportPortal */ protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) { - StartLaunchRQ rq = new StartLaunchRQ(); - rq.setName(parameters.getLaunchName()); - rq.setStartTime(Calendar.getInstance().getTime()); - rq.setMode(parameters.getLaunchRunningMode()); - rq.setAttributes(new HashSet<>(parameters.getAttributes())); - if (isNotBlank(parameters.getDescription())) { - rq.setDescription(parameters.getDescription()); - } - rq.setRerun(parameters.isRerun()); - if (isNotBlank(parameters.getRerunOf())) { - rq.setRerunOf(parameters.getRerunOf()); - } - if (null != parameters.getSkippedAnIssue()) { - ItemAttributesRQ skippedIssueAttribute = new ItemAttributesRQ(); - skippedIssueAttribute.setKey(ReportPortalUtils.SKIPPED_ISSUE_KEY); - skippedIssueAttribute.setValue(parameters.getSkippedAnIssue().toString()); - skippedIssueAttribute.setSystem(true); - rq.getAttributes().add(skippedIssueAttribute); - } - rq.getAttributes().addAll(SystemAttributesExtractor.extract(AGENT_PROPERTIES_FILE, - ReportPortalUtils.class.getClassLoader())); - return rq; + return ReportPortalUtils.buildStartLaunchRq(parameters); } public ReportPortalPublisher(ReportPortal reportPortal) { @@ -119,20 +72,18 @@ public ReportPortalPublisher(ReportPortal reportPortal) { ListenerParameters params = reportPortal.getParameters(); StartLaunchRQ rq = buildStartLaunchRq(params); Launch newLaunch = reportPortal.newLaunch(rq); - shutDownHook = getShutdownHook(() -> newLaunch); - Runtime.getRuntime().addShutdownHook(shutDownHook); + shutDownHook = registerShutdownHook(() -> newLaunch); return newLaunch; }); } public ReportPortalPublisher(Supplier launchSupplier) { launch = new MemoizingSupplier<>(launchSupplier); - shutDownHook = getShutdownHook(launch); - Runtime.getRuntime().addShutdownHook(shutDownHook); + shutDownHook = registerShutdownHook(launch); } /** - * Starts launch instance + * Start sending Launch data to ReportPortal. */ public void startLaunch() { //noinspection ReactiveStreamsUnusedPublisher @@ -140,73 +91,27 @@ public void startLaunch() { } /** - * Finish launch - */ - public void finishLaunch() { - FinishExecutionRQ rq = new FinishExecutionRQ(); - rq.setEndTime(Calendar.getInstance().getTime()); - ListenerParameters parameters = launch.get().getParameters(); - LOGGER.info("Launch URL: {}/ui/#{}/launches/all/{}", parameters.getBaseUrl(), parameters.getProjectName(), - System.getProperty("rp.launch.id")); - launch.get().finish(rq); - Runtime.getRuntime().removeShutdownHook(shutDownHook); - } - - /** - * Returns code reference for feature files by URI and Scenario reference + * Customize start Launch finish event/request. * - * @param scenario Karate's Scenario object instance - * @return a code reference + * @param parameters Launch configuration parameters + * @return request to ReportPortal */ @Nonnull - protected String getCodeRef(@Nonnull Scenario scenario) { - if (scenario.isOutlineExample()) { - return String.format(EXAMPLE_CODE_REFERENCE_PATTERN, scenario.getFeature().getResource().getRelativePath(), - scenario.getName(), ReportPortalUtils.formatExampleKey(scenario.getExampleData())); - } else { - return String.format(SCENARIO_CODE_REFERENCE_PATTERN, scenario.getFeature().getResource().getRelativePath(), - scenario.getName()); - } + protected FinishExecutionRQ buildFinishLaunchRq(@Nonnull ListenerParameters parameters) { + return ReportPortalUtils.buildFinishLaunchRq(parameters); } /** - * Return a Test Case ID for a Scenario in a Feature file - * - * @param scenario Karate's Scenario object instance - * @return Test Case ID entity or null if it's not possible to calculate + * Finish sending Launch data to ReportPortal. */ - @Nullable - protected TestCaseIdEntry getTestCaseId(@Nonnull Scenario scenario) { - return TestCaseIdUtils.getTestCaseId(getCodeRef(scenario), null); - } - - /** - * Customize start test item event/request - * - * @param name item's name - * @param startTime item's start time in Date format - * @param type item's type (e.g. feature, scenario, step, etc.) - * @return request to ReportPortal - */ - @Nonnull - protected StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Date startTime, - @Nonnull ItemType type) { - StartTestItemRQ rq = new StartTestItemRQ(); - rq.setName(name); - rq.setStartTime(startTime); - rq.setType(type.name()); - return rq; - } - - @Nullable - private Set toAttributes(@Nullable List tags) { - Set attributes = ofNullable(tags).orElse(Collections.emptyList()).stream().flatMap(tag -> { - if (tag.getValues().isEmpty()) { - return Stream.of(new ItemAttributesRQ(null, tag.getName())); - } - return AttributeParser.createItemAttributes(tag.getName(), tag.getValues().toArray(new String[0])).stream(); - }).collect(Collectors.toSet()); - return attributes.isEmpty() ? null : attributes; + public void finishLaunch() { + Launch launchObject = launch.get(); + ListenerParameters parameters = launchObject.getParameters(); + FinishExecutionRQ rq = buildFinishLaunchRq(parameters); + LOGGER.info("Launch URL: {}/ui/#{}/launches/all/{}", parameters.getBaseUrl(), parameters.getProjectName(), + System.getProperty("rp.launch.id")); + launchObject.finish(rq); + unregisterShutdownHook(shutDownHook); } /** @@ -217,21 +122,11 @@ private Set toAttributes(@Nullable List tags) { */ @Nonnull protected StartTestItemRQ buildStartFeatureRq(@Nonnull FeatureResult featureResult) { - Feature feature = featureResult.getFeature(); - StartTestItemRQ rq = buildStartTestItemRq(feature.getName(), Calendar.getInstance().getTime(), ItemType.STORY); - rq.setAttributes(toAttributes(feature.getTags())); - String featurePath = feature.getResource().getUri().toString(); - String description = feature.getDescription(); - if (isNotBlank(description)) { - rq.setDescription(String.format(MARKDOWN_DELIMITER_PATTERN, featurePath, description)); - } else { - rq.setDescription(featurePath); - } - return rq; + return ReportPortalUtils.buildStartFeatureRq(featureResult.getFeature()); } /** - * Start sending feature data to ReportPortal. + * Start sending Feature data to ReportPortal. * * @param featureResult feature result */ @@ -242,22 +137,19 @@ public void startFeature(@Nonnull FeatureResult featureResult) { } /** - * Customize start test item event/request + * Build ReportPortal request for finish Feature event. * - * @param endTime item's end time - * @param status item's status + * @param featureResult Karate's FeatureResult object instance * @return request to ReportPortal */ - protected FinishTestItemRQ buildFinishTestItemRq(@Nonnull Date endTime, - @Nonnull ItemStatus status) { - FinishTestItemRQ rq = new FinishTestItemRQ(); - rq.setEndTime(endTime); - rq.setStatus(status.name()); - return rq; + @Nonnull + protected FinishTestItemRQ buildFinishFeatureRq(@Nonnull FeatureResult featureResult) { + return buildFinishTestItemRq(Calendar.getInstance().getTime(), + featureResult.isFailed() ? ItemStatus.FAILED : ItemStatus.PASSED); } /** - * Finish sending feature data to ReportPortal + * Finish sending Feature data to ReportPortal. * * @param featureResult feature result */ @@ -273,70 +165,31 @@ public void finishFeature(FeatureResult featureResult) { for (StepResult stepResult : stepResults) { startStep(stepResult, scenarioResult); sendStepResults(stepResult); - finishStep(stepResult); + finishStep(stepResult, scenarioResult); } stepStartTimeMap.clear(); finishScenario(scenarioResult); } - FinishTestItemRQ rq = buildFinishTestItemRq(Calendar.getInstance().getTime(), - featureResult.isFailed() ? ItemStatus.FAILED : ItemStatus.PASSED); + FinishTestItemRQ rq = buildFinishFeatureRq(featureResult); //noinspection ReactiveStreamsUnusedPublisher launch.get().finishTestItem(featureIdMap.remove(featureResult.getCallNameForReport()), rq); } - @Nullable - private List getParameters(@Nonnull Scenario scenario) { - if (scenario.getExampleIndex() < 0) { - return null; - } - return scenario.getExampleData().entrySet().stream().map(e -> { - ParameterResource parameterResource = new ParameterResource(); - parameterResource.setKey(e.getKey()); - parameterResource.setValue(ofNullable(e.getValue()).map(Object::toString).orElse(NULL_VALUE)); - return parameterResource; - }).collect(Collectors.toList()); - } - /** - * Build ReportPortal request for start Scenario event + * Build ReportPortal request for start Scenario event. * * @param scenarioResult Karate's ScenarioResult object instance * @return request to ReportPortal */ + @Nonnull protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioResult scenarioResult) { - StartTestItemRQ rq = buildStartTestItemRq(scenarioResult.getScenario().getName(), - Calendar.getInstance().getTime(), - ItemType.STEP); - Scenario scenario = scenarioResult.getScenario(); - rq.setCodeRef(getCodeRef(scenario)); - rq.setTestCaseId(ofNullable(getTestCaseId(scenario)).map(TestCaseIdEntry::getId).orElse(null)); - rq.setAttributes(toAttributes(scenario.getTags())); - List parameters = getParameters(scenario); - boolean hasParameters = ofNullable(parameters).filter(p -> !p.isEmpty()).isPresent(); - if (hasParameters) { - rq.setParameters(parameters); - } - - String description = scenario.getDescription(); - if (isNotBlank(description)) { - if (hasParameters) { - rq.setDescription( - String.format(MARKDOWN_DELIMITER_PATTERN, - String.format(PARAMETERS_PATTERN, ParameterUtils.formatParametersAsTable(parameters)), - description)); - } else { - rq.setDescription(description); - } - } else if (hasParameters) { - rq.setDescription(String.format(PARAMETERS_PATTERN, ParameterUtils.formatParametersAsTable(parameters))); - } - return rq; + return ReportPortalUtils.buildStartScenarioRq(scenarioResult.getScenario()); } /** - * Start sending scenario data to ReportPortal + * Start sending Scenario data to ReportPortal. * * @param scenarioResult scenario result * @param featureResult feature result @@ -349,7 +202,20 @@ public void startScenario(ScenarioResult scenarioResult, FeatureResult featureRe } /** - * Finish sending scenario data to ReportPortal + * Build ReportPortal request for finish Scenario event. + * + * @param scenarioResult Karate's ScenarioResult object instance + * @return request to ReportPortal + */ + @Nonnull + protected FinishTestItemRQ buildFinishScenarioRq(@Nonnull ScenarioResult scenarioResult) { + return buildFinishTestItemRq(Calendar.getInstance().getTime(), + scenarioResult.getFailureMessageForDisplay() == null ? ItemStatus.PASSED : ItemStatus.FAILED); + + } + + /** + * Finish sending Scenario data to ReportPortal. * * @param scenarioResult scenario result */ @@ -358,24 +224,90 @@ public void finishScenario(ScenarioResult scenarioResult) { LOGGER.error("ERROR: Trying to finish unspecified scenario."); } - FinishTestItemRQ rq = buildFinishTestItemRq(Calendar.getInstance().getTime(), - scenarioResult.getFailureMessageForDisplay() == null ? ItemStatus.PASSED : ItemStatus.FAILED); + FinishTestItemRQ rq = buildFinishScenarioRq(scenarioResult); Maybe removedScenarioId = scenarioIdMap.remove(scenarioResult.getScenario().getName()); //noinspection ReactiveStreamsUnusedPublisher launch.get().finishTestItem(removedScenarioId, rq); - backgroundId = null; + finishBackground(null, scenarioResult); } + /** + * Build ReportPortal request for start Background event. + * + * @param stepResult Karate's StepResult object instance + * @param scenarioResult Karate's ScenarioResult object instance + * @return request to ReportPortal + */ @Nonnull @SuppressWarnings("unused") protected StartTestItemRQ buildStartBackgroundRq(@Nonnull StepResult stepResult, @Nonnull ScenarioResult scenarioResult) { - StartTestItemRQ rq = buildStartTestItemRq(Background.KEYWORD, Calendar.getInstance().getTime(), ItemType.STEP); - rq.setHasStats(false); - return rq; + return ReportPortalUtils.buildStartBackgroundRq(stepResult.getStep(), scenarioResult.getScenario()); } /** - * Customize start step test item event/request + * Start sending Background data to ReportPortal. + * + * @param stepResult step result + * @param scenarioResult scenario result + */ + public void startBackground(@Nonnull StepResult stepResult, @Nonnull ScenarioResult scenarioResult) { + backgroundId = ofNullable(backgroundId).orElseGet(() -> { + StartTestItemRQ backgroundRq = buildStartBackgroundRq(stepResult, scenarioResult); + return launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), + backgroundRq); + }); + } + + /** + * Build ReportPortal request for finish Background event. + * + * @param scenarioResult Karate's ScenarioResult object instance + * @return request to ReportPortal + */ + @Nonnull + @SuppressWarnings("unused") + protected FinishTestItemRQ buildFinishBackgroundRq(@Nullable StepResult stepResult, @Nonnull ScenarioResult scenarioResult) { + return buildFinishTestItemRq(Calendar.getInstance().getTime(), null); + + } + + /** + * Finish sending Scenario data to ReportPortal. + * + * @param stepResult step result + * @param scenarioResult scenario result + */ + public void finishBackground(@Nullable StepResult stepResult, @Nonnull ScenarioResult scenarioResult) { + ofNullable(backgroundId).ifPresent(id -> { + FinishTestItemRQ finishRq = buildFinishBackgroundRq(stepResult, scenarioResult); + //noinspection ReactiveStreamsUnusedPublisher + launch.get().finishTestItem(id, finishRq); + }); + backgroundId = null; + } + + /** + * Get step start time. To keep the steps order in case previous step startTime == current step startTime or + * previous step startTime > current step startTime. + * + * @param stepId step ID. + * @return step new startTime in Date format. + */ + private Date getStepStartTime(@Nonnull Maybe stepId) { + long currentStepStartTime = Calendar.getInstance().getTime().getTime(); + + if (!stepStartTimeMap.keySet().isEmpty()) { + long lastStepStartTime = stepStartTimeMap.get(stepId); + + if (lastStepStartTime >= currentStepStartTime) { + currentStepStartTime += (lastStepStartTime - currentStepStartTime) + 1; + } + } + return new Date(currentStepStartTime); + } + + /** + * Customize start Step test item event/request. * * @param stepResult Karate's StepResult class instance * @param scenarioResult Karate's ScenarioResult class instance @@ -383,46 +315,23 @@ protected StartTestItemRQ buildStartBackgroundRq(@Nonnull StepResult stepResult, */ @Nonnull protected StartTestItemRQ buildStartStepRq(@Nonnull StepResult stepResult, @Nonnull ScenarioResult scenarioResult) { - Step step = stepResult.getStep(); - String stepName = step.getPrefix() + " " + step.getText(); - StartTestItemRQ rq = buildStartTestItemRq(stepName, getStepStartTime(stepStartTimeMap, stepId), ItemType.STEP); - rq.setHasStats(false); - if (step.isOutline()) { - Scenario scenario = scenarioResult.getScenario(); - List parameters = scenario - .getExampleData() - .entrySet() - .stream() - .filter(e -> Pattern.compile(String.format(VARIABLE_PATTERN, e.getKey())) - .matcher(step.getText()).find()) - .map(e -> { - ParameterResource param = new ParameterResource(); - param.setKey(e.getKey()); - var value = ofNullable(e.getValue()).map(Object::toString).orElse(NULL_VALUE); - param.setValue(value); - return param; - }) - .collect(Collectors.toList()); - rq.setParameters(parameters); - } + StartTestItemRQ rq = ReportPortalUtils.buildStartStepRq(stepResult.getStep(), scenarioResult.getScenario()); + Date startTime = getStepStartTime(stepId); + rq.setStartTime(startTime); return rq; } /** - * Start sending step data to ReportPortal + * Start sending Step data to ReportPortal. * * @param stepResult step result * @param scenarioResult scenario result */ public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { if (stepResult.getStep().isBackground()) { - backgroundId = ofNullable(backgroundId).orElseGet(() -> { - StartTestItemRQ backgroundRq = buildStartBackgroundRq(stepResult, scenarioResult); - return launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), - backgroundRq); - }); + startBackground(stepResult, scenarioResult); } else { - backgroundId = null; + finishBackground(stepResult, scenarioResult); } StartTestItemRQ stepRq = buildStartStepRq(stepResult, scenarioResult); stepId = launch.get() @@ -442,24 +351,37 @@ public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { } /** - * Finish sending scenario data to ReportPortal + * Build ReportPortal request for finish Step event. + * + * @param stepResult Karate's StepResult class instance + * @param scenarioResult Karate's ScenarioResult class instance + * @return request to ReportPortal + */ + @Nonnull + @SuppressWarnings("unused") + protected FinishTestItemRQ buildFinishStepRq(@Nonnull StepResult stepResult, @Nonnull ScenarioResult scenarioResult) { + return buildFinishTestItemRq(Calendar.getInstance().getTime(), getStepStatus(stepResult.getResult().getStatus())); + } + + /** + * Finish sending Step data to ReportPortal. * - * @param stepResult step result + * @param stepResult Karate's StepResult class instance + * @param scenarioResult Karate's ScenarioResult class instance */ - public void finishStep(StepResult stepResult) { + public void finishStep(StepResult stepResult, ScenarioResult scenarioResult) { if (stepId == null) { LOGGER.error("ERROR: Trying to finish unspecified step."); return; } - FinishTestItemRQ rq = buildFinishTestItemRq(Calendar.getInstance().getTime(), - getStepStatus(stepResult.getResult().getStatus())); + FinishTestItemRQ rq = buildFinishStepRq(stepResult, scenarioResult); //noinspection ReactiveStreamsUnusedPublisher launch.get().finishTestItem(stepId, rq); } /** - * Send step execution results to ReportPortal + * Send Step execution results to ReportPortal. * * @param stepResult step execution results */ @@ -488,13 +410,13 @@ public void sendStepResults(StepResult stepResult) { } /** - * Send step logs and/or execution results to ReportPortal + * Send Step logs to ReportPortal. * * @param itemId item ID future * @param message log message to send * @param level log level */ - public void sendLog(Maybe itemId, String message, LogLevel level) { + protected void sendLog(Maybe itemId, String message, LogLevel level) { ReportPortal.emitLog(itemId, id -> { SaveLogRQ rq = new SaveLogRQ(); rq.setMessage(message); @@ -504,46 +426,4 @@ public void sendLog(Maybe itemId, String message, LogLevel level) { return rq; }); } - - private ItemStatus getStepStatus(String status) { - switch (status) { - case "failed": - return ItemStatus.FAILED; - case "passed": - return ItemStatus.PASSED; - case "skipped": - return ItemStatus.SKIPPED; - case "stopped": - return ItemStatus.STOPPED; - case "interrupted": - return ItemStatus.INTERRUPTED; - case "cancelled": - return ItemStatus.CANCELLED; - default: - LOGGER.warn("Unknown step status received! Set it as SKIPPED"); - return ItemStatus.SKIPPED; - } - } - - /** - * Get step start time to keep the steps order - * in case previous step startTime == current step startTime or previous step startTime > current step startTime. - * - * @param stepStartTimeMap ConcurrentHashMap of steps within a scenario. - * @param stepId step ID. - * @return step new startTime in Date format. - */ - private Date getStepStartTime(Map, Long> stepStartTimeMap, Maybe stepId) { - long currentStepStartTime = Calendar.getInstance().getTime().getTime(); - - if (!stepStartTimeMap.keySet().isEmpty()) { - long lastStepStartTime = stepStartTimeMap.get(stepId); - - if (lastStepStartTime >= currentStepStartTime) { - currentStepStartTime += (lastStepStartTime - currentStepStartTime) + 1; - } - } - - return new Date(currentStepStartTime); - } } diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java index 37c9b11..c488311 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java @@ -15,25 +15,61 @@ */ package com.epam.reportportal.karate; +import com.epam.reportportal.listeners.ItemStatus; +import com.epam.reportportal.listeners.ItemType; +import com.epam.reportportal.listeners.ListenerParameters; +import com.epam.reportportal.service.Launch; +import com.epam.reportportal.service.item.TestCaseIdEntry; +import com.epam.reportportal.utils.AttributeParser; +import com.epam.reportportal.utils.ParameterUtils; +import com.epam.reportportal.utils.TestCaseIdUtils; +import com.epam.reportportal.utils.properties.SystemAttributesExtractor; +import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; +import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; +import com.epam.ta.reportportal.ws.model.ParameterResource; +import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; +import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; +import com.intuit.karate.core.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import javax.annotation.Nonnull; -import java.util.Map; +import javax.annotation.Nullable; +import java.util.*; +import java.util.function.Supplier; +import java.util.regex.Pattern; import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.utils.ParameterUtils.NULL_VALUE; +import static java.util.Optional.ofNullable; +import static org.apache.commons.lang3.StringUtils.isNotBlank; /** * Set of useful utils related to Karate -> ReportPortal integration */ public class ReportPortalUtils { + private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalUtils.class); + public static final String PARAMETERS_PATTERN = "Parameters:\n\n%s"; private static final String PARAMETER_ITEMS_START = "["; private static final String PARAMETER_ITEMS_END = "]"; private static final String PARAMETER_ITEMS_DELIMITER = ";"; private static final String KEY_VALUE_SEPARATOR = ":"; + public static final String VARIABLE_PATTERN = + "(?:(?<=#\\()%1$s(?=\\)))|(?:(?<=[\\s=+-/*<>(]|^)%1$s(?=[\\s=+-/*<>)]|(?:\\r?\\n)|$))"; public static final String AGENT_PROPERTIES_FILE = "agent.properties"; public static final String SKIPPED_ISSUE_KEY = "skippedIssue"; + public static final String SCENARIO_CODE_REFERENCE_PATTERN = "%s/[SCENARIO:%s]"; + public static final String EXAMPLE_CODE_REFERENCE_PATTERN = "%s/[EXAMPLE:%s%s]"; + + public static final String MARKDOWN_DELIMITER_PATTERN = "%s\n\n---\n\n%s"; + private ReportPortalUtils() { - throw new AssertionError("No instances should exist for the class!"); + throw new RuntimeException("No instances should exist for the class!"); } /** @@ -49,4 +85,309 @@ public static String formatExampleKey(@Nonnull final Map example .map(e -> e.getKey() + KEY_VALUE_SEPARATOR + e.getValue().toString()) .collect(Collectors.joining(PARAMETER_ITEMS_DELIMITER, PARAMETER_ITEMS_START, PARAMETER_ITEMS_END)); } + + /** + * Create a launch finish hook which will be called on JVM shutdown. Prevents from long unfinished launches for + * interrupted tests. + * + * @param launch Launch object provider + * @return a Thread which executes Launch finish and exits + */ + @Nonnull + public static Thread createShutdownHook(@Nonnull Supplier launch) { + return new Thread(() -> { + FinishExecutionRQ rq = new FinishExecutionRQ(); + rq.setEndTime(Calendar.getInstance().getTime()); + launch.get().finish(rq); + }); + } + + /** + * Create and register a launch finish hook which will be called on JVM shutdown. Prevents from long unfinished + * launches for interrupted tests. + * + * @param launch Launch object provider + * @return a Thread which executes Launch finish and exits + */ + @Nonnull + public static Thread registerShutdownHook(@Nonnull Supplier launch) { + Thread shutDownHook = createShutdownHook(launch); + Runtime.getRuntime().addShutdownHook(shutDownHook); + return shutDownHook; + } + + /** + * Remove a launch finish hook. Use it if the launch finished gracefully. + * + * @param hook a Thread which represents Launch finish hook + */ + public static void unregisterShutdownHook(@Nonnull Thread hook) { + Runtime.getRuntime().removeShutdownHook(hook); + } + + /** + * Build default start launch event/request + * + * @param parameters Launch configuration parameters + * @return request to ReportPortal + */ + @Nonnull + public static StartLaunchRQ buildStartLaunchRq(@Nonnull ListenerParameters parameters) { + StartLaunchRQ rq = new StartLaunchRQ(); + rq.setName(parameters.getLaunchName()); + rq.setStartTime(Calendar.getInstance().getTime()); + rq.setMode(parameters.getLaunchRunningMode()); + rq.setAttributes(new HashSet<>(parameters.getAttributes())); + if (isNotBlank(parameters.getDescription())) { + rq.setDescription(parameters.getDescription()); + } + rq.setRerun(parameters.isRerun()); + if (isNotBlank(parameters.getRerunOf())) { + rq.setRerunOf(parameters.getRerunOf()); + } + if (null != parameters.getSkippedAnIssue()) { + ItemAttributesRQ skippedIssueAttribute = new ItemAttributesRQ(); + skippedIssueAttribute.setKey(ReportPortalUtils.SKIPPED_ISSUE_KEY); + skippedIssueAttribute.setValue(parameters.getSkippedAnIssue().toString()); + skippedIssueAttribute.setSystem(true); + rq.getAttributes().add(skippedIssueAttribute); + } + rq.getAttributes().addAll(SystemAttributesExtractor.extract(AGENT_PROPERTIES_FILE, + ReportPortalUtils.class.getClassLoader())); + return rq; + } + + /** + * Build default finish launch event/request + * + * @param parameters Launch configuration parameters + * @return request to ReportPortal + */ + @Nonnull + @SuppressWarnings("unused") + public static FinishExecutionRQ buildFinishLaunchRq(@Nonnull ListenerParameters parameters) { + FinishExecutionRQ rq = new FinishExecutionRQ(); + rq.setEndTime(Calendar.getInstance().getTime()); + return rq; + } + + /** + * Returns code reference for feature files by URI and Scenario reference + * + * @param scenario Karate's Scenario object instance + * @return a code reference + */ + @Nonnull + public static String getCodeRef(@Nonnull Scenario scenario) { + if (scenario.isOutlineExample()) { + return String.format(EXAMPLE_CODE_REFERENCE_PATTERN, scenario.getFeature().getResource().getRelativePath(), + scenario.getName(), ReportPortalUtils.formatExampleKey(scenario.getExampleData())); + } else { + return String.format(SCENARIO_CODE_REFERENCE_PATTERN, scenario.getFeature().getResource().getRelativePath(), + scenario.getName()); + } + } + + /** + * Build default start test item event/request + * + * @param name item's name + * @param startTime item's start time in Date format + * @param type item's type (e.g. feature, scenario, step, etc.) + * @return request to ReportPortal + */ + @Nonnull + public static StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Date startTime, + @Nonnull ItemType type) { + StartTestItemRQ rq = new StartTestItemRQ(); + rq.setName(name); + rq.setStartTime(startTime); + rq.setType(type.name()); + return rq; + } + + /** + * Build default finish test item event/request + * + * @param endTime item's end time + * @param status item's status + * @return request to ReportPortal + */ + @Nonnull + public static FinishTestItemRQ buildFinishTestItemRq(@Nonnull Date endTime, @Nullable ItemStatus status) { + FinishTestItemRQ rq = new FinishTestItemRQ(); + rq.setEndTime(endTime); + rq.setStatus(ofNullable(status).map(Enum::name).orElse(null)); + return rq; + } + + @Nullable + public static Set toAttributes(@Nullable List tags) { + Set attributes = ofNullable(tags).orElse(Collections.emptyList()).stream().flatMap(tag -> { + if (tag.getValues().isEmpty()) { + return Stream.of(new ItemAttributesRQ(null, tag.getName())); + } + return AttributeParser.createItemAttributes(tag.getName(), tag.getValues().toArray(new String[0])).stream(); + }).collect(Collectors.toSet()); + return attributes.isEmpty() ? null : attributes; + } + + /** + * Build ReportPortal request for start Feature event. + * + * @param feature Karate's Feature object instance + * @return request to ReportPortal + */ + @Nonnull + public static StartTestItemRQ buildStartFeatureRq(@Nonnull Feature feature) { + StartTestItemRQ rq = buildStartTestItemRq(feature.getName(), Calendar.getInstance().getTime(), ItemType.STORY); + rq.setAttributes(toAttributes(feature.getTags())); + String featurePath = feature.getResource().getUri().toString(); + String description = feature.getDescription(); + if (isNotBlank(description)) { + rq.setDescription(String.format(MARKDOWN_DELIMITER_PATTERN, featurePath, description)); + } else { + rq.setDescription(featurePath); + } + return rq; + } + + /** + * Extract and transform ScenarioOutline parameters to ReportPortal parameter list. + * + * @param scenario Karate's Scenario object instance + * @return parameters + */ + @Nullable + public static List getParameters(@Nonnull Scenario scenario) { + if (scenario.isOutlineExample()) { + return null; + } + return scenario.getExampleData().entrySet().stream().map(e -> { + ParameterResource parameterResource = new ParameterResource(); + parameterResource.setKey(e.getKey()); + parameterResource.setValue(ofNullable(e.getValue()).map(Object::toString).orElse(NULL_VALUE)); + return parameterResource; + }).collect(Collectors.toList()); + } + + /** + * Return a Test Case ID for a Scenario in a Feature file + * + * @param scenario Karate's Scenario object instance + * @return Test Case ID entity or null if it's not possible to calculate + */ + @Nullable + public static TestCaseIdEntry getTestCaseId(@Nonnull Scenario scenario) { + return TestCaseIdUtils.getTestCaseId(getCodeRef(scenario), null); + } + + /** + * Build ReportPortal request for start Scenario event + * + * @param scenario Karate's Scenario object instance + * @return request to ReportPortal + */ + @Nonnull + public static StartTestItemRQ buildStartScenarioRq(@Nonnull Scenario scenario) { + StartTestItemRQ rq = buildStartTestItemRq(scenario.getName(), + Calendar.getInstance().getTime(), + ItemType.STEP); + rq.setCodeRef(getCodeRef(scenario)); + rq.setTestCaseId(ofNullable(getTestCaseId(scenario)).map(TestCaseIdEntry::getId).orElse(null)); + rq.setAttributes(toAttributes(scenario.getTags())); + List parameters = getParameters(scenario); + boolean hasParameters = ofNullable(parameters).filter(p -> !p.isEmpty()).isPresent(); + if (hasParameters) { + rq.setParameters(parameters); + } + + String description = scenario.getDescription(); + if (isNotBlank(description)) { + if (hasParameters) { + rq.setDescription( + String.format(MARKDOWN_DELIMITER_PATTERN, + String.format(PARAMETERS_PATTERN, ParameterUtils.formatParametersAsTable(parameters)), + description)); + } else { + rq.setDescription(description); + } + } else if (hasParameters) { + rq.setDescription(String.format(PARAMETERS_PATTERN, ParameterUtils.formatParametersAsTable(parameters))); + } + return rq; + } + + /** + * Build ReportPortal request for start Background event. + * + * @param step Karate's Step object instance + * @param scenario Karate's Scenario object instance + * @return request to ReportPortal + */ + @Nonnull + @SuppressWarnings("unused") + public static StartTestItemRQ buildStartBackgroundRq(@Nonnull Step step, @Nonnull Scenario scenario) { + StartTestItemRQ rq = buildStartTestItemRq(Background.KEYWORD, Calendar.getInstance().getTime(), ItemType.STEP); + rq.setHasStats(false); + return rq; + } + + /** + * Customize start step test item event/request + * + * @param step Karate's Step object instance + * @param scenario Karate's Scenario object instance + * @return request to ReportPortal + */ + @Nonnull + public static StartTestItemRQ buildStartStepRq(@Nonnull Step step, @Nonnull Scenario scenario) { + String stepName = step.getPrefix() + " " + step.getText(); + StartTestItemRQ rq = buildStartTestItemRq(stepName, Calendar.getInstance().getTime(), ItemType.STEP); + rq.setHasStats(false); + if (step.isOutline()) { + List parameters = scenario + .getExampleData() + .entrySet() + .stream() + .filter(e -> Pattern.compile(String.format(VARIABLE_PATTERN, e.getKey())) + .matcher(step.getText()).find()) + .map(e -> { + ParameterResource param = new ParameterResource(); + param.setKey(e.getKey()); + var value = ofNullable(e.getValue()).map(Object::toString).orElse(NULL_VALUE); + param.setValue(value); + return param; + }) + .collect(Collectors.toList()); + rq.setParameters(parameters); + } + return rq; + } + + /** + * Map Karate's item status to ReportPortal status object. + * + * @param status Karate item status + * @return ReportPortal status + */ + public static ItemStatus getStepStatus(String status) { + switch (status) { + case "failed": + return ItemStatus.FAILED; + case "passed": + return ItemStatus.PASSED; + case "skipped": + return ItemStatus.SKIPPED; + case "stopped": + return ItemStatus.STOPPED; + case "interrupted": + return ItemStatus.INTERRUPTED; + case "cancelled": + return ItemStatus.CANCELLED; + default: + LOGGER.warn("Unknown step status received! Set it as SKIPPED"); + return ItemStatus.SKIPPED; + } + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java b/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java index 671eda4..6755c5c 100644 --- a/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java @@ -1,6 +1,6 @@ package com.epam.reportportal.karate.description; -import com.epam.reportportal.karate.ReportPortalPublisher; +import com.epam.reportportal.karate.ReportPortalUtils; import com.epam.reportportal.karate.utils.TestUtils; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.ReportPortalClient; @@ -31,11 +31,11 @@ public class DescriptionExamplesTest { .collect(Collectors.toList()); public static final String FIRST_EXAMPLE_DESCRIPTION = String.format( - ReportPortalPublisher.MARKDOWN_DELIMITER_PATTERN, + ReportPortalUtils.MARKDOWN_DELIMITER_PATTERN, NoDescriptionExamplesTest.FIRST_EXAMPLE_DESCRIPTION, SimpleDescriptionTest.SCENARIO_DESCRIPTION); public static final String SECOND_EXAMPLE_DESCRIPTION = String.format( - ReportPortalPublisher.MARKDOWN_DELIMITER_PATTERN, + ReportPortalUtils.MARKDOWN_DELIMITER_PATTERN, NoDescriptionExamplesTest.SECOND_EXAMPLE_DESCRIPTION, SimpleDescriptionTest.SCENARIO_DESCRIPTION); From 683595d1cd31b6b8ffd08b31dd3bbe36b167ce38 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 2 Jan 2024 20:30:52 +0300 Subject: [PATCH 52/76] Fix parameter reporting --- .../java/com/epam/reportportal/karate/ReportPortalUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java index c488311..fb6515c 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java @@ -260,7 +260,7 @@ public static StartTestItemRQ buildStartFeatureRq(@Nonnull Feature feature) { */ @Nullable public static List getParameters(@Nonnull Scenario scenario) { - if (scenario.isOutlineExample()) { + if (!scenario.isOutlineExample()) { return null; } return scenario.getExampleData().entrySet().stream().map(e -> { From c4ca33544dcedc3ce56157fcef8a750840adda33 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 2 Jan 2024 20:34:39 +0300 Subject: [PATCH 53/76] Fix javadocs --- .../com/epam/reportportal/karate/ReportPortalPublisher.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 709df32..918ef97 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -247,8 +247,8 @@ protected StartTestItemRQ buildStartBackgroundRq(@Nonnull StepResult stepResult, /** * Start sending Background data to ReportPortal. * - * @param stepResult step result - * @param scenarioResult scenario result + * @param stepResult Karate's StepResult object instance + * @param scenarioResult Karate's ScenarioResult object instance */ public void startBackground(@Nonnull StepResult stepResult, @Nonnull ScenarioResult scenarioResult) { backgroundId = ofNullable(backgroundId).orElseGet(() -> { @@ -261,6 +261,7 @@ public void startBackground(@Nonnull StepResult stepResult, @Nonnull ScenarioRes /** * Build ReportPortal request for finish Background event. * + * @param stepResult Karate's StepResult object instance * @param scenarioResult Karate's ScenarioResult object instance * @return request to ReportPortal */ From ee376c1ac09b30b3041ff9029139f75da3a5e8ef Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 4 Jan 2024 18:23:35 +0300 Subject: [PATCH 54/76] ReportPortalHook: WIP --- .../reportportal/karate/ReportPortalHook.java | 157 ++++++++++++++++-- .../karate/ReportPortalPublisher.java | 21 ++- .../karate/ReportPortalUtils.java | 41 +++-- 3 files changed, 180 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java index 4efd140..683179b 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java @@ -16,53 +16,166 @@ package com.epam.reportportal.karate; +import com.epam.reportportal.listeners.ItemStatus; +import com.epam.reportportal.listeners.ListenerParameters; +import com.epam.reportportal.service.Launch; import com.epam.reportportal.service.ReportPortal; +import com.epam.reportportal.utils.MemoizingSupplier; +import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; +import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; +import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; import com.intuit.karate.RuntimeHook; import com.intuit.karate.Suite; -import com.intuit.karate.core.FeatureRuntime; -import com.intuit.karate.core.ScenarioRuntime; -import com.intuit.karate.core.Step; -import com.intuit.karate.core.StepResult; +import com.intuit.karate.core.*; import com.intuit.karate.http.HttpRequest; import com.intuit.karate.http.Response; +import io.reactivex.Maybe; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nonnull; +import java.util.Calendar; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Supplier; + +import static com.epam.reportportal.karate.ReportPortalUtils.*; +import static com.epam.reportportal.utils.ParameterUtils.formatParametersAsTable; +import static java.util.Optional.ofNullable; +import static org.apache.commons.lang3.StringUtils.isNotBlank; public class ReportPortalHook implements RuntimeHook { - public ReportPortalHook(ReportPortal reportPortal) { + private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalHook.class); + + private final Map> featureIdMap = new ConcurrentHashMap<>(); + + protected final MemoizingSupplier launch; + + private volatile Thread shutDownHook; + + /** + * Customize start launch event/request + * + * @param parameters Launch configuration parameters + * @return request to ReportPortal + */ + protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) { + return ReportPortalUtils.buildStartLaunchRq(parameters); + } + + /** + * Customize start Launch finish event/request. + * + * @param parameters Launch configuration parameters + * @return request to ReportPortal + */ + @Nonnull + protected FinishExecutionRQ buildFinishLaunchRq(@Nonnull ListenerParameters parameters) { + return ReportPortalUtils.buildFinishLaunchRq(parameters); + } + /** + * Finish sending Launch data to ReportPortal. + */ + public void finishLaunch() { + Launch launchObject = launch.get(); + ListenerParameters parameters = launchObject.getParameters(); + FinishExecutionRQ rq = buildFinishLaunchRq(parameters); + LOGGER.info("Launch URL: {}/ui/#{}/launches/all/{}", parameters.getBaseUrl(), parameters.getProjectName(), + System.getProperty("rp.launch.id")); + launchObject.finish(rq); + if (Thread.currentThread() != shutDownHook) { + unregisterShutdownHook(shutDownHook); + } + } + + public ReportPortalHook(ReportPortal reportPortal) { + launch = new MemoizingSupplier<>(() -> { + ListenerParameters params = reportPortal.getParameters(); + StartLaunchRQ rq = buildStartLaunchRq(params); + Launch newLaunch = reportPortal.newLaunch(rq); + //noinspection ReactiveStreamsUnusedPublisher + newLaunch.start(); + shutDownHook = registerShutdownHook(this::finishLaunch); + return newLaunch; + }); } public ReportPortalHook() { this(ReportPortal.builder().build()); } - @Override - public boolean beforeScenario(ScenarioRuntime sr) { - return RuntimeHook.super.beforeScenario(sr); + public ReportPortalHook(Supplier launchSupplier) { + launch = new MemoizingSupplier<>(launchSupplier); + shutDownHook = registerShutdownHook(this::finishLaunch); } - @Override - public void afterScenario(ScenarioRuntime sr) { - RuntimeHook.super.afterScenario(sr); + /** + * Build ReportPortal request for start Feature event. + * + * @param fr Karate's FeatureRuntime object instance + * @return request to ReportPortal + */ + @Nonnull + @SuppressWarnings("unchecked") + protected StartTestItemRQ buildStartFeatureRq(@Nonnull FeatureRuntime fr) { + StartTestItemRQ rq = ReportPortalUtils.buildStartFeatureRq(fr.featureCall.feature); + ofNullable(fr.caller).map(c -> c.arg).map(a -> (Map) a.getValue()) + .filter(args -> !args.isEmpty()).ifPresent(args -> { + // TODO: cover with tests + String parameters = String.format(PARAMETERS_PATTERN, formatParametersAsTable(getParameters(args))); + String description = rq.getDescription(); + if (isNotBlank(description)) { + rq.setDescription(String.format(MARKDOWN_DELIMITER_PATTERN, parameters, description)); + } else { + rq.setDescription(parameters); + } + }); + return rq; } @Override public boolean beforeFeature(FeatureRuntime fr) { - return RuntimeHook.super.beforeFeature(fr); + StartTestItemRQ rq = buildStartFeatureRq(fr); + Maybe featureId = launch.get().startTestItem(rq); + Feature feature = fr.featureCall.feature; + featureIdMap.put(feature.getNameForReport(), featureId); + return true; + } + + /** + * Build ReportPortal request for finish Feature event. + * + * @param fr Karate's FeatureRuntime object instance + * @return request to ReportPortal + */ + @Nonnull + protected FinishTestItemRQ buildFinishFeatureRq(@Nonnull FeatureRuntime fr) { + return buildFinishTestItemRq(Calendar.getInstance().getTime(), + fr.result.isFailed() ? ItemStatus.FAILED : ItemStatus.PASSED); } @Override public void afterFeature(FeatureRuntime fr) { - RuntimeHook.super.afterFeature(fr); + Feature feature = fr.featureCall.feature; + Maybe featureId = featureIdMap.remove(feature.getNameForReport()); + if (featureId == null) { + LOGGER.error("ERROR: Trying to finish unspecified feature."); + } + FinishTestItemRQ rq = buildFinishFeatureRq(fr); + //noinspection ReactiveStreamsUnusedPublisher + launch.get().finishTestItem(featureId, rq); } @Override - public void beforeSuite(Suite suite) { - RuntimeHook.super.beforeSuite(suite); + public boolean beforeScenario(ScenarioRuntime sr) { + return RuntimeHook.super.beforeScenario(sr); } @Override - public void afterSuite(Suite suite) { - RuntimeHook.super.afterSuite(suite); + public void afterScenario(ScenarioRuntime sr) { + RuntimeHook.super.afterScenario(sr); } @Override @@ -84,4 +197,14 @@ public void beforeHttpCall(HttpRequest request, ScenarioRuntime sr) { public void afterHttpCall(HttpRequest request, Response response, ScenarioRuntime sr) { RuntimeHook.super.afterHttpCall(request, response, sr); } + + @Override + public void beforeSuite(Suite suite) { + // Omit Suite logic, since there is no Suite names in Karate + } + + @Override + public void afterSuite(Suite suite) { + // Omit Suite logic, since there is no Suite names in Karate + } } diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 918ef97..83a2ad5 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -72,14 +72,14 @@ public ReportPortalPublisher(ReportPortal reportPortal) { ListenerParameters params = reportPortal.getParameters(); StartLaunchRQ rq = buildStartLaunchRq(params); Launch newLaunch = reportPortal.newLaunch(rq); - shutDownHook = registerShutdownHook(() -> newLaunch); + shutDownHook = registerShutdownHook(this::finishLaunch); return newLaunch; }); } public ReportPortalPublisher(Supplier launchSupplier) { launch = new MemoizingSupplier<>(launchSupplier); - shutDownHook = registerShutdownHook(launch); + shutDownHook = registerShutdownHook(this::finishLaunch); } /** @@ -111,7 +111,9 @@ public void finishLaunch() { LOGGER.info("Launch URL: {}/ui/#{}/launches/all/{}", parameters.getBaseUrl(), parameters.getProjectName(), System.getProperty("rp.launch.id")); launchObject.finish(rq); - unregisterShutdownHook(shutDownHook); + if (Thread.currentThread() != shutDownHook) { + unregisterShutdownHook(shutDownHook); + } } /** @@ -122,7 +124,18 @@ public void finishLaunch() { */ @Nonnull protected StartTestItemRQ buildStartFeatureRq(@Nonnull FeatureResult featureResult) { - return ReportPortalUtils.buildStartFeatureRq(featureResult.getFeature()); + StartTestItemRQ rq = ReportPortalUtils.buildStartFeatureRq(featureResult.getFeature()); + ofNullable(featureResult.getCallArg()).filter(args -> !args.isEmpty()).ifPresent(args -> { + // TODO: cover with tests + String parameters = String.format(PARAMETERS_PATTERN, formatParametersAsTable(getParameters(args))); + String description = rq.getDescription(); + if (isNotBlank(description)) { + rq.setDescription(String.format(MARKDOWN_DELIMITER_PATTERN, parameters, description)); + } else { + rq.setDescription(parameters); + } + }); + return rq; } /** diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java index fb6515c..478faee 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java @@ -18,7 +18,6 @@ import com.epam.reportportal.listeners.ItemStatus; import com.epam.reportportal.listeners.ItemType; import com.epam.reportportal.listeners.ListenerParameters; -import com.epam.reportportal.service.Launch; import com.epam.reportportal.service.item.TestCaseIdEntry; import com.epam.reportportal.utils.AttributeParser; import com.epam.reportportal.utils.ParameterUtils; @@ -37,7 +36,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.*; -import java.util.function.Supplier; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -90,28 +88,24 @@ public static String formatExampleKey(@Nonnull final Map example * Create a launch finish hook which will be called on JVM shutdown. Prevents from long unfinished launches for * interrupted tests. * - * @param launch Launch object provider + * @param actions Shutdown actions to perform * @return a Thread which executes Launch finish and exits */ @Nonnull - public static Thread createShutdownHook(@Nonnull Supplier launch) { - return new Thread(() -> { - FinishExecutionRQ rq = new FinishExecutionRQ(); - rq.setEndTime(Calendar.getInstance().getTime()); - launch.get().finish(rq); - }); + public static Thread createShutdownHook(@Nonnull Runnable actions) { + return new Thread(actions); } /** * Create and register a launch finish hook which will be called on JVM shutdown. Prevents from long unfinished * launches for interrupted tests. * - * @param launch Launch object provider + * @param actions Shutdown actions to perform * @return a Thread which executes Launch finish and exits */ @Nonnull - public static Thread registerShutdownHook(@Nonnull Supplier launch) { - Thread shutDownHook = createShutdownHook(launch); + public static Thread registerShutdownHook(@Nonnull Runnable actions) { + Thread shutDownHook = createShutdownHook(actions); Runtime.getRuntime().addShutdownHook(shutDownHook); return shutDownHook; } @@ -252,6 +246,22 @@ public static StartTestItemRQ buildStartFeatureRq(@Nonnull Feature feature) { return rq; } + /** + * Transform Map of parameters to ReportPortal parameter list. + * + * @param args argument Map + * @return parameters + */ + @Nonnull + public static List getParameters(@Nonnull Map args) { + return args.entrySet().stream().map(e -> { + ParameterResource parameterResource = new ParameterResource(); + parameterResource.setKey(e.getKey()); + parameterResource.setValue(ofNullable(e.getValue()).map(Object::toString).orElse(NULL_VALUE)); + return parameterResource; + }).collect(Collectors.toList()); + } + /** * Extract and transform ScenarioOutline parameters to ReportPortal parameter list. * @@ -263,12 +273,7 @@ public static List getParameters(@Nonnull Scenario scenario) if (!scenario.isOutlineExample()) { return null; } - return scenario.getExampleData().entrySet().stream().map(e -> { - ParameterResource parameterResource = new ParameterResource(); - parameterResource.setKey(e.getKey()); - parameterResource.setValue(ofNullable(e.getValue()).map(Object::toString).orElse(NULL_VALUE)); - return parameterResource; - }).collect(Collectors.toList()); + return getParameters(scenario.getExampleData()); } /** From 39b0cb047e5eefe445f0773f5c8e1e4aeb9da15a Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 5 Jan 2024 21:48:05 +0300 Subject: [PATCH 55/76] ReportPortalHook: WIP --- .../reportportal/karate/ReportPortalHook.java | 203 +++++++++++++++++- .../karate/ReportPortalPublisher.java | 10 +- .../karate/ReportPortalUtils.java | 22 ++ 3 files changed, 221 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java index 683179b..e4e03e6 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java @@ -18,6 +18,7 @@ import com.epam.reportportal.listeners.ItemStatus; import com.epam.reportportal.listeners.ListenerParameters; +import com.epam.reportportal.listeners.LogLevel; import com.epam.reportportal.service.Launch; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.utils.MemoizingSupplier; @@ -35,13 +36,16 @@ import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.Calendar; +import java.util.Date; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; import static com.epam.reportportal.karate.ReportPortalUtils.*; import static com.epam.reportportal.utils.ParameterUtils.formatParametersAsTable; +import static com.epam.reportportal.utils.markdown.MarkdownUtils.formatDataTable; import static java.util.Optional.ofNullable; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -49,6 +53,10 @@ public class ReportPortalHook implements RuntimeHook { private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalHook.class); private final Map> featureIdMap = new ConcurrentHashMap<>(); + private final Map> scenarioIdMap = new ConcurrentHashMap<>(); + private final Map> backgroundIdMap = new ConcurrentHashMap<>(); + private final Map> stepIdMap = new ConcurrentHashMap<>(); + private final Map, Date> stepStartTimeMap = new ConcurrentHashMap<>(); protected final MemoizingSupplier launch; @@ -168,24 +176,209 @@ public void afterFeature(FeatureRuntime fr) { launch.get().finishTestItem(featureId, rq); } + /** + * Build ReportPortal request for start Scenario event. + * + * @param sr Karate's ScenarioRuntime object instance + * @return request to ReportPortal + */ + @Nonnull + protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioRuntime sr) { + return ReportPortalUtils.buildStartScenarioRq(sr.scenario); + } + @Override public boolean beforeScenario(ScenarioRuntime sr) { - return RuntimeHook.super.beforeScenario(sr); + StartTestItemRQ rq = buildStartScenarioRq(sr); + + Maybe scenarioId = launch.get() + .startTestItem(featureIdMap.get(sr.featureRuntime.featureCall.feature.getNameForReport()), rq); + scenarioIdMap.put(sr.scenario.getUniqueId(), scenarioId); + return true; + } + + /** + * Build ReportPortal request for finish Scenario event. + * + * @param sr Karate's ScenarioRuntime object instance + * @return request to ReportPortal + */ + @Nonnull + protected FinishTestItemRQ buildFinishScenarioRq(@Nonnull ScenarioRuntime sr) { + return buildFinishTestItemRq(Calendar.getInstance().getTime(), + sr.result.getFailureMessageForDisplay() == null ? ItemStatus.PASSED : ItemStatus.FAILED); + } + + /** + * Build ReportPortal request for start Background event. + * + * @param step Karate's Step object instance + * @param sr Karate's ScenarioRuntime object instance + * @return request to ReportPortal + */ + @Nonnull + @SuppressWarnings("unused") + protected StartTestItemRQ buildStartBackgroundRq(@Nonnull Step step, @Nonnull ScenarioRuntime sr) { + return ReportPortalUtils.buildStartBackgroundRq(step, sr.scenario); + } + + /** + * Start sending Background data to ReportPortal. + * + * @param step Karate's Step object instance + * @param sr Karate's ScenarioRuntime object instance + */ + public Maybe startBackground(@Nonnull Step step, @Nonnull ScenarioRuntime sr) { + return backgroundIdMap.computeIfAbsent(sr.scenario.getUniqueId(), k-> { + StartTestItemRQ backgroundRq = buildStartBackgroundRq(step, sr); + return launch.get().startTestItem(scenarioIdMap.get(sr.scenario.getUniqueId()), + backgroundRq); + }); + } + + /** + * Build ReportPortal request for finish Background event. + * + * @param step Karate's Step object instance + * @param sr Karate's ScenarioRuntime object instance + * @return request to ReportPortal + */ + @Nonnull + @SuppressWarnings("unused") + protected FinishTestItemRQ buildFinishBackgroundRq(@Nullable Step step, @Nonnull ScenarioRuntime sr) { + return buildFinishTestItemRq(Calendar.getInstance().getTime(), null); + + } + + /** + * Finish sending Scenario data to ReportPortal. + * + * @param step Karate's Step object instance + * @param sr Karate's ScenarioRuntime object instance + */ + public void finishBackground(@Nullable Step step, @Nonnull ScenarioRuntime sr) { + Maybe backgroundId = backgroundIdMap.remove(sr.scenario.getUniqueId()); + if (backgroundId != null) { + FinishTestItemRQ finishRq = buildFinishBackgroundRq(step, sr); + //noinspection ReactiveStreamsUnusedPublisher + launch.get().finishTestItem(backgroundId, finishRq); + } } @Override public void afterScenario(ScenarioRuntime sr) { - RuntimeHook.super.afterScenario(sr); + Maybe scenarioId = featureIdMap.remove(sr.scenario.getUniqueId()); + if (scenarioId == null) { + LOGGER.error("ERROR: Trying to finish unspecified scenario."); + } + + FinishTestItemRQ rq = buildFinishScenarioRq(sr); + //noinspection ReactiveStreamsUnusedPublisher + launch.get().finishTestItem(scenarioId, rq); + finishBackground(null, sr); + } + + /** + * Get step start time. To keep the steps order in case previous step startTime == current step startTime or + * previous step startTime > current step startTime. + * + * @param stepId step ID. + * @return step new startTime in Date format. + */ + @Nonnull + private Date getStepStartTime(@Nullable Maybe stepId) { + Date currentStepStartTime = Calendar.getInstance().getTime(); + if (stepId == null || stepStartTimeMap.isEmpty()) { + return currentStepStartTime; + } + Date lastStepStartTime = stepStartTimeMap.get(stepId); + if (lastStepStartTime.compareTo(currentStepStartTime) >= 0) { + currentStepStartTime.setTime(lastStepStartTime.getTime() + 1); + } + return currentStepStartTime; + } + + /** + * Customize start Step test item event/request. + * + * @param step Karate's Step object instance + * @param sr Karate's ScenarioRuntime object instance + * @return request to ReportPortal + */ + @Nonnull + protected StartTestItemRQ buildStartStepRq(@Nonnull Step step, @Nonnull ScenarioRuntime sr) { + StartTestItemRQ rq = ReportPortalUtils.buildStartStepRq(step, sr.scenario); + Maybe stepId = stepIdMap.get(sr.scenario.getUniqueId()); + Date startTime = getStepStartTime(stepId); + rq.setStartTime(startTime); + return rq; + } + + /** + * Send Step logs to ReportPortal. + * + * @param itemId item ID future + * @param message log message to send + * @param level log level + */ + protected void sendLog(Maybe itemId, String message, LogLevel level) { + ReportPortalUtils.sendLog(itemId, message, level); } @Override public boolean beforeStep(Step step, ScenarioRuntime sr) { - return RuntimeHook.super.beforeStep(step, sr); + boolean background = step.isBackground(); + Maybe backgroundId = null; + if (background) { + backgroundId = startBackground(step, sr); + } else { + finishBackground(step, sr); + } + StartTestItemRQ stepRq = buildStartStepRq(step, sr); + + String scenarioId = sr.scenario.getUniqueId(); + Maybe stepId = launch.get() + .startTestItem( + background ? backgroundId : scenarioIdMap.get(scenarioId), + stepRq + ); + stepStartTimeMap.put(stepId, stepRq.getStartTime()); + stepIdMap.put(scenarioId, stepId); + ofNullable(stepRq.getParameters()) + .filter(params -> !params.isEmpty()) + .ifPresent(params -> + sendLog(stepId, String.format(PARAMETERS_PATTERN, formatParametersAsTable(params)), + LogLevel.INFO)); + ofNullable(step.getTable()) + .ifPresent(table -> + sendLog(stepId, "Table:\n\n" + formatDataTable(table.getRows()), LogLevel.INFO)); + return true; + } + + /** + * Build ReportPortal request for finish Step event. + * + * @param stepResult Karate's StepResult class instance + * @param sr Karate's ScenarioRuntime object instance + * @return request to ReportPortal + */ + @Nonnull + @SuppressWarnings("unused") + protected FinishTestItemRQ buildFinishStepRq(@Nonnull StepResult stepResult, @Nonnull ScenarioRuntime sr) { + return buildFinishTestItemRq(Calendar.getInstance().getTime(), getStepStatus(stepResult.getResult().getStatus())); } @Override - public void afterStep(StepResult result, ScenarioRuntime sr) { - RuntimeHook.super.afterStep(result, sr); + public void afterStep(StepResult stepResult, ScenarioRuntime sr) { + Maybe stepId = stepIdMap.get(sr.scenario.getUniqueId()); + if (stepId == null) { + LOGGER.error("ERROR: Trying to finish unspecified step."); + return; + } + + FinishTestItemRQ rq = buildFinishStepRq(stepResult, sr); + //noinspection ReactiveStreamsUnusedPublisher + launch.get().finishTestItem(stepId, rq); } @Override diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 83a2ad5..a6d85b5 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -26,7 +26,6 @@ import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; -import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; import com.intuit.karate.core.*; import io.reactivex.Maybe; import org.slf4j.Logger; @@ -431,13 +430,6 @@ public void sendStepResults(StepResult stepResult) { * @param level log level */ protected void sendLog(Maybe itemId, String message, LogLevel level) { - ReportPortal.emitLog(itemId, id -> { - SaveLogRQ rq = new SaveLogRQ(); - rq.setMessage(message); - rq.setItemUuid(id); - rq.setLevel(level.name()); - rq.setLogTime(Calendar.getInstance().getTime()); - return rq; - }); + ReportPortalUtils.sendLog(itemId, message, level); } } diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java index 478faee..27ee8cb 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java @@ -18,6 +18,8 @@ import com.epam.reportportal.listeners.ItemStatus; import com.epam.reportportal.listeners.ItemType; import com.epam.reportportal.listeners.ListenerParameters; +import com.epam.reportportal.listeners.LogLevel; +import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.item.TestCaseIdEntry; import com.epam.reportportal.utils.AttributeParser; import com.epam.reportportal.utils.ParameterUtils; @@ -29,7 +31,9 @@ import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; +import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; import com.intuit.karate.core.*; +import io.reactivex.Maybe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -395,4 +399,22 @@ public static ItemStatus getStepStatus(String status) { return ItemStatus.SKIPPED; } } + + /** + * Send Step logs to ReportPortal. + * + * @param itemId item ID future + * @param message log message to send + * @param level log level + */ + public static void sendLog(Maybe itemId, String message, LogLevel level) { + ReportPortal.emitLog(itemId, id -> { + SaveLogRQ rq = new SaveLogRQ(); + rq.setMessage(message); + rq.setItemUuid(id); + rq.setLevel(level.name()); + rq.setLogTime(Calendar.getInstance().getTime()); + return rq; + }); + } } From 7028aa84de9ec520fc4536eacbe54f3aba05fab8 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 5 Jan 2024 23:02:26 +0300 Subject: [PATCH 56/76] ReportPortalHook: WIP --- .../reportportal/karate/ReportPortalHook.java | 33 +++++++++++++++++++ .../karate/ReportPortalPublisher.java | 27 +++++++-------- .../karate/ReportPortalUtils.java | 11 +++++++ 3 files changed, 56 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java index e4e03e6..2046526 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java @@ -355,6 +355,36 @@ public boolean beforeStep(Step step, ScenarioRuntime sr) { return true; } + /** + * Send Step execution results to ReportPortal. + * + * @param stepResult step execution results + * @param sr Karate's ScenarioRuntime object instance + */ + public void sendStepResults(StepResult stepResult, ScenarioRuntime sr) { + Maybe stepId = stepIdMap.get(sr.scenario.getUniqueId()); + Step step = stepResult.getStep(); + String docString = step.getDocString(); + if (isNotBlank(docString)) { + sendLog(stepId, "Docstring:\n\n" + asMarkdownCode(step.getDocString()), LogLevel.INFO); + } + + Result result = stepResult.getResult(); + String stepLog = stepResult.getStepLog(); + if (isNotBlank(stepLog)) { + sendLog(stepId, stepLog, LogLevel.INFO); + } + if (result.isFailed()) { + String fullErrorMessage = step.getPrefix() + " " + step.getText(); + String errorMessage = result.getErrorMessage(); + if (isNotBlank(errorMessage)) { + fullErrorMessage = fullErrorMessage + "\n" + errorMessage; + + } + sendLog(stepId, fullErrorMessage, LogLevel.ERROR); + } + } + /** * Build ReportPortal request for finish Step event. * @@ -370,6 +400,7 @@ protected FinishTestItemRQ buildFinishStepRq(@Nonnull StepResult stepResult, @No @Override public void afterStep(StepResult stepResult, ScenarioRuntime sr) { + sendStepResults(stepResult, sr); Maybe stepId = stepIdMap.get(sr.scenario.getUniqueId()); if (stepId == null) { LOGGER.error("ERROR: Trying to finish unspecified step."); @@ -383,11 +414,13 @@ public void afterStep(StepResult stepResult, ScenarioRuntime sr) { @Override public void beforeHttpCall(HttpRequest request, ScenarioRuntime sr) { + // TODO: Implement better HTTP request logging later RuntimeHook.super.beforeHttpCall(request, sr); } @Override public void afterHttpCall(HttpRequest request, Response response, ScenarioRuntime sr) { + // TODO: Implement better HTTP response logging later RuntimeHook.super.afterHttpCall(request, response, sr); } diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index a6d85b5..26add09 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -43,8 +43,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class ReportPortalPublisher { - public static final String MARKDOWN_CODE_PATTERN = "```\n%s\n```"; - private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalPublisher.class); private final Map> featureIdMap = new HashMap<>(); private final Map> scenarioIdMap = new HashMap<>(); @@ -393,6 +391,17 @@ public void finishStep(StepResult stepResult, ScenarioResult scenarioResult) { launch.get().finishTestItem(stepId, rq); } + /** + * Send Step logs to ReportPortal. + * + * @param itemId item ID future + * @param message log message to send + * @param level log level + */ + protected void sendLog(Maybe itemId, String message, LogLevel level) { + ReportPortalUtils.sendLog(itemId, message, level); + } + /** * Send Step execution results to ReportPortal. * @@ -402,8 +411,7 @@ public void sendStepResults(StepResult stepResult) { Step step = stepResult.getStep(); String docString = step.getDocString(); if (isNotBlank(docString)) { - sendLog(stepId, "Docstring:\n\n" + String.format(MARKDOWN_CODE_PATTERN, step.getDocString()), - LogLevel.INFO); + sendLog(stepId, "Docstring:\n\n" + asMarkdownCode(step.getDocString()), LogLevel.INFO); } Result result = stepResult.getResult(); @@ -421,15 +429,4 @@ public void sendStepResults(StepResult stepResult) { sendLog(stepId, fullErrorMessage, LogLevel.ERROR); } } - - /** - * Send Step logs to ReportPortal. - * - * @param itemId item ID future - * @param message log message to send - * @param level log level - */ - protected void sendLog(Maybe itemId, String message, LogLevel level) { - ReportPortalUtils.sendLog(itemId, message, level); - } } diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java index 27ee8cb..08a6eb9 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java @@ -54,6 +54,7 @@ public class ReportPortalUtils { private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalUtils.class); + public static final String MARKDOWN_CODE_PATTERN = "```\n%s\n```"; public static final String PARAMETERS_PATTERN = "Parameters:\n\n%s"; private static final String PARAMETER_ITEMS_START = "["; private static final String PARAMETER_ITEMS_END = "]"; @@ -417,4 +418,14 @@ public static void sendLog(Maybe itemId, String message, LogLevel level) return rq; }); } + + /** + * Builds markdown representation of some code or script to be logged to ReportPortal + * + * @param code Code or Script + * @return Message to be sent to ReportPortal + */ + public static String asMarkdownCode(String code) { + return String.format(MARKDOWN_CODE_PATTERN, code); + } } From db08eda539c4a5a6a7a5a7f1a74510eb96697220 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Sat, 6 Jan 2024 01:14:07 +0300 Subject: [PATCH 57/76] ReportPortalHook: Tests WIP --- .../attributes/DifferentAttributesTest.java | 17 +++++++++++++---- .../karate/attributes/LaunchAttributesTest.java | 17 +++++++++++++---- .../karate/attributes/NoAttributesTest.java | 17 +++++++++++++---- .../karate/attributes/SystemAttributesTest.java | 17 +++++++++++++---- .../background/BackgroundExamplesTest.java | 17 +++++++++++++---- .../karate/background/BackgroundTest.java | 17 +++++++++++++---- .../background/BackgroundTwoStepsTest.java | 17 +++++++++++++---- .../karate/coderef/ExamplesCodeRefTest.java | 17 +++++++++++++---- .../karate/coderef/ScenarioCodeRefTest.java | 17 +++++++++++++---- .../description/DescriptionExamplesTest.java | 17 +++++++++++++---- .../description/LaunchDescriptionTest.java | 17 +++++++++++++---- .../description/NoDescriptionExamplesTest.java | 17 +++++++++++++---- .../karate/description/NoDescriptionTest.java | 17 +++++++++++++---- .../description/NoLaunchDescriptionTest.java | 17 +++++++++++++---- .../description/SimpleDescriptionTest.java | 17 +++++++++++++---- 15 files changed, 195 insertions(+), 60 deletions(-) diff --git a/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java index 6dec4d0..80e4f24 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java @@ -22,9 +22,11 @@ import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; +import com.intuit.karate.Results; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -39,6 +41,7 @@ import static org.mockito.Mockito.*; public class DifferentAttributesTest { + private static final String TEST_FEATURE = "classpath:feature/tags.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -53,9 +56,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_different_attributes() { - var results = TestUtils.runAsReport(rp, "classpath:feature/tags.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_different_attributes(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java index ee59bad..5273a28 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java @@ -23,8 +23,10 @@ import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; +import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.Arrays; @@ -41,6 +43,7 @@ import static org.mockito.Mockito.verify; public class LaunchAttributesTest { + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -59,9 +62,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void verify_start_launch_request_contains_launch_attributes() { - var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void verify_start_launch_request_contains_launch_attributes(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java index dd6a4ce..8c371b0 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java @@ -21,8 +21,10 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -36,6 +38,7 @@ import static org.mockito.Mockito.*; public class NoAttributesTest { + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -50,9 +53,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_different_attributes() { - var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_different_attributes(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java index a5cb85e..5a1a85f 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java @@ -22,8 +22,10 @@ import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ; import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; +import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -38,6 +40,7 @@ import static org.mockito.Mockito.verify; public class SystemAttributesTest { + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -52,9 +55,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void verify_start_launch_request_contains_system_attributes() { - var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void verify_start_launch_request_contains_system_attributes(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java index bdf0b09..14a2b72 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java @@ -6,10 +6,12 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import com.intuit.karate.core.Background; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -25,6 +27,7 @@ import static org.mockito.Mockito.*; public class BackgroundExamplesTest { + private static final String TEST_FEATURE = "classpath:feature/background_examples.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")) .limit(2).collect(Collectors.toList()); @@ -50,9 +53,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_background_steps() { - var results = TestUtils.runAsReport(rp, "classpath:feature/background_examples.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_background_steps(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java index fa81516..f869904 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java @@ -6,10 +6,12 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import com.intuit.karate.core.Background; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -24,6 +26,7 @@ import static org.mockito.Mockito.*; public class BackgroundTest { + private static final String TEST_FEATURE = "classpath:feature/background.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -41,9 +44,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_background_steps() { - var results = TestUtils.runAsReport(rp, "classpath:feature/background.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_background_steps(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java index 4659a40..5c92af0 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java @@ -6,10 +6,12 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import com.intuit.karate.core.Background; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -25,6 +27,7 @@ import static org.mockito.Mockito.*; public class BackgroundTwoStepsTest { + private static final String TEST_FEATURE = "classpath:feature/background_two_steps.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -44,9 +47,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_background_steps() { - var results = TestUtils.runAsReport(rp, "classpath:feature/background_two_steps.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_background_steps(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java index 961de3a..8de1055 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java @@ -6,9 +6,11 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -22,6 +24,7 @@ import static org.mockito.Mockito.*; public class ExamplesCodeRefTest { + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) .collect(Collectors.toList()); @@ -46,9 +49,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_examples_code_reference() { - var results = TestUtils.runAsReport(rp, "classpath:feature/examples.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_examples_code_reference(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java index fe0c31e..d267413 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java @@ -6,8 +6,10 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -21,6 +23,7 @@ import static org.mockito.Mockito.*; public class ScenarioCodeRefTest { + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -37,9 +40,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_scenario_code_reference() { - var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_scenario_code_reference(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java b/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java index 6755c5c..3cee9d1 100644 --- a/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java @@ -6,9 +6,11 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -22,6 +24,7 @@ import static org.mockito.Mockito.*; public class DescriptionExamplesTest { + private static final String TEST_FEATURE = "classpath:feature/description_examples.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) .collect(Collectors.toList()); @@ -48,9 +51,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_examples_description() { - var results = TestUtils.runAsReport(rp, "classpath:feature/description_examples.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_examples_description(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java index 91819f9..a255582 100644 --- a/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java @@ -22,8 +22,10 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; +import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -37,6 +39,7 @@ import static org.mockito.Mockito.verify; public class LaunchDescriptionTest { + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; private static final String TEST_DESCRIPTION = "My test description"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); @@ -55,9 +58,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void verify_start_launch_request_contains_launch_description() { - var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void verify_start_launch_request_contains_launch_description(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java index d8a896b..ddc57c0 100644 --- a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java @@ -6,9 +6,11 @@ import com.epam.reportportal.util.test.CommonUtils; import com.epam.reportportal.utils.markdown.MarkdownUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -22,6 +24,7 @@ import static org.mockito.Mockito.*; public class NoDescriptionExamplesTest { + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) .collect(Collectors.toList()); @@ -51,9 +54,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_examples_no_description() { - var results = TestUtils.runAsReport(rp, "classpath:feature/examples.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_examples_no_description(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java index 05b4b97..d972090 100644 --- a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java @@ -5,8 +5,10 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -21,6 +23,7 @@ import static org.mockito.Mockito.*; public class NoDescriptionTest { + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -35,9 +38,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_description_for_all_possible_items() { - var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_description_for_all_possible_items(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java index e552cbd..f92c195 100644 --- a/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java @@ -22,8 +22,10 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; +import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.mockito.ArgumentCaptor; @@ -40,6 +42,7 @@ import static org.mockito.Mockito.verify; public class NoLaunchDescriptionTest { + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -53,21 +56,27 @@ public void setupMock() { mockBatchLogging(client); } - public static List dataValues() { - return Arrays.asList( + public static List dataValues() { + List descriptions = Arrays.asList( null, "", " " ); + return Arrays.asList(Arguments.of(true, descriptions), Arguments.of(false, descriptions)); } @ParameterizedTest @MethodSource("dataValues") - public void verify_start_launch_request_contains_no_launch_description(String description) { + public void verify_start_launch_request_contains_no_launch_description(boolean report, String description) { ListenerParameters parameters = standardParameters(); parameters.setDescription(description); ReportPortal rp = ReportPortal.create(client, parameters, testExecutor()); - var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java index 94186ce..5b76ffb 100644 --- a/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java @@ -5,10 +5,12 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import com.intuit.karate.core.Background; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -23,6 +25,7 @@ import static org.mockito.Mockito.*; public class SimpleDescriptionTest { + private static final String TEST_FEATURE = "classpath:feature/description.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -42,9 +45,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_description_for_all_possible_items() { - var results = TestUtils.runAsReport(rp, "classpath:feature/description.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_description_for_all_possible_items(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); From 0d8697fc73af36860c3e0b53bc7c9cd57e9cbafb Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 8 Jan 2024 13:06:09 +0300 Subject: [PATCH 58/76] ReportPortalHook: Tests WIP --- .../karate/description/NoLaunchDescriptionTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java index f92c195..dab86a2 100644 --- a/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java @@ -56,13 +56,13 @@ public void setupMock() { mockBatchLogging(client); } - public static List dataValues() { + public static Stream dataValues() { List descriptions = Arrays.asList( null, "", " " ); - return Arrays.asList(Arguments.of(true, descriptions), Arguments.of(false, descriptions)); + return Stream.of(true, false).flatMap(b -> descriptions.stream().map(d -> Arguments.of(b, d))); } @ParameterizedTest From 0c33fe8fc68b97663c33f45645a64ace14e07e27 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 8 Jan 2024 13:46:12 +0300 Subject: [PATCH 59/76] ReportPortalHook: Tests WIP --- .../karate/id/ExamplesTestCaseIdTest.java | 16 +++++++++++++--- .../karate/id/ScenarioTestCaseIdTest.java | 18 ++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java b/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java index 1ca7ff6..35c67e2 100644 --- a/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java +++ b/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java @@ -5,9 +5,12 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -21,6 +24,7 @@ import static org.mockito.Mockito.*; public class ExamplesTestCaseIdTest { + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) .collect(Collectors.toList()); @@ -45,9 +49,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_examples_test_case_id() { - var results = TestUtils.runAsReport(rp, "classpath:feature/examples.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_examples_test_case_id(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java b/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java index 38dd509..e83a431 100644 --- a/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java +++ b/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java @@ -5,8 +5,11 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -20,6 +23,7 @@ import static org.mockito.Mockito.*; public class ScenarioTestCaseIdTest { + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -36,10 +40,16 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_test_case_id() { - var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_test_case_id(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0));; ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client, times(1)).startTestItem(captor.capture()); From b00232d41a5788573d1c3a4e699ab749aabdec99 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 8 Jan 2024 13:58:59 +0300 Subject: [PATCH 60/76] ReportPortalHook: Tests WIP --- .../karate/id/ScenarioTestCaseIdTest.java | 2 +- .../karate/launch/LaunchRequiredFieldsTest.java | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java b/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java index e83a431..cc2cbdb 100644 --- a/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java +++ b/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java @@ -49,7 +49,7 @@ public void test_test_case_id(boolean report) { } else { results = TestUtils.runAsHook(rp, TEST_FEATURE); } - assertThat(results.getFailCount(), equalTo(0));; + assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client, times(1)).startTestItem(captor.capture()); diff --git a/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java b/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java index 7d4cd6a..d98bd33 100644 --- a/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java +++ b/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java @@ -21,8 +21,11 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; +import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -37,6 +40,7 @@ import static org.mockito.Mockito.verify; public class LaunchRequiredFieldsTest { + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -51,9 +55,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void verify_start_launch_request_contains_required_fields() { - var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void verify_start_launch_request_contains_required_fields(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); From 2b992603c12355a2d97edfc326528dfa0e98e2f2 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 8 Jan 2024 16:33:06 +0300 Subject: [PATCH 61/76] ReportPortalHook: Tests WIP --- .../reportportal/karate/ReportPortalHook.java | 19 +++++---------- .../karate/ReportPortalPublisher.java | 16 ++++++------- .../logging/HttpRequestLoggingTest.java | 23 +++++++++++++------ .../logging/SimpleFailureLoggingTest.java | 21 ++++++++++++----- 4 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java index 2046526..db0f955 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java @@ -145,8 +145,7 @@ protected StartTestItemRQ buildStartFeatureRq(@Nonnull FeatureRuntime fr) { @Override public boolean beforeFeature(FeatureRuntime fr) { - StartTestItemRQ rq = buildStartFeatureRq(fr); - Maybe featureId = launch.get().startTestItem(rq); + Maybe featureId = launch.get().startTestItem(buildStartFeatureRq(fr)); Feature feature = fr.featureCall.feature; featureIdMap.put(feature.getNameForReport(), featureId); return true; @@ -267,7 +266,7 @@ public void finishBackground(@Nullable Step step, @Nonnull ScenarioRuntime sr) { @Override public void afterScenario(ScenarioRuntime sr) { - Maybe scenarioId = featureIdMap.remove(sr.scenario.getUniqueId()); + Maybe scenarioId = scenarioIdMap.remove(sr.scenario.getUniqueId()); if (scenarioId == null) { LOGGER.error("ERROR: Trying to finish unspecified scenario."); } @@ -352,6 +351,10 @@ public boolean beforeStep(Step step, ScenarioRuntime sr) { ofNullable(step.getTable()) .ifPresent(table -> sendLog(stepId, "Table:\n\n" + formatDataTable(table.getRows()), LogLevel.INFO)); + String docString = step.getDocString(); + if (isNotBlank(docString)) { + sendLog(stepId, "Docstring:\n\n" + asMarkdownCode(step.getDocString()), LogLevel.INFO); + } return true; } @@ -364,22 +367,12 @@ public boolean beforeStep(Step step, ScenarioRuntime sr) { public void sendStepResults(StepResult stepResult, ScenarioRuntime sr) { Maybe stepId = stepIdMap.get(sr.scenario.getUniqueId()); Step step = stepResult.getStep(); - String docString = step.getDocString(); - if (isNotBlank(docString)) { - sendLog(stepId, "Docstring:\n\n" + asMarkdownCode(step.getDocString()), LogLevel.INFO); - } - Result result = stepResult.getResult(); - String stepLog = stepResult.getStepLog(); - if (isNotBlank(stepLog)) { - sendLog(stepId, stepLog, LogLevel.INFO); - } if (result.isFailed()) { String fullErrorMessage = step.getPrefix() + " " + step.getText(); String errorMessage = result.getErrorMessage(); if (isNotBlank(errorMessage)) { fullErrorMessage = fullErrorMessage + "\n" + errorMessage; - } sendLog(stepId, fullErrorMessage, LogLevel.ERROR); } diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 26add09..be94aca 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -339,7 +339,8 @@ protected StartTestItemRQ buildStartStepRq(@Nonnull StepResult stepResult, @Nonn * @param scenarioResult scenario result */ public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { - if (stepResult.getStep().isBackground()) { + Step step = stepResult.getStep(); + if (step.isBackground()) { startBackground(stepResult, scenarioResult); } else { finishBackground(stepResult, scenarioResult); @@ -356,9 +357,13 @@ public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { .ifPresent(params -> sendLog(stepId, String.format(PARAMETERS_PATTERN, formatParametersAsTable(params)), LogLevel.INFO)); - ofNullable(stepResult.getStep().getTable()) + ofNullable(step.getTable()) .ifPresent(table -> sendLog(stepId, "Table:\n\n" + formatDataTable(table.getRows()), LogLevel.INFO)); + String docString = step.getDocString(); + if (isNotBlank(docString)) { + sendLog(stepId, "Docstring:\n\n" + asMarkdownCode(step.getDocString()), LogLevel.INFO); + } } /** @@ -409,15 +414,10 @@ protected void sendLog(Maybe itemId, String message, LogLevel level) { */ public void sendStepResults(StepResult stepResult) { Step step = stepResult.getStep(); - String docString = step.getDocString(); - if (isNotBlank(docString)) { - sendLog(stepId, "Docstring:\n\n" + asMarkdownCode(step.getDocString()), LogLevel.INFO); - } - Result result = stepResult.getResult(); String stepLog = stepResult.getStepLog(); if (isNotBlank(stepLog)) { - sendLog(stepId, stepLog, LogLevel.INFO); + sendLog(stepId, stepLog, LogLevel.DEBUG); } if (result.isFailed()) { String fullErrorMessage = step.getPrefix() + " " + step.getText(); diff --git a/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java b/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java index 17a88f9..329f268 100644 --- a/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java +++ b/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java @@ -22,9 +22,11 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; +import com.intuit.karate.Results; import okhttp3.MultipartBody; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -37,6 +39,7 @@ import static org.mockito.Mockito.*; public class HttpRequestLoggingTest { + private static final String TEST_FEATURE = "classpath:feature/http_request.feature"; private final String launchUuid = CommonUtils.namedId("launch_"); private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); @@ -52,10 +55,16 @@ public void setupMock() { mockBatchLogging(client); } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) @SuppressWarnings({"unchecked", "rawtypes"}) - public void test_http_request_logging() { - var results = TestUtils.runAsReport(rp, "classpath:feature/http_request.feature"); + public void test_http_request_logging(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); @@ -64,12 +73,12 @@ public void test_http_request_logging() { .getAllValues(). stream() .flatMap(rq -> extractJsonParts((List) rq).stream()) - .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel())) + .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel()) || LogLevel.DEBUG.name().equals(rq.getLevel())) .collect(Collectors.toList()); - assertThat(logs, hasSize(2)); + assertThat(logs, hasSize(greaterThanOrEqualTo(2))); List messages = logs.stream().map(SaveLogRQ::getMessage).collect(Collectors.toList()); - assertThat(messages, containsInAnyOrder( + assertThat(messages, hasItems( equalTo("Docstring:\n\n```\n{\n" + " username: 'user',\n" + " password: 'password',\n" + diff --git a/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java b/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java index bcc3337..4102953 100644 --- a/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java +++ b/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java @@ -22,9 +22,11 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; +import com.intuit.karate.Results; import okhttp3.MultipartBody; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -37,6 +39,7 @@ import static org.mockito.Mockito.*; public class SimpleFailureLoggingTest { + private static final String TEST_FEATURE = "classpath:feature/simple_failed.feature"; private final String launchUuid = CommonUtils.namedId("launch_"); private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); @@ -52,10 +55,16 @@ public void setupMock() { mockBatchLogging(client); } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) @SuppressWarnings({"unchecked", "rawtypes"}) - public void test_simple_one_step_failed_error_log() { - var results = TestUtils.runAsReport(rp, "classpath:feature/simple_failed.feature"); + public void test_simple_one_step_failed_error_log(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(1)); ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); @@ -67,8 +76,8 @@ public void test_simple_one_step_failed_error_log() { .filter(rq -> LogLevel.ERROR.name().equals(rq.getLevel())) .collect(Collectors.toList()); - assertThat(logs, hasSize(1)); - SaveLogRQ log = logs.get(0); + assertThat(logs, hasSize(greaterThan(0))); + SaveLogRQ log = logs.get(logs.size() - 1); assertThat(log.getItemUuid(), oneOf(stepIds.toArray(new String[0]))); assertThat(log.getLaunchUuid(), equalTo(launchUuid)); assertThat(log.getMessage(), equalTo("Then assert actualFour != four\n" From e21c219e0997d044baa4327a37dff722307b1881 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 8 Jan 2024 16:35:13 +0300 Subject: [PATCH 62/76] ReportPortalHook: Tests WIP --- .../karate/name/SimpleItemNameTest.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java b/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java index 982fcea..8ee70a3 100644 --- a/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java +++ b/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java @@ -5,8 +5,10 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -20,6 +22,7 @@ import static org.mockito.Mockito.*; public class SimpleItemNameTest { + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -37,9 +40,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_item_names_simple() { - var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_item_names_simple(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); From 19c772c70b4762412180f9d94b68dfd4339e1970 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 8 Jan 2024 16:41:42 +0300 Subject: [PATCH 63/76] ReportPortalHook: Tests WIP --- .../ExamplesScenarioParametersTest.java | 17 +++++++++++++---- .../parameters/ExamplesStepParametersTest.java | 17 +++++++++++++---- .../karate/parameters/NoParametersTest.java | 17 +++++++++++++---- .../karate/parameters/TableParametersTest.java | 17 +++++++++++++---- src/test/resources/logback.xml | 1 + 5 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java index 2324133..ef7e4fc 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java @@ -6,9 +6,11 @@ import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.ParameterResource; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -22,6 +24,7 @@ import static org.mockito.Mockito.*; public class ExamplesScenarioParametersTest { + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) .collect(Collectors.toList()); @@ -39,9 +42,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_examples_scenario_parameters() { - var results = TestUtils.runAsReport(rp, "classpath:feature/examples.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_examples_scenario_parameters(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java index 5281922..25a17ea 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java @@ -8,10 +8,12 @@ import com.epam.ta.reportportal.ws.model.ParameterResource; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; +import com.intuit.karate.Results; import okhttp3.MultipartBody; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.Collection; @@ -30,6 +32,7 @@ import static org.mockito.Mockito.*; public class ExamplesStepParametersTest { + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) .collect(Collectors.toList()); @@ -54,10 +57,16 @@ private static Set toParameterStringList(List paramet .collect(Collectors.toSet()); } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) @SuppressWarnings({"unchecked", "rawtypes"}) - public void test_examples_parameters_for_steps() { - var results = TestUtils.runAsReport(rp, "classpath:feature/examples.feature"); + public void test_examples_parameters_for_steps(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java index fa931ad..440f7c6 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java @@ -5,8 +5,10 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -20,6 +22,7 @@ import static org.mockito.Mockito.*; public class NoParametersTest { + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -34,9 +37,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_no_parameters_reporting() { - var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_no_parameters_reporting(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java index 7ed7a89..7f87d43 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java @@ -7,9 +7,11 @@ import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; +import com.intuit.karate.Results; import okhttp3.MultipartBody; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -24,6 +26,7 @@ import static org.mockito.Mockito.*; public class TableParametersTest { + private static final String TEST_FEATURE = "classpath:feature/table.feature"; private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) @@ -38,10 +41,16 @@ public void setupMock() { mockBatchLogging(client); } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) @SuppressWarnings({"unchecked", "rawtypes"}) - public void test_table_parameters_reporting() { - var results = TestUtils.runAsReport(rp, "classpath:feature/table.feature"); + public void test_table_parameters_reporting(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/resources/logback.xml b/src/test/resources/logback.xml index 017378b..351fb98 100644 --- a/src/test/resources/logback.xml +++ b/src/test/resources/logback.xml @@ -35,6 +35,7 @@ + From 3e8cf83b48862220f08fbedd1e46079b72940750 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 8 Jan 2024 16:45:54 +0300 Subject: [PATCH 64/76] ReportPortalHook: Tests WIP --- .../reportportal/karate/ReportPortalHook.java | 1 + .../karate/status/SimpleAllPassedTest.java | 17 +++++++++++++---- .../karate/status/SimpleOneStepFailedTest.java | 17 +++++++++++++---- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java index db0f955..be1b9b3 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java @@ -145,6 +145,7 @@ protected StartTestItemRQ buildStartFeatureRq(@Nonnull FeatureRuntime fr) { @Override public boolean beforeFeature(FeatureRuntime fr) { + // TODO: add item start time test Maybe featureId = launch.get().startTestItem(buildStartFeatureRq(fr)); Feature feature = fr.featureCall.feature; featureIdMap.put(feature.getNameForReport(), featureId); diff --git a/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java b/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java index 93e4543..af23e48 100644 --- a/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java +++ b/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java @@ -22,8 +22,10 @@ import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; +import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -37,6 +39,7 @@ import static org.mockito.Mockito.*; public class SimpleAllPassedTest { + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; private final String launchUuid = CommonUtils.namedId("launch_"); private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); @@ -52,9 +55,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_simple_all_passed() { - var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_simple_all_passed(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(0)); ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java b/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java index f66675f..888232d 100644 --- a/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java +++ b/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java @@ -23,8 +23,10 @@ import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.FinishExecutionRQ; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; +import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import java.util.List; @@ -38,6 +40,7 @@ import static org.mockito.Mockito.*; public class SimpleOneStepFailedTest { + private static final String TEST_FEATURE = "classpath:feature/simple_failed.feature"; private final String launchUuid = CommonUtils.namedId("launch_"); private final String featureId = CommonUtils.namedId("feature_"); private final String scenarioId = CommonUtils.namedId("scenario_"); @@ -53,9 +56,15 @@ public void setupMock() { mockBatchLogging(client); } - @Test - public void test_simple_one_step_failed() { - var results = TestUtils.runAsReport(rp, "classpath:feature/simple_failed.feature"); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_simple_one_step_failed(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } assertThat(results.getFailCount(), equalTo(1)); ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); From 4f9c469da8300b3be3dda3554baf1d7177c7f97f Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 9 Jan 2024 14:08:56 +0300 Subject: [PATCH 65/76] Add timing test and javadocs --- .../reportportal/karate/ReportPortalHook.java | 32 +++--- .../karate/ReportPortalPublisher.java | 3 + .../karate/timing/SimpleTimingTest.java | 101 ++++++++++++++++++ 3 files changed, 121 insertions(+), 15 deletions(-) create mode 100644 src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java index be1b9b3..4580942 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java @@ -49,6 +49,9 @@ import static java.util.Optional.ofNullable; import static org.apache.commons.lang3.StringUtils.isNotBlank; +/** + * ReportPortal test results reporting hook for Karate. This class publish results in the process of test pass. + */ public class ReportPortalHook implements RuntimeHook { private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalHook.class); @@ -145,7 +148,6 @@ protected StartTestItemRQ buildStartFeatureRq(@Nonnull FeatureRuntime fr) { @Override public boolean beforeFeature(FeatureRuntime fr) { - // TODO: add item start time test Maybe featureId = launch.get().startTestItem(buildStartFeatureRq(fr)); Feature feature = fr.featureCall.feature; featureIdMap.put(feature.getNameForReport(), featureId); @@ -212,8 +214,8 @@ protected FinishTestItemRQ buildFinishScenarioRq(@Nonnull ScenarioRuntime sr) { /** * Build ReportPortal request for start Background event. * - * @param step Karate's Step object instance - * @param sr Karate's ScenarioRuntime object instance + * @param step Karate's Step object instance + * @param sr Karate's ScenarioRuntime object instance * @return request to ReportPortal */ @Nonnull @@ -225,11 +227,11 @@ protected StartTestItemRQ buildStartBackgroundRq(@Nonnull Step step, @Nonnull Sc /** * Start sending Background data to ReportPortal. * - * @param step Karate's Step object instance - * @param sr Karate's ScenarioRuntime object instance + * @param step Karate's Step object instance + * @param sr Karate's ScenarioRuntime object instance */ public Maybe startBackground(@Nonnull Step step, @Nonnull ScenarioRuntime sr) { - return backgroundIdMap.computeIfAbsent(sr.scenario.getUniqueId(), k-> { + return backgroundIdMap.computeIfAbsent(sr.scenario.getUniqueId(), k -> { StartTestItemRQ backgroundRq = buildStartBackgroundRq(step, sr); return launch.get().startTestItem(scenarioIdMap.get(sr.scenario.getUniqueId()), backgroundRq); @@ -239,8 +241,8 @@ public Maybe startBackground(@Nonnull Step step, @Nonnull ScenarioRuntim /** * Build ReportPortal request for finish Background event. * - * @param step Karate's Step object instance - * @param sr Karate's ScenarioRuntime object instance + * @param step Karate's Step object instance + * @param sr Karate's ScenarioRuntime object instance * @return request to ReportPortal */ @Nonnull @@ -253,8 +255,8 @@ protected FinishTestItemRQ buildFinishBackgroundRq(@Nullable Step step, @Nonnull /** * Finish sending Scenario data to ReportPortal. * - * @param step Karate's Step object instance - * @param sr Karate's ScenarioRuntime object instance + * @param step Karate's Step object instance + * @param sr Karate's ScenarioRuntime object instance */ public void finishBackground(@Nullable Step step, @Nonnull ScenarioRuntime sr) { Maybe backgroundId = backgroundIdMap.remove(sr.scenario.getUniqueId()); @@ -301,8 +303,8 @@ private Date getStepStartTime(@Nullable Maybe stepId) { /** * Customize start Step test item event/request. * - * @param step Karate's Step object instance - * @param sr Karate's ScenarioRuntime object instance + * @param step Karate's Step object instance + * @param sr Karate's ScenarioRuntime object instance * @return request to ReportPortal */ @Nonnull @@ -363,7 +365,7 @@ public boolean beforeStep(Step step, ScenarioRuntime sr) { * Send Step execution results to ReportPortal. * * @param stepResult step execution results - * @param sr Karate's ScenarioRuntime object instance + * @param sr Karate's ScenarioRuntime object instance */ public void sendStepResults(StepResult stepResult, ScenarioRuntime sr) { Maybe stepId = stepIdMap.get(sr.scenario.getUniqueId()); @@ -382,8 +384,8 @@ public void sendStepResults(StepResult stepResult, ScenarioRuntime sr) { /** * Build ReportPortal request for finish Step event. * - * @param stepResult Karate's StepResult class instance - * @param sr Karate's ScenarioRuntime object instance + * @param stepResult Karate's StepResult class instance + * @param sr Karate's ScenarioRuntime object instance * @return request to ReportPortal */ @Nonnull diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index be94aca..1579757 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -42,6 +42,9 @@ import static java.util.Optional.ofNullable; import static org.apache.commons.lang3.StringUtils.isNotBlank; +/** + * ReportPortal test results publisher for Karate. This class publish results after test pass. + */ public class ReportPortalPublisher { private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalPublisher.class); private final Map> featureIdMap = new HashMap<>(); diff --git a/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java b/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java new file mode 100644 index 0000000..675a548 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java @@ -0,0 +1,101 @@ +/* + * Copyright 2023 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 + * + * 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, + * 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. + */ + +package com.epam.reportportal.karate.timing; + +import com.epam.reportportal.karate.utils.TestUtils; +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.StartTestItemRQ; +import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; +import com.intuit.karate.Results; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.mockito.Mockito.*; + +public class SimpleTimingTest { + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_each_item_has_correct_start_date(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor launchCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(launchCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + + StartLaunchRQ launchRq = launchCaptor.getValue(); + StartTestItemRQ featureRq = featureCaptor.getValue(); + StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); + + assertThat("Launch start time is greater than Feature start time.", + featureRq.getStartTime(), greaterThanOrEqualTo(launchRq.getStartTime())); + assertThat("Feature start time is greater than Scenario start time.", + scenarioRq.getStartTime(), greaterThanOrEqualTo(featureRq.getStartTime())); + + List steps = stepCaptor.getAllValues(); + StartTestItemRQ firstStep = steps.stream() + .filter(s -> "Given def four = 4".equals(s.getName())).findAny().orElseThrow(); + StartTestItemRQ secondStep = steps.stream() + .filter(s -> "When def actualFour = 2 * 2".equals(s.getName())).findAny().orElseThrow(); + StartTestItemRQ thirdStep = steps.stream() + .filter(s -> "Then assert actualFour == four".equals(s.getName())).findAny().orElseThrow(); + + assertThat("Scenario start time is greater than Step start time.", + firstStep.getStartTime(), greaterThanOrEqualTo(scenarioRq.getStartTime())); + assertThat("First Step start time is greater or equal than Second Step start time.", + secondStep.getStartTime(), greaterThan(firstStep.getStartTime())); + assertThat("Second Step start time is greater or equal than Third Step start time.", + thirdStep.getStartTime(), greaterThan(secondStep.getStartTime())); + } +} From 11cef43548f5ad1bcd838b0ab6e1a6fc1367f2a5 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 9 Jan 2024 18:01:49 +0300 Subject: [PATCH 66/76] Add feature parameters tests --- .../karate/ReportPortalPublisher.java | 13 +-- .../CallWithParametersHookTest.java | 98 +++++++++++++++++++ .../CallWithParametersPublisherTest.java | 65 ++++++++++++ .../reportportal/karate/utils/TestUtils.java | 11 ++- src/test/resources/feature/call.feature | 4 + src/test/resources/feature/called.feature | 7 ++ 6 files changed, 182 insertions(+), 16 deletions(-) create mode 100644 src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java create mode 100644 src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java create mode 100644 src/test/resources/feature/call.feature create mode 100644 src/test/resources/feature/called.feature diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 1579757..efa7b5b 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -124,18 +124,7 @@ public void finishLaunch() { */ @Nonnull protected StartTestItemRQ buildStartFeatureRq(@Nonnull FeatureResult featureResult) { - StartTestItemRQ rq = ReportPortalUtils.buildStartFeatureRq(featureResult.getFeature()); - ofNullable(featureResult.getCallArg()).filter(args -> !args.isEmpty()).ifPresent(args -> { - // TODO: cover with tests - String parameters = String.format(PARAMETERS_PATTERN, formatParametersAsTable(getParameters(args))); - String description = rq.getDescription(); - if (isNotBlank(description)) { - rq.setDescription(String.format(MARKDOWN_DELIMITER_PATTERN, parameters, description)); - } else { - rq.setDescription(parameters); - } - }); - return rq; + return ReportPortalUtils.buildStartFeatureRq(featureResult.getFeature()); } /** diff --git a/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java new file mode 100644 index 0000000..c6ea7fd --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java @@ -0,0 +1,98 @@ +/* + * Copyright 2024 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 + * + * 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, + * 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. + */ + +package com.epam.reportportal.karate.description; + +import com.epam.reportportal.karate.utils.TestUtils; +import com.epam.reportportal.service.ReportPortal; +import com.epam.reportportal.service.ReportPortalClient; +import com.epam.reportportal.util.test.CommonUtils; +import com.epam.reportportal.utils.markdown.MarkdownUtils; +import com.epam.ta.reportportal.ws.model.StartTestItemRQ; +import com.intuit.karate.Results; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.startsWith; +import static org.hamcrest.Matchers.*; +import static org.mockito.Mockito.*; + +public class CallWithParametersHookTest { + private static final String TEST_FEATURE = "classpath:feature/call.feature"; + private final List featureIds = Stream.generate(() -> CommonUtils.namedId("feature_")) + .limit(2).collect(Collectors.toList()); + private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")) + .limit(2).collect(Collectors.toList()); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(4).collect(Collectors.toList()); + + private final List>>>> features = + Stream.of( + Pair.of(featureIds.get(0), (Collection>>) Collections.singletonList(Pair.of(scenarioIds.get(0), Collections.singletonList(stepIds.get(0))))), + Pair.of(featureIds.get(1), (Collection>>) Collections.singletonList(Pair.of(scenarioIds.get(1), stepIds.subList(1, stepIds.size())))) + ).collect(Collectors.toList()); + + private static final String PARAMETERS_DESCRIPTION_PATTERN = + "Parameters:\n\n" + + MarkdownUtils.TABLE_INDENT + + "| vara | result |\n" + + MarkdownUtils.TABLE_INDENT + + "|------|--------|\n" + + MarkdownUtils.TABLE_INDENT + + "|  2   |   4    |\n\n" + + MarkdownUtils.TABLE_ROW_SEPARATOR; + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null); + mockFeatures(client, features); + mockBatchLogging(client); + } + + @Test + public void test_call_feature_with_parameters_hook_reporting() { + Results results = TestUtils.runAsHook(rp, TEST_FEATURE); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureIds.get(0)), scenarioCaptor.capture()); + verify(client).startTestItem(same(featureIds.get(1)), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(scenarioIds.get(0)), stepCaptor.capture()); + verify(client, times(3)).startTestItem(same(scenarioIds.get(1)), stepCaptor.capture()); + + StartTestItemRQ calledFeature = featureCaptor.getAllValues().stream() + .filter(rq -> "a feature which is called with parameters".equals(rq.getName())).findAny().orElseThrow(); + + assertThat(calledFeature.getDescription(), allOf(endsWith("feature/called.feature"), startsWith(PARAMETERS_DESCRIPTION_PATTERN))); + } +} diff --git a/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java new file mode 100644 index 0000000..b2a5a10 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2024 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 + * + * 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, + * 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. + */ + +package com.epam.reportportal.karate.description; + +import com.epam.reportportal.karate.utils.TestUtils; +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.StartTestItemRQ; +import com.intuit.karate.Results; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.epam.reportportal.karate.utils.TestUtils.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.*; + +public class CallWithParametersPublisherTest { + private static final String TEST_FEATURE = "classpath:feature/call.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(1).collect(Collectors.toList()); + + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } + + @Test + public void test_call_feature_with_parameters_publisher_reporting() { + Results results = TestUtils.runAsReport(rp, TEST_FEATURE); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(scenarioId), stepCaptor.capture()); + } +} diff --git a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java index fced60f..e691150 100644 --- a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java +++ b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java @@ -98,6 +98,13 @@ public static > void mockLaunch( mockFeature(client, featureUuid, scenarioSteps); } + public static void mockLaunch( + @Nonnull final ReportPortalClient client, @Nullable final String launchUuid) { + String launch = ofNullable(launchUuid).orElse(CommonUtils.namedId("launch_")); + when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launch, 1L))); + when(client.finishLaunch(eq(launch), any())).thenReturn(Maybe.just(new OperationCompletionRS())); + } + public static > void mockFeature( @Nonnull final ReportPortalClient client, @Nullable final String featureUuid, @Nonnull final Collection> scenarioSteps) { @@ -165,10 +172,6 @@ public static void mockBatchLogging(final ReportPortalClient client) { when(client.log(any(List.class))).thenReturn(Maybe.just(new BatchSaveOperatingRS())); } - 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() diff --git a/src/test/resources/feature/call.feature b/src/test/resources/feature/call.feature new file mode 100644 index 0000000..79546bb --- /dev/null +++ b/src/test/resources/feature/call.feature @@ -0,0 +1,4 @@ +Feature: calling another feature file + + Scenario: calling a feature with parameters + * def result = call read('called.feature') { vara: 2, result: 4 } diff --git a/src/test/resources/feature/called.feature b/src/test/resources/feature/called.feature new file mode 100644 index 0000000..12883cf --- /dev/null +++ b/src/test/resources/feature/called.feature @@ -0,0 +1,7 @@ +@ignore +Feature: a feature which is called with parameters + + Scenario: Verify different maths + Given def varb = 2 + Given def mathResult = vara + varb + Then assert mathResult == result From ec74b371ba3ba177c5b5470edccb3106af75ed02 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 10 Jan 2024 13:12:17 +0300 Subject: [PATCH 67/76] Bump version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index b3dc51a..ef09a8a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ name=agent-java-karate -version=1.0.6 +version=5.0.0 description=EPAM ReportPortal. Karate test framework [1.3.1, ) adapter gradle_version=8.2 karate_version=[1.3.1, ) From a564218c6b3edf7660af60c823939ba7ba29a98e Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 12 Jan 2024 12:18:58 +0300 Subject: [PATCH 68/76] Client version update --- CHANGELOG.md | 3 ++- build.gradle | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 222ffbd..13980a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Changelog ## [Unreleased] -- Take items' startTime and endTime from Karate. +### Changed +- Refactored and implemented main ReportPortal agent features, by @HardNorth ## [1.0.6] ### Changed diff --git a/build.gradle b/build.gradle index 3620a20..a16bf13 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,7 @@ repositories { } dependencies { - api 'com.epam.reportportal:client-java:5.1.26' + api 'com.epam.reportportal:client-java:5.2.0' api "com.intuit.karate:karate-core:${project.karate_version}" implementation 'org.slf4j:slf4j-api:2.0.7' @@ -54,6 +54,7 @@ dependencies { testImplementation "org.mockito:mockito-core:${project.mockito_version}" testImplementation "org.mockito:mockito-junit-jupiter:${project.mockito_version}" testImplementation 'org.hamcrest:hamcrest-core:2.2' + testImplementation 'com.squareup.okhttp3:okhttp:4.12.0' } test { From 68aa65c65c6f21faefc676372bfa9c7534379c0e Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 12 Jan 2024 15:40:21 +0300 Subject: [PATCH 69/76] Client version update --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a16bf13..fc56d23 100644 --- a/build.gradle +++ b/build.gradle @@ -46,7 +46,7 @@ dependencies { api "com.intuit.karate:karate-core:${project.karate_version}" implementation 'org.slf4j:slf4j-api:2.0.7' - testImplementation 'com.epam.reportportal:logger-java-logback:5.1.6' + testImplementation 'com.epam.reportportal:logger-java-logback:5.2.0' testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.2' testImplementation "org.junit.jupiter:junit-jupiter-api:${project.junit_version}" testImplementation "org.junit.jupiter:junit-jupiter-engine:${project.junit_version}" From 844d36b1a123ad250f18f0db6a709676ba0646d6 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 12 Jan 2024 23:30:41 +0300 Subject: [PATCH 70/76] Fix version number --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ef09a8a..3a284cd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ name=agent-java-karate -version=5.0.0 +version=5.0.0-SNAPSHOT description=EPAM ReportPortal. Karate test framework [1.3.1, ) adapter gradle_version=8.2 karate_version=[1.3.1, ) From 820d9e16c6e55f2eb5a5089442618592bf462589 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 16 Jan 2024 13:34:18 +0300 Subject: [PATCH 71/76] Update copyrights --- build-quality.gradle | 2 +- build.gradle | 2 +- .../karate/KarateReportPortalRunner.java | 16 + .../reportportal/karate/ReportPortalHook.java | 20 +- .../karate/ReportPortalPublisher.java | 20 +- .../karate/ReportPortalUtils.java | 4 +- .../epam/reportportal/karate/KarateTest.java | 40 +- .../karate/ReportPortalPublisherTest.java | 118 +++--- .../attributes/DifferentAttributesTest.java | 104 ++--- .../attributes/LaunchAttributesTest.java | 82 ++-- .../karate/attributes/NoAttributesTest.java | 86 ++-- .../attributes/SystemAttributesTest.java | 78 ++-- .../background/BackgroundExamplesTest.java | 148 +++---- .../karate/background/BackgroundTest.java | 116 +++--- .../background/BackgroundTwoStepsTest.java | 120 +++--- .../karate/coderef/ExamplesCodeRefTest.java | 126 +++--- .../karate/coderef/ScenarioCodeRefTest.java | 96 +++-- .../CallWithParametersHookTest.java | 113 +++--- .../CallWithParametersPublisherTest.java | 64 +-- .../description/DescriptionExamplesTest.java | 112 +++--- .../description/LaunchDescriptionTest.java | 66 ++-- .../NoDescriptionExamplesTest.java | 118 +++--- .../karate/description/NoDescriptionTest.java | 84 ++-- .../description/NoLaunchDescriptionTest.java | 78 ++-- .../description/SimpleDescriptionTest.java | 104 ++--- .../karate/id/ExamplesTestCaseIdTest.java | 105 ++--- .../karate/id/ScenarioTestCaseIdTest.java | 83 ++-- .../launch/LaunchRequiredFieldsTest.java | 65 ++- .../logging/HttpRequestLoggingTest.java | 104 ++--- .../logging/SimpleFailureLoggingTest.java | 100 ++--- .../karate/name/SimpleItemNameTest.java | 94 +++-- .../ExamplesScenarioParametersTest.java | 110 +++--- .../ExamplesStepParametersTest.java | 150 +++---- .../karate/parameters/NoParametersTest.java | 84 ++-- .../parameters/TableParametersTest.java | 100 +++-- .../karate/status/SimpleAllPassedTest.java | 110 +++--- .../status/SimpleOneStepFailedTest.java | 112 +++--- .../karate/timing/SimpleTimingTest.java | 124 +++--- .../karate/utils/ReflectUtils.java | 38 +- .../reportportal/karate/utils/TestUtils.java | 374 +++++++++--------- src/test/resources/logback.xml | 16 + 41 files changed, 2008 insertions(+), 1678 deletions(-) diff --git a/build-quality.gradle b/build-quality.gradle index d3c4c51..9669e07 100644 --- a/build-quality.gradle +++ b/build-quality.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2019 EPAM Systems + * Copyright 2024 EPAM Systems * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/build.gradle b/build.gradle index fc56d23..ab4faa8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 EPAM Systems * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java b/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java index 221bb01..1af15be 100644 --- a/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java +++ b/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate; import com.epam.reportportal.service.ReportPortal; diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java index 4580942..9d4a846 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java @@ -1,17 +1,17 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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 * - * https://www.apache.org/licenses/LICENSE-2.0 + * 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. + * 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. */ package com.epam.reportportal.karate; diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index efa7b5b..78dd8db 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -1,17 +1,17 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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 * - * https://www.apache.org/licenses/LICENSE-2.0 + * 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. + * 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. */ package com.epam.reportportal.karate; diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java index 08a6eb9..f71e41e 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java @@ -1,11 +1,11 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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, diff --git a/src/test/java/com/epam/reportportal/karate/KarateTest.java b/src/test/java/com/epam/reportportal/karate/KarateTest.java index 957c3fe..03c00b1 100644 --- a/src/test/java/com/epam/reportportal/karate/KarateTest.java +++ b/src/test/java/com/epam/reportportal/karate/KarateTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate; import com.intuit.karate.Results; @@ -7,16 +23,16 @@ import static org.junit.jupiter.api.Assertions.assertTrue; class KarateTest { - @Test - void testParallel() { - Results results = KarateReportPortalRunner - .path("classpath:feature") - .outputCucumberJson(true) - .tags("~@ignore", "@To_run") - .parallel(2); - assertEquals(0, results.getFailCount()); - assertEquals(0, results.getErrors().size()); - assertTrue(results.getSuite().parallel); - assertEquals(2, results.getScenariosTotal()); - } + @Test + void testParallel() { + Results results = KarateReportPortalRunner + .path("classpath:feature") + .outputCucumberJson(true) + .tags("~@ignore", "@To_run") + .parallel(2); + assertEquals(0, results.getFailCount()); + assertEquals(0, results.getErrors().size()); + assertTrue(results.getSuite().parallel); + assertEquals(2, results.getScenariosTotal()); + } } \ No newline at end of file diff --git a/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java b/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java index 39ee91b..f3d7ea4 100644 --- a/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java +++ b/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate; import com.epam.reportportal.karate.utils.ReflectUtils; @@ -24,61 +40,61 @@ @ExtendWith(MockitoExtension.class) public class ReportPortalPublisherTest { - private ReportPortalPublisher reportPortalPublisher; - @Mock - Launch launchMock; + @Mock + Launch launchMock; + private ReportPortalPublisher reportPortalPublisher; - @BeforeEach - public void setUp() { - reportPortalPublisher = new ReportPortalPublisher(() -> launchMock); - } + @BeforeEach + public void setUp() { + reportPortalPublisher = new ReportPortalPublisher(() -> launchMock); + } - @Test - public void shouldStartLaunch() { - reportPortalPublisher.startLaunch(); - verify(launchMock, times(1)).start(); - } + @Test + public void shouldStartLaunch() { + reportPortalPublisher.startLaunch(); + verify(launchMock, times(1)).start(); + } - @Test - public void shouldFinishLaunch() { - when(launchMock.getParameters()).thenReturn(getListenerParameters()); - reportPortalPublisher.finishLaunch(); - verify(launchMock, times(1)).finish(any(FinishExecutionRQ.class)); - } + @Test + public void shouldFinishLaunch() { + when(launchMock.getParameters()).thenReturn(getListenerParameters()); + reportPortalPublisher.finishLaunch(); + verify(launchMock, times(1)).finish(any(FinishExecutionRQ.class)); + } - @SuppressWarnings("unchecked") - @Test - public void shouldStartFeature() throws URISyntaxException { - FeatureResult featureResult = mock(FeatureResult.class); - Feature feature = mock(Feature.class); - Resource resource = mock(Resource.class); - when(featureResult.getFeature()).thenReturn(feature); - when(featureResult.getCallNameForReport()).thenReturn("featureName"); - when(feature.getResource()).thenReturn(resource); - when(resource.getUri()).thenReturn(new URI("file:///feature/simple.feature")); - when(launchMock.startTestItem(any(StartTestItemRQ.class))).thenReturn(mock(Maybe.class)); - reportPortalPublisher.startFeature(featureResult); - verify(launchMock, times(1)).startTestItem(any(StartTestItemRQ.class)); - } + @SuppressWarnings("unchecked") + @Test + public void shouldStartFeature() throws URISyntaxException { + FeatureResult featureResult = mock(FeatureResult.class); + Feature feature = mock(Feature.class); + Resource resource = mock(Resource.class); + when(featureResult.getFeature()).thenReturn(feature); + when(featureResult.getCallNameForReport()).thenReturn("featureName"); + when(feature.getResource()).thenReturn(resource); + when(resource.getUri()).thenReturn(new URI("file:///feature/simple.feature")); + when(launchMock.startTestItem(any(StartTestItemRQ.class))).thenReturn(mock(Maybe.class)); + reportPortalPublisher.startFeature(featureResult); + verify(launchMock, times(1)).startTestItem(any(StartTestItemRQ.class)); + } - @SuppressWarnings("unchecked") - @Test - public void shouldFinishFeature() throws NoSuchFieldException { - FeatureResult featureResult = mock(FeatureResult.class); - when(featureResult.getCallNameForReport()).thenReturn("featureName"); - ConcurrentHashMap> featureIdMap = new ConcurrentHashMap<>(); - featureIdMap.put("featureName", mock(Maybe.class)); - ReflectUtils.setField(reportPortalPublisher, ReportPortalPublisher.class.getDeclaredField("featureIdMap"), featureIdMap); - reportPortalPublisher.finishFeature(featureResult); - verify(launchMock, times(1)).finishTestItem(any(Maybe.class), any(FinishTestItemRQ.class)); - } + @SuppressWarnings("unchecked") + @Test + public void shouldFinishFeature() throws NoSuchFieldException { + FeatureResult featureResult = mock(FeatureResult.class); + when(featureResult.getCallNameForReport()).thenReturn("featureName"); + ConcurrentHashMap> featureIdMap = new ConcurrentHashMap<>(); + featureIdMap.put("featureName", mock(Maybe.class)); + ReflectUtils.setField(reportPortalPublisher, ReportPortalPublisher.class.getDeclaredField("featureIdMap"), featureIdMap); + reportPortalPublisher.finishFeature(featureResult); + verify(launchMock, times(1)).finishTestItem(any(Maybe.class), any(FinishTestItemRQ.class)); + } - private ListenerParameters getListenerParameters() { - ListenerParameters parameters = new ListenerParameters(); - parameters.setLaunchName("launch"); - parameters.setBaseUrl("url"); - parameters.setProjectName("project"); - System.setProperty("rp.launch.id", "launchId"); - return parameters; - } + private ListenerParameters getListenerParameters() { + ListenerParameters parameters = new ListenerParameters(); + parameters.setLaunchName("launch"); + parameters.setBaseUrl("url"); + parameters.setProjectName("project"); + System.setProperty("rp.launch.id", "launchId"); + return parameters; + } } diff --git a/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java index 80e4f24..32ec07c 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java @@ -1,17 +1,17 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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 * - * https://www.apache.org/licenses/LICENSE-2.0 + * 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. + * 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. */ package com.epam.reportportal.karate.attributes; @@ -41,54 +41,54 @@ import static org.mockito.Mockito.*; public class DifferentAttributesTest { - private static final String TEST_FEATURE = "classpath:feature/tags.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/tags.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_different_attributes(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_different_attributes(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(1)).startTestItem(same(featureId), captor.capture()); - verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(5)); + List items = captor.getAllValues(); + assertThat(items, hasSize(5)); - StartTestItemRQ featureRq = items.get(0); - StartTestItemRQ scenarioRq = items.get(1); + StartTestItemRQ featureRq = items.get(0); + StartTestItemRQ scenarioRq = items.get(1); - assertThat(featureRq.getAttributes(), hasSize(1)); - ItemAttributesRQ featureAttribute = featureRq.getAttributes().iterator().next(); - assertThat(featureAttribute.getKey(), nullValue()); - assertThat(featureAttribute.getValue(), equalTo("tag_test")); + assertThat(featureRq.getAttributes(), hasSize(1)); + ItemAttributesRQ featureAttribute = featureRq.getAttributes().iterator().next(); + assertThat(featureAttribute.getKey(), nullValue()); + assertThat(featureAttribute.getValue(), equalTo("tag_test")); - assertThat(scenarioRq.getAttributes(), hasSize(4)); - Set> scenarioAttributes = scenarioRq - .getAttributes().stream().map(a -> Pair.of(a.getKey(), a.getValue())).collect(Collectors.toSet()); - assertThat(scenarioAttributes, hasItem(Pair.of(null, "math"))); - assertThat(scenarioAttributes, hasItem(Pair.of("scope", "smoke"))); - assertThat(scenarioAttributes, hasItem(Pair.of("environment", "dev"))); - assertThat(scenarioAttributes, hasItem(Pair.of("environment", "qa"))); - } + assertThat(scenarioRq.getAttributes(), hasSize(4)); + Set> scenarioAttributes = scenarioRq + .getAttributes().stream().map(a -> Pair.of(a.getKey(), a.getValue())).collect(Collectors.toSet()); + assertThat(scenarioAttributes, hasItem(Pair.of(null, "math"))); + assertThat(scenarioAttributes, hasItem(Pair.of("scope", "smoke"))); + assertThat(scenarioAttributes, hasItem(Pair.of("environment", "dev"))); + assertThat(scenarioAttributes, hasItem(Pair.of("environment", "qa"))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java index 5273a28..8884325 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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, @@ -43,49 +43,49 @@ import static org.mockito.Mockito.verify; public class LaunchAttributesTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private ReportPortal rp; + private final ReportPortalClient client = mock(ReportPortalClient.class); + private ReportPortal rp; - @BeforeEach - public void setupMock() { - ListenerParameters parameters = standardParameters(); - parameters.setAttributes(new HashSet<>(Arrays.asList(new ItemAttributesRQ("key", "value"), - new ItemAttributesRQ(null, "value")))); - rp = ReportPortal.create(client, parameters, testExecutor()); - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + ListenerParameters parameters = standardParameters(); + parameters.setAttributes(new HashSet<>(Arrays.asList(new ItemAttributesRQ("key", "value"), + new ItemAttributesRQ(null, "value")))); + rp = ReportPortal.create(client, parameters, testExecutor()); + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void verify_start_launch_request_contains_launch_attributes(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void verify_start_launch_request_contains_launch_attributes(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); - verify(client).startLaunch(startCaptor.capture()); + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); - StartLaunchRQ launchStart = startCaptor.getValue(); + StartLaunchRQ launchStart = startCaptor.getValue(); - Set attributes = launchStart.getAttributes(); - assertThat(attributes, allOf(notNullValue(), hasSize(greaterThan(0)))); - Set attributesStr = attributes.stream() - .filter(a -> !a.isSystem()) - .map(e -> e.getKey() + ":" + e.getValue()) - .collect(Collectors.toSet()); - assertThat(attributesStr, hasSize(2)); - assertThat(attributesStr, hasItem("key:value")); - assertThat(attributesStr, hasItem("null:value")); - } + Set attributes = launchStart.getAttributes(); + assertThat(attributes, allOf(notNullValue(), hasSize(greaterThan(0)))); + Set attributesStr = attributes.stream() + .filter(a -> !a.isSystem()) + .map(e -> e.getKey() + ":" + e.getValue()) + .collect(Collectors.toSet()); + assertThat(attributesStr, hasSize(2)); + assertThat(attributesStr, hasItem("key:value")); + assertThat(attributesStr, hasItem("null:value")); + } } diff --git a/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java index 8c371b0..e30bdf1 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java @@ -1,17 +1,17 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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 * - * https://www.apache.org/licenses/LICENSE-2.0 + * 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. + * 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. */ package com.epam.reportportal.karate.attributes; @@ -38,44 +38,44 @@ import static org.mockito.Mockito.*; public class NoAttributesTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_different_attributes(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_different_attributes(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(1)).startTestItem(same(featureId), captor.capture()); - verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(5)); + List items = captor.getAllValues(); + assertThat(items, hasSize(5)); - StartTestItemRQ featureRq = items.get(0); - StartTestItemRQ scenarioRq = items.get(1); + StartTestItemRQ featureRq = items.get(0); + StartTestItemRQ scenarioRq = items.get(1); - assertThat(featureRq.getAttributes(), nullValue()); - assertThat(scenarioRq.getAttributes(), nullValue()); - } + assertThat(featureRq.getAttributes(), nullValue()); + assertThat(scenarioRq.getAttributes(), nullValue()); + } } diff --git a/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java index 5a1a85f..a02d216 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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, @@ -40,47 +40,47 @@ import static org.mockito.Mockito.verify; public class SystemAttributesTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void verify_start_launch_request_contains_system_attributes(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void verify_start_launch_request_contains_system_attributes(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); - verify(client).startLaunch(startCaptor.capture()); + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); - StartLaunchRQ launchStart = startCaptor.getValue(); + StartLaunchRQ launchStart = startCaptor.getValue(); - Set attributes = launchStart.getAttributes(); - assertThat(attributes, allOf(notNullValue(), hasSize(greaterThan(0)))); - Set attributesStr = attributes.stream() - .filter(ItemAttributesRQ::isSystem) - .map(e -> e.getKey() + ":" + e.getValue()) - .collect(Collectors.toSet()); - assertThat(attributesStr, hasSize(4)); - assertThat(attributesStr, hasItem("skippedIssue:true")); - assertThat(attributesStr, hasItem("agent:karate-test-agent|test-1.0")); - assertThat(attributesStr, hasItem(startsWith("os:"))); - assertThat(attributesStr, hasItem(startsWith("jvm:"))); - } + Set attributes = launchStart.getAttributes(); + assertThat(attributes, allOf(notNullValue(), hasSize(greaterThan(0)))); + Set attributesStr = attributes.stream() + .filter(ItemAttributesRQ::isSystem) + .map(e -> e.getKey() + ":" + e.getValue()) + .collect(Collectors.toSet()); + assertThat(attributesStr, hasSize(4)); + assertThat(attributesStr, hasItem("skippedIssue:true")); + assertThat(attributesStr, hasItem("agent:karate-test-agent|test-1.0")); + assertThat(attributesStr, hasItem(startsWith("os:"))); + assertThat(attributesStr, hasItem(startsWith("jvm:"))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java index 14a2b72..14e986b 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.background; import com.epam.reportportal.karate.utils.TestUtils; @@ -27,80 +43,80 @@ import static org.mockito.Mockito.*; public class BackgroundExamplesTest { - private static final String TEST_FEATURE = "classpath:feature/background_examples.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")) - .limit(2).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/background_examples.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")) + .limit(2).collect(Collectors.toList()); - private final List>> scenarioSteps = scenarioIds - .stream().map(s -> - Pair.of(s, Stream.generate(() -> - CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()))) - .collect(Collectors.toList()); - private final List> nestedStepIds = scenarioSteps - .stream() - .flatMap(s -> s.getValue().stream()) - .map(s -> Pair.of(s, CommonUtils.namedId("nested_step_"))) - .collect(Collectors.toList()); + private final List>> scenarioSteps = scenarioIds + .stream().map(s -> + Pair.of(s, Stream.generate(() -> + CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()))) + .collect(Collectors.toList()); + private final List> nestedStepIds = scenarioSteps + .stream() + .flatMap(s -> s.getValue().stream()) + .map(s -> Pair.of(s, CommonUtils.namedId("nested_step_"))) + .collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioSteps); - mockNestedSteps(client, nestedStepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioSteps); + mockNestedSteps(client, nestedStepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_background_steps(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_background_steps(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(captor.capture()); - verify(client, times(2)).startTestItem(same(featureId), captor.capture()); - ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioIds.get(0)), firstStepCaptor.capture()); - ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioIds.get(1)), secondStepCaptor.capture()); - ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client, times(2)).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioIds.get(0)), firstStepCaptor.capture()); + ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioIds.get(1)), secondStepCaptor.capture()); + ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(3)); - List firstSteps = firstStepCaptor.getAllValues(); - assertThat(firstSteps, hasSize(3)); - List secondSteps = secondStepCaptor.getAllValues(); - assertThat(firstSteps, hasSize(3)); + List items = captor.getAllValues(); + assertThat(items, hasSize(3)); + List firstSteps = firstStepCaptor.getAllValues(); + assertThat(firstSteps, hasSize(3)); + List secondSteps = secondStepCaptor.getAllValues(); + assertThat(firstSteps, hasSize(3)); - List firstBackgroundSteps = firstSteps.stream() - .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); - assertThat(firstBackgroundSteps, hasSize(1)); - List secondBackgroundSteps = secondSteps.stream() - .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); - assertThat(secondBackgroundSteps, hasSize(1)); + List firstBackgroundSteps = firstSteps.stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); + assertThat(firstBackgroundSteps, hasSize(1)); + List secondBackgroundSteps = secondSteps.stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); + assertThat(secondBackgroundSteps, hasSize(1)); - Stream.concat(firstBackgroundSteps.stream(), secondBackgroundSteps.stream()).forEach(backgroundStep -> { - assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate - assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); - assertThat(backgroundStep.getStartTime(), notNullValue()); - assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); - }); + Stream.concat(firstBackgroundSteps.stream(), secondBackgroundSteps.stream()).forEach(backgroundStep -> { + assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate + assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); + assertThat(backgroundStep.getStartTime(), notNullValue()); + assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); + }); - List nestedSteps = nestedStepCaptor.getAllValues(); - assertThat(nestedSteps, hasSize(2)); - nestedSteps.forEach(step -> assertThat(step.isHasStats(), equalTo(Boolean.FALSE))); - Set nestedStepNames = nestedSteps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet()); + List nestedSteps = nestedStepCaptor.getAllValues(); + assertThat(nestedSteps, hasSize(2)); + nestedSteps.forEach(step -> assertThat(step.isHasStats(), equalTo(Boolean.FALSE))); + Set nestedStepNames = nestedSteps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet()); - assertThat(nestedStepNames, hasSize(1)); - assertThat(nestedStepNames, hasItem("Given def varb = 2")); - } + assertThat(nestedStepNames, hasSize(1)); + assertThat(nestedStepNames, hasItem("Given def varb = 2")); + } } diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java index f869904..efe74cb 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.background; import com.epam.reportportal.karate.utils.TestUtils; @@ -26,61 +42,61 @@ import static org.mockito.Mockito.*; public class BackgroundTest { - private static final String TEST_FEATURE = "classpath:feature/background.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); - private final List> nestedStepIds = stepIds.stream() - .map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/background.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + private final List> nestedStepIds = stepIds.stream() + .map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockNestedSteps(client, nestedStepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockNestedSteps(client, nestedStepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_background_steps(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_background_steps(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(captor.capture()); - verify(client).startTestItem(same(featureId), captor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); - ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(2)); - List steps = stepCaptor.getAllValues(); - assertThat(steps, hasSize(3)); + List items = captor.getAllValues(); + assertThat(items, hasSize(2)); + List steps = stepCaptor.getAllValues(); + assertThat(steps, hasSize(3)); - List backgroundSteps = steps.stream() - .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); - assertThat(backgroundSteps, hasSize(1)); - StartTestItemRQ backgroundStep = backgroundSteps.get(0); - assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate - assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); - assertThat(backgroundStep.getStartTime(), notNullValue()); - assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); + List backgroundSteps = steps.stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); + assertThat(backgroundSteps, hasSize(1)); + StartTestItemRQ backgroundStep = backgroundSteps.get(0); + assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate + assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); + assertThat(backgroundStep.getStartTime(), notNullValue()); + assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); - List nestedSteps = nestedStepCaptor.getAllValues(); - assertThat(nestedSteps, hasSize(1)); - StartTestItemRQ nestedStep = nestedSteps.get(0); - assertThat(nestedStep.getName(), equalTo("Given def four = 4")); - assertThat(nestedStep.isHasStats(), equalTo(Boolean.FALSE)); - } + List nestedSteps = nestedStepCaptor.getAllValues(); + assertThat(nestedSteps, hasSize(1)); + StartTestItemRQ nestedStep = nestedSteps.get(0); + assertThat(nestedStep.getName(), equalTo("Given def four = 4")); + assertThat(nestedStep.isHasStats(), equalTo(Boolean.FALSE)); + } } diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java index 5c92af0..23f6469 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.background; import com.epam.reportportal.karate.utils.TestUtils; @@ -27,64 +43,64 @@ import static org.mockito.Mockito.*; public class BackgroundTwoStepsTest { - private static final String TEST_FEATURE = "classpath:feature/background_two_steps.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(2).collect(Collectors.toList()); - private final List> nestedStepIds = Stream.concat( - stepIds.stream().map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))), - stepIds.stream().map(id -> Pair.of(id, CommonUtils.namedId("nested_step_")))).collect(Collectors.toList() - ); + private static final String TEST_FEATURE = "classpath:feature/background_two_steps.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2).collect(Collectors.toList()); + private final List> nestedStepIds = Stream.concat( + stepIds.stream().map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))), + stepIds.stream().map(id -> Pair.of(id, CommonUtils.namedId("nested_step_")))).collect(Collectors.toList() + ); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockNestedSteps(client, nestedStepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockNestedSteps(client, nestedStepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_background_steps(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_background_steps(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(captor.capture()); - verify(client, times(1)).startTestItem(same(featureId), captor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(scenarioId), stepCaptor.capture()); - ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(2)); - List steps = stepCaptor.getAllValues(); - assertThat(steps, hasSize(2)); + List items = captor.getAllValues(); + assertThat(items, hasSize(2)); + List steps = stepCaptor.getAllValues(); + assertThat(steps, hasSize(2)); - List backgroundSteps = steps.stream() - .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); - assertThat(backgroundSteps, hasSize(1)); - StartTestItemRQ backgroundStep = backgroundSteps.get(0); - assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate - assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); - assertThat(backgroundStep.getStartTime(), notNullValue()); - assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); + List backgroundSteps = steps.stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); + assertThat(backgroundSteps, hasSize(1)); + StartTestItemRQ backgroundStep = backgroundSteps.get(0); + assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate + assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); + assertThat(backgroundStep.getStartTime(), notNullValue()); + assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); - List nestedSteps = nestedStepCaptor.getAllValues(); - assertThat(nestedSteps, hasSize(2)); - nestedSteps.forEach(step -> assertThat(step.isHasStats(), equalTo(Boolean.FALSE))); - Set nestedStepNames = nestedSteps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet()); + List nestedSteps = nestedStepCaptor.getAllValues(); + assertThat(nestedSteps, hasSize(2)); + nestedSteps.forEach(step -> assertThat(step.isHasStats(), equalTo(Boolean.FALSE))); + Set nestedStepNames = nestedSteps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet()); - assertThat(nestedStepNames, allOf(hasItem("Given def vara = 2"), hasItem("And def varb = 2"))); - } + assertThat(nestedStepNames, allOf(hasItem("Given def vara = 2"), hasItem("And def varb = 2"))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java index 8de1055..6bac079 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.coderef; import com.epam.reportportal.karate.utils.TestUtils; @@ -24,67 +40,65 @@ import static org.mockito.Mockito.*; public class ExamplesCodeRefTest { - private static final String TEST_FEATURE = "classpath:feature/examples.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) - .collect(Collectors.toList()); - private final List>> stepIds = exampleIds.stream() - .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(2).collect(Collectors.toList()))) - .collect(Collectors.toList()); - - private static final String EXAMPLE_CODE_REFERENCE_PATTERN = - "feature/examples.feature/[EXAMPLE:Verify different maths[%s]]"; - private static final String FIRST_EXAMPLE_CODE_REFERENCE = - String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "result:4;vara:2;varb:2"); - private static final String SECOND_EXAMPLE_CODE_REFERENCE = - String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "result:3;vara:1;varb:2"); - - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; + private static final String EXAMPLE_CODE_REFERENCE_PATTERN = + "feature/examples.feature/[EXAMPLE:Verify different maths[%s]]"; + private static final String FIRST_EXAMPLE_CODE_REFERENCE = + String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "result:4;vara:2;varb:2"); + private static final String SECOND_EXAMPLE_CODE_REFERENCE = + String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "result:3;vara:1;varb:2"); + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) + .collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_examples_code_reference(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_examples_code_reference(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); - ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); + ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); - StartTestItemRQ featureRq = featureCaptor.getValue(); - assertThat(featureRq.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); + StartTestItemRQ featureRq = featureCaptor.getValue(); + assertThat(featureRq.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); - List scenarios = scenarioCaptor.getAllValues(); - StartTestItemRQ firstScenarioRq = scenarios.get(0); - assertThat(firstScenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); - assertThat(firstScenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_CODE_REFERENCE))); + List scenarios = scenarioCaptor.getAllValues(); + StartTestItemRQ firstScenarioRq = scenarios.get(0); + assertThat(firstScenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(firstScenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_CODE_REFERENCE))); - StartTestItemRQ secondScenarioRq = scenarios.get(1); - assertThat(secondScenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); - assertThat(secondScenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_CODE_REFERENCE))); + StartTestItemRQ secondScenarioRq = scenarios.get(1); + assertThat(secondScenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(secondScenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_CODE_REFERENCE))); - Stream.concat(firstStepCaptor.getAllValues().stream(), secondStepCaptor.getAllValues().stream()) - .forEach(step -> { - assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); - assertThat(step.isHasStats(), equalTo(Boolean.FALSE)); - }); - } + Stream.concat(firstStepCaptor.getAllValues().stream(), secondStepCaptor.getAllValues().stream()) + .forEach(step -> { + assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(step.isHasStats(), equalTo(Boolean.FALSE)); + }); + } } diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java index d267413..16e0e9f 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.coderef; import com.epam.reportportal.karate.utils.TestUtils; @@ -23,52 +39,50 @@ import static org.mockito.Mockito.*; public class ScenarioCodeRefTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); - - private static final String SIMPLE_CODE_REFERENCE = "feature/simple.feature/[SCENARIO:Verify math]"; - - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private static final String SIMPLE_CODE_REFERENCE = "feature/simple.feature/[SCENARIO:Verify math]"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_scenario_code_reference(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_scenario_code_reference(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); - StartTestItemRQ featureRq = featureCaptor.getValue(); - StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); + StartTestItemRQ featureRq = featureCaptor.getValue(); + StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); - assertThat(featureRq.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); + assertThat(featureRq.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); - assertThat(scenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); - assertThat(scenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(SIMPLE_CODE_REFERENCE))); + assertThat(scenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(scenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(SIMPLE_CODE_REFERENCE))); - stepCaptor.getAllValues().forEach(step -> { - assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); - assertThat(step.isHasStats(), equalTo(Boolean.FALSE)); - }); - } + stepCaptor.getAllValues().forEach(step -> { + assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(step.isHasStats(), equalTo(Boolean.FALSE)); + }); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java index c6ea7fd..078566e 100644 --- a/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java @@ -1,17 +1,17 @@ /* - * Copyright 2024 EPAM Systems + * Copyright 2024 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 + * 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 * - * https://www.apache.org/licenses/LICENSE-2.0 + * 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. + * 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. */ package com.epam.reportportal.karate.description; @@ -42,57 +42,54 @@ import static org.mockito.Mockito.*; public class CallWithParametersHookTest { - private static final String TEST_FEATURE = "classpath:feature/call.feature"; - private final List featureIds = Stream.generate(() -> CommonUtils.namedId("feature_")) - .limit(2).collect(Collectors.toList()); - private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")) - .limit(2).collect(Collectors.toList()); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(4).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/call.feature"; + private static final String PARAMETERS_DESCRIPTION_PATTERN = + "Parameters:\n\n" + + MarkdownUtils.TABLE_INDENT + + "| vara | result |\n" + + MarkdownUtils.TABLE_INDENT + + "|------|--------|\n" + + MarkdownUtils.TABLE_INDENT + + "|  2   |   4    |\n\n" + + MarkdownUtils.TABLE_ROW_SEPARATOR; + private final List featureIds = Stream.generate(() -> CommonUtils.namedId("feature_")) + .limit(2).collect(Collectors.toList()); + private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")) + .limit(2).collect(Collectors.toList()); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(4).collect(Collectors.toList()); + private final List>>>> features = + Stream.of( + Pair.of(featureIds.get(0), (Collection>>) Collections.singletonList(Pair.of(scenarioIds.get(0), Collections.singletonList(stepIds.get(0))))), + Pair.of(featureIds.get(1), (Collection>>) Collections.singletonList(Pair.of(scenarioIds.get(1), stepIds.subList(1, stepIds.size())))) + ).collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - private final List>>>> features = - Stream.of( - Pair.of(featureIds.get(0), (Collection>>) Collections.singletonList(Pair.of(scenarioIds.get(0), Collections.singletonList(stepIds.get(0))))), - Pair.of(featureIds.get(1), (Collection>>) Collections.singletonList(Pair.of(scenarioIds.get(1), stepIds.subList(1, stepIds.size())))) - ).collect(Collectors.toList()); + @BeforeEach + public void setupMock() { + mockLaunch(client, null); + mockFeatures(client, features); + mockBatchLogging(client); + } - private static final String PARAMETERS_DESCRIPTION_PATTERN = - "Parameters:\n\n" - + MarkdownUtils.TABLE_INDENT - + "| vara | result |\n" - + MarkdownUtils.TABLE_INDENT - + "|------|--------|\n" - + MarkdownUtils.TABLE_INDENT - + "|  2   |   4    |\n\n" - + MarkdownUtils.TABLE_ROW_SEPARATOR; + @Test + public void test_call_feature_with_parameters_hook_reporting() { + Results results = TestUtils.runAsHook(rp, TEST_FEATURE); + assertThat(results.getFailCount(), equalTo(0)); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureIds.get(0)), scenarioCaptor.capture()); + verify(client).startTestItem(same(featureIds.get(1)), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(scenarioIds.get(0)), stepCaptor.capture()); + verify(client, times(3)).startTestItem(same(scenarioIds.get(1)), stepCaptor.capture()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null); - mockFeatures(client, features); - mockBatchLogging(client); - } + StartTestItemRQ calledFeature = featureCaptor.getAllValues().stream() + .filter(rq -> "a feature which is called with parameters".equals(rq.getName())).findAny().orElseThrow(); - @Test - public void test_call_feature_with_parameters_hook_reporting() { - Results results = TestUtils.runAsHook(rp, TEST_FEATURE); - assertThat(results.getFailCount(), equalTo(0)); - - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(featureIds.get(0)), scenarioCaptor.capture()); - verify(client).startTestItem(same(featureIds.get(1)), scenarioCaptor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(scenarioIds.get(0)), stepCaptor.capture()); - verify(client, times(3)).startTestItem(same(scenarioIds.get(1)), stepCaptor.capture()); - - StartTestItemRQ calledFeature = featureCaptor.getAllValues().stream() - .filter(rq -> "a feature which is called with parameters".equals(rq.getName())).findAny().orElseThrow(); - - assertThat(calledFeature.getDescription(), allOf(endsWith("feature/called.feature"), startsWith(PARAMETERS_DESCRIPTION_PATTERN))); - } + assertThat(calledFeature.getDescription(), allOf(endsWith("feature/called.feature"), startsWith(PARAMETERS_DESCRIPTION_PATTERN))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java index b2a5a10..0ea501a 100644 --- a/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java @@ -1,17 +1,17 @@ /* - * Copyright 2024 EPAM Systems + * Copyright 2024 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 + * 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 * - * https://www.apache.org/licenses/LICENSE-2.0 + * 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. + * 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. */ package com.epam.reportportal.karate.description; @@ -36,30 +36,30 @@ import static org.mockito.Mockito.*; public class CallWithParametersPublisherTest { - private static final String TEST_FEATURE = "classpath:feature/call.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(1).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/call.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(1).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @Test - public void test_call_feature_with_parameters_publisher_reporting() { - Results results = TestUtils.runAsReport(rp, TEST_FEATURE); - assertThat(results.getFailCount(), equalTo(0)); + @Test + public void test_call_feature_with_parameters_publisher_reporting() { + Results results = TestUtils.runAsReport(rp, TEST_FEATURE); + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(captor.capture()); - verify(client).startTestItem(same(featureId), captor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(scenarioId), stepCaptor.capture()); - } + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(scenarioId), stepCaptor.capture()); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java b/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java index 3cee9d1..a818ce0 100644 --- a/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.description; import com.epam.reportportal.karate.ReportPortalUtils; @@ -24,58 +40,56 @@ import static org.mockito.Mockito.*; public class DescriptionExamplesTest { - private static final String TEST_FEATURE = "classpath:feature/description_examples.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) - .collect(Collectors.toList()); - private final List>> stepIds = exampleIds.stream() - .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(2).collect(Collectors.toList()))) - .collect(Collectors.toList()); - - public static final String FIRST_EXAMPLE_DESCRIPTION = String.format( - ReportPortalUtils.MARKDOWN_DELIMITER_PATTERN, - NoDescriptionExamplesTest.FIRST_EXAMPLE_DESCRIPTION, - SimpleDescriptionTest.SCENARIO_DESCRIPTION); - public static final String SECOND_EXAMPLE_DESCRIPTION = String.format( - ReportPortalUtils.MARKDOWN_DELIMITER_PATTERN, - NoDescriptionExamplesTest.SECOND_EXAMPLE_DESCRIPTION, - SimpleDescriptionTest.SCENARIO_DESCRIPTION); - - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + public static final String FIRST_EXAMPLE_DESCRIPTION = String.format( + ReportPortalUtils.MARKDOWN_DELIMITER_PATTERN, + NoDescriptionExamplesTest.FIRST_EXAMPLE_DESCRIPTION, + SimpleDescriptionTest.SCENARIO_DESCRIPTION); + public static final String SECOND_EXAMPLE_DESCRIPTION = String.format( + ReportPortalUtils.MARKDOWN_DELIMITER_PATTERN, + NoDescriptionExamplesTest.SECOND_EXAMPLE_DESCRIPTION, + SimpleDescriptionTest.SCENARIO_DESCRIPTION); + private static final String TEST_FEATURE = "classpath:feature/description_examples.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) + .collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_examples_description(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_examples_description(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); - ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); + ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); - List scenarios = scenarioCaptor.getAllValues(); - StartTestItemRQ firstScenarioRq = scenarios.get(0); - assertThat(firstScenarioRq.getDescription(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_DESCRIPTION))); + List scenarios = scenarioCaptor.getAllValues(); + StartTestItemRQ firstScenarioRq = scenarios.get(0); + assertThat(firstScenarioRq.getDescription(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_DESCRIPTION))); - StartTestItemRQ secondScenarioRq = scenarios.get(1); - assertThat(secondScenarioRq.getDescription(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_DESCRIPTION))); - } + StartTestItemRQ secondScenarioRq = scenarios.get(1); + assertThat(secondScenarioRq.getDescription(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_DESCRIPTION))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java index a255582..94ba58a 100644 --- a/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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, @@ -39,41 +39,41 @@ import static org.mockito.Mockito.verify; public class LaunchDescriptionTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private static final String TEST_DESCRIPTION = "My test description"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private static final String TEST_DESCRIPTION = "My test description"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private ReportPortal rp; + private final ReportPortalClient client = mock(ReportPortalClient.class); + private ReportPortal rp; - @BeforeEach - public void setupMock() { - ListenerParameters parameters = standardParameters(); - parameters.setDescription(TEST_DESCRIPTION); - rp = ReportPortal.create(client, parameters, testExecutor()); - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + ListenerParameters parameters = standardParameters(); + parameters.setDescription(TEST_DESCRIPTION); + rp = ReportPortal.create(client, parameters, testExecutor()); + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void verify_start_launch_request_contains_launch_description(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void verify_start_launch_request_contains_launch_description(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); - verify(client).startLaunch(startCaptor.capture()); + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); - StartLaunchRQ launchStart = startCaptor.getValue(); + StartLaunchRQ launchStart = startCaptor.getValue(); - assertThat(launchStart.getDescription(), equalTo(TEST_DESCRIPTION)); - } + assertThat(launchStart.getDescription(), equalTo(TEST_DESCRIPTION)); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java index ddc57c0..a9ae375 100644 --- a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.description; import com.epam.reportportal.karate.utils.TestUtils; @@ -24,61 +40,59 @@ import static org.mockito.Mockito.*; public class NoDescriptionExamplesTest { - private static final String TEST_FEATURE = "classpath:feature/examples.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) - .collect(Collectors.toList()); - private final List>> stepIds = exampleIds.stream() - .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(2).collect(Collectors.toList()))) - .collect(Collectors.toList()); - - private static final String EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN = - "Parameters:\n\n" - + MarkdownUtils.TABLE_INDENT - + "| vara | varb | result |\n" - + MarkdownUtils.TABLE_INDENT - + "|------|------|--------|\n" - + MarkdownUtils.TABLE_INDENT; - public static final String FIRST_EXAMPLE_DESCRIPTION = EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN - + "|  2   |  2   |   4    |"; - public static final String SECOND_EXAMPLE_DESCRIPTION = EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN - + "|  1   |  2   |   3    |"; - - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; + private static final String EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN = + "Parameters:\n\n" + + MarkdownUtils.TABLE_INDENT + + "| vara | varb | result |\n" + + MarkdownUtils.TABLE_INDENT + + "|------|------|--------|\n" + + MarkdownUtils.TABLE_INDENT; + public static final String FIRST_EXAMPLE_DESCRIPTION = EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN + + "|  2   |  2   |   4    |"; + public static final String SECOND_EXAMPLE_DESCRIPTION = EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN + + "|  1   |  2   |   3    |"; + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) + .collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_examples_no_description(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_examples_no_description(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); - ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); + ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); - List scenarios = scenarioCaptor.getAllValues(); - StartTestItemRQ firstScenarioRq = scenarios.get(0); - assertThat(firstScenarioRq.getDescription(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_DESCRIPTION))); + List scenarios = scenarioCaptor.getAllValues(); + StartTestItemRQ firstScenarioRq = scenarios.get(0); + assertThat(firstScenarioRq.getDescription(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_DESCRIPTION))); - StartTestItemRQ secondScenarioRq = scenarios.get(1); - assertThat(secondScenarioRq.getDescription(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_DESCRIPTION))); - } + StartTestItemRQ secondScenarioRq = scenarios.get(1); + assertThat(secondScenarioRq.getDescription(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_DESCRIPTION))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java index d972090..4c9041a 100644 --- a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.description; import com.epam.reportportal.karate.utils.TestUtils; @@ -23,45 +39,45 @@ import static org.mockito.Mockito.*; public class NoDescriptionTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_description_for_all_possible_items(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_description_for_all_possible_items(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); - StartTestItemRQ featureStart = featureCaptor.getValue(); - assertThat(featureStart.getDescription(), endsWith("feature/simple.feature")); + StartTestItemRQ featureStart = featureCaptor.getValue(); + assertThat(featureStart.getDescription(), endsWith("feature/simple.feature")); - StartTestItemRQ scenarioStart = scenarioCaptor.getValue(); - assertThat(scenarioStart.getDescription(), nullValue()); + StartTestItemRQ scenarioStart = scenarioCaptor.getValue(); + assertThat(scenarioStart.getDescription(), nullValue()); - stepCaptor.getAllValues().forEach(step -> assertThat(step.getDescription(), nullValue())); - } + stepCaptor.getAllValues().forEach(step -> assertThat(step.getDescription(), nullValue())); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java index dab86a2..8567027 100644 --- a/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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, @@ -42,48 +42,48 @@ import static org.mockito.Mockito.verify; public class NoLaunchDescriptionTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortalClient client = mock(ReportPortalClient.class); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + public static Stream dataValues() { + List descriptions = Arrays.asList( + null, + "", + " " + ); + return Stream.of(true, false).flatMap(b -> descriptions.stream().map(d -> Arguments.of(b, d))); + } - public static Stream dataValues() { - List descriptions = Arrays.asList( - null, - "", - " " - ); - return Stream.of(true, false).flatMap(b -> descriptions.stream().map(d -> Arguments.of(b, d))); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @MethodSource("dataValues") - public void verify_start_launch_request_contains_no_launch_description(boolean report, String description) { - ListenerParameters parameters = standardParameters(); - parameters.setDescription(description); - ReportPortal rp = ReportPortal.create(client, parameters, testExecutor()); - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @MethodSource("dataValues") + public void verify_start_launch_request_contains_no_launch_description(boolean report, String description) { + ListenerParameters parameters = standardParameters(); + parameters.setDescription(description); + ReportPortal rp = ReportPortal.create(client, parameters, testExecutor()); + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); - verify(client).startLaunch(startCaptor.capture()); + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); - StartLaunchRQ launchStart = startCaptor.getValue(); + StartLaunchRQ launchStart = startCaptor.getValue(); - assertThat(launchStart.getDescription(), nullValue()); - } + assertThat(launchStart.getDescription(), nullValue()); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java index 5b76ffb..c320514 100644 --- a/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.description; import com.epam.reportportal.karate.utils.TestUtils; @@ -25,55 +41,53 @@ import static org.mockito.Mockito.*; public class SimpleDescriptionTest { - private static final String TEST_FEATURE = "classpath:feature/description.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); - private final List> nestedStepIds = stepIds.stream() - .map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))).collect(Collectors.toList()); - - public static final String SCENARIO_DESCRIPTION = "This is my Scenario description."; - - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + public static final String SCENARIO_DESCRIPTION = "This is my Scenario description."; + private static final String TEST_FEATURE = "classpath:feature/description.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + private final List> nestedStepIds = stepIds.stream() + .map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))).collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockNestedSteps(client, nestedStepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockNestedSteps(client, nestedStepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_description_for_all_possible_items(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_description_for_all_possible_items(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); - StartTestItemRQ featureStart = featureCaptor.getValue(); - assertThat(featureStart.getDescription(), endsWith("feature/description.feature\n\n---\n\nThis is my Feature description.")); + StartTestItemRQ featureStart = featureCaptor.getValue(); + assertThat(featureStart.getDescription(), endsWith("feature/description.feature\n\n---\n\nThis is my Feature description.")); - StartTestItemRQ scenarioStart = scenarioCaptor.getValue(); - assertThat(scenarioStart.getDescription(), equalTo(SCENARIO_DESCRIPTION)); + StartTestItemRQ scenarioStart = scenarioCaptor.getValue(); + assertThat(scenarioStart.getDescription(), equalTo(SCENARIO_DESCRIPTION)); - List backgroundSteps = stepCaptor.getAllValues().stream() - .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); - assertThat(backgroundSteps, hasSize(1)); - StartTestItemRQ backgroundStep = backgroundSteps.get(0); - assertThat("No support of Background description in Karate yet. But this is a part of Gherkin standard.", - backgroundStep.getDescription(), nullValue()); - } + List backgroundSteps = stepCaptor.getAllValues().stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); + assertThat(backgroundSteps, hasSize(1)); + StartTestItemRQ backgroundStep = backgroundSteps.get(0); + assertThat("No support of Background description in Karate yet. But this is a part of Gherkin standard.", + backgroundStep.getDescription(), nullValue()); + } } diff --git a/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java b/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java index 35c67e2..1fe9bba 100644 --- a/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java +++ b/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.id; import com.epam.reportportal.karate.utils.TestUtils; @@ -8,7 +24,6 @@ import com.intuit.karate.Results; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; @@ -24,55 +39,53 @@ import static org.mockito.Mockito.*; public class ExamplesTestCaseIdTest { - private static final String TEST_FEATURE = "classpath:feature/examples.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) - .collect(Collectors.toList()); - private final List>> stepIds = exampleIds.stream() - .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(2).collect(Collectors.toList()))) - .collect(Collectors.toList()); - - private static final String EXAMPLE_TEST_CASE_ID_PATTERN = - "feature/examples.feature/[EXAMPLE:Verify different maths[%s]]"; - private static final String FIRST_EXAMPLE_TEST_CASE_ID = - String.format(EXAMPLE_TEST_CASE_ID_PATTERN, "result:4;vara:2;varb:2"); - private static final String SECOND_EXAMPLE_TEST_CASE_ID = - String.format(EXAMPLE_TEST_CASE_ID_PATTERN, "result:3;vara:1;varb:2"); - - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; + private static final String EXAMPLE_TEST_CASE_ID_PATTERN = + "feature/examples.feature/[EXAMPLE:Verify different maths[%s]]"; + private static final String FIRST_EXAMPLE_TEST_CASE_ID = + String.format(EXAMPLE_TEST_CASE_ID_PATTERN, "result:4;vara:2;varb:2"); + private static final String SECOND_EXAMPLE_TEST_CASE_ID = + String.format(EXAMPLE_TEST_CASE_ID_PATTERN, "result:3;vara:1;varb:2"); + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) + .collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_examples_test_case_id(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_examples_test_case_id(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(2)).startTestItem(same(featureId), captor.capture()); - verify(client, times(2)).startTestItem(same(exampleIds.get(0)), captor.capture()); - verify(client, times(2)).startTestItem(same(exampleIds.get(1)), captor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(2)).startTestItem(same(featureId), captor.capture()); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), captor.capture()); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), captor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(7)); + List items = captor.getAllValues(); + assertThat(items, hasSize(7)); - StartTestItemRQ firstScenarioRq = items.get(1); - assertThat(firstScenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_TEST_CASE_ID))); + StartTestItemRQ firstScenarioRq = items.get(1); + assertThat(firstScenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_TEST_CASE_ID))); - StartTestItemRQ secondScenarioRq = items.get(2); - assertThat(secondScenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_TEST_CASE_ID))); - } + StartTestItemRQ secondScenarioRq = items.get(2); + assertThat(secondScenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_TEST_CASE_ID))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java b/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java index cc2cbdb..b85331c 100644 --- a/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java +++ b/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.id; import com.epam.reportportal.karate.utils.TestUtils; @@ -7,7 +23,6 @@ import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; @@ -23,43 +38,41 @@ import static org.mockito.Mockito.*; public class ScenarioTestCaseIdTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); - - private static final String SIMPLE_TEST_CASE_ID = "feature/simple.feature/[SCENARIO:Verify math]"; - - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private static final String SIMPLE_TEST_CASE_ID = "feature/simple.feature/[SCENARIO:Verify math]"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_test_case_id(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_test_case_id(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(1)).startTestItem(same(featureId), captor.capture()); - verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(5)); + List items = captor.getAllValues(); + assertThat(items, hasSize(5)); - StartTestItemRQ scenarioRq = items.get(1); - assertThat(scenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(SIMPLE_TEST_CASE_ID))); - } + StartTestItemRQ scenarioRq = items.get(1); + assertThat(scenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(SIMPLE_TEST_CASE_ID))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java b/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java index d98bd33..256bf91 100644 --- a/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java +++ b/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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, @@ -23,7 +23,6 @@ import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; import com.intuit.karate.Results; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; @@ -40,40 +39,40 @@ import static org.mockito.Mockito.verify; public class LaunchRequiredFieldsTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void verify_start_launch_request_contains_required_fields(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void verify_start_launch_request_contains_required_fields(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); - verify(client).startLaunch(startCaptor.capture()); + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); - StartLaunchRQ launchStart = startCaptor.getValue(); - assertThat(launchStart.getName(), startsWith("My-test-launch")); - assertThat(launchStart.getStartTime(), notNullValue()); - assertThat(System.currentTimeMillis() - launchStart.getStartTime().getTime(), - not(greaterThan(TimeUnit.SECONDS.toMillis(10)))); + StartLaunchRQ launchStart = startCaptor.getValue(); + assertThat(launchStart.getName(), startsWith("My-test-launch")); + assertThat(launchStart.getStartTime(), notNullValue()); + assertThat(System.currentTimeMillis() - launchStart.getStartTime().getTime(), + not(greaterThan(TimeUnit.SECONDS.toMillis(10)))); - } + } } diff --git a/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java b/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java index 329f268..6c2effe 100644 --- a/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java +++ b/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java @@ -1,17 +1,17 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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 * - * https://www.apache.org/licenses/LICENSE-2.0 + * 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. + * 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. */ package com.epam.reportportal.karate.logging; @@ -39,51 +39,51 @@ import static org.mockito.Mockito.*; public class HttpRequestLoggingTest { - private static final String TEST_FEATURE = "classpath:feature/http_request.feature"; - private final String launchUuid = CommonUtils.namedId("launch_"); - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(6).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/http_request.feature"; + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(6).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - @SuppressWarnings({"unchecked", "rawtypes"}) - public void test_http_request_logging(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + @SuppressWarnings({"unchecked", "rawtypes"}) + public void test_http_request_logging(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); - verify(client, atLeastOnce()).log(logCaptor.capture()); - List logs = logCaptor - .getAllValues(). - stream() - .flatMap(rq -> extractJsonParts((List) rq).stream()) - .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel()) || LogLevel.DEBUG.name().equals(rq.getLevel())) - .collect(Collectors.toList()); + ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); + verify(client, atLeastOnce()).log(logCaptor.capture()); + List logs = logCaptor + .getAllValues(). + stream() + .flatMap(rq -> extractJsonParts((List) rq).stream()) + .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel()) || LogLevel.DEBUG.name().equals(rq.getLevel())) + .collect(Collectors.toList()); - assertThat(logs, hasSize(greaterThanOrEqualTo(2))); - List messages = logs.stream().map(SaveLogRQ::getMessage).collect(Collectors.toList()); - assertThat(messages, hasItems( - equalTo("Docstring:\n\n```\n{\n" + - " username: 'user',\n" + - " password: 'password',\n" + - " grant_type: 'password'\n" + - "}\n```"), - containsString("{\"username\":\"user\",\"password\":\"password\",\"grant_type\":\"password\"}"))); - } + assertThat(logs, hasSize(greaterThanOrEqualTo(2))); + List messages = logs.stream().map(SaveLogRQ::getMessage).collect(Collectors.toList()); + assertThat(messages, hasItems( + equalTo("Docstring:\n\n```\n{\n" + + " username: 'user',\n" + + " password: 'password',\n" + + " grant_type: 'password'\n" + + "}\n```"), + containsString("{\"username\":\"user\",\"password\":\"password\",\"grant_type\":\"password\"}"))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java b/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java index 4102953..d99f07a 100644 --- a/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java +++ b/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java @@ -1,17 +1,17 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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 * - * https://www.apache.org/licenses/LICENSE-2.0 + * 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. + * 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. */ package com.epam.reportportal.karate.logging; @@ -39,49 +39,49 @@ import static org.mockito.Mockito.*; public class SimpleFailureLoggingTest { - private static final String TEST_FEATURE = "classpath:feature/simple_failed.feature"; - private final String launchUuid = CommonUtils.namedId("launch_"); - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple_failed.feature"; + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - @SuppressWarnings({"unchecked", "rawtypes"}) - public void test_simple_one_step_failed_error_log(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(1)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + @SuppressWarnings({"unchecked", "rawtypes"}) + public void test_simple_one_step_failed_error_log(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(1)); - ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); - verify(client, atLeastOnce()).log(logCaptor.capture()); - List logs = logCaptor - .getAllValues(). - stream() - .flatMap(rq -> extractJsonParts((List) rq).stream()) - .filter(rq -> LogLevel.ERROR.name().equals(rq.getLevel())) - .collect(Collectors.toList()); + ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); + verify(client, atLeastOnce()).log(logCaptor.capture()); + List logs = logCaptor + .getAllValues(). + stream() + .flatMap(rq -> extractJsonParts((List) rq).stream()) + .filter(rq -> LogLevel.ERROR.name().equals(rq.getLevel())) + .collect(Collectors.toList()); - assertThat(logs, hasSize(greaterThan(0))); - SaveLogRQ log = logs.get(logs.size() - 1); - assertThat(log.getItemUuid(), oneOf(stepIds.toArray(new String[0]))); - assertThat(log.getLaunchUuid(), equalTo(launchUuid)); - assertThat(log.getMessage(), equalTo("Then assert actualFour != four\n" - + "did not evaluate to 'true': actualFour != four\n" - + "classpath:feature/simple_failed.feature:6")); - } + assertThat(logs, hasSize(greaterThan(0))); + SaveLogRQ log = logs.get(logs.size() - 1); + assertThat(log.getItemUuid(), oneOf(stepIds.toArray(new String[0]))); + assertThat(log.getLaunchUuid(), equalTo(launchUuid)); + assertThat(log.getMessage(), equalTo("Then assert actualFour != four\n" + + "did not evaluate to 'true': actualFour != four\n" + + "classpath:feature/simple_failed.feature:6")); + } } diff --git a/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java b/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java index 8ee70a3..8e392ef 100644 --- a/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java +++ b/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.name; import com.epam.reportportal.karate.utils.TestUtils; @@ -22,51 +38,49 @@ import static org.mockito.Mockito.*; public class SimpleItemNameTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); - - private static final String[] STEP_NAMES = new String[]{"Given def four = 4", "When def actualFour = 2 * 2", - "Then assert actualFour == four"}; - - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private static final String[] STEP_NAMES = new String[]{"Given def four = 4", "When def actualFour = 2 * 2", + "Then assert actualFour == four"}; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_item_names_simple(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_item_names_simple(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); - StartTestItemRQ featureRq = featureCaptor.getValue(); - StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); + StartTestItemRQ featureRq = featureCaptor.getValue(); + StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); - assertThat(featureRq.getName(), allOf(notNullValue(), equalTo("the very basic test to run by Karate"))); + assertThat(featureRq.getName(), allOf(notNullValue(), equalTo("the very basic test to run by Karate"))); - assertThat(scenarioRq.getName(), allOf(notNullValue(), equalTo("Verify math"))); + assertThat(scenarioRq.getName(), allOf(notNullValue(), equalTo("Verify math"))); - List stepNames = stepCaptor.getAllValues().stream().map(StartTestItemRQ::getName) - .collect(Collectors.toList()); - assertThat(stepNames, containsInAnyOrder(STEP_NAMES)); - } + List stepNames = stepCaptor.getAllValues().stream().map(StartTestItemRQ::getName) + .collect(Collectors.toList()); + assertThat(stepNames, containsInAnyOrder(STEP_NAMES)); + } } diff --git a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java index ef7e4fc..b9763aa 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.parameters; import com.epam.reportportal.karate.utils.TestUtils; @@ -24,58 +40,58 @@ import static org.mockito.Mockito.*; public class ExamplesScenarioParametersTest { - private static final String TEST_FEATURE = "classpath:feature/examples.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) - .collect(Collectors.toList()); - private final List>> stepIds = exampleIds.stream() - .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(2).collect(Collectors.toList()))) - .collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) + .collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_examples_scenario_parameters(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_examples_scenario_parameters(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(2)).startTestItem(same(featureId), captor.capture()); - verify(client, times(2)).startTestItem(same(exampleIds.get(0)), captor.capture()); - verify(client, times(2)).startTestItem(same(exampleIds.get(1)), captor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(2)).startTestItem(same(featureId), captor.capture()); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), captor.capture()); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), captor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(7)); + List items = captor.getAllValues(); + assertThat(items, hasSize(7)); - StartTestItemRQ firstScenarioRq = items.get(1); - StartTestItemRQ secondScenarioRq = items.get(2); - List firstParameters = firstScenarioRq.getParameters(); - List secondParameters = secondScenarioRq.getParameters(); - assertThat(firstParameters, hasSize(3)); - assertThat(secondParameters, hasSize(3)); + StartTestItemRQ firstScenarioRq = items.get(1); + StartTestItemRQ secondScenarioRq = items.get(2); + List firstParameters = firstScenarioRq.getParameters(); + List secondParameters = secondScenarioRq.getParameters(); + assertThat(firstParameters, hasSize(3)); + assertThat(secondParameters, hasSize(3)); - assertThat( - firstParameters.stream().map(p -> p.getKey() + ":" + p.getValue()).collect(Collectors.toSet()), - allOf(hasItem("vara:2"), hasItem("varb:2"), hasItem("result:4")) - ); - assertThat( - secondParameters.stream().map(p -> p.getKey() + ":" + p.getValue()).collect(Collectors.toSet()), - allOf(hasItem("vara:1"), hasItem("varb:2"), hasItem("result:3")) - ); - } + assertThat( + firstParameters.stream().map(p -> p.getKey() + ":" + p.getValue()).collect(Collectors.toSet()), + allOf(hasItem("vara:2"), hasItem("varb:2"), hasItem("result:4")) + ); + assertThat( + secondParameters.stream().map(p -> p.getKey() + ":" + p.getValue()).collect(Collectors.toSet()), + allOf(hasItem("vara:1"), hasItem("varb:2"), hasItem("result:3")) + ); + } } diff --git a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java index 25a17ea..ba675f2 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.parameters; import com.epam.reportportal.karate.utils.TestUtils; @@ -32,80 +48,80 @@ import static org.mockito.Mockito.*; public class ExamplesStepParametersTest { - private static final String TEST_FEATURE = "classpath:feature/examples.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) - .collect(Collectors.toList()); - private final List>> stepIds = exampleIds.stream() - .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(2).collect(Collectors.toList()))) - .collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) + .collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, stepIds); - mockBatchLogging(client); - } + private static Set toParameterStringList(List parameters) { + return ofNullable(parameters) + .flatMap(Collection::stream) + .map(p -> p.getKey() + ":" + p.getValue()) + .collect(Collectors.toSet()); + } - private static Set toParameterStringList(List parameters) { - return ofNullable(parameters) - .flatMap(Collection::stream) - .map(p -> p.getKey() + ":" + p.getValue()) - .collect(Collectors.toSet()); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - @SuppressWarnings({"unchecked", "rawtypes"}) - public void test_examples_parameters_for_steps(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + @SuppressWarnings({"unchecked", "rawtypes"}) + public void test_examples_parameters_for_steps(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(captor.capture()); - verify(client, times(2)).startTestItem(same(featureId), captor.capture()); - ArgumentCaptor firstExampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstExampleCaptor.capture()); - ArgumentCaptor secondExampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondExampleCaptor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client, times(2)).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor firstExampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstExampleCaptor.capture()); + ArgumentCaptor secondExampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondExampleCaptor.capture()); - List firstSteps = firstExampleCaptor.getAllValues(); - Set parameterStrings = toParameterStringList(firstSteps.get(0).getParameters()); - assertThat(parameterStrings, hasSize(2)); - assertThat(parameterStrings, allOf(hasItem("vara:2"), hasItem("varb:2"))); - parameterStrings = toParameterStringList(firstSteps.get(1).getParameters()); - assertThat(parameterStrings, hasSize(1)); - assertThat(parameterStrings, hasItem("result:4")); + List firstSteps = firstExampleCaptor.getAllValues(); + Set parameterStrings = toParameterStringList(firstSteps.get(0).getParameters()); + assertThat(parameterStrings, hasSize(2)); + assertThat(parameterStrings, allOf(hasItem("vara:2"), hasItem("varb:2"))); + parameterStrings = toParameterStringList(firstSteps.get(1).getParameters()); + assertThat(parameterStrings, hasSize(1)); + assertThat(parameterStrings, hasItem("result:4")); - List secondSteps = secondExampleCaptor.getAllValues(); - parameterStrings = toParameterStringList(secondSteps.get(0).getParameters()); - assertThat(parameterStrings, hasSize(2)); - assertThat(parameterStrings, allOf(hasItem("vara:1"), hasItem("varb:2"))); - parameterStrings = toParameterStringList(secondSteps.get(1).getParameters()); - assertThat(parameterStrings, hasSize(1)); - assertThat(parameterStrings, hasItem("result:3")); + List secondSteps = secondExampleCaptor.getAllValues(); + parameterStrings = toParameterStringList(secondSteps.get(0).getParameters()); + assertThat(parameterStrings, hasSize(2)); + assertThat(parameterStrings, allOf(hasItem("vara:1"), hasItem("varb:2"))); + parameterStrings = toParameterStringList(secondSteps.get(1).getParameters()); + assertThat(parameterStrings, hasSize(1)); + assertThat(parameterStrings, hasItem("result:3")); - ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); - verify(client, atLeastOnce()).log(logCaptor.capture()); - Map logs = logCaptor - .getAllValues(). - stream() - .flatMap(rq -> extractJsonParts((List) rq).stream()) - .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel())) - .collect(Collectors.toMap(SaveLogRQ::getItemUuid, v -> v)); + ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); + verify(client, atLeastOnce()).log(logCaptor.capture()); + Map logs = logCaptor + .getAllValues(). + stream() + .flatMap(rq -> extractJsonParts((List) rq).stream()) + .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel())) + .collect(Collectors.toMap(SaveLogRQ::getItemUuid, v -> v)); - List stepIdList = stepIds.stream().flatMap(e -> e.getValue().stream()).collect(Collectors.toList()); - assertThat(logs.keySet(), hasSize(stepIdList.size())); - stepIdList.forEach(id -> assertThat(logs, hasKey(id))); - assertThat(logs.values().stream().map(SaveLogRQ::getMessage).collect(Collectors.toList()), - everyItem(startsWith("Parameters:\n\n"))); - } + List stepIdList = stepIds.stream().flatMap(e -> e.getValue().stream()).collect(Collectors.toList()); + assertThat(logs.keySet(), hasSize(stepIdList.size())); + stepIdList.forEach(id -> assertThat(logs, hasKey(id))); + assertThat(logs.values().stream().map(SaveLogRQ::getMessage).collect(Collectors.toList()), + everyItem(startsWith("Parameters:\n\n"))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java index 440f7c6..ff530f3 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.parameters; import com.epam.reportportal.karate.utils.TestUtils; @@ -22,46 +38,46 @@ import static org.mockito.Mockito.*; public class NoParametersTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_no_parameters_reporting(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_no_parameters_reporting(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(1)).startTestItem(same(featureId), captor.capture()); - verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(5)); + List items = captor.getAllValues(); + assertThat(items, hasSize(5)); - StartTestItemRQ featureRq = items.get(0); - StartTestItemRQ scenarioRq = items.get(1); + StartTestItemRQ featureRq = items.get(0); + StartTestItemRQ scenarioRq = items.get(1); - assertThat(featureRq.getParameters(), nullValue()); - assertThat(scenarioRq.getParameters(), nullValue()); + assertThat(featureRq.getParameters(), nullValue()); + assertThat(scenarioRq.getParameters(), nullValue()); - items.subList(2, items.size()).forEach(step -> assertThat(step.getParameters(), nullValue())); - } + items.subList(2, items.size()).forEach(step -> assertThat(step.getParameters(), nullValue())); + } } diff --git a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java index 7f87d43..db4523b 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.parameters; import com.epam.reportportal.karate.utils.TestUtils; @@ -26,52 +42,52 @@ import static org.mockito.Mockito.*; public class TableParametersTest { - private static final String TEST_FEATURE = "classpath:feature/table.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(4).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/table.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(4).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - @SuppressWarnings({"unchecked", "rawtypes"}) - public void test_table_parameters_reporting(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + @SuppressWarnings({"unchecked", "rawtypes"}) + public void test_table_parameters_reporting(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(1)).startTestItem(same(featureId), captor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(4)).startTestItem(same(scenarioId), stepCaptor.capture()); - ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); - verify(client, atLeastOnce()).log(logCaptor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(4)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); + verify(client, atLeastOnce()).log(logCaptor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(2)); + List items = captor.getAllValues(); + assertThat(items, hasSize(2)); - List logs = logCaptor - .getAllValues(). - stream() - .flatMap(rq -> extractJsonParts((List) rq).stream()) - .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel())) - .collect(Collectors.toList()); - assertThat(logs, hasSize(1)); - assertThat(logs.get(0).getMessage(), startsWith("Table:\n\n")); - assertThat(logs.get(0).getItemUuid(), startsWith("step_")); - } + List logs = logCaptor + .getAllValues(). + stream() + .flatMap(rq -> extractJsonParts((List) rq).stream()) + .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel())) + .collect(Collectors.toList()); + assertThat(logs, hasSize(1)); + assertThat(logs.get(0).getMessage(), startsWith("Table:\n\n")); + assertThat(logs.get(0).getItemUuid(), startsWith("step_")); + } } diff --git a/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java b/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java index af23e48..5192377 100644 --- a/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java +++ b/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java @@ -1,17 +1,17 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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 * - * https://www.apache.org/licenses/LICENSE-2.0 + * 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. + * 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. */ package com.epam.reportportal.karate.status; @@ -39,57 +39,57 @@ import static org.mockito.Mockito.*; public class SimpleAllPassedTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String launchUuid = CommonUtils.namedId("launch_"); - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_simple_all_passed(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_simple_all_passed(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - verify(client).finishTestItem(same(featureId), featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - verify(client).finishTestItem(same(scenarioId), scenarioCaptor.capture()); - List> stepCaptors = - Stream.generate(() -> ArgumentCaptor.forClass(FinishTestItemRQ.class)).limit(stepIds.size()).collect(Collectors.toList()); - IntStream.range(0, stepIds.size()).forEach(i -> verify(client).finishTestItem(same(stepIds.get(i)), stepCaptors.get(i).capture())); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(client).finishTestItem(same(featureId), featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(client).finishTestItem(same(scenarioId), scenarioCaptor.capture()); + List> stepCaptors = + Stream.generate(() -> ArgumentCaptor.forClass(FinishTestItemRQ.class)).limit(stepIds.size()).collect(Collectors.toList()); + IntStream.range(0, stepIds.size()).forEach(i -> verify(client).finishTestItem(same(stepIds.get(i)), stepCaptors.get(i).capture())); - FinishTestItemRQ featureRq = featureCaptor.getValue(); - FinishTestItemRQ scenarioRq = scenarioCaptor.getValue(); + FinishTestItemRQ featureRq = featureCaptor.getValue(); + FinishTestItemRQ scenarioRq = scenarioCaptor.getValue(); - assertThat(featureRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); - assertThat(featureRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); - assertThat(featureRq.getEndTime(), notNullValue()); + assertThat(featureRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); + assertThat(featureRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(featureRq.getEndTime(), notNullValue()); - assertThat(scenarioRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); - assertThat(scenarioRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); - assertThat(scenarioRq.getEndTime(), notNullValue()); + assertThat(scenarioRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); + assertThat(scenarioRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(scenarioRq.getEndTime(), notNullValue()); - stepCaptors.forEach(stepCaptor -> { - FinishTestItemRQ step = stepCaptor.getValue(); - assertThat(step.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); - assertThat(step.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); - assertThat(step.getEndTime(), notNullValue()); - }); - } + stepCaptors.forEach(stepCaptor -> { + FinishTestItemRQ step = stepCaptor.getValue(); + assertThat(step.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); + assertThat(step.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(step.getEndTime(), notNullValue()); + }); + } } \ No newline at end of file diff --git a/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java b/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java index 888232d..02656b5 100644 --- a/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java +++ b/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java @@ -1,17 +1,17 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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 * - * https://www.apache.org/licenses/LICENSE-2.0 + * 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. + * 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. */ package com.epam.reportportal.karate.status; @@ -40,58 +40,58 @@ import static org.mockito.Mockito.*; public class SimpleOneStepFailedTest { - private static final String TEST_FEATURE = "classpath:feature/simple_failed.feature"; - private final String launchUuid = CommonUtils.namedId("launch_"); - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple_failed.feature"; + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_simple_one_step_failed(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(1)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_simple_one_step_failed(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(1)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - verify(client).finishTestItem(same(featureId), featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - verify(client).finishTestItem(same(scenarioId), scenarioCaptor.capture()); - List> stepCaptors = - Stream.generate(() -> ArgumentCaptor.forClass(FinishTestItemRQ.class)).limit(stepIds.size()).collect(Collectors.toList()); - IntStream.range(0, stepIds.size()).forEach(i -> verify(client).finishTestItem(same(stepIds.get(i)), stepCaptors.get(i).capture())); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(client).finishTestItem(same(featureId), featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(client).finishTestItem(same(scenarioId), scenarioCaptor.capture()); + List> stepCaptors = + Stream.generate(() -> ArgumentCaptor.forClass(FinishTestItemRQ.class)).limit(stepIds.size()).collect(Collectors.toList()); + IntStream.range(0, stepIds.size()).forEach(i -> verify(client).finishTestItem(same(stepIds.get(i)), stepCaptors.get(i).capture())); - FinishTestItemRQ featureRq = featureCaptor.getValue(); - FinishTestItemRQ scenarioRq = scenarioCaptor.getValue(); + FinishTestItemRQ featureRq = featureCaptor.getValue(); + FinishTestItemRQ scenarioRq = scenarioCaptor.getValue(); - assertThat(featureRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.FAILED.name()))); - assertThat(featureRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); - assertThat(featureRq.getEndTime(), notNullValue()); + assertThat(featureRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.FAILED.name()))); + assertThat(featureRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(featureRq.getEndTime(), notNullValue()); - assertThat(scenarioRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.FAILED.name()))); - assertThat(scenarioRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); - assertThat(scenarioRq.getEndTime(), notNullValue()); + assertThat(scenarioRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.FAILED.name()))); + assertThat(scenarioRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(scenarioRq.getEndTime(), notNullValue()); - List steps = stepCaptors.stream().map(ArgumentCaptor::getValue).collect(Collectors.toList()); - steps.forEach(step -> { - assertThat(step.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); - assertThat(step.getEndTime(), notNullValue()); - }); - List statuses = steps.stream().map(FinishExecutionRQ::getStatus).collect(Collectors.toList()); - assertThat(statuses, containsInAnyOrder("PASSED", "PASSED", "FAILED")); - } + List steps = stepCaptors.stream().map(ArgumentCaptor::getValue).collect(Collectors.toList()); + steps.forEach(step -> { + assertThat(step.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(step.getEndTime(), notNullValue()); + }); + List statuses = steps.stream().map(FinishExecutionRQ::getStatus).collect(Collectors.toList()); + assertThat(statuses, containsInAnyOrder("PASSED", "PASSED", "FAILED")); + } } diff --git a/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java b/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java index 675a548..d6fb98a 100644 --- a/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java +++ b/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java @@ -1,17 +1,17 @@ /* - * Copyright 2023 EPAM Systems + * Copyright 2024 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 + * 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 * - * https://www.apache.org/licenses/LICENSE-2.0 + * 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. + * 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. */ package com.epam.reportportal.karate.timing; @@ -38,64 +38,64 @@ import static org.mockito.Mockito.*; public class SimpleTimingTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String launchUuid = CommonUtils.namedId("launch_"); - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_each_item_has_correct_start_date(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void test_each_item_has_correct_start_date(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor launchCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); - verify(client).startLaunch(launchCaptor.capture()); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor launchCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(launchCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); - StartLaunchRQ launchRq = launchCaptor.getValue(); - StartTestItemRQ featureRq = featureCaptor.getValue(); - StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); + StartLaunchRQ launchRq = launchCaptor.getValue(); + StartTestItemRQ featureRq = featureCaptor.getValue(); + StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); - assertThat("Launch start time is greater than Feature start time.", - featureRq.getStartTime(), greaterThanOrEqualTo(launchRq.getStartTime())); - assertThat("Feature start time is greater than Scenario start time.", - scenarioRq.getStartTime(), greaterThanOrEqualTo(featureRq.getStartTime())); + assertThat("Launch start time is greater than Feature start time.", + featureRq.getStartTime(), greaterThanOrEqualTo(launchRq.getStartTime())); + assertThat("Feature start time is greater than Scenario start time.", + scenarioRq.getStartTime(), greaterThanOrEqualTo(featureRq.getStartTime())); - List steps = stepCaptor.getAllValues(); - StartTestItemRQ firstStep = steps.stream() - .filter(s -> "Given def four = 4".equals(s.getName())).findAny().orElseThrow(); - StartTestItemRQ secondStep = steps.stream() - .filter(s -> "When def actualFour = 2 * 2".equals(s.getName())).findAny().orElseThrow(); - StartTestItemRQ thirdStep = steps.stream() - .filter(s -> "Then assert actualFour == four".equals(s.getName())).findAny().orElseThrow(); + List steps = stepCaptor.getAllValues(); + StartTestItemRQ firstStep = steps.stream() + .filter(s -> "Given def four = 4".equals(s.getName())).findAny().orElseThrow(); + StartTestItemRQ secondStep = steps.stream() + .filter(s -> "When def actualFour = 2 * 2".equals(s.getName())).findAny().orElseThrow(); + StartTestItemRQ thirdStep = steps.stream() + .filter(s -> "Then assert actualFour == four".equals(s.getName())).findAny().orElseThrow(); - assertThat("Scenario start time is greater than Step start time.", - firstStep.getStartTime(), greaterThanOrEqualTo(scenarioRq.getStartTime())); - assertThat("First Step start time is greater or equal than Second Step start time.", - secondStep.getStartTime(), greaterThan(firstStep.getStartTime())); - assertThat("Second Step start time is greater or equal than Third Step start time.", - thirdStep.getStartTime(), greaterThan(secondStep.getStartTime())); - } + assertThat("Scenario start time is greater than Step start time.", + firstStep.getStartTime(), greaterThanOrEqualTo(scenarioRq.getStartTime())); + assertThat("First Step start time is greater or equal than Second Step start time.", + secondStep.getStartTime(), greaterThan(firstStep.getStartTime())); + assertThat("Second Step start time is greater or equal than Third Step start time.", + thirdStep.getStartTime(), greaterThan(secondStep.getStartTime())); + } } diff --git a/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java b/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java index f1a1488..b8169ab 100644 --- a/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java +++ b/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java @@ -1,19 +1,35 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.utils; import java.lang.reflect.Field; public class ReflectUtils { - private ReflectUtils() { - } + private ReflectUtils() { + } - public static void setField(Object object, Field fld, Object value) { - try { - fld.setAccessible(true); - fld.set(object, value); - } catch (IllegalAccessException e) { - String fieldName = fld.getName(); - throw new RuntimeException("Failed to set " + fieldName + " of object", e); - } - } + public static void setField(Object object, Field fld, Object value) { + try { + fld.setAccessible(true); + fld.set(object, value); + } catch (IllegalAccessException e) { + String fieldName = fld.getName(); + throw new RuntimeException("Failed to set " + fieldName + " of object", e); + } + } } diff --git a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java index e691150..9d66e95 100644 --- a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java +++ b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java @@ -1,3 +1,19 @@ +/* + * Copyright 2024 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. + */ + package com.epam.reportportal.karate.utils; import com.epam.reportportal.karate.KarateReportPortalRunner; @@ -36,183 +52,183 @@ import static org.mockito.Mockito.when; public class TestUtils { - public static final String ROOT_SUITE_PREFIX = "root_"; - - private TestUtils() { - } - - public static ExecutorService testExecutor() { - return Executors.newSingleThreadExecutor(r -> { - Thread t = new Thread(r); - t.setDaemon(true); - return t; - }); - } - - public static Results runAsReport(ReportPortal reportPortal, String... paths) { - return KarateReportPortalRunner - .path(paths) - .withReportPortal(reportPortal) - .outputCucumberJson(false) - .parallel(1); - } - - public static Results runAsHook(ReportPortal reportPortal, String... paths) { - return Runner - .path(paths) - .hook(new ReportPortalHook(reportPortal)) - .outputCucumberJson(false) - .parallel(1); - } - - public static ListenerParameters standardParameters() { - ListenerParameters result = new ListenerParameters(); - result.setClientJoin(false); - result.setLaunchName("My-test-launch" + generateUniqueId()); - result.setProjectName("test-project"); - result.setEnable(true); - result.setCallbackReportingEnabled(true); - result.setBaseUrl("http://localhost:8080"); - return result; - } - - public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid, - @Nullable final String featureUuid, @Nonnull String scenarioUuid, - @Nonnull String stepUuid) { - mockLaunch(client, launchUuid, featureUuid, scenarioUuid, Collections.singleton(stepUuid)); - } - - public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid, - @Nullable final String featureUuid, @Nonnull String scenarioUuid, - @Nonnull Collection stepList) { - mockLaunch(client, launchUuid, featureUuid, Collections.singletonList(Pair.of(scenarioUuid, stepList))); - } - - public static > void mockLaunch( - @Nonnull final ReportPortalClient client, @Nullable final String launchUuid, - @Nullable final String featureUuid, @Nonnull final Collection> scenarioSteps) { - String launch = ofNullable(launchUuid).orElse(CommonUtils.namedId("launch_")); - when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launch, 1L))); - when(client.finishLaunch(eq(launch), any())).thenReturn(Maybe.just(new OperationCompletionRS())); - - mockFeature(client, featureUuid, scenarioSteps); - } - - public static void mockLaunch( - @Nonnull final ReportPortalClient client, @Nullable final String launchUuid) { - String launch = ofNullable(launchUuid).orElse(CommonUtils.namedId("launch_")); - when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launch, 1L))); - when(client.finishLaunch(eq(launch), any())).thenReturn(Maybe.just(new OperationCompletionRS())); - } - - public static > void mockFeature( - @Nonnull final ReportPortalClient client, @Nullable final String featureUuid, - @Nonnull final Collection> scenarioSteps) { - String rootItemId = ofNullable(featureUuid).orElseGet(() -> CommonUtils.namedId(ROOT_SUITE_PREFIX)); - mockFeatures(client, Collections.singletonList(Pair.of(rootItemId, scenarioSteps))); - } - - @SuppressWarnings("unchecked") - public static > void mockFeatures( - @Nonnull final ReportPortalClient client, - @Nonnull final List>>> features) { - if (features.isEmpty()) { - return; - } - String firstFeature = features.get(0).getKey(); - Maybe first = Maybe.just(new ItemCreatedRS(firstFeature, firstFeature)); - Maybe[] other = (Maybe[]) features.subList(1, features.size()) - .stream() - .map(Pair::getKey) - .map(s -> Maybe.just(new ItemCreatedRS(s, s))) - .toArray(Maybe[]::new); - when(client.startTestItem(any())).thenReturn(first, other); - - features.forEach(i -> { - Maybe rootFinishMaybe = Maybe.just(new OperationCompletionRS()); - when(client.finishTestItem(same(i.getKey()), any())).thenReturn(rootFinishMaybe); - mockScenario(client, i.getKey(), i.getValue()); - }); - } - - @SuppressWarnings("unchecked") - public static > void mockScenario( - @Nonnull final ReportPortalClient client, @Nonnull final String featureUuid, - @Nonnull final Collection> scenarioSteps) { - List> testResponses = scenarioSteps.stream() - .map(Pair::getKey) - .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) - .collect(Collectors.toList()); - - Maybe first = testResponses.get(0); - Maybe[] other = testResponses.subList(1, testResponses.size()).toArray(new Maybe[0]); - when(client.startTestItem(same(featureUuid), any())).thenReturn(first, other); - - scenarioSteps.forEach(test -> { - String scenarioUuid = test.getKey(); - List> stepResponses = test.getValue() - .stream() - .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) - .collect(Collectors.toList()); - when(client.finishTestItem(same(scenarioUuid), any())).thenReturn(Maybe.just(new OperationCompletionRS())); - if (!stepResponses.isEmpty()) { - Maybe myFirst = stepResponses.get(0); - Maybe[] myOther = stepResponses.subList(1, stepResponses.size()).toArray(new Maybe[0]); - when(client.startTestItem(same(scenarioUuid), any())).thenReturn(myFirst, myOther); - new HashSet<>(test.getValue()).forEach(testMethodUuid -> when( - client.finishTestItem(same(testMethodUuid), - any() - )).thenReturn(Maybe.just(new OperationCompletionRS()))); - } - }); - } - - @SuppressWarnings("unchecked") - public static void mockBatchLogging(final ReportPortalClient client) { - when(client.log(any(List.class))).thenReturn(Maybe.just(new BatchSaveOperatingRS())); - } - - @SuppressWarnings("unchecked") - public static void mockNestedSteps(final ReportPortalClient client, final List> parentNestedPairs) { - Map> responseOrders = parentNestedPairs.stream() - .collect(Collectors.groupingBy(Pair::getKey, Collectors.mapping(Pair::getValue, Collectors.toList()))); - responseOrders.forEach((k, v) -> { - List> responses = v.stream() - .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) - .collect(Collectors.toList()); - - Maybe first = responses.get(0); - Maybe[] other = responses.subList(1, responses.size()).toArray(new Maybe[0]); - when(client.startTestItem(eq(k), any())).thenReturn(first, other); - }); - parentNestedPairs.forEach(p -> when(client.finishTestItem(same(p.getValue()), - any() - )).thenAnswer((Answer>) invocation -> Maybe.just(new OperationCompletionRS()))); - } - - public static List extractJsonParts(List parts) { - return parts.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 final String ROOT_SUITE_PREFIX = "root_"; + + private TestUtils() { + } + + public static ExecutorService testExecutor() { + return Executors.newSingleThreadExecutor(r -> { + Thread t = new Thread(r); + t.setDaemon(true); + return t; + }); + } + + public static Results runAsReport(ReportPortal reportPortal, String... paths) { + return KarateReportPortalRunner + .path(paths) + .withReportPortal(reportPortal) + .outputCucumberJson(false) + .parallel(1); + } + + public static Results runAsHook(ReportPortal reportPortal, String... paths) { + return Runner + .path(paths) + .hook(new ReportPortalHook(reportPortal)) + .outputCucumberJson(false) + .parallel(1); + } + + public static ListenerParameters standardParameters() { + ListenerParameters result = new ListenerParameters(); + result.setClientJoin(false); + result.setLaunchName("My-test-launch" + generateUniqueId()); + result.setProjectName("test-project"); + result.setEnable(true); + result.setCallbackReportingEnabled(true); + result.setBaseUrl("http://localhost:8080"); + return result; + } + + public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid, + @Nullable final String featureUuid, @Nonnull String scenarioUuid, + @Nonnull String stepUuid) { + mockLaunch(client, launchUuid, featureUuid, scenarioUuid, Collections.singleton(stepUuid)); + } + + public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid, + @Nullable final String featureUuid, @Nonnull String scenarioUuid, + @Nonnull Collection stepList) { + mockLaunch(client, launchUuid, featureUuid, Collections.singletonList(Pair.of(scenarioUuid, stepList))); + } + + public static > void mockLaunch( + @Nonnull final ReportPortalClient client, @Nullable final String launchUuid, + @Nullable final String featureUuid, @Nonnull final Collection> scenarioSteps) { + String launch = ofNullable(launchUuid).orElse(CommonUtils.namedId("launch_")); + when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launch, 1L))); + when(client.finishLaunch(eq(launch), any())).thenReturn(Maybe.just(new OperationCompletionRS())); + + mockFeature(client, featureUuid, scenarioSteps); + } + + public static void mockLaunch( + @Nonnull final ReportPortalClient client, @Nullable final String launchUuid) { + String launch = ofNullable(launchUuid).orElse(CommonUtils.namedId("launch_")); + when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launch, 1L))); + when(client.finishLaunch(eq(launch), any())).thenReturn(Maybe.just(new OperationCompletionRS())); + } + + public static > void mockFeature( + @Nonnull final ReportPortalClient client, @Nullable final String featureUuid, + @Nonnull final Collection> scenarioSteps) { + String rootItemId = ofNullable(featureUuid).orElseGet(() -> CommonUtils.namedId(ROOT_SUITE_PREFIX)); + mockFeatures(client, Collections.singletonList(Pair.of(rootItemId, scenarioSteps))); + } + + @SuppressWarnings("unchecked") + public static > void mockFeatures( + @Nonnull final ReportPortalClient client, + @Nonnull final List>>> features) { + if (features.isEmpty()) { + return; + } + String firstFeature = features.get(0).getKey(); + Maybe first = Maybe.just(new ItemCreatedRS(firstFeature, firstFeature)); + Maybe[] other = (Maybe[]) features.subList(1, features.size()) + .stream() + .map(Pair::getKey) + .map(s -> Maybe.just(new ItemCreatedRS(s, s))) + .toArray(Maybe[]::new); + when(client.startTestItem(any())).thenReturn(first, other); + + features.forEach(i -> { + Maybe rootFinishMaybe = Maybe.just(new OperationCompletionRS()); + when(client.finishTestItem(same(i.getKey()), any())).thenReturn(rootFinishMaybe); + mockScenario(client, i.getKey(), i.getValue()); + }); + } + + @SuppressWarnings("unchecked") + public static > void mockScenario( + @Nonnull final ReportPortalClient client, @Nonnull final String featureUuid, + @Nonnull final Collection> scenarioSteps) { + List> testResponses = scenarioSteps.stream() + .map(Pair::getKey) + .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) + .collect(Collectors.toList()); + + Maybe first = testResponses.get(0); + Maybe[] other = testResponses.subList(1, testResponses.size()).toArray(new Maybe[0]); + when(client.startTestItem(same(featureUuid), any())).thenReturn(first, other); + + scenarioSteps.forEach(test -> { + String scenarioUuid = test.getKey(); + List> stepResponses = test.getValue() + .stream() + .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) + .collect(Collectors.toList()); + when(client.finishTestItem(same(scenarioUuid), any())).thenReturn(Maybe.just(new OperationCompletionRS())); + if (!stepResponses.isEmpty()) { + Maybe myFirst = stepResponses.get(0); + Maybe[] myOther = stepResponses.subList(1, stepResponses.size()).toArray(new Maybe[0]); + when(client.startTestItem(same(scenarioUuid), any())).thenReturn(myFirst, myOther); + new HashSet<>(test.getValue()).forEach(testMethodUuid -> when( + client.finishTestItem(same(testMethodUuid), + any() + )).thenReturn(Maybe.just(new OperationCompletionRS()))); + } + }); + } + + @SuppressWarnings("unchecked") + public static void mockBatchLogging(final ReportPortalClient client) { + when(client.log(any(List.class))).thenReturn(Maybe.just(new BatchSaveOperatingRS())); + } + + @SuppressWarnings("unchecked") + public static void mockNestedSteps(final ReportPortalClient client, final List> parentNestedPairs) { + Map> responseOrders = parentNestedPairs.stream() + .collect(Collectors.groupingBy(Pair::getKey, Collectors.mapping(Pair::getValue, Collectors.toList()))); + responseOrders.forEach((k, v) -> { + List> responses = v.stream() + .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) + .collect(Collectors.toList()); + + Maybe first = responses.get(0); + Maybe[] other = responses.subList(1, responses.size()).toArray(new Maybe[0]); + when(client.startTestItem(eq(k), any())).thenReturn(first, other); + }); + parentNestedPairs.forEach(p -> when(client.finishTestItem(same(p.getValue()), + any() + )).thenAnswer((Answer>) invocation -> Maybe.just(new OperationCompletionRS()))); + } + + public static List extractJsonParts(List parts) { + return parts.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()); + } } diff --git a/src/test/resources/logback.xml b/src/test/resources/logback.xml index 351fb98..d5266de 100644 --- a/src/test/resources/logback.xml +++ b/src/test/resources/logback.xml @@ -1,4 +1,20 @@ + + From 17dc10aabddaa4d5b2858dd72811396ef677b9f5 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 16 Jan 2024 13:38:35 +0300 Subject: [PATCH 72/76] Update copyrights --- build-quality.gradle | 2 +- build.gradle | 2 +- .../com/epam/reportportal/karate/KarateReportPortalRunner.java | 2 +- .../java/com/epam/reportportal/karate/ReportPortalHook.java | 2 +- .../com/epam/reportportal/karate/ReportPortalPublisher.java | 2 +- .../java/com/epam/reportportal/karate/ReportPortalUtils.java | 3 ++- src/test/java/com/epam/reportportal/karate/KarateTest.java | 2 +- .../epam/reportportal/karate/ReportPortalPublisherTest.java | 2 +- .../karate/attributes/DifferentAttributesTest.java | 2 +- .../reportportal/karate/attributes/LaunchAttributesTest.java | 2 +- .../epam/reportportal/karate/attributes/NoAttributesTest.java | 2 +- .../reportportal/karate/attributes/SystemAttributesTest.java | 2 +- .../reportportal/karate/background/BackgroundExamplesTest.java | 2 +- .../epam/reportportal/karate/background/BackgroundTest.java | 2 +- .../reportportal/karate/background/BackgroundTwoStepsTest.java | 2 +- .../epam/reportportal/karate/coderef/ExamplesCodeRefTest.java | 2 +- .../epam/reportportal/karate/coderef/ScenarioCodeRefTest.java | 2 +- .../karate/description/CallWithParametersHookTest.java | 2 +- .../karate/description/CallWithParametersPublisherTest.java | 2 +- .../karate/description/DescriptionExamplesTest.java | 2 +- .../reportportal/karate/description/LaunchDescriptionTest.java | 2 +- .../karate/description/NoDescriptionExamplesTest.java | 2 +- .../reportportal/karate/description/NoDescriptionTest.java | 2 +- .../karate/description/NoLaunchDescriptionTest.java | 2 +- .../reportportal/karate/description/SimpleDescriptionTest.java | 2 +- .../epam/reportportal/karate/id/ExamplesTestCaseIdTest.java | 2 +- .../epam/reportportal/karate/id/ScenarioTestCaseIdTest.java | 2 +- .../reportportal/karate/launch/LaunchRequiredFieldsTest.java | 2 +- .../reportportal/karate/logging/HttpRequestLoggingTest.java | 2 +- .../reportportal/karate/logging/SimpleFailureLoggingTest.java | 2 +- .../com/epam/reportportal/karate/name/SimpleItemNameTest.java | 2 +- .../karate/parameters/ExamplesScenarioParametersTest.java | 2 +- .../karate/parameters/ExamplesStepParametersTest.java | 2 +- .../epam/reportportal/karate/parameters/NoParametersTest.java | 2 +- .../reportportal/karate/parameters/TableParametersTest.java | 2 +- .../epam/reportportal/karate/status/SimpleAllPassedTest.java | 2 +- .../reportportal/karate/status/SimpleOneStepFailedTest.java | 2 +- .../com/epam/reportportal/karate/timing/SimpleTimingTest.java | 2 +- .../java/com/epam/reportportal/karate/utils/ReflectUtils.java | 2 +- .../java/com/epam/reportportal/karate/utils/TestUtils.java | 2 +- src/test/resources/logback.xml | 2 +- 41 files changed, 42 insertions(+), 41 deletions(-) diff --git a/build-quality.gradle b/build-quality.gradle index 9669e07..003f61f 100644 --- a/build-quality.gradle +++ b/build-quality.gradle @@ -5,7 +5,7 @@ * 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, diff --git a/build.gradle b/build.gradle index ab4faa8..016f87b 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ * 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, diff --git a/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java b/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java index 1af15be..19f97cc 100644 --- a/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java +++ b/src/main/java/com/epam/reportportal/karate/KarateReportPortalRunner.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java index 9d4a846..cd377b2 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index 78dd8db..ef827f8 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java index f71e41e..297c38f 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java @@ -5,7 +5,7 @@ * 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, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.epam.reportportal.karate; import com.epam.reportportal.listeners.ItemStatus; diff --git a/src/test/java/com/epam/reportportal/karate/KarateTest.java b/src/test/java/com/epam/reportportal/karate/KarateTest.java index 03c00b1..8d5230c 100644 --- a/src/test/java/com/epam/reportportal/karate/KarateTest.java +++ b/src/test/java/com/epam/reportportal/karate/KarateTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java b/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java index f3d7ea4..fb64dcb 100644 --- a/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java +++ b/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java index 32ec07c..eb526d9 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java index 8884325..ffa77b3 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java index e30bdf1..baece01 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java index a02d216..788bc2b 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java index 14e986b..5c6b5ee 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java index efe74cb..1d72e8a 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java index 23f6469..e66bcea 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java index 6bac079..ddd5f22 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java index 16e0e9f..f459afc 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java index 078566e..3b09ebb 100644 --- a/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java index 0ea501a..f6234c2 100644 --- a/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java b/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java index a818ce0..7da4374 100644 --- a/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java index 94ba58a..9c51dc0 100644 --- a/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java index a9ae375..4d30e48 100644 --- a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java index 4c9041a..57f4e1b 100644 --- a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java index 8567027..a8c0201 100644 --- a/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java index c320514..e8a89f4 100644 --- a/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java b/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java index 1fe9bba..05b232f 100644 --- a/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java +++ b/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java b/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java index b85331c..a3eff8e 100644 --- a/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java +++ b/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java b/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java index 256bf91..5688962 100644 --- a/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java +++ b/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java b/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java index 6c2effe..019efbb 100644 --- a/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java +++ b/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java b/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java index d99f07a..fbfe232 100644 --- a/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java +++ b/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java b/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java index 8e392ef..7fbf724 100644 --- a/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java +++ b/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java index b9763aa..b2a689b 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java index ba675f2..6dc426c 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java index ff530f3..a063c51 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java index db4523b..9d30ae3 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java b/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java index 5192377..2bf7dda 100644 --- a/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java +++ b/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java b/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java index 02656b5..5dd8d33 100644 --- a/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java +++ b/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java b/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java index d6fb98a..af448d6 100644 --- a/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java +++ b/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java b/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java index b8169ab..b940910 100644 --- a/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java +++ b/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java index 9d66e95..3a77ff6 100644 --- a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java +++ b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java @@ -5,7 +5,7 @@ * 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, diff --git a/src/test/resources/logback.xml b/src/test/resources/logback.xml index d5266de..231f74c 100644 --- a/src/test/resources/logback.xml +++ b/src/test/resources/logback.xml @@ -6,7 +6,7 @@ ~ 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, From 1dbae8cace102bc612f186a385cdee8735bcd872 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 16 Jan 2024 13:41:48 +0300 Subject: [PATCH 73/76] Code format apply --- .../reportportal/karate/ReportPortalHook.java | 84 ++--- .../karate/ReportPortalPublisher.java | 56 ++- .../karate/ReportPortalUtils.java | 56 ++- .../epam/reportportal/karate/KarateTest.java | 23 +- .../karate/ReportPortalPublisherTest.java | 102 +++--- .../attributes/DifferentAttributesTest.java | 85 ++--- .../attributes/LaunchAttributesTest.java | 76 ++-- .../karate/attributes/NoAttributesTest.java | 65 ++-- .../attributes/SystemAttributesTest.java | 73 ++-- .../background/BackgroundExamplesTest.java | 130 ++++--- .../karate/background/BackgroundTest.java | 101 +++--- .../background/BackgroundTwoStepsTest.java | 104 +++--- .../karate/coderef/ExamplesCodeRefTest.java | 102 +++--- .../karate/coderef/ScenarioCodeRefTest.java | 77 ++-- .../CallWithParametersHookTest.java | 94 ++--- .../CallWithParametersPublisherTest.java | 43 ++- .../description/DescriptionExamplesTest.java | 94 ++--- .../description/LaunchDescriptionTest.java | 61 ++-- .../NoDescriptionExamplesTest.java | 92 +++-- .../karate/description/NoDescriptionTest.java | 67 ++-- .../description/NoLaunchDescriptionTest.java | 69 ++-- .../description/SimpleDescriptionTest.java | 91 ++--- .../karate/id/ExamplesTestCaseIdTest.java | 81 ++--- .../karate/id/ScenarioTestCaseIdTest.java | 63 ++-- .../launch/LaunchRequiredFieldsTest.java | 58 ++- .../logging/HttpRequestLoggingTest.java | 82 ++--- .../logging/SimpleFailureLoggingTest.java | 79 ++-- .../karate/name/SimpleItemNameTest.java | 74 ++-- .../ExamplesScenarioParametersTest.java | 92 +++-- .../ExamplesStepParametersTest.java | 129 ++++--- .../karate/parameters/NoParametersTest.java | 67 ++-- .../parameters/TableParametersTest.java | 82 ++--- .../karate/status/SimpleAllPassedTest.java | 90 ++--- .../status/SimpleOneStepFailedTest.java | 92 ++--- .../karate/timing/SimpleTimingTest.java | 118 +++--- .../karate/utils/ReflectUtils.java | 22 +- .../reportportal/karate/utils/TestUtils.java | 343 +++++++++--------- src/test/resources/feature/table.feature | 1 + src/test/resources/reportportal.properties | 1 - 39 files changed, 1577 insertions(+), 1642 deletions(-) diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java index cd377b2..1cc9530 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java @@ -54,16 +54,34 @@ */ public class ReportPortalHook implements RuntimeHook { private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalHook.class); - + protected final MemoizingSupplier launch; private final Map> featureIdMap = new ConcurrentHashMap<>(); private final Map> scenarioIdMap = new ConcurrentHashMap<>(); private final Map> backgroundIdMap = new ConcurrentHashMap<>(); private final Map> stepIdMap = new ConcurrentHashMap<>(); private final Map, Date> stepStartTimeMap = new ConcurrentHashMap<>(); + private volatile Thread shutDownHook; - protected final MemoizingSupplier launch; + public ReportPortalHook(ReportPortal reportPortal) { + launch = new MemoizingSupplier<>(() -> { + ListenerParameters params = reportPortal.getParameters(); + StartLaunchRQ rq = buildStartLaunchRq(params); + Launch newLaunch = reportPortal.newLaunch(rq); + //noinspection ReactiveStreamsUnusedPublisher + newLaunch.start(); + shutDownHook = registerShutdownHook(this::finishLaunch); + return newLaunch; + }); + } - private volatile Thread shutDownHook; + public ReportPortalHook() { + this(ReportPortal.builder().build()); + } + + public ReportPortalHook(Supplier launchSupplier) { + launch = new MemoizingSupplier<>(launchSupplier); + shutDownHook = registerShutdownHook(this::finishLaunch); + } /** * Customize start launch event/request @@ -93,35 +111,17 @@ public void finishLaunch() { Launch launchObject = launch.get(); ListenerParameters parameters = launchObject.getParameters(); FinishExecutionRQ rq = buildFinishLaunchRq(parameters); - LOGGER.info("Launch URL: {}/ui/#{}/launches/all/{}", parameters.getBaseUrl(), parameters.getProjectName(), - System.getProperty("rp.launch.id")); + LOGGER.info("Launch URL: {}/ui/#{}/launches/all/{}", + parameters.getBaseUrl(), + parameters.getProjectName(), + System.getProperty("rp.launch.id") + ); launchObject.finish(rq); if (Thread.currentThread() != shutDownHook) { unregisterShutdownHook(shutDownHook); } } - public ReportPortalHook(ReportPortal reportPortal) { - launch = new MemoizingSupplier<>(() -> { - ListenerParameters params = reportPortal.getParameters(); - StartLaunchRQ rq = buildStartLaunchRq(params); - Launch newLaunch = reportPortal.newLaunch(rq); - //noinspection ReactiveStreamsUnusedPublisher - newLaunch.start(); - shutDownHook = registerShutdownHook(this::finishLaunch); - return newLaunch; - }); - } - - public ReportPortalHook() { - this(ReportPortal.builder().build()); - } - - public ReportPortalHook(Supplier launchSupplier) { - launch = new MemoizingSupplier<>(launchSupplier); - shutDownHook = registerShutdownHook(this::finishLaunch); - } - /** * Build ReportPortal request for start Feature event. * @@ -132,8 +132,10 @@ public ReportPortalHook(Supplier launchSupplier) { @SuppressWarnings("unchecked") protected StartTestItemRQ buildStartFeatureRq(@Nonnull FeatureRuntime fr) { StartTestItemRQ rq = ReportPortalUtils.buildStartFeatureRq(fr.featureCall.feature); - ofNullable(fr.caller).map(c -> c.arg).map(a -> (Map) a.getValue()) - .filter(args -> !args.isEmpty()).ifPresent(args -> { + ofNullable(fr.caller).map(c -> c.arg) + .map(a -> (Map) a.getValue()) + .filter(args -> !args.isEmpty()) + .ifPresent(args -> { // TODO: cover with tests String parameters = String.format(PARAMETERS_PATTERN, formatParametersAsTable(getParameters(args))); String description = rq.getDescription(); @@ -162,8 +164,7 @@ public boolean beforeFeature(FeatureRuntime fr) { */ @Nonnull protected FinishTestItemRQ buildFinishFeatureRq(@Nonnull FeatureRuntime fr) { - return buildFinishTestItemRq(Calendar.getInstance().getTime(), - fr.result.isFailed() ? ItemStatus.FAILED : ItemStatus.PASSED); + return buildFinishTestItemRq(Calendar.getInstance().getTime(), fr.result.isFailed() ? ItemStatus.FAILED : ItemStatus.PASSED); } @Override @@ -208,7 +209,8 @@ public boolean beforeScenario(ScenarioRuntime sr) { @Nonnull protected FinishTestItemRQ buildFinishScenarioRq(@Nonnull ScenarioRuntime sr) { return buildFinishTestItemRq(Calendar.getInstance().getTime(), - sr.result.getFailureMessageForDisplay() == null ? ItemStatus.PASSED : ItemStatus.FAILED); + sr.result.getFailureMessageForDisplay() == null ? ItemStatus.PASSED : ItemStatus.FAILED + ); } /** @@ -233,8 +235,7 @@ protected StartTestItemRQ buildStartBackgroundRq(@Nonnull Step step, @Nonnull Sc public Maybe startBackground(@Nonnull Step step, @Nonnull ScenarioRuntime sr) { return backgroundIdMap.computeIfAbsent(sr.scenario.getUniqueId(), k -> { StartTestItemRQ backgroundRq = buildStartBackgroundRq(step, sr); - return launch.get().startTestItem(scenarioIdMap.get(sr.scenario.getUniqueId()), - backgroundRq); + return launch.get().startTestItem(scenarioIdMap.get(sr.scenario.getUniqueId()), backgroundRq); }); } @@ -339,21 +340,12 @@ public boolean beforeStep(Step step, ScenarioRuntime sr) { StartTestItemRQ stepRq = buildStartStepRq(step, sr); String scenarioId = sr.scenario.getUniqueId(); - Maybe stepId = launch.get() - .startTestItem( - background ? backgroundId : scenarioIdMap.get(scenarioId), - stepRq - ); + Maybe stepId = launch.get().startTestItem(background ? backgroundId : scenarioIdMap.get(scenarioId), stepRq); stepStartTimeMap.put(stepId, stepRq.getStartTime()); stepIdMap.put(scenarioId, stepId); - ofNullable(stepRq.getParameters()) - .filter(params -> !params.isEmpty()) - .ifPresent(params -> - sendLog(stepId, String.format(PARAMETERS_PATTERN, formatParametersAsTable(params)), - LogLevel.INFO)); - ofNullable(step.getTable()) - .ifPresent(table -> - sendLog(stepId, "Table:\n\n" + formatDataTable(table.getRows()), LogLevel.INFO)); + ofNullable(stepRq.getParameters()).filter(params -> !params.isEmpty()) + .ifPresent(params -> sendLog(stepId, String.format(PARAMETERS_PATTERN, formatParametersAsTable(params)), LogLevel.INFO)); + ofNullable(step.getTable()).ifPresent(table -> sendLog(stepId, "Table:\n\n" + formatDataTable(table.getRows()), LogLevel.INFO)); String docString = step.getDocString(); if (isNotBlank(docString)) { sendLog(stepId, "Docstring:\n\n" + asMarkdownCode(step.getDocString()), LogLevel.INFO); diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java index ef827f8..90d68e8 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java @@ -47,26 +47,14 @@ */ public class ReportPortalPublisher { private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalPublisher.class); + protected final MemoizingSupplier launch; private final Map> featureIdMap = new HashMap<>(); private final Map> scenarioIdMap = new HashMap<>(); private final Map, Long> stepStartTimeMap = new HashMap<>(); private Maybe backgroundId; private Maybe stepId; - - protected final MemoizingSupplier launch; - private Thread shutDownHook; - /** - * Customize start launch event/request - * - * @param parameters Launch configuration parameters - * @return request to ReportPortal - */ - protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) { - return ReportPortalUtils.buildStartLaunchRq(parameters); - } - public ReportPortalPublisher(ReportPortal reportPortal) { launch = new MemoizingSupplier<>(() -> { ListenerParameters params = reportPortal.getParameters(); @@ -82,6 +70,16 @@ public ReportPortalPublisher(Supplier launchSupplier) { shutDownHook = registerShutdownHook(this::finishLaunch); } + /** + * Customize start launch event/request + * + * @param parameters Launch configuration parameters + * @return request to ReportPortal + */ + protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) { + return ReportPortalUtils.buildStartLaunchRq(parameters); + } + /** * Start sending Launch data to ReportPortal. */ @@ -108,8 +106,11 @@ public void finishLaunch() { Launch launchObject = launch.get(); ListenerParameters parameters = launchObject.getParameters(); FinishExecutionRQ rq = buildFinishLaunchRq(parameters); - LOGGER.info("Launch URL: {}/ui/#{}/launches/all/{}", parameters.getBaseUrl(), parameters.getProjectName(), - System.getProperty("rp.launch.id")); + LOGGER.info("Launch URL: {}/ui/#{}/launches/all/{}", + parameters.getBaseUrl(), + parameters.getProjectName(), + System.getProperty("rp.launch.id") + ); launchObject.finish(rq); if (Thread.currentThread() != shutDownHook) { unregisterShutdownHook(shutDownHook); @@ -146,8 +147,7 @@ public void startFeature(@Nonnull FeatureResult featureResult) { */ @Nonnull protected FinishTestItemRQ buildFinishFeatureRq(@Nonnull FeatureResult featureResult) { - return buildFinishTestItemRq(Calendar.getInstance().getTime(), - featureResult.isFailed() ? ItemStatus.FAILED : ItemStatus.PASSED); + return buildFinishTestItemRq(Calendar.getInstance().getTime(), featureResult.isFailed() ? ItemStatus.FAILED : ItemStatus.PASSED); } /** @@ -212,7 +212,8 @@ public void startScenario(ScenarioResult scenarioResult, FeatureResult featureRe @Nonnull protected FinishTestItemRQ buildFinishScenarioRq(@Nonnull ScenarioResult scenarioResult) { return buildFinishTestItemRq(Calendar.getInstance().getTime(), - scenarioResult.getFailureMessageForDisplay() == null ? ItemStatus.PASSED : ItemStatus.FAILED); + scenarioResult.getFailureMessageForDisplay() == null ? ItemStatus.PASSED : ItemStatus.FAILED + ); } @@ -255,8 +256,7 @@ protected StartTestItemRQ buildStartBackgroundRq(@Nonnull StepResult stepResult, public void startBackground(@Nonnull StepResult stepResult, @Nonnull ScenarioResult scenarioResult) { backgroundId = ofNullable(backgroundId).orElseGet(() -> { StartTestItemRQ backgroundRq = buildStartBackgroundRq(stepResult, scenarioResult); - return launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), - backgroundRq); + return launch.get().startTestItem(scenarioIdMap.get(scenarioResult.getScenario().getName()), backgroundRq); }); } @@ -339,19 +339,11 @@ public void startStep(StepResult stepResult, ScenarioResult scenarioResult) { } StartTestItemRQ stepRq = buildStartStepRq(stepResult, scenarioResult); stepId = launch.get() - .startTestItem( - backgroundId != null ? backgroundId : scenarioIdMap.get(scenarioResult.getScenario().getName()), - stepRq - ); + .startTestItem(backgroundId != null ? backgroundId : scenarioIdMap.get(scenarioResult.getScenario().getName()), stepRq); stepStartTimeMap.put(stepId, stepRq.getStartTime().getTime()); - ofNullable(stepRq.getParameters()) - .filter(params -> !params.isEmpty()) - .ifPresent(params -> - sendLog(stepId, String.format(PARAMETERS_PATTERN, formatParametersAsTable(params)), - LogLevel.INFO)); - ofNullable(step.getTable()) - .ifPresent(table -> - sendLog(stepId, "Table:\n\n" + formatDataTable(table.getRows()), LogLevel.INFO)); + ofNullable(stepRq.getParameters()).filter(params -> !params.isEmpty()) + .ifPresent(params -> sendLog(stepId, String.format(PARAMETERS_PATTERN, formatParametersAsTable(params)), LogLevel.INFO)); + ofNullable(step.getTable()).ifPresent(table -> sendLog(stepId, "Table:\n\n" + formatDataTable(table.getRows()), LogLevel.INFO)); String docString = step.getDocString(); if (isNotBlank(docString)) { sendLog(stepId, "Docstring:\n\n" + asMarkdownCode(step.getDocString()), LogLevel.INFO); diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java index 297c38f..ed5da64 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java @@ -53,24 +53,19 @@ * Set of useful utils related to Karate -> ReportPortal integration */ public class ReportPortalUtils { - private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalUtils.class); - public static final String MARKDOWN_CODE_PATTERN = "```\n%s\n```"; public static final String PARAMETERS_PATTERN = "Parameters:\n\n%s"; - private static final String PARAMETER_ITEMS_START = "["; - private static final String PARAMETER_ITEMS_END = "]"; - private static final String PARAMETER_ITEMS_DELIMITER = ";"; - private static final String KEY_VALUE_SEPARATOR = ":"; - public static final String VARIABLE_PATTERN = - "(?:(?<=#\\()%1$s(?=\\)))|(?:(?<=[\\s=+-/*<>(]|^)%1$s(?=[\\s=+-/*<>)]|(?:\\r?\\n)|$))"; - + public static final String VARIABLE_PATTERN = "(?:(?<=#\\()%1$s(?=\\)))|(?:(?<=[\\s=+-/*<>(]|^)%1$s(?=[\\s=+-/*<>)]|(?:\\r?\\n)|$))"; public static final String AGENT_PROPERTIES_FILE = "agent.properties"; public static final String SKIPPED_ISSUE_KEY = "skippedIssue"; - public static final String SCENARIO_CODE_REFERENCE_PATTERN = "%s/[SCENARIO:%s]"; public static final String EXAMPLE_CODE_REFERENCE_PATTERN = "%s/[EXAMPLE:%s%s]"; - public static final String MARKDOWN_DELIMITER_PATTERN = "%s\n\n---\n\n%s"; + private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalUtils.class); + private static final String PARAMETER_ITEMS_START = "["; + private static final String PARAMETER_ITEMS_END = "]"; + private static final String PARAMETER_ITEMS_DELIMITER = ";"; + private static final String KEY_VALUE_SEPARATOR = ":"; private ReportPortalUtils() { throw new RuntimeException("No instances should exist for the class!"); @@ -152,8 +147,7 @@ public static StartLaunchRQ buildStartLaunchRq(@Nonnull ListenerParameters param skippedIssueAttribute.setSystem(true); rq.getAttributes().add(skippedIssueAttribute); } - rq.getAttributes().addAll(SystemAttributesExtractor.extract(AGENT_PROPERTIES_FILE, - ReportPortalUtils.class.getClassLoader())); + rq.getAttributes().addAll(SystemAttributesExtractor.extract(AGENT_PROPERTIES_FILE, ReportPortalUtils.class.getClassLoader())); return rq; } @@ -180,11 +174,16 @@ public static FinishExecutionRQ buildFinishLaunchRq(@Nonnull ListenerParameters @Nonnull public static String getCodeRef(@Nonnull Scenario scenario) { if (scenario.isOutlineExample()) { - return String.format(EXAMPLE_CODE_REFERENCE_PATTERN, scenario.getFeature().getResource().getRelativePath(), - scenario.getName(), ReportPortalUtils.formatExampleKey(scenario.getExampleData())); + return String.format(EXAMPLE_CODE_REFERENCE_PATTERN, + scenario.getFeature().getResource().getRelativePath(), + scenario.getName(), + ReportPortalUtils.formatExampleKey(scenario.getExampleData()) + ); } else { - return String.format(SCENARIO_CODE_REFERENCE_PATTERN, scenario.getFeature().getResource().getRelativePath(), - scenario.getName()); + return String.format(SCENARIO_CODE_REFERENCE_PATTERN, + scenario.getFeature().getResource().getRelativePath(), + scenario.getName() + ); } } @@ -197,8 +196,7 @@ public static String getCodeRef(@Nonnull Scenario scenario) { * @return request to ReportPortal */ @Nonnull - public static StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Date startTime, - @Nonnull ItemType type) { + public static StartTestItemRQ buildStartTestItemRq(@Nonnull String name, @Nonnull Date startTime, @Nonnull ItemType type) { StartTestItemRQ rq = new StartTestItemRQ(); rq.setName(name); rq.setStartTime(startTime); @@ -301,9 +299,7 @@ public static TestCaseIdEntry getTestCaseId(@Nonnull Scenario scenario) { */ @Nonnull public static StartTestItemRQ buildStartScenarioRq(@Nonnull Scenario scenario) { - StartTestItemRQ rq = buildStartTestItemRq(scenario.getName(), - Calendar.getInstance().getTime(), - ItemType.STEP); + StartTestItemRQ rq = buildStartTestItemRq(scenario.getName(), Calendar.getInstance().getTime(), ItemType.STEP); rq.setCodeRef(getCodeRef(scenario)); rq.setTestCaseId(ofNullable(getTestCaseId(scenario)).map(TestCaseIdEntry::getId).orElse(null)); rq.setAttributes(toAttributes(scenario.getTags())); @@ -316,10 +312,10 @@ public static StartTestItemRQ buildStartScenarioRq(@Nonnull Scenario scenario) { String description = scenario.getDescription(); if (isNotBlank(description)) { if (hasParameters) { - rq.setDescription( - String.format(MARKDOWN_DELIMITER_PATTERN, - String.format(PARAMETERS_PATTERN, ParameterUtils.formatParametersAsTable(parameters)), - description)); + rq.setDescription(String.format(MARKDOWN_DELIMITER_PATTERN, + String.format(PARAMETERS_PATTERN, ParameterUtils.formatParametersAsTable(parameters)), + description + )); } else { rq.setDescription(description); } @@ -357,12 +353,10 @@ public static StartTestItemRQ buildStartStepRq(@Nonnull Step step, @Nonnull Scen StartTestItemRQ rq = buildStartTestItemRq(stepName, Calendar.getInstance().getTime(), ItemType.STEP); rq.setHasStats(false); if (step.isOutline()) { - List parameters = scenario - .getExampleData() + List parameters = scenario.getExampleData() .entrySet() .stream() - .filter(e -> Pattern.compile(String.format(VARIABLE_PATTERN, e.getKey())) - .matcher(step.getText()).find()) + .filter(e -> Pattern.compile(String.format(VARIABLE_PATTERN, e.getKey())).matcher(step.getText()).find()) .map(e -> { ParameterResource param = new ParameterResource(); param.setKey(e.getKey()); @@ -423,7 +417,7 @@ public static void sendLog(Maybe itemId, String message, LogLevel level) /** * Builds markdown representation of some code or script to be logged to ReportPortal * - * @param code Code or Script + * @param code Code or Script * @return Message to be sent to ReportPortal */ public static String asMarkdownCode(String code) { diff --git a/src/test/java/com/epam/reportportal/karate/KarateTest.java b/src/test/java/com/epam/reportportal/karate/KarateTest.java index 8d5230c..dc64830 100644 --- a/src/test/java/com/epam/reportportal/karate/KarateTest.java +++ b/src/test/java/com/epam/reportportal/karate/KarateTest.java @@ -23,16 +23,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue; class KarateTest { - @Test - void testParallel() { - Results results = KarateReportPortalRunner - .path("classpath:feature") - .outputCucumberJson(true) - .tags("~@ignore", "@To_run") - .parallel(2); - assertEquals(0, results.getFailCount()); - assertEquals(0, results.getErrors().size()); - assertTrue(results.getSuite().parallel); - assertEquals(2, results.getScenariosTotal()); - } + @Test + void testParallel() { + Results results = KarateReportPortalRunner.path("classpath:feature") + .outputCucumberJson(true) + .tags("~@ignore", "@To_run") + .parallel(2); + assertEquals(0, results.getFailCount()); + assertEquals(0, results.getErrors().size()); + assertTrue(results.getSuite().parallel); + assertEquals(2, results.getScenariosTotal()); + } } \ No newline at end of file diff --git a/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java b/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java index fb64dcb..536bc9d 100644 --- a/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java +++ b/src/test/java/com/epam/reportportal/karate/ReportPortalPublisherTest.java @@ -40,61 +40,61 @@ @ExtendWith(MockitoExtension.class) public class ReportPortalPublisherTest { - @Mock - Launch launchMock; - private ReportPortalPublisher reportPortalPublisher; + @Mock + Launch launchMock; + private ReportPortalPublisher reportPortalPublisher; - @BeforeEach - public void setUp() { - reportPortalPublisher = new ReportPortalPublisher(() -> launchMock); - } + @BeforeEach + public void setUp() { + reportPortalPublisher = new ReportPortalPublisher(() -> launchMock); + } - @Test - public void shouldStartLaunch() { - reportPortalPublisher.startLaunch(); - verify(launchMock, times(1)).start(); - } + @Test + public void shouldStartLaunch() { + reportPortalPublisher.startLaunch(); + verify(launchMock, times(1)).start(); + } - @Test - public void shouldFinishLaunch() { - when(launchMock.getParameters()).thenReturn(getListenerParameters()); - reportPortalPublisher.finishLaunch(); - verify(launchMock, times(1)).finish(any(FinishExecutionRQ.class)); - } + @Test + public void shouldFinishLaunch() { + when(launchMock.getParameters()).thenReturn(getListenerParameters()); + reportPortalPublisher.finishLaunch(); + verify(launchMock, times(1)).finish(any(FinishExecutionRQ.class)); + } - @SuppressWarnings("unchecked") - @Test - public void shouldStartFeature() throws URISyntaxException { - FeatureResult featureResult = mock(FeatureResult.class); - Feature feature = mock(Feature.class); - Resource resource = mock(Resource.class); - when(featureResult.getFeature()).thenReturn(feature); - when(featureResult.getCallNameForReport()).thenReturn("featureName"); - when(feature.getResource()).thenReturn(resource); - when(resource.getUri()).thenReturn(new URI("file:///feature/simple.feature")); - when(launchMock.startTestItem(any(StartTestItemRQ.class))).thenReturn(mock(Maybe.class)); - reportPortalPublisher.startFeature(featureResult); - verify(launchMock, times(1)).startTestItem(any(StartTestItemRQ.class)); - } + @SuppressWarnings("unchecked") + @Test + public void shouldStartFeature() throws URISyntaxException { + FeatureResult featureResult = mock(FeatureResult.class); + Feature feature = mock(Feature.class); + Resource resource = mock(Resource.class); + when(featureResult.getFeature()).thenReturn(feature); + when(featureResult.getCallNameForReport()).thenReturn("featureName"); + when(feature.getResource()).thenReturn(resource); + when(resource.getUri()).thenReturn(new URI("file:///feature/simple.feature")); + when(launchMock.startTestItem(any(StartTestItemRQ.class))).thenReturn(mock(Maybe.class)); + reportPortalPublisher.startFeature(featureResult); + verify(launchMock, times(1)).startTestItem(any(StartTestItemRQ.class)); + } - @SuppressWarnings("unchecked") - @Test - public void shouldFinishFeature() throws NoSuchFieldException { - FeatureResult featureResult = mock(FeatureResult.class); - when(featureResult.getCallNameForReport()).thenReturn("featureName"); - ConcurrentHashMap> featureIdMap = new ConcurrentHashMap<>(); - featureIdMap.put("featureName", mock(Maybe.class)); - ReflectUtils.setField(reportPortalPublisher, ReportPortalPublisher.class.getDeclaredField("featureIdMap"), featureIdMap); - reportPortalPublisher.finishFeature(featureResult); - verify(launchMock, times(1)).finishTestItem(any(Maybe.class), any(FinishTestItemRQ.class)); - } + @SuppressWarnings("unchecked") + @Test + public void shouldFinishFeature() throws NoSuchFieldException { + FeatureResult featureResult = mock(FeatureResult.class); + when(featureResult.getCallNameForReport()).thenReturn("featureName"); + ConcurrentHashMap> featureIdMap = new ConcurrentHashMap<>(); + featureIdMap.put("featureName", mock(Maybe.class)); + ReflectUtils.setField(reportPortalPublisher, ReportPortalPublisher.class.getDeclaredField("featureIdMap"), featureIdMap); + reportPortalPublisher.finishFeature(featureResult); + verify(launchMock, times(1)).finishTestItem(any(Maybe.class), any(FinishTestItemRQ.class)); + } - private ListenerParameters getListenerParameters() { - ListenerParameters parameters = new ListenerParameters(); - parameters.setLaunchName("launch"); - parameters.setBaseUrl("url"); - parameters.setProjectName("project"); - System.setProperty("rp.launch.id", "launchId"); - return parameters; - } + private ListenerParameters getListenerParameters() { + ListenerParameters parameters = new ListenerParameters(); + parameters.setLaunchName("launch"); + parameters.setBaseUrl("url"); + parameters.setProjectName("project"); + System.setProperty("rp.launch.id", "launchId"); + return parameters; + } } diff --git a/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java index eb526d9..aa0573b 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/DifferentAttributesTest.java @@ -41,54 +41,55 @@ import static org.mockito.Mockito.*; public class DifferentAttributesTest { - private static final String TEST_FEATURE = "classpath:feature/tags.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/tags.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_different_attributes(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_different_attributes(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(1)).startTestItem(same(featureId), captor.capture()); - verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(5)); + List items = captor.getAllValues(); + assertThat(items, hasSize(5)); - StartTestItemRQ featureRq = items.get(0); - StartTestItemRQ scenarioRq = items.get(1); + StartTestItemRQ featureRq = items.get(0); + StartTestItemRQ scenarioRq = items.get(1); - assertThat(featureRq.getAttributes(), hasSize(1)); - ItemAttributesRQ featureAttribute = featureRq.getAttributes().iterator().next(); - assertThat(featureAttribute.getKey(), nullValue()); - assertThat(featureAttribute.getValue(), equalTo("tag_test")); + assertThat(featureRq.getAttributes(), hasSize(1)); + ItemAttributesRQ featureAttribute = featureRq.getAttributes().iterator().next(); + assertThat(featureAttribute.getKey(), nullValue()); + assertThat(featureAttribute.getValue(), equalTo("tag_test")); - assertThat(scenarioRq.getAttributes(), hasSize(4)); - Set> scenarioAttributes = scenarioRq - .getAttributes().stream().map(a -> Pair.of(a.getKey(), a.getValue())).collect(Collectors.toSet()); - assertThat(scenarioAttributes, hasItem(Pair.of(null, "math"))); - assertThat(scenarioAttributes, hasItem(Pair.of("scope", "smoke"))); - assertThat(scenarioAttributes, hasItem(Pair.of("environment", "dev"))); - assertThat(scenarioAttributes, hasItem(Pair.of("environment", "qa"))); - } + assertThat(scenarioRq.getAttributes(), hasSize(4)); + Set> scenarioAttributes = scenarioRq.getAttributes() + .stream() + .map(a -> Pair.of(a.getKey(), a.getValue())) + .collect(Collectors.toSet()); + assertThat(scenarioAttributes, hasItem(Pair.of(null, "math"))); + assertThat(scenarioAttributes, hasItem(Pair.of("scope", "smoke"))); + assertThat(scenarioAttributes, hasItem(Pair.of("environment", "dev"))); + assertThat(scenarioAttributes, hasItem(Pair.of("environment", "qa"))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java index ffa77b3..c419888 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/LaunchAttributesTest.java @@ -43,49 +43,47 @@ import static org.mockito.Mockito.verify; public class LaunchAttributesTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private ReportPortal rp; + private final ReportPortalClient client = mock(ReportPortalClient.class); + private ReportPortal rp; - @BeforeEach - public void setupMock() { - ListenerParameters parameters = standardParameters(); - parameters.setAttributes(new HashSet<>(Arrays.asList(new ItemAttributesRQ("key", "value"), - new ItemAttributesRQ(null, "value")))); - rp = ReportPortal.create(client, parameters, testExecutor()); - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + ListenerParameters parameters = standardParameters(); + parameters.setAttributes(new HashSet<>(Arrays.asList(new ItemAttributesRQ("key", "value"), new ItemAttributesRQ(null, "value")))); + rp = ReportPortal.create(client, parameters, testExecutor()); + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void verify_start_launch_request_contains_launch_attributes(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void verify_start_launch_request_contains_launch_attributes(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); - verify(client).startLaunch(startCaptor.capture()); + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); - StartLaunchRQ launchStart = startCaptor.getValue(); + StartLaunchRQ launchStart = startCaptor.getValue(); - Set attributes = launchStart.getAttributes(); - assertThat(attributes, allOf(notNullValue(), hasSize(greaterThan(0)))); - Set attributesStr = attributes.stream() - .filter(a -> !a.isSystem()) - .map(e -> e.getKey() + ":" + e.getValue()) - .collect(Collectors.toSet()); - assertThat(attributesStr, hasSize(2)); - assertThat(attributesStr, hasItem("key:value")); - assertThat(attributesStr, hasItem("null:value")); - } + Set attributes = launchStart.getAttributes(); + assertThat(attributes, allOf(notNullValue(), hasSize(greaterThan(0)))); + Set attributesStr = attributes.stream() + .filter(a -> !a.isSystem()) + .map(e -> e.getKey() + ":" + e.getValue()) + .collect(Collectors.toSet()); + assertThat(attributesStr, hasSize(2)); + assertThat(attributesStr, hasItem("key:value")); + assertThat(attributesStr, hasItem("null:value")); + } } diff --git a/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java index baece01..9ae4a8b 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/NoAttributesTest.java @@ -38,44 +38,43 @@ import static org.mockito.Mockito.*; public class NoAttributesTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_different_attributes(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_different_attributes(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(1)).startTestItem(same(featureId), captor.capture()); - verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(5)); + List items = captor.getAllValues(); + assertThat(items, hasSize(5)); - StartTestItemRQ featureRq = items.get(0); - StartTestItemRQ scenarioRq = items.get(1); + StartTestItemRQ featureRq = items.get(0); + StartTestItemRQ scenarioRq = items.get(1); - assertThat(featureRq.getAttributes(), nullValue()); - assertThat(scenarioRq.getAttributes(), nullValue()); - } + assertThat(featureRq.getAttributes(), nullValue()); + assertThat(scenarioRq.getAttributes(), nullValue()); + } } diff --git a/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java b/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java index 788bc2b..23664a9 100644 --- a/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java +++ b/src/test/java/com/epam/reportportal/karate/attributes/SystemAttributesTest.java @@ -40,47 +40,46 @@ import static org.mockito.Mockito.verify; public class SystemAttributesTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void verify_start_launch_request_contains_system_attributes(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void verify_start_launch_request_contains_system_attributes(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); - verify(client).startLaunch(startCaptor.capture()); + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); - StartLaunchRQ launchStart = startCaptor.getValue(); + StartLaunchRQ launchStart = startCaptor.getValue(); - Set attributes = launchStart.getAttributes(); - assertThat(attributes, allOf(notNullValue(), hasSize(greaterThan(0)))); - Set attributesStr = attributes.stream() - .filter(ItemAttributesRQ::isSystem) - .map(e -> e.getKey() + ":" + e.getValue()) - .collect(Collectors.toSet()); - assertThat(attributesStr, hasSize(4)); - assertThat(attributesStr, hasItem("skippedIssue:true")); - assertThat(attributesStr, hasItem("agent:karate-test-agent|test-1.0")); - assertThat(attributesStr, hasItem(startsWith("os:"))); - assertThat(attributesStr, hasItem(startsWith("jvm:"))); - } + Set attributes = launchStart.getAttributes(); + assertThat(attributes, allOf(notNullValue(), hasSize(greaterThan(0)))); + Set attributesStr = attributes.stream() + .filter(ItemAttributesRQ::isSystem) + .map(e -> e.getKey() + ":" + e.getValue()) + .collect(Collectors.toSet()); + assertThat(attributesStr, hasSize(4)); + assertThat(attributesStr, hasItem("skippedIssue:true")); + assertThat(attributesStr, hasItem("agent:karate-test-agent|test-1.0")); + assertThat(attributesStr, hasItem(startsWith("os:"))); + assertThat(attributesStr, hasItem(startsWith("jvm:"))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java index 5c6b5ee..df30ea9 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundExamplesTest.java @@ -43,80 +43,78 @@ import static org.mockito.Mockito.*; public class BackgroundExamplesTest { - private static final String TEST_FEATURE = "classpath:feature/background_examples.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")) - .limit(2).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/background_examples.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")).limit(2).collect(Collectors.toList()); - private final List>> scenarioSteps = scenarioIds - .stream().map(s -> - Pair.of(s, Stream.generate(() -> - CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()))) - .collect(Collectors.toList()); - private final List> nestedStepIds = scenarioSteps - .stream() - .flatMap(s -> s.getValue().stream()) - .map(s -> Pair.of(s, CommonUtils.namedId("nested_step_"))) - .collect(Collectors.toList()); + private final List>> scenarioSteps = scenarioIds.stream() + .map(s -> Pair.of(s, Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()))) + .collect(Collectors.toList()); + private final List> nestedStepIds = scenarioSteps.stream() + .flatMap(s -> s.getValue().stream()) + .map(s -> Pair.of(s, CommonUtils.namedId("nested_step_"))) + .collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioSteps); - mockNestedSteps(client, nestedStepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioSteps); + mockNestedSteps(client, nestedStepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_background_steps(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_background_steps(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(captor.capture()); - verify(client, times(2)).startTestItem(same(featureId), captor.capture()); - ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioIds.get(0)), firstStepCaptor.capture()); - ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioIds.get(1)), secondStepCaptor.capture()); - ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client, times(2)).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioIds.get(0)), firstStepCaptor.capture()); + ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioIds.get(1)), secondStepCaptor.capture()); + ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(3)); - List firstSteps = firstStepCaptor.getAllValues(); - assertThat(firstSteps, hasSize(3)); - List secondSteps = secondStepCaptor.getAllValues(); - assertThat(firstSteps, hasSize(3)); + List items = captor.getAllValues(); + assertThat(items, hasSize(3)); + List firstSteps = firstStepCaptor.getAllValues(); + assertThat(firstSteps, hasSize(3)); + List secondSteps = secondStepCaptor.getAllValues(); + assertThat(firstSteps, hasSize(3)); - List firstBackgroundSteps = firstSteps.stream() - .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); - assertThat(firstBackgroundSteps, hasSize(1)); - List secondBackgroundSteps = secondSteps.stream() - .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); - assertThat(secondBackgroundSteps, hasSize(1)); + List firstBackgroundSteps = firstSteps.stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)) + .collect(Collectors.toList()); + assertThat(firstBackgroundSteps, hasSize(1)); + List secondBackgroundSteps = secondSteps.stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)) + .collect(Collectors.toList()); + assertThat(secondBackgroundSteps, hasSize(1)); - Stream.concat(firstBackgroundSteps.stream(), secondBackgroundSteps.stream()).forEach(backgroundStep -> { - assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate - assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); - assertThat(backgroundStep.getStartTime(), notNullValue()); - assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); - }); + Stream.concat(firstBackgroundSteps.stream(), secondBackgroundSteps.stream()).forEach(backgroundStep -> { + assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate + assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); + assertThat(backgroundStep.getStartTime(), notNullValue()); + assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); + }); - List nestedSteps = nestedStepCaptor.getAllValues(); - assertThat(nestedSteps, hasSize(2)); - nestedSteps.forEach(step -> assertThat(step.isHasStats(), equalTo(Boolean.FALSE))); - Set nestedStepNames = nestedSteps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet()); + List nestedSteps = nestedStepCaptor.getAllValues(); + assertThat(nestedSteps, hasSize(2)); + nestedSteps.forEach(step -> assertThat(step.isHasStats(), equalTo(Boolean.FALSE))); + Set nestedStepNames = nestedSteps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet()); - assertThat(nestedStepNames, hasSize(1)); - assertThat(nestedStepNames, hasItem("Given def varb = 2")); - } + assertThat(nestedStepNames, hasSize(1)); + assertThat(nestedStepNames, hasItem("Given def varb = 2")); + } } diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java index 1d72e8a..6a6aaac 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTest.java @@ -42,61 +42,62 @@ import static org.mockito.Mockito.*; public class BackgroundTest { - private static final String TEST_FEATURE = "classpath:feature/background.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); - private final List> nestedStepIds = stepIds.stream() - .map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/background.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); + private final List> nestedStepIds = stepIds.stream() + .map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))) + .collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockNestedSteps(client, nestedStepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockNestedSteps(client, nestedStepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_background_steps(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_background_steps(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(captor.capture()); - verify(client).startTestItem(same(featureId), captor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); - ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(2)); - List steps = stepCaptor.getAllValues(); - assertThat(steps, hasSize(3)); + List items = captor.getAllValues(); + assertThat(items, hasSize(2)); + List steps = stepCaptor.getAllValues(); + assertThat(steps, hasSize(3)); - List backgroundSteps = steps.stream() - .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); - assertThat(backgroundSteps, hasSize(1)); - StartTestItemRQ backgroundStep = backgroundSteps.get(0); - assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate - assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); - assertThat(backgroundStep.getStartTime(), notNullValue()); - assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); + List backgroundSteps = steps.stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)) + .collect(Collectors.toList()); + assertThat(backgroundSteps, hasSize(1)); + StartTestItemRQ backgroundStep = backgroundSteps.get(0); + assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate + assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); + assertThat(backgroundStep.getStartTime(), notNullValue()); + assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); - List nestedSteps = nestedStepCaptor.getAllValues(); - assertThat(nestedSteps, hasSize(1)); - StartTestItemRQ nestedStep = nestedSteps.get(0); - assertThat(nestedStep.getName(), equalTo("Given def four = 4")); - assertThat(nestedStep.isHasStats(), equalTo(Boolean.FALSE)); - } + List nestedSteps = nestedStepCaptor.getAllValues(); + assertThat(nestedSteps, hasSize(1)); + StartTestItemRQ nestedStep = nestedSteps.get(0); + assertThat(nestedStep.getName(), equalTo("Given def four = 4")); + assertThat(nestedStep.isHasStats(), equalTo(Boolean.FALSE)); + } } diff --git a/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java b/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java index e66bcea..67bd971 100644 --- a/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java +++ b/src/test/java/com/epam/reportportal/karate/background/BackgroundTwoStepsTest.java @@ -43,64 +43,64 @@ import static org.mockito.Mockito.*; public class BackgroundTwoStepsTest { - private static final String TEST_FEATURE = "classpath:feature/background_two_steps.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(2).collect(Collectors.toList()); - private final List> nestedStepIds = Stream.concat( - stepIds.stream().map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))), - stepIds.stream().map(id -> Pair.of(id, CommonUtils.namedId("nested_step_")))).collect(Collectors.toList() - ); + private static final String TEST_FEATURE = "classpath:feature/background_two_steps.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(2).collect(Collectors.toList()); + private final List> nestedStepIds = Stream.concat( + stepIds.stream().map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))), + stepIds.stream().map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))) + ).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockNestedSteps(client, nestedStepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockNestedSteps(client, nestedStepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_background_steps(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_background_steps(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(captor.capture()); - verify(client, times(1)).startTestItem(same(featureId), captor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(scenarioId), stepCaptor.capture()); - ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor nestedStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(startsWith("step_"), nestedStepCaptor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(2)); - List steps = stepCaptor.getAllValues(); - assertThat(steps, hasSize(2)); + List items = captor.getAllValues(); + assertThat(items, hasSize(2)); + List steps = stepCaptor.getAllValues(); + assertThat(steps, hasSize(2)); - List backgroundSteps = steps.stream() - .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); - assertThat(backgroundSteps, hasSize(1)); - StartTestItemRQ backgroundStep = backgroundSteps.get(0); - assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate - assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); - assertThat(backgroundStep.getStartTime(), notNullValue()); - assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); + List backgroundSteps = steps.stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)) + .collect(Collectors.toList()); + assertThat(backgroundSteps, hasSize(1)); + StartTestItemRQ backgroundStep = backgroundSteps.get(0); + assertThat(backgroundStep.getName(), equalTo(Background.KEYWORD)); // No name for Background in Karate + assertThat(backgroundStep.isHasStats(), equalTo(Boolean.FALSE)); + assertThat(backgroundStep.getStartTime(), notNullValue()); + assertThat(backgroundStep.getType(), equalTo(ItemType.STEP.name())); - List nestedSteps = nestedStepCaptor.getAllValues(); - assertThat(nestedSteps, hasSize(2)); - nestedSteps.forEach(step -> assertThat(step.isHasStats(), equalTo(Boolean.FALSE))); - Set nestedStepNames = nestedSteps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet()); + List nestedSteps = nestedStepCaptor.getAllValues(); + assertThat(nestedSteps, hasSize(2)); + nestedSteps.forEach(step -> assertThat(step.isHasStats(), equalTo(Boolean.FALSE))); + Set nestedStepNames = nestedSteps.stream().map(StartTestItemRQ::getName).collect(Collectors.toSet()); - assertThat(nestedStepNames, allOf(hasItem("Given def vara = 2"), hasItem("And def varb = 2"))); - } + assertThat(nestedStepNames, allOf(hasItem("Given def vara = 2"), hasItem("And def varb = 2"))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java index ddd5f22..0975f38 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ExamplesCodeRefTest.java @@ -40,65 +40,59 @@ import static org.mockito.Mockito.*; public class ExamplesCodeRefTest { - private static final String TEST_FEATURE = "classpath:feature/examples.feature"; - private static final String EXAMPLE_CODE_REFERENCE_PATTERN = - "feature/examples.feature/[EXAMPLE:Verify different maths[%s]]"; - private static final String FIRST_EXAMPLE_CODE_REFERENCE = - String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "result:4;vara:2;varb:2"); - private static final String SECOND_EXAMPLE_CODE_REFERENCE = - String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "result:3;vara:1;varb:2"); - private final String featureId = CommonUtils.namedId("feature_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) - .collect(Collectors.toList()); - private final List>> stepIds = exampleIds.stream() - .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(2).collect(Collectors.toList()))) - .collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; + private static final String EXAMPLE_CODE_REFERENCE_PATTERN = "feature/examples.feature/[EXAMPLE:Verify different maths[%s]]"; + private static final String FIRST_EXAMPLE_CODE_REFERENCE = String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "result:4;vara:2;varb:2"); + private static final String SECOND_EXAMPLE_CODE_REFERENCE = String.format(EXAMPLE_CODE_REFERENCE_PATTERN, "result:3;vara:1;varb:2"); + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2).collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")).limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_examples_code_reference(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_examples_code_reference(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); - ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); + ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); - StartTestItemRQ featureRq = featureCaptor.getValue(); - assertThat(featureRq.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); + StartTestItemRQ featureRq = featureCaptor.getValue(); + assertThat(featureRq.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); - List scenarios = scenarioCaptor.getAllValues(); - StartTestItemRQ firstScenarioRq = scenarios.get(0); - assertThat(firstScenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); - assertThat(firstScenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_CODE_REFERENCE))); + List scenarios = scenarioCaptor.getAllValues(); + StartTestItemRQ firstScenarioRq = scenarios.get(0); + assertThat(firstScenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(firstScenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_CODE_REFERENCE))); - StartTestItemRQ secondScenarioRq = scenarios.get(1); - assertThat(secondScenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); - assertThat(secondScenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_CODE_REFERENCE))); + StartTestItemRQ secondScenarioRq = scenarios.get(1); + assertThat(secondScenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(secondScenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_CODE_REFERENCE))); - Stream.concat(firstStepCaptor.getAllValues().stream(), secondStepCaptor.getAllValues().stream()) - .forEach(step -> { - assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); - assertThat(step.isHasStats(), equalTo(Boolean.FALSE)); - }); - } + Stream.concat(firstStepCaptor.getAllValues().stream(), secondStepCaptor.getAllValues().stream()).forEach(step -> { + assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(step.isHasStats(), equalTo(Boolean.FALSE)); + }); + } } diff --git a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java index f459afc..4285363 100644 --- a/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/karate/coderef/ScenarioCodeRefTest.java @@ -39,50 +39,49 @@ import static org.mockito.Mockito.*; public class ScenarioCodeRefTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private static final String SIMPLE_CODE_REFERENCE = "feature/simple.feature/[SCENARIO:Verify math]"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private static final String SIMPLE_CODE_REFERENCE = "feature/simple.feature/[SCENARIO:Verify math]"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_scenario_code_reference(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_scenario_code_reference(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); - StartTestItemRQ featureRq = featureCaptor.getValue(); - StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); + StartTestItemRQ featureRq = featureCaptor.getValue(); + StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); - assertThat(featureRq.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); + assertThat(featureRq.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); - assertThat(scenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); - assertThat(scenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(SIMPLE_CODE_REFERENCE))); + assertThat(scenarioRq.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(scenarioRq.getCodeRef(), allOf(notNullValue(), equalTo(SIMPLE_CODE_REFERENCE))); - stepCaptor.getAllValues().forEach(step -> { - assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); - assertThat(step.isHasStats(), equalTo(Boolean.FALSE)); - }); - } + stepCaptor.getAllValues().forEach(step -> { + assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); + assertThat(step.isHasStats(), equalTo(Boolean.FALSE)); + }); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java index 3b09ebb..1fc96db 100644 --- a/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java @@ -42,54 +42,58 @@ import static org.mockito.Mockito.*; public class CallWithParametersHookTest { - private static final String TEST_FEATURE = "classpath:feature/call.feature"; - private static final String PARAMETERS_DESCRIPTION_PATTERN = - "Parameters:\n\n" - + MarkdownUtils.TABLE_INDENT - + "| vara | result |\n" - + MarkdownUtils.TABLE_INDENT - + "|------|--------|\n" - + MarkdownUtils.TABLE_INDENT - + "|  2   |   4    |\n\n" - + MarkdownUtils.TABLE_ROW_SEPARATOR; - private final List featureIds = Stream.generate(() -> CommonUtils.namedId("feature_")) - .limit(2).collect(Collectors.toList()); - private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")) - .limit(2).collect(Collectors.toList()); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(4).collect(Collectors.toList()); - private final List>>>> features = - Stream.of( - Pair.of(featureIds.get(0), (Collection>>) Collections.singletonList(Pair.of(scenarioIds.get(0), Collections.singletonList(stepIds.get(0))))), - Pair.of(featureIds.get(1), (Collection>>) Collections.singletonList(Pair.of(scenarioIds.get(1), stepIds.subList(1, stepIds.size())))) - ).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private static final String TEST_FEATURE = "classpath:feature/call.feature"; + private static final String PARAMETERS_DESCRIPTION_PATTERN = + "Parameters:\n\n" + MarkdownUtils.TABLE_INDENT + "| vara | result |\n" + MarkdownUtils.TABLE_INDENT + "|------|--------|\n" + + MarkdownUtils.TABLE_INDENT + "|  2   |   4    |\n\n" + MarkdownUtils.TABLE_ROW_SEPARATOR; + private final List featureIds = Stream.generate(() -> CommonUtils.namedId("feature_")).limit(2).collect(Collectors.toList()); + private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")).limit(2).collect(Collectors.toList()); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(4).collect(Collectors.toList()); + private final List>>>> features = Stream.of( + Pair.of(featureIds.get(0), + (Collection>>) Collections.singletonList(Pair.of( + scenarioIds.get(0), + Collections.singletonList(stepIds.get(0)) + )) + ), + Pair.of( + featureIds.get(1), + (Collection>>) Collections.singletonList(Pair.of( + scenarioIds.get(1), + stepIds.subList(1, stepIds.size()) + )) + ) + ).collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null); - mockFeatures(client, features); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null); + mockFeatures(client, features); + mockBatchLogging(client); + } - @Test - public void test_call_feature_with_parameters_hook_reporting() { - Results results = TestUtils.runAsHook(rp, TEST_FEATURE); - assertThat(results.getFailCount(), equalTo(0)); + @Test + public void test_call_feature_with_parameters_hook_reporting() { + Results results = TestUtils.runAsHook(rp, TEST_FEATURE); + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(featureIds.get(0)), scenarioCaptor.capture()); - verify(client).startTestItem(same(featureIds.get(1)), scenarioCaptor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(scenarioIds.get(0)), stepCaptor.capture()); - verify(client, times(3)).startTestItem(same(scenarioIds.get(1)), stepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureIds.get(0)), scenarioCaptor.capture()); + verify(client).startTestItem(same(featureIds.get(1)), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(scenarioIds.get(0)), stepCaptor.capture()); + verify(client, times(3)).startTestItem(same(scenarioIds.get(1)), stepCaptor.capture()); - StartTestItemRQ calledFeature = featureCaptor.getAllValues().stream() - .filter(rq -> "a feature which is called with parameters".equals(rq.getName())).findAny().orElseThrow(); + StartTestItemRQ calledFeature = featureCaptor.getAllValues() + .stream() + .filter(rq -> "a feature which is called with parameters".equals(rq.getName())) + .findAny() + .orElseThrow(); - assertThat(calledFeature.getDescription(), allOf(endsWith("feature/called.feature"), startsWith(PARAMETERS_DESCRIPTION_PATTERN))); - } + assertThat(calledFeature.getDescription(), allOf(endsWith("feature/called.feature"), startsWith(PARAMETERS_DESCRIPTION_PATTERN))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java index f6234c2..fdf1048 100644 --- a/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java @@ -36,30 +36,29 @@ import static org.mockito.Mockito.*; public class CallWithParametersPublisherTest { - private static final String TEST_FEATURE = "classpath:feature/call.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(1).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/call.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(1).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @Test - public void test_call_feature_with_parameters_publisher_reporting() { - Results results = TestUtils.runAsReport(rp, TEST_FEATURE); - assertThat(results.getFailCount(), equalTo(0)); + @Test + public void test_call_feature_with_parameters_publisher_reporting() { + Results results = TestUtils.runAsReport(rp, TEST_FEATURE); + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(captor.capture()); - verify(client).startTestItem(same(featureId), captor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(scenarioId), stepCaptor.capture()); - } + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(scenarioId), stepCaptor.capture()); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java b/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java index 7da4374..d7ca77b 100644 --- a/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/DescriptionExamplesTest.java @@ -40,56 +40,56 @@ import static org.mockito.Mockito.*; public class DescriptionExamplesTest { - public static final String FIRST_EXAMPLE_DESCRIPTION = String.format( - ReportPortalUtils.MARKDOWN_DELIMITER_PATTERN, - NoDescriptionExamplesTest.FIRST_EXAMPLE_DESCRIPTION, - SimpleDescriptionTest.SCENARIO_DESCRIPTION); - public static final String SECOND_EXAMPLE_DESCRIPTION = String.format( - ReportPortalUtils.MARKDOWN_DELIMITER_PATTERN, - NoDescriptionExamplesTest.SECOND_EXAMPLE_DESCRIPTION, - SimpleDescriptionTest.SCENARIO_DESCRIPTION); - private static final String TEST_FEATURE = "classpath:feature/description_examples.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) - .collect(Collectors.toList()); - private final List>> stepIds = exampleIds.stream() - .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(2).collect(Collectors.toList()))) - .collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + public static final String FIRST_EXAMPLE_DESCRIPTION = String.format( + ReportPortalUtils.MARKDOWN_DELIMITER_PATTERN, + NoDescriptionExamplesTest.FIRST_EXAMPLE_DESCRIPTION, + SimpleDescriptionTest.SCENARIO_DESCRIPTION + ); + public static final String SECOND_EXAMPLE_DESCRIPTION = String.format( + ReportPortalUtils.MARKDOWN_DELIMITER_PATTERN, + NoDescriptionExamplesTest.SECOND_EXAMPLE_DESCRIPTION, + SimpleDescriptionTest.SCENARIO_DESCRIPTION + ); + private static final String TEST_FEATURE = "classpath:feature/description_examples.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2).collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")).limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_examples_description(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_examples_description(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); - ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); + ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); - List scenarios = scenarioCaptor.getAllValues(); - StartTestItemRQ firstScenarioRq = scenarios.get(0); - assertThat(firstScenarioRq.getDescription(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_DESCRIPTION))); + List scenarios = scenarioCaptor.getAllValues(); + StartTestItemRQ firstScenarioRq = scenarios.get(0); + assertThat(firstScenarioRq.getDescription(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_DESCRIPTION))); - StartTestItemRQ secondScenarioRq = scenarios.get(1); - assertThat(secondScenarioRq.getDescription(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_DESCRIPTION))); - } + StartTestItemRQ secondScenarioRq = scenarios.get(1); + assertThat(secondScenarioRq.getDescription(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_DESCRIPTION))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java index 9c51dc0..b71479d 100644 --- a/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/LaunchDescriptionTest.java @@ -39,41 +39,40 @@ import static org.mockito.Mockito.verify; public class LaunchDescriptionTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private static final String TEST_DESCRIPTION = "My test description"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private static final String TEST_DESCRIPTION = "My test description"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private ReportPortal rp; + private final ReportPortalClient client = mock(ReportPortalClient.class); + private ReportPortal rp; - @BeforeEach - public void setupMock() { - ListenerParameters parameters = standardParameters(); - parameters.setDescription(TEST_DESCRIPTION); - rp = ReportPortal.create(client, parameters, testExecutor()); - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + ListenerParameters parameters = standardParameters(); + parameters.setDescription(TEST_DESCRIPTION); + rp = ReportPortal.create(client, parameters, testExecutor()); + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void verify_start_launch_request_contains_launch_description(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void verify_start_launch_request_contains_launch_description(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); - verify(client).startLaunch(startCaptor.capture()); + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); - StartLaunchRQ launchStart = startCaptor.getValue(); + StartLaunchRQ launchStart = startCaptor.getValue(); - assertThat(launchStart.getDescription(), equalTo(TEST_DESCRIPTION)); - } + assertThat(launchStart.getDescription(), equalTo(TEST_DESCRIPTION)); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java index 4d30e48..340d728 100644 --- a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionExamplesTest.java @@ -40,59 +40,51 @@ import static org.mockito.Mockito.*; public class NoDescriptionExamplesTest { - private static final String TEST_FEATURE = "classpath:feature/examples.feature"; - private static final String EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN = - "Parameters:\n\n" - + MarkdownUtils.TABLE_INDENT - + "| vara | varb | result |\n" - + MarkdownUtils.TABLE_INDENT - + "|------|------|--------|\n" - + MarkdownUtils.TABLE_INDENT; - public static final String FIRST_EXAMPLE_DESCRIPTION = EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN - + "|  2   |  2   |   4    |"; - public static final String SECOND_EXAMPLE_DESCRIPTION = EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN - + "|  1   |  2   |   3    |"; - private final String featureId = CommonUtils.namedId("feature_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) - .collect(Collectors.toList()); - private final List>> stepIds = exampleIds.stream() - .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(2).collect(Collectors.toList()))) - .collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; + private static final String EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN = + "Parameters:\n\n" + MarkdownUtils.TABLE_INDENT + "| vara | varb | result |\n" + MarkdownUtils.TABLE_INDENT + + "|------|------|--------|\n" + MarkdownUtils.TABLE_INDENT; + public static final String FIRST_EXAMPLE_DESCRIPTION = EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN + "|  2   |  2   |   4    |"; + public static final String SECOND_EXAMPLE_DESCRIPTION = EXAMPLE_PARAMETERS_DESCRIPTION_PATTERN + "|  1   |  2   |   3    |"; + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2).collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")).limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_examples_no_description(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_examples_no_description(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); - ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor firstStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstStepCaptor.capture()); + ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondStepCaptor.capture()); - List scenarios = scenarioCaptor.getAllValues(); - StartTestItemRQ firstScenarioRq = scenarios.get(0); - assertThat(firstScenarioRq.getDescription(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_DESCRIPTION))); + List scenarios = scenarioCaptor.getAllValues(); + StartTestItemRQ firstScenarioRq = scenarios.get(0); + assertThat(firstScenarioRq.getDescription(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_DESCRIPTION))); - StartTestItemRQ secondScenarioRq = scenarios.get(1); - assertThat(secondScenarioRq.getDescription(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_DESCRIPTION))); - } + StartTestItemRQ secondScenarioRq = scenarios.get(1); + assertThat(secondScenarioRq.getDescription(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_DESCRIPTION))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java index 57f4e1b..8128ee4 100644 --- a/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/NoDescriptionTest.java @@ -39,45 +39,44 @@ import static org.mockito.Mockito.*; public class NoDescriptionTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_description_for_all_possible_items(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_description_for_all_possible_items(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); - StartTestItemRQ featureStart = featureCaptor.getValue(); - assertThat(featureStart.getDescription(), endsWith("feature/simple.feature")); + StartTestItemRQ featureStart = featureCaptor.getValue(); + assertThat(featureStart.getDescription(), endsWith("feature/simple.feature")); - StartTestItemRQ scenarioStart = scenarioCaptor.getValue(); - assertThat(scenarioStart.getDescription(), nullValue()); + StartTestItemRQ scenarioStart = scenarioCaptor.getValue(); + assertThat(scenarioStart.getDescription(), nullValue()); - stepCaptor.getAllValues().forEach(step -> assertThat(step.getDescription(), nullValue())); - } + stepCaptor.getAllValues().forEach(step -> assertThat(step.getDescription(), nullValue())); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java index a8c0201..f54dab8 100644 --- a/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/NoLaunchDescriptionTest.java @@ -42,48 +42,43 @@ import static org.mockito.Mockito.verify; public class NoLaunchDescriptionTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortalClient client = mock(ReportPortalClient.class); - public static Stream dataValues() { - List descriptions = Arrays.asList( - null, - "", - " " - ); - return Stream.of(true, false).flatMap(b -> descriptions.stream().map(d -> Arguments.of(b, d))); - } + public static Stream dataValues() { + List descriptions = Arrays.asList(null, "", " "); + return Stream.of(true, false).flatMap(b -> descriptions.stream().map(d -> Arguments.of(b, d))); + } - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @MethodSource("dataValues") - public void verify_start_launch_request_contains_no_launch_description(boolean report, String description) { - ListenerParameters parameters = standardParameters(); - parameters.setDescription(description); - ReportPortal rp = ReportPortal.create(client, parameters, testExecutor()); - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @MethodSource("dataValues") + public void verify_start_launch_request_contains_no_launch_description(boolean report, String description) { + ListenerParameters parameters = standardParameters(); + parameters.setDescription(description); + ReportPortal rp = ReportPortal.create(client, parameters, testExecutor()); + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); - verify(client).startLaunch(startCaptor.capture()); + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); - StartLaunchRQ launchStart = startCaptor.getValue(); + StartLaunchRQ launchStart = startCaptor.getValue(); - assertThat(launchStart.getDescription(), nullValue()); - } + assertThat(launchStart.getDescription(), nullValue()); + } } diff --git a/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java b/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java index e8a89f4..2e621e7 100644 --- a/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java +++ b/src/test/java/com/epam/reportportal/karate/description/SimpleDescriptionTest.java @@ -41,53 +41,58 @@ import static org.mockito.Mockito.*; public class SimpleDescriptionTest { - public static final String SCENARIO_DESCRIPTION = "This is my Scenario description."; - private static final String TEST_FEATURE = "classpath:feature/description.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); - private final List> nestedStepIds = stepIds.stream() - .map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + public static final String SCENARIO_DESCRIPTION = "This is my Scenario description."; + private static final String TEST_FEATURE = "classpath:feature/description.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); + private final List> nestedStepIds = stepIds.stream() + .map(id -> Pair.of(id, CommonUtils.namedId("nested_step_"))) + .collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockNestedSteps(client, nestedStepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockNestedSteps(client, nestedStepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_description_for_all_possible_items(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_description_for_all_possible_items(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); - StartTestItemRQ featureStart = featureCaptor.getValue(); - assertThat(featureStart.getDescription(), endsWith("feature/description.feature\n\n---\n\nThis is my Feature description.")); + StartTestItemRQ featureStart = featureCaptor.getValue(); + assertThat(featureStart.getDescription(), endsWith("feature/description.feature\n\n---\n\nThis is my Feature description.")); - StartTestItemRQ scenarioStart = scenarioCaptor.getValue(); - assertThat(scenarioStart.getDescription(), equalTo(SCENARIO_DESCRIPTION)); + StartTestItemRQ scenarioStart = scenarioCaptor.getValue(); + assertThat(scenarioStart.getDescription(), equalTo(SCENARIO_DESCRIPTION)); - List backgroundSteps = stepCaptor.getAllValues().stream() - .filter(s -> s.getName().startsWith(Background.KEYWORD)).collect(Collectors.toList()); - assertThat(backgroundSteps, hasSize(1)); - StartTestItemRQ backgroundStep = backgroundSteps.get(0); - assertThat("No support of Background description in Karate yet. But this is a part of Gherkin standard.", - backgroundStep.getDescription(), nullValue()); - } + List backgroundSteps = stepCaptor.getAllValues() + .stream() + .filter(s -> s.getName().startsWith(Background.KEYWORD)) + .collect(Collectors.toList()); + assertThat(backgroundSteps, hasSize(1)); + StartTestItemRQ backgroundStep = backgroundSteps.get(0); + assertThat( + "No support of Background description in Karate yet. But this is a part of Gherkin standard.", + backgroundStep.getDescription(), + nullValue() + ); + } } diff --git a/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java b/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java index 05b232f..0da55a9 100644 --- a/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java +++ b/src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.java @@ -39,53 +39,48 @@ import static org.mockito.Mockito.*; public class ExamplesTestCaseIdTest { - private static final String TEST_FEATURE = "classpath:feature/examples.feature"; - private static final String EXAMPLE_TEST_CASE_ID_PATTERN = - "feature/examples.feature/[EXAMPLE:Verify different maths[%s]]"; - private static final String FIRST_EXAMPLE_TEST_CASE_ID = - String.format(EXAMPLE_TEST_CASE_ID_PATTERN, "result:4;vara:2;varb:2"); - private static final String SECOND_EXAMPLE_TEST_CASE_ID = - String.format(EXAMPLE_TEST_CASE_ID_PATTERN, "result:3;vara:1;varb:2"); - private final String featureId = CommonUtils.namedId("feature_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) - .collect(Collectors.toList()); - private final List>> stepIds = exampleIds.stream() - .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(2).collect(Collectors.toList()))) - .collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; + private static final String EXAMPLE_TEST_CASE_ID_PATTERN = "feature/examples.feature/[EXAMPLE:Verify different maths[%s]]"; + private static final String FIRST_EXAMPLE_TEST_CASE_ID = String.format(EXAMPLE_TEST_CASE_ID_PATTERN, "result:4;vara:2;varb:2"); + private static final String SECOND_EXAMPLE_TEST_CASE_ID = String.format(EXAMPLE_TEST_CASE_ID_PATTERN, "result:3;vara:1;varb:2"); + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2).collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")).limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_examples_test_case_id(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_examples_test_case_id(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(2)).startTestItem(same(featureId), captor.capture()); - verify(client, times(2)).startTestItem(same(exampleIds.get(0)), captor.capture()); - verify(client, times(2)).startTestItem(same(exampleIds.get(1)), captor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(2)).startTestItem(same(featureId), captor.capture()); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), captor.capture()); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), captor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(7)); + List items = captor.getAllValues(); + assertThat(items, hasSize(7)); - StartTestItemRQ firstScenarioRq = items.get(1); - assertThat(firstScenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_TEST_CASE_ID))); + StartTestItemRQ firstScenarioRq = items.get(1); + assertThat(firstScenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(FIRST_EXAMPLE_TEST_CASE_ID))); - StartTestItemRQ secondScenarioRq = items.get(2); - assertThat(secondScenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_TEST_CASE_ID))); - } + StartTestItemRQ secondScenarioRq = items.get(2); + assertThat(secondScenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(SECOND_EXAMPLE_TEST_CASE_ID))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java b/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java index a3eff8e..9084271 100644 --- a/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java +++ b/src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.java @@ -38,41 +38,40 @@ import static org.mockito.Mockito.*; public class ScenarioTestCaseIdTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private static final String SIMPLE_TEST_CASE_ID = "feature/simple.feature/[SCENARIO:Verify math]"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private static final String SIMPLE_TEST_CASE_ID = "feature/simple.feature/[SCENARIO:Verify math]"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_test_case_id(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_test_case_id(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(1)).startTestItem(same(featureId), captor.capture()); - verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(5)); + List items = captor.getAllValues(); + assertThat(items, hasSize(5)); - StartTestItemRQ scenarioRq = items.get(1); - assertThat(scenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(SIMPLE_TEST_CASE_ID))); - } + StartTestItemRQ scenarioRq = items.get(1); + assertThat(scenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(SIMPLE_TEST_CASE_ID))); + } } diff --git a/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java b/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java index 5688962..52be11a 100644 --- a/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java +++ b/src/test/java/com/epam/reportportal/karate/launch/LaunchRequiredFieldsTest.java @@ -39,40 +39,38 @@ import static org.mockito.Mockito.verify; public class LaunchRequiredFieldsTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void verify_start_launch_request_contains_required_fields(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void verify_start_launch_request_contains_required_fields(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); - verify(client).startLaunch(startCaptor.capture()); + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(startCaptor.capture()); - StartLaunchRQ launchStart = startCaptor.getValue(); - assertThat(launchStart.getName(), startsWith("My-test-launch")); - assertThat(launchStart.getStartTime(), notNullValue()); - assertThat(System.currentTimeMillis() - launchStart.getStartTime().getTime(), - not(greaterThan(TimeUnit.SECONDS.toMillis(10)))); + StartLaunchRQ launchStart = startCaptor.getValue(); + assertThat(launchStart.getName(), startsWith("My-test-launch")); + assertThat(launchStart.getStartTime(), notNullValue()); + assertThat(System.currentTimeMillis() - launchStart.getStartTime().getTime(), not(greaterThan(TimeUnit.SECONDS.toMillis(10)))); - } + } } diff --git a/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java b/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java index 019efbb..7f2e67f 100644 --- a/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java +++ b/src/test/java/com/epam/reportportal/karate/logging/HttpRequestLoggingTest.java @@ -39,51 +39,49 @@ import static org.mockito.Mockito.*; public class HttpRequestLoggingTest { - private static final String TEST_FEATURE = "classpath:feature/http_request.feature"; - private final String launchUuid = CommonUtils.namedId("launch_"); - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(6).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/http_request.feature"; + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(6).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - @SuppressWarnings({"unchecked", "rawtypes"}) - public void test_http_request_logging(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void test_http_request_logging(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); - verify(client, atLeastOnce()).log(logCaptor.capture()); - List logs = logCaptor - .getAllValues(). - stream() - .flatMap(rq -> extractJsonParts((List) rq).stream()) - .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel()) || LogLevel.DEBUG.name().equals(rq.getLevel())) - .collect(Collectors.toList()); + ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); + verify(client, atLeastOnce()).log(logCaptor.capture()); + List logs = logCaptor.getAllValues() + .stream() + .flatMap(rq -> extractJsonParts((List) rq).stream()) + .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel()) || LogLevel.DEBUG.name().equals(rq.getLevel())) + .collect(Collectors.toList()); - assertThat(logs, hasSize(greaterThanOrEqualTo(2))); - List messages = logs.stream().map(SaveLogRQ::getMessage).collect(Collectors.toList()); - assertThat(messages, hasItems( - equalTo("Docstring:\n\n```\n{\n" + - " username: 'user',\n" + - " password: 'password',\n" + - " grant_type: 'password'\n" + - "}\n```"), - containsString("{\"username\":\"user\",\"password\":\"password\",\"grant_type\":\"password\"}"))); - } + assertThat(logs, hasSize(greaterThanOrEqualTo(2))); + List messages = logs.stream().map(SaveLogRQ::getMessage).collect(Collectors.toList()); + assertThat(messages, + hasItems(equalTo( + "Docstring:\n\n```\n{\n" + " username: 'user',\n" + " password: 'password',\n" + " grant_type: 'password'\n" + + "}\n```"), + containsString("{\"username\":\"user\",\"password\":\"password\",\"grant_type\":\"password\"}") + ) + ); + } } diff --git a/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java b/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java index fbfe232..466d1df 100644 --- a/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java +++ b/src/test/java/com/epam/reportportal/karate/logging/SimpleFailureLoggingTest.java @@ -39,49 +39,48 @@ import static org.mockito.Mockito.*; public class SimpleFailureLoggingTest { - private static final String TEST_FEATURE = "classpath:feature/simple_failed.feature"; - private final String launchUuid = CommonUtils.namedId("launch_"); - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple_failed.feature"; + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - @SuppressWarnings({"unchecked", "rawtypes"}) - public void test_simple_one_step_failed_error_log(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(1)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void test_simple_one_step_failed_error_log(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(1)); - ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); - verify(client, atLeastOnce()).log(logCaptor.capture()); - List logs = logCaptor - .getAllValues(). - stream() - .flatMap(rq -> extractJsonParts((List) rq).stream()) - .filter(rq -> LogLevel.ERROR.name().equals(rq.getLevel())) - .collect(Collectors.toList()); + ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); + verify(client, atLeastOnce()).log(logCaptor.capture()); + List logs = logCaptor.getAllValues() + .stream() + .flatMap(rq -> extractJsonParts((List) rq).stream()) + .filter(rq -> LogLevel.ERROR.name().equals(rq.getLevel())) + .collect(Collectors.toList()); - assertThat(logs, hasSize(greaterThan(0))); - SaveLogRQ log = logs.get(logs.size() - 1); - assertThat(log.getItemUuid(), oneOf(stepIds.toArray(new String[0]))); - assertThat(log.getLaunchUuid(), equalTo(launchUuid)); - assertThat(log.getMessage(), equalTo("Then assert actualFour != four\n" - + "did not evaluate to 'true': actualFour != four\n" - + "classpath:feature/simple_failed.feature:6")); - } + assertThat(logs, hasSize(greaterThan(0))); + SaveLogRQ log = logs.get(logs.size() - 1); + assertThat(log.getItemUuid(), oneOf(stepIds.toArray(new String[0]))); + assertThat(log.getLaunchUuid(), equalTo(launchUuid)); + assertThat(log.getMessage(), + equalTo("Then assert actualFour != four\n" + "did not evaluate to 'true': actualFour != four\n" + + "classpath:feature/simple_failed.feature:6") + ); + } } diff --git a/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java b/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java index 7fbf724..fe90e95 100644 --- a/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java +++ b/src/test/java/com/epam/reportportal/karate/name/SimpleItemNameTest.java @@ -38,49 +38,47 @@ import static org.mockito.Mockito.*; public class SimpleItemNameTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private static final String[] STEP_NAMES = new String[]{"Given def four = 4", "When def actualFour = 2 * 2", - "Then assert actualFour == four"}; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private static final String[] STEP_NAMES = new String[] { "Given def four = 4", "When def actualFour = 2 * 2", + "Then assert actualFour == four" }; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_item_names_simple(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_item_names_simple(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); - StartTestItemRQ featureRq = featureCaptor.getValue(); - StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); + StartTestItemRQ featureRq = featureCaptor.getValue(); + StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); - assertThat(featureRq.getName(), allOf(notNullValue(), equalTo("the very basic test to run by Karate"))); + assertThat(featureRq.getName(), allOf(notNullValue(), equalTo("the very basic test to run by Karate"))); - assertThat(scenarioRq.getName(), allOf(notNullValue(), equalTo("Verify math"))); + assertThat(scenarioRq.getName(), allOf(notNullValue(), equalTo("Verify math"))); - List stepNames = stepCaptor.getAllValues().stream().map(StartTestItemRQ::getName) - .collect(Collectors.toList()); - assertThat(stepNames, containsInAnyOrder(STEP_NAMES)); - } + List stepNames = stepCaptor.getAllValues().stream().map(StartTestItemRQ::getName).collect(Collectors.toList()); + assertThat(stepNames, containsInAnyOrder(STEP_NAMES)); + } } diff --git a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java index b2a689b..9e779e1 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesScenarioParametersTest.java @@ -40,58 +40,56 @@ import static org.mockito.Mockito.*; public class ExamplesScenarioParametersTest { - private static final String TEST_FEATURE = "classpath:feature/examples.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) - .collect(Collectors.toList()); - private final List>> stepIds = exampleIds.stream() - .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(2).collect(Collectors.toList()))) - .collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2).collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")).limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_examples_scenario_parameters(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_examples_scenario_parameters(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(2)).startTestItem(same(featureId), captor.capture()); - verify(client, times(2)).startTestItem(same(exampleIds.get(0)), captor.capture()); - verify(client, times(2)).startTestItem(same(exampleIds.get(1)), captor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(2)).startTestItem(same(featureId), captor.capture()); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), captor.capture()); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), captor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(7)); + List items = captor.getAllValues(); + assertThat(items, hasSize(7)); - StartTestItemRQ firstScenarioRq = items.get(1); - StartTestItemRQ secondScenarioRq = items.get(2); - List firstParameters = firstScenarioRq.getParameters(); - List secondParameters = secondScenarioRq.getParameters(); - assertThat(firstParameters, hasSize(3)); - assertThat(secondParameters, hasSize(3)); + StartTestItemRQ firstScenarioRq = items.get(1); + StartTestItemRQ secondScenarioRq = items.get(2); + List firstParameters = firstScenarioRq.getParameters(); + List secondParameters = secondScenarioRq.getParameters(); + assertThat(firstParameters, hasSize(3)); + assertThat(secondParameters, hasSize(3)); - assertThat( - firstParameters.stream().map(p -> p.getKey() + ":" + p.getValue()).collect(Collectors.toSet()), - allOf(hasItem("vara:2"), hasItem("varb:2"), hasItem("result:4")) - ); - assertThat( - secondParameters.stream().map(p -> p.getKey() + ":" + p.getValue()).collect(Collectors.toSet()), - allOf(hasItem("vara:1"), hasItem("varb:2"), hasItem("result:3")) - ); - } + assertThat( + firstParameters.stream().map(p -> p.getKey() + ":" + p.getValue()).collect(Collectors.toSet()), + allOf(hasItem("vara:2"), hasItem("varb:2"), hasItem("result:4")) + ); + assertThat( + secondParameters.stream().map(p -> p.getKey() + ":" + p.getValue()).collect(Collectors.toSet()), + allOf(hasItem("vara:1"), hasItem("varb:2"), hasItem("result:3")) + ); + } } diff --git a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java index 6dc426c..929b136 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/ExamplesStepParametersTest.java @@ -48,80 +48,75 @@ import static org.mockito.Mockito.*; public class ExamplesStepParametersTest { - private static final String TEST_FEATURE = "classpath:feature/examples.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) - .collect(Collectors.toList()); - private final List>> stepIds = exampleIds.stream() - .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(2).collect(Collectors.toList()))) - .collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/examples.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2).collect(Collectors.toList()); + private final List>> stepIds = exampleIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")).limit(2).collect(Collectors.toList()))) + .collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - private static Set toParameterStringList(List parameters) { - return ofNullable(parameters) - .flatMap(Collection::stream) - .map(p -> p.getKey() + ":" + p.getValue()) - .collect(Collectors.toSet()); - } + private static Set toParameterStringList(List parameters) { + return ofNullable(parameters).flatMap(Collection::stream).map(p -> p.getKey() + ":" + p.getValue()).collect(Collectors.toSet()); + } - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - @SuppressWarnings({"unchecked", "rawtypes"}) - public void test_examples_parameters_for_steps(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void test_examples_parameters_for_steps(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(captor.capture()); - verify(client, times(2)).startTestItem(same(featureId), captor.capture()); - ArgumentCaptor firstExampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstExampleCaptor.capture()); - ArgumentCaptor secondExampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondExampleCaptor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(captor.capture()); + verify(client, times(2)).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor firstExampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(0)), firstExampleCaptor.capture()); + ArgumentCaptor secondExampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(exampleIds.get(1)), secondExampleCaptor.capture()); - List firstSteps = firstExampleCaptor.getAllValues(); - Set parameterStrings = toParameterStringList(firstSteps.get(0).getParameters()); - assertThat(parameterStrings, hasSize(2)); - assertThat(parameterStrings, allOf(hasItem("vara:2"), hasItem("varb:2"))); - parameterStrings = toParameterStringList(firstSteps.get(1).getParameters()); - assertThat(parameterStrings, hasSize(1)); - assertThat(parameterStrings, hasItem("result:4")); + List firstSteps = firstExampleCaptor.getAllValues(); + Set parameterStrings = toParameterStringList(firstSteps.get(0).getParameters()); + assertThat(parameterStrings, hasSize(2)); + assertThat(parameterStrings, allOf(hasItem("vara:2"), hasItem("varb:2"))); + parameterStrings = toParameterStringList(firstSteps.get(1).getParameters()); + assertThat(parameterStrings, hasSize(1)); + assertThat(parameterStrings, hasItem("result:4")); - List secondSteps = secondExampleCaptor.getAllValues(); - parameterStrings = toParameterStringList(secondSteps.get(0).getParameters()); - assertThat(parameterStrings, hasSize(2)); - assertThat(parameterStrings, allOf(hasItem("vara:1"), hasItem("varb:2"))); - parameterStrings = toParameterStringList(secondSteps.get(1).getParameters()); - assertThat(parameterStrings, hasSize(1)); - assertThat(parameterStrings, hasItem("result:3")); + List secondSteps = secondExampleCaptor.getAllValues(); + parameterStrings = toParameterStringList(secondSteps.get(0).getParameters()); + assertThat(parameterStrings, hasSize(2)); + assertThat(parameterStrings, allOf(hasItem("vara:1"), hasItem("varb:2"))); + parameterStrings = toParameterStringList(secondSteps.get(1).getParameters()); + assertThat(parameterStrings, hasSize(1)); + assertThat(parameterStrings, hasItem("result:3")); - ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); - verify(client, atLeastOnce()).log(logCaptor.capture()); - Map logs = logCaptor - .getAllValues(). - stream() - .flatMap(rq -> extractJsonParts((List) rq).stream()) - .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel())) - .collect(Collectors.toMap(SaveLogRQ::getItemUuid, v -> v)); + ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); + verify(client, atLeastOnce()).log(logCaptor.capture()); + Map logs = logCaptor.getAllValues() + .stream() + .flatMap(rq -> extractJsonParts((List) rq).stream()) + .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel())) + .collect(Collectors.toMap(SaveLogRQ::getItemUuid, v -> v)); - List stepIdList = stepIds.stream().flatMap(e -> e.getValue().stream()).collect(Collectors.toList()); - assertThat(logs.keySet(), hasSize(stepIdList.size())); - stepIdList.forEach(id -> assertThat(logs, hasKey(id))); - assertThat(logs.values().stream().map(SaveLogRQ::getMessage).collect(Collectors.toList()), - everyItem(startsWith("Parameters:\n\n"))); - } + List stepIdList = stepIds.stream().flatMap(e -> e.getValue().stream()).collect(Collectors.toList()); + assertThat(logs.keySet(), hasSize(stepIdList.size())); + stepIdList.forEach(id -> assertThat(logs, hasKey(id))); + assertThat(logs.values().stream().map(SaveLogRQ::getMessage).collect(Collectors.toList()), + everyItem(startsWith("Parameters:\n\n")) + ); + } } diff --git a/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java index a063c51..715418b 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/NoParametersTest.java @@ -38,46 +38,45 @@ import static org.mockito.Mockito.*; public class NoParametersTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_no_parameters_reporting(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_no_parameters_reporting(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(1)).startTestItem(same(featureId), captor.capture()); - verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + verify(client, times(3)).startTestItem(same(scenarioId), captor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(5)); + List items = captor.getAllValues(); + assertThat(items, hasSize(5)); - StartTestItemRQ featureRq = items.get(0); - StartTestItemRQ scenarioRq = items.get(1); + StartTestItemRQ featureRq = items.get(0); + StartTestItemRQ scenarioRq = items.get(1); - assertThat(featureRq.getParameters(), nullValue()); - assertThat(scenarioRq.getParameters(), nullValue()); + assertThat(featureRq.getParameters(), nullValue()); + assertThat(scenarioRq.getParameters(), nullValue()); - items.subList(2, items.size()).forEach(step -> assertThat(step.getParameters(), nullValue())); - } + items.subList(2, items.size()).forEach(step -> assertThat(step.getParameters(), nullValue())); + } } diff --git a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java index 9d30ae3..4784329 100644 --- a/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java +++ b/src/test/java/com/epam/reportportal/karate/parameters/TableParametersTest.java @@ -42,52 +42,50 @@ import static org.mockito.Mockito.*; public class TableParametersTest { - private static final String TEST_FEATURE = "classpath:feature/table.feature"; - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(4).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/table.feature"; + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(4).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, null, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, null, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - @SuppressWarnings({"unchecked", "rawtypes"}) - public void test_table_parameters_reporting(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void test_table_parameters_reporting(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(1)).startTestItem(captor.capture()); - verify(client, times(1)).startTestItem(same(featureId), captor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(4)).startTestItem(same(scenarioId), stepCaptor.capture()); - ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); - verify(client, atLeastOnce()).log(logCaptor.capture()); + ArgumentCaptor captor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(captor.capture()); + verify(client, times(1)).startTestItem(same(featureId), captor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(4)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor logCaptor = ArgumentCaptor.forClass(List.class); + verify(client, atLeastOnce()).log(logCaptor.capture()); - List items = captor.getAllValues(); - assertThat(items, hasSize(2)); + List items = captor.getAllValues(); + assertThat(items, hasSize(2)); - List logs = logCaptor - .getAllValues(). - stream() - .flatMap(rq -> extractJsonParts((List) rq).stream()) - .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel())) - .collect(Collectors.toList()); - assertThat(logs, hasSize(1)); - assertThat(logs.get(0).getMessage(), startsWith("Table:\n\n")); - assertThat(logs.get(0).getItemUuid(), startsWith("step_")); - } + List logs = logCaptor.getAllValues() + .stream() + .flatMap(rq -> extractJsonParts((List) rq).stream()) + .filter(rq -> LogLevel.INFO.name().equals(rq.getLevel())) + .collect(Collectors.toList()); + assertThat(logs, hasSize(1)); + assertThat(logs.get(0).getMessage(), startsWith("Table:\n\n")); + assertThat(logs.get(0).getItemUuid(), startsWith("step_")); + } } diff --git a/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java b/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java index 2bf7dda..0174ece 100644 --- a/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java +++ b/src/test/java/com/epam/reportportal/karate/status/SimpleAllPassedTest.java @@ -39,57 +39,57 @@ import static org.mockito.Mockito.*; public class SimpleAllPassedTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String launchUuid = CommonUtils.namedId("launch_"); - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_simple_all_passed(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_simple_all_passed(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - verify(client).finishTestItem(same(featureId), featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - verify(client).finishTestItem(same(scenarioId), scenarioCaptor.capture()); - List> stepCaptors = - Stream.generate(() -> ArgumentCaptor.forClass(FinishTestItemRQ.class)).limit(stepIds.size()).collect(Collectors.toList()); - IntStream.range(0, stepIds.size()).forEach(i -> verify(client).finishTestItem(same(stepIds.get(i)), stepCaptors.get(i).capture())); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(client).finishTestItem(same(featureId), featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(client).finishTestItem(same(scenarioId), scenarioCaptor.capture()); + List> stepCaptors = Stream.generate(() -> ArgumentCaptor.forClass(FinishTestItemRQ.class)) + .limit(stepIds.size()) + .collect(Collectors.toList()); + IntStream.range(0, stepIds.size()).forEach(i -> verify(client).finishTestItem(same(stepIds.get(i)), stepCaptors.get(i).capture())); - FinishTestItemRQ featureRq = featureCaptor.getValue(); - FinishTestItemRQ scenarioRq = scenarioCaptor.getValue(); + FinishTestItemRQ featureRq = featureCaptor.getValue(); + FinishTestItemRQ scenarioRq = scenarioCaptor.getValue(); - assertThat(featureRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); - assertThat(featureRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); - assertThat(featureRq.getEndTime(), notNullValue()); + assertThat(featureRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); + assertThat(featureRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(featureRq.getEndTime(), notNullValue()); - assertThat(scenarioRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); - assertThat(scenarioRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); - assertThat(scenarioRq.getEndTime(), notNullValue()); + assertThat(scenarioRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); + assertThat(scenarioRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(scenarioRq.getEndTime(), notNullValue()); - stepCaptors.forEach(stepCaptor -> { - FinishTestItemRQ step = stepCaptor.getValue(); - assertThat(step.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); - assertThat(step.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); - assertThat(step.getEndTime(), notNullValue()); - }); - } + stepCaptors.forEach(stepCaptor -> { + FinishTestItemRQ step = stepCaptor.getValue(); + assertThat(step.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); + assertThat(step.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(step.getEndTime(), notNullValue()); + }); + } } \ No newline at end of file diff --git a/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java b/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java index 5dd8d33..5b82026 100644 --- a/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java +++ b/src/test/java/com/epam/reportportal/karate/status/SimpleOneStepFailedTest.java @@ -40,58 +40,58 @@ import static org.mockito.Mockito.*; public class SimpleOneStepFailedTest { - private static final String TEST_FEATURE = "classpath:feature/simple_failed.feature"; - private final String launchUuid = CommonUtils.namedId("launch_"); - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple_failed.feature"; + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_simple_one_step_failed(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(1)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_simple_one_step_failed(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(1)); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - verify(client).finishTestItem(same(featureId), featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - verify(client).finishTestItem(same(scenarioId), scenarioCaptor.capture()); - List> stepCaptors = - Stream.generate(() -> ArgumentCaptor.forClass(FinishTestItemRQ.class)).limit(stepIds.size()).collect(Collectors.toList()); - IntStream.range(0, stepIds.size()).forEach(i -> verify(client).finishTestItem(same(stepIds.get(i)), stepCaptors.get(i).capture())); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(client).finishTestItem(same(featureId), featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(client).finishTestItem(same(scenarioId), scenarioCaptor.capture()); + List> stepCaptors = Stream.generate(() -> ArgumentCaptor.forClass(FinishTestItemRQ.class)) + .limit(stepIds.size()) + .collect(Collectors.toList()); + IntStream.range(0, stepIds.size()).forEach(i -> verify(client).finishTestItem(same(stepIds.get(i)), stepCaptors.get(i).capture())); - FinishTestItemRQ featureRq = featureCaptor.getValue(); - FinishTestItemRQ scenarioRq = scenarioCaptor.getValue(); + FinishTestItemRQ featureRq = featureCaptor.getValue(); + FinishTestItemRQ scenarioRq = scenarioCaptor.getValue(); - assertThat(featureRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.FAILED.name()))); - assertThat(featureRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); - assertThat(featureRq.getEndTime(), notNullValue()); + assertThat(featureRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.FAILED.name()))); + assertThat(featureRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(featureRq.getEndTime(), notNullValue()); - assertThat(scenarioRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.FAILED.name()))); - assertThat(scenarioRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); - assertThat(scenarioRq.getEndTime(), notNullValue()); + assertThat(scenarioRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.FAILED.name()))); + assertThat(scenarioRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(scenarioRq.getEndTime(), notNullValue()); - List steps = stepCaptors.stream().map(ArgumentCaptor::getValue).collect(Collectors.toList()); - steps.forEach(step -> { - assertThat(step.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); - assertThat(step.getEndTime(), notNullValue()); - }); - List statuses = steps.stream().map(FinishExecutionRQ::getStatus).collect(Collectors.toList()); - assertThat(statuses, containsInAnyOrder("PASSED", "PASSED", "FAILED")); - } + List steps = stepCaptors.stream().map(ArgumentCaptor::getValue).collect(Collectors.toList()); + steps.forEach(step -> { + assertThat(step.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(step.getEndTime(), notNullValue()); + }); + List statuses = steps.stream().map(FinishExecutionRQ::getStatus).collect(Collectors.toList()); + assertThat(statuses, containsInAnyOrder("PASSED", "PASSED", "FAILED")); + } } diff --git a/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java b/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java index af448d6..c71d24d 100644 --- a/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java +++ b/src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java @@ -38,64 +38,78 @@ import static org.mockito.Mockito.*; public class SimpleTimingTest { - private static final String TEST_FEATURE = "classpath:feature/simple.feature"; - private final String launchUuid = CommonUtils.namedId("launch_"); - private final String featureId = CommonUtils.namedId("feature_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) - .limit(3).collect(Collectors.toList()); + private static final String TEST_FEATURE = "classpath:feature/simple.feature"; + private final String launchUuid = CommonUtils.namedId("launch_"); + private final String featureId = CommonUtils.namedId("feature_"); + private final String scenarioId = CommonUtils.namedId("scenario_"); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()); - private final ReportPortalClient client = mock(ReportPortalClient.class); - private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); + private final ReportPortalClient client = mock(ReportPortalClient.class); + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); - @BeforeEach - public void setupMock() { - mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); - mockBatchLogging(client); - } + @BeforeEach + public void setupMock() { + mockLaunch(client, launchUuid, featureId, scenarioId, stepIds); + mockBatchLogging(client); + } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - public void test_each_item_has_correct_start_date(boolean report) { - Results results; - if (report) { - results = TestUtils.runAsReport(rp, TEST_FEATURE); - } else { - results = TestUtils.runAsHook(rp, TEST_FEATURE); - } - assertThat(results.getFailCount(), equalTo(0)); + @ParameterizedTest + @ValueSource(booleans = { true, false }) + public void test_each_item_has_correct_start_date(boolean report) { + Results results; + if (report) { + results = TestUtils.runAsReport(rp, TEST_FEATURE); + } else { + results = TestUtils.runAsHook(rp, TEST_FEATURE); + } + assertThat(results.getFailCount(), equalTo(0)); - ArgumentCaptor launchCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); - verify(client).startLaunch(launchCaptor.capture()); - ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(featureCaptor.capture()); - ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); - ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor launchCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class); + verify(client).startLaunch(launchCaptor.capture()); + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture()); - StartLaunchRQ launchRq = launchCaptor.getValue(); - StartTestItemRQ featureRq = featureCaptor.getValue(); - StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); + StartLaunchRQ launchRq = launchCaptor.getValue(); + StartTestItemRQ featureRq = featureCaptor.getValue(); + StartTestItemRQ scenarioRq = scenarioCaptor.getValue(); - assertThat("Launch start time is greater than Feature start time.", - featureRq.getStartTime(), greaterThanOrEqualTo(launchRq.getStartTime())); - assertThat("Feature start time is greater than Scenario start time.", - scenarioRq.getStartTime(), greaterThanOrEqualTo(featureRq.getStartTime())); + assertThat( + "Launch start time is greater than Feature start time.", + featureRq.getStartTime(), + greaterThanOrEqualTo(launchRq.getStartTime()) + ); + assertThat( + "Feature start time is greater than Scenario start time.", + scenarioRq.getStartTime(), + greaterThanOrEqualTo(featureRq.getStartTime()) + ); - List steps = stepCaptor.getAllValues(); - StartTestItemRQ firstStep = steps.stream() - .filter(s -> "Given def four = 4".equals(s.getName())).findAny().orElseThrow(); - StartTestItemRQ secondStep = steps.stream() - .filter(s -> "When def actualFour = 2 * 2".equals(s.getName())).findAny().orElseThrow(); - StartTestItemRQ thirdStep = steps.stream() - .filter(s -> "Then assert actualFour == four".equals(s.getName())).findAny().orElseThrow(); + List steps = stepCaptor.getAllValues(); + StartTestItemRQ firstStep = steps.stream().filter(s -> "Given def four = 4".equals(s.getName())).findAny().orElseThrow(); + StartTestItemRQ secondStep = steps.stream().filter(s -> "When def actualFour = 2 * 2".equals(s.getName())).findAny().orElseThrow(); + StartTestItemRQ thirdStep = steps.stream() + .filter(s -> "Then assert actualFour == four".equals(s.getName())) + .findAny() + .orElseThrow(); - assertThat("Scenario start time is greater than Step start time.", - firstStep.getStartTime(), greaterThanOrEqualTo(scenarioRq.getStartTime())); - assertThat("First Step start time is greater or equal than Second Step start time.", - secondStep.getStartTime(), greaterThan(firstStep.getStartTime())); - assertThat("Second Step start time is greater or equal than Third Step start time.", - thirdStep.getStartTime(), greaterThan(secondStep.getStartTime())); - } + assertThat( + "Scenario start time is greater than Step start time.", + firstStep.getStartTime(), + greaterThanOrEqualTo(scenarioRq.getStartTime()) + ); + assertThat( + "First Step start time is greater or equal than Second Step start time.", + secondStep.getStartTime(), + greaterThan(firstStep.getStartTime()) + ); + assertThat( + "Second Step start time is greater or equal than Third Step start time.", + thirdStep.getStartTime(), + greaterThan(secondStep.getStartTime()) + ); + } } diff --git a/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java b/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java index b940910..bb61de3 100644 --- a/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java +++ b/src/test/java/com/epam/reportportal/karate/utils/ReflectUtils.java @@ -20,16 +20,16 @@ public class ReflectUtils { - private ReflectUtils() { - } + private ReflectUtils() { + } - public static void setField(Object object, Field fld, Object value) { - try { - fld.setAccessible(true); - fld.set(object, value); - } catch (IllegalAccessException e) { - String fieldName = fld.getName(); - throw new RuntimeException("Failed to set " + fieldName + " of object", e); - } - } + public static void setField(Object object, Field fld, Object value) { + try { + fld.setAccessible(true); + fld.set(object, value); + } catch (IllegalAccessException e) { + String fieldName = fld.getName(); + throw new RuntimeException("Failed to set " + fieldName + " of object", e); + } + } } diff --git a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java index 3a77ff6..520bacc 100644 --- a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java +++ b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java @@ -52,183 +52,168 @@ import static org.mockito.Mockito.when; public class TestUtils { - public static final String ROOT_SUITE_PREFIX = "root_"; - - private TestUtils() { - } - - public static ExecutorService testExecutor() { - return Executors.newSingleThreadExecutor(r -> { - Thread t = new Thread(r); - t.setDaemon(true); - return t; - }); - } - - public static Results runAsReport(ReportPortal reportPortal, String... paths) { - return KarateReportPortalRunner - .path(paths) - .withReportPortal(reportPortal) - .outputCucumberJson(false) - .parallel(1); - } - - public static Results runAsHook(ReportPortal reportPortal, String... paths) { - return Runner - .path(paths) - .hook(new ReportPortalHook(reportPortal)) - .outputCucumberJson(false) - .parallel(1); - } - - public static ListenerParameters standardParameters() { - ListenerParameters result = new ListenerParameters(); - result.setClientJoin(false); - result.setLaunchName("My-test-launch" + generateUniqueId()); - result.setProjectName("test-project"); - result.setEnable(true); - result.setCallbackReportingEnabled(true); - result.setBaseUrl("http://localhost:8080"); - return result; - } - - public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid, - @Nullable final String featureUuid, @Nonnull String scenarioUuid, - @Nonnull String stepUuid) { - mockLaunch(client, launchUuid, featureUuid, scenarioUuid, Collections.singleton(stepUuid)); - } - - public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid, - @Nullable final String featureUuid, @Nonnull String scenarioUuid, - @Nonnull Collection stepList) { - mockLaunch(client, launchUuid, featureUuid, Collections.singletonList(Pair.of(scenarioUuid, stepList))); - } - - public static > void mockLaunch( - @Nonnull final ReportPortalClient client, @Nullable final String launchUuid, - @Nullable final String featureUuid, @Nonnull final Collection> scenarioSteps) { - String launch = ofNullable(launchUuid).orElse(CommonUtils.namedId("launch_")); - when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launch, 1L))); - when(client.finishLaunch(eq(launch), any())).thenReturn(Maybe.just(new OperationCompletionRS())); - - mockFeature(client, featureUuid, scenarioSteps); - } - - public static void mockLaunch( - @Nonnull final ReportPortalClient client, @Nullable final String launchUuid) { - String launch = ofNullable(launchUuid).orElse(CommonUtils.namedId("launch_")); - when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launch, 1L))); - when(client.finishLaunch(eq(launch), any())).thenReturn(Maybe.just(new OperationCompletionRS())); - } - - public static > void mockFeature( - @Nonnull final ReportPortalClient client, @Nullable final String featureUuid, - @Nonnull final Collection> scenarioSteps) { - String rootItemId = ofNullable(featureUuid).orElseGet(() -> CommonUtils.namedId(ROOT_SUITE_PREFIX)); - mockFeatures(client, Collections.singletonList(Pair.of(rootItemId, scenarioSteps))); - } - - @SuppressWarnings("unchecked") - public static > void mockFeatures( - @Nonnull final ReportPortalClient client, - @Nonnull final List>>> features) { - if (features.isEmpty()) { - return; - } - String firstFeature = features.get(0).getKey(); - Maybe first = Maybe.just(new ItemCreatedRS(firstFeature, firstFeature)); - Maybe[] other = (Maybe[]) features.subList(1, features.size()) - .stream() - .map(Pair::getKey) - .map(s -> Maybe.just(new ItemCreatedRS(s, s))) - .toArray(Maybe[]::new); - when(client.startTestItem(any())).thenReturn(first, other); - - features.forEach(i -> { - Maybe rootFinishMaybe = Maybe.just(new OperationCompletionRS()); - when(client.finishTestItem(same(i.getKey()), any())).thenReturn(rootFinishMaybe); - mockScenario(client, i.getKey(), i.getValue()); - }); - } - - @SuppressWarnings("unchecked") - public static > void mockScenario( - @Nonnull final ReportPortalClient client, @Nonnull final String featureUuid, - @Nonnull final Collection> scenarioSteps) { - List> testResponses = scenarioSteps.stream() - .map(Pair::getKey) - .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) - .collect(Collectors.toList()); - - Maybe first = testResponses.get(0); - Maybe[] other = testResponses.subList(1, testResponses.size()).toArray(new Maybe[0]); - when(client.startTestItem(same(featureUuid), any())).thenReturn(first, other); - - scenarioSteps.forEach(test -> { - String scenarioUuid = test.getKey(); - List> stepResponses = test.getValue() - .stream() - .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) - .collect(Collectors.toList()); - when(client.finishTestItem(same(scenarioUuid), any())).thenReturn(Maybe.just(new OperationCompletionRS())); - if (!stepResponses.isEmpty()) { - Maybe myFirst = stepResponses.get(0); - Maybe[] myOther = stepResponses.subList(1, stepResponses.size()).toArray(new Maybe[0]); - when(client.startTestItem(same(scenarioUuid), any())).thenReturn(myFirst, myOther); - new HashSet<>(test.getValue()).forEach(testMethodUuid -> when( - client.finishTestItem(same(testMethodUuid), - any() - )).thenReturn(Maybe.just(new OperationCompletionRS()))); - } - }); - } - - @SuppressWarnings("unchecked") - public static void mockBatchLogging(final ReportPortalClient client) { - when(client.log(any(List.class))).thenReturn(Maybe.just(new BatchSaveOperatingRS())); - } - - @SuppressWarnings("unchecked") - public static void mockNestedSteps(final ReportPortalClient client, final List> parentNestedPairs) { - Map> responseOrders = parentNestedPairs.stream() - .collect(Collectors.groupingBy(Pair::getKey, Collectors.mapping(Pair::getValue, Collectors.toList()))); - responseOrders.forEach((k, v) -> { - List> responses = v.stream() - .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) - .collect(Collectors.toList()); - - Maybe first = responses.get(0); - Maybe[] other = responses.subList(1, responses.size()).toArray(new Maybe[0]); - when(client.startTestItem(eq(k), any())).thenReturn(first, other); - }); - parentNestedPairs.forEach(p -> when(client.finishTestItem(same(p.getValue()), - any() - )).thenAnswer((Answer>) invocation -> Maybe.just(new OperationCompletionRS()))); - } - - public static List extractJsonParts(List parts) { - return parts.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 final String ROOT_SUITE_PREFIX = "root_"; + + private TestUtils() { + } + + public static ExecutorService testExecutor() { + return Executors.newSingleThreadExecutor(r -> { + Thread t = new Thread(r); + t.setDaemon(true); + return t; + }); + } + + public static Results runAsReport(ReportPortal reportPortal, String... paths) { + return KarateReportPortalRunner.path(paths).withReportPortal(reportPortal).outputCucumberJson(false).parallel(1); + } + + public static Results runAsHook(ReportPortal reportPortal, String... paths) { + return Runner.path(paths).hook(new ReportPortalHook(reportPortal)).outputCucumberJson(false).parallel(1); + } + + public static ListenerParameters standardParameters() { + ListenerParameters result = new ListenerParameters(); + result.setClientJoin(false); + result.setLaunchName("My-test-launch" + generateUniqueId()); + result.setProjectName("test-project"); + result.setEnable(true); + result.setCallbackReportingEnabled(true); + result.setBaseUrl("http://localhost:8080"); + return result; + } + + public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid, + @Nullable final String featureUuid, @Nonnull String scenarioUuid, @Nonnull String stepUuid) { + mockLaunch(client, launchUuid, featureUuid, scenarioUuid, Collections.singleton(stepUuid)); + } + + public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid, + @Nullable final String featureUuid, @Nonnull String scenarioUuid, @Nonnull Collection stepList) { + mockLaunch(client, launchUuid, featureUuid, Collections.singletonList(Pair.of(scenarioUuid, stepList))); + } + + public static > void mockLaunch(@Nonnull final ReportPortalClient client, + @Nullable final String launchUuid, @Nullable final String featureUuid, + @Nonnull final Collection> scenarioSteps) { + String launch = ofNullable(launchUuid).orElse(CommonUtils.namedId("launch_")); + when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launch, 1L))); + when(client.finishLaunch(eq(launch), any())).thenReturn(Maybe.just(new OperationCompletionRS())); + + mockFeature(client, featureUuid, scenarioSteps); + } + + public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid) { + String launch = ofNullable(launchUuid).orElse(CommonUtils.namedId("launch_")); + when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launch, 1L))); + when(client.finishLaunch(eq(launch), any())).thenReturn(Maybe.just(new OperationCompletionRS())); + } + + public static > void mockFeature(@Nonnull final ReportPortalClient client, + @Nullable final String featureUuid, @Nonnull final Collection> scenarioSteps) { + String rootItemId = ofNullable(featureUuid).orElseGet(() -> CommonUtils.namedId(ROOT_SUITE_PREFIX)); + mockFeatures(client, Collections.singletonList(Pair.of(rootItemId, scenarioSteps))); + } + + @SuppressWarnings("unchecked") + public static > void mockFeatures(@Nonnull final ReportPortalClient client, + @Nonnull final List>>> features) { + if (features.isEmpty()) { + return; + } + String firstFeature = features.get(0).getKey(); + Maybe first = Maybe.just(new ItemCreatedRS(firstFeature, firstFeature)); + Maybe[] other = (Maybe[]) features.subList(1, features.size()) + .stream() + .map(Pair::getKey) + .map(s -> Maybe.just(new ItemCreatedRS(s, s))) + .toArray(Maybe[]::new); + when(client.startTestItem(any())).thenReturn(first, other); + + features.forEach(i -> { + Maybe rootFinishMaybe = Maybe.just(new OperationCompletionRS()); + when(client.finishTestItem(same(i.getKey()), any())).thenReturn(rootFinishMaybe); + mockScenario(client, i.getKey(), i.getValue()); + }); + } + + @SuppressWarnings("unchecked") + public static > void mockScenario(@Nonnull final ReportPortalClient client, + @Nonnull final String featureUuid, @Nonnull final Collection> scenarioSteps) { + List> testResponses = scenarioSteps.stream() + .map(Pair::getKey) + .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) + .collect(Collectors.toList()); + + Maybe first = testResponses.get(0); + Maybe[] other = testResponses.subList(1, testResponses.size()).toArray(new Maybe[0]); + when(client.startTestItem(same(featureUuid), any())).thenReturn(first, other); + + scenarioSteps.forEach(test -> { + String scenarioUuid = test.getKey(); + List> stepResponses = test.getValue() + .stream() + .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) + .collect(Collectors.toList()); + when(client.finishTestItem(same(scenarioUuid), any())).thenReturn(Maybe.just(new OperationCompletionRS())); + if (!stepResponses.isEmpty()) { + Maybe myFirst = stepResponses.get(0); + Maybe[] myOther = stepResponses.subList(1, stepResponses.size()).toArray(new Maybe[0]); + when(client.startTestItem(same(scenarioUuid), any())).thenReturn(myFirst, myOther); + new HashSet<>(test.getValue()).forEach(testMethodUuid -> when(client.finishTestItem(same(testMethodUuid), + any() + )).thenReturn(Maybe.just(new OperationCompletionRS()))); + } + }); + } + + @SuppressWarnings("unchecked") + public static void mockBatchLogging(final ReportPortalClient client) { + when(client.log(any(List.class))).thenReturn(Maybe.just(new BatchSaveOperatingRS())); + } + + @SuppressWarnings("unchecked") + public static void mockNestedSteps(final ReportPortalClient client, final List> parentNestedPairs) { + Map> responseOrders = parentNestedPairs.stream() + .collect(Collectors.groupingBy(Pair::getKey, Collectors.mapping(Pair::getValue, Collectors.toList()))); + responseOrders.forEach((k, v) -> { + List> responses = v.stream() + .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) + .collect(Collectors.toList()); + + Maybe first = responses.get(0); + Maybe[] other = responses.subList(1, responses.size()).toArray(new Maybe[0]); + when(client.startTestItem(eq(k), any())).thenReturn(first, other); + }); + parentNestedPairs.forEach(p -> when(client.finishTestItem(same(p.getValue()), + any() + )).thenAnswer((Answer>) invocation -> Maybe.just(new OperationCompletionRS()))); + } + + public static List extractJsonParts(List parts) { + return parts.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()); + } } diff --git a/src/test/resources/feature/table.feature b/src/test/resources/feature/table.feature index db2e93e..3a23ad3 100644 --- a/src/test/resources/feature/table.feature +++ b/src/test/resources/feature/table.feature @@ -1,4 +1,5 @@ Feature: test with parameter table + Scenario: Verify parameter table Given def one = 'hello' And def two = { baz: 'world' } diff --git a/src/test/resources/reportportal.properties b/src/test/resources/reportportal.properties index 2fa4d22..4e3b746 100644 --- a/src/test/resources/reportportal.properties +++ b/src/test/resources/reportportal.properties @@ -2,7 +2,6 @@ # rp.api.key= # rp.launch= # rp.project= - ## OPTIONAL PARAMETERS # rp.reporting.async=true # rp.reporting.callback=true From 3d825b6cfaaed471f87d4c4192fa543c7948e1f9 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 16 Jan 2024 14:24:21 +0300 Subject: [PATCH 74/76] Add README_TEMPLATE.md file --- README_TEMPLATE.md | 127 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 README_TEMPLATE.md diff --git a/README_TEMPLATE.md b/README_TEMPLATE.md new file mode 100644 index 0000000..bc5d28a --- /dev/null +++ b/README_TEMPLATE.md @@ -0,0 +1,127 @@ +# ReportPortal runtime Hook for Karate tests +Karate reporters which uploads the results to a ReportPortal server. + +> **DISCLAIMER**: We use Google Analytics for sending anonymous usage information such as agent's and client's names, and their versions +> 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-karate.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.epam.reportportal/agent-java-karate) +[![CI Build](https://github.com/reportportal/agent-java-karate/actions/workflows/ci.yml/badge.svg)](https://github.com/reportportal/agent-java-karate/actions/workflows/ci.yml) +[![codecov](https://codecov.io/github/reportportal/agent-java-karate/graph/badge.svg?token=wJr9F6hZln)](https://codecov.io/github/reportportal/agent-java-karate) +[![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) + +The latest version: $LATEST_VERSION. Please use `Maven Central` link above to get the agent. + +## Agent Configuration +Until the agent-java-karate project is published to Maven repository, +the following configuration can be used: + +* Add jitpack repository to get agent project from GitHub: + * Maven pom.xml + ```xml + + + jitpack.io + https://jitpack.io + + + ``` + + * Gradle build.gradle + ```groovy + repositories { + maven { url 'https://jitpack.io' } + } + ``` + +* Add dependency for the agent project: + * Maven pom.xml + ```xml + + com.github.vrymar + agent-java-karate + Tag_or_Version + + ``` + + * Gradle build.gradle + ```groovy + implementation 'com.github.vrymar:agent-java-karate:Tag_or_Version' + ``` + + +* Add reportportal `client-java` dependency: + * Maven pom.xml + ```xml + + com.epam.reportportal + client-java + Tag_or_Version + + ``` + * Gradle build.gradle + ```groovy + implementation 'com.epam.reportportal:client-java:Tag_or_Version' + ``` + + +**Note**: When the agent is approved by ReportPortal, +the agent repository can be taken from `reportportal`. E.g.: +* Maven pom.xml + ```xml + + com.github.reportportal + agent-java-karate + Tag_or_Version + + ``` + +* Gradle build.gradle + ```groovy + implementation 'com.github.reportportal:agent-java-karate:Tag_or_Version' + ``` + +## Properties File Configuration +* Create `reportportal.properties` file in `src\main\resources` directory. +* Add the following parameters: +``` +rp.endpoint = +rp.uuid = +rp.launch = +rp.project = + +OPTIONAL PARAMETERS +rp.reporting.async=true +rp.reporting.callback=true +rp.enable=true +rp.description=My awesome launch +rp.attributes=key:value;value +rp.rerun=true +rp.rerun.of=ae586912-841c-48de-9391-50720c35dd5a +rp.convertimage=true +rp.mode=DEFAULT +rp.skipped.issue=true +rp.batch.size.logs=20 +rp.keystore.resource= +rp.keystore.password= +``` + +## Execution +To publish test results to ReportPortal, the test project should run by `KarateReportPortalRunner` instead of Karate runner. +E.g.: + + ```java + class scenarioRunnerTest { + + @Test + void testParallel() { + KarateReportPortalRunner + .path("classpath:examples") + .outputCucumberJson(true) + .tags("~@ignore") + .parallel(1); + } + } + ``` From fd6d3615fc5538411ac1a077300332f6d65a64f9 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 16 Jan 2024 16:13:33 +0300 Subject: [PATCH 75/76] Update README_TEMPLATE.md file --- README_TEMPLATE.md | 262 +++++++++++++++++++++++++++------------------ 1 file changed, 156 insertions(+), 106 deletions(-) diff --git a/README_TEMPLATE.md b/README_TEMPLATE.md index bc5d28a..79ab35e 100644 --- a/README_TEMPLATE.md +++ b/README_TEMPLATE.md @@ -1,4 +1,5 @@ # ReportPortal runtime Hook for Karate tests + Karate reporters which uploads the results to a ReportPortal server. > **DISCLAIMER**: We use Google Analytics for sending anonymous usage information such as agent's and client's names, and their versions @@ -14,114 +15,163 @@ Karate reporters which uploads the results to a ReportPortal server. The latest version: $LATEST_VERSION. Please use `Maven Central` link above to get the agent. -## Agent Configuration -Until the agent-java-karate project is published to Maven repository, -the following configuration can be used: - -* Add jitpack repository to get agent project from GitHub: - * Maven pom.xml - ```xml - - - jitpack.io - https://jitpack.io - - - ``` - - * Gradle build.gradle - ```groovy - repositories { - maven { url 'https://jitpack.io' } - } - ``` - -* Add dependency for the agent project: - * Maven pom.xml - ```xml - - com.github.vrymar - agent-java-karate - Tag_or_Version - - ``` - - * Gradle build.gradle - ```groovy - implementation 'com.github.vrymar:agent-java-karate:Tag_or_Version' - ``` - - -* Add reportportal `client-java` dependency: - * Maven pom.xml - ```xml +## Overview: How to Add ReportPortal Logging to Your Project + +To start using ReportPortal with Karate framework please do the following steps: + +1. [Configuration](#configuration) + * Create/update the `reportportal.properties` configuration file + * Build system configuration + * Add Listener + * Runtime + * Post-running +2. [Logging configuration](#logging) + * Loggers and their types +3. [Running tests](#running-tests) + * Build system commands + +## Configuration + +### 'reportportal.properties' configuration file + +As the first step you need to create a file named `reportportal.properties` in your Java project in a source +folder `src/main/resources` or `src/test/resources` (depending on where your tests are located): + +**reportportal.properties** + +``` +rp.endpoint = http://localhost:8080 +rp.api.key = test_YIvQraKKSquDZqrA6JLCWCX5qwmMZBk_7tTm_fkN44AHCi18Ze0RtYqxWNYKxk5p +rp.launch = Karate Tests +rp.project = default_personal +``` + +**Property description** + +* `rp.endpoint` - the URL for the ReportPortal server (actual link). +* `rp.api.key` - an access token for ReportPortal which is used for user identification. It can be found on your report + portal user profile page. +* `rp.project` - a project ID on which the agent will report test launches. Must be set to one of your assigned + projects. +* `rp.launch` - a user-selected identifier of test launches. + +The full list of supported properties is located here in client-java library documentation (a common library for all +Java agents): https://github.com/reportportal/client-java + +## Build system configuration + +### Maven + +If your project is Maven-based you need to add dependencies to `pom.xml` file: + +```xml + + + + - com.epam.reportportal - client-java - Tag_or_Version + com.epam.reportportal + agent-java-karate + $LATEST_VERSION + test - ``` - * Gradle build.gradle - ```groovy - implementation 'com.epam.reportportal:client-java:Tag_or_Version' - ``` - - -**Note**: When the agent is approved by ReportPortal, -the agent repository can be taken from `reportportal`. E.g.: -* Maven pom.xml - ```xml - - com.github.reportportal - agent-java-karate - Tag_or_Version - - ``` - -* Gradle build.gradle - ```groovy - implementation 'com.github.reportportal:agent-java-karate:Tag_or_Version' - ``` - -## Properties File Configuration -* Create `reportportal.properties` file in `src\main\resources` directory. -* Add the following parameters: + + + ``` -rp.endpoint = -rp.uuid = -rp.launch = -rp.project = - -OPTIONAL PARAMETERS -rp.reporting.async=true -rp.reporting.callback=true -rp.enable=true -rp.description=My awesome launch -rp.attributes=key:value;value -rp.rerun=true -rp.rerun.of=ae586912-841c-48de-9391-50720c35dd5a -rp.convertimage=true -rp.mode=DEFAULT -rp.skipped.issue=true -rp.batch.size.logs=20 -rp.keystore.resource= -rp.keystore.password= + +You are free to use you own version of Karate, but not earlier than 1.0.0. If you leave just Agent dependency it will +be still OK, it will use transitive Karate version. + +### Gradle + +For Gradle-based projects please update dependencies section in `build.gradle` file: + +```groovy +dependencies { + testImplementation 'com.epam.reportportal:agent-java-karate:$LATEST_VERSION' +} +``` + +## Listener configuration + +### Runtime + +Runtime publisher uploads Karate tests on ReportPortal during the test execution, providing real-time monitoring capabilities. To publish +test results in this case, the test project should use by `ReportPortalHook` class, an instance of which you should pass to Karate runner. +E.G.: + +```java +import com.epam.reportportal.karate.ReportPortalHook; +import com.intuit.karate.Runner; + +class ScenarioRunnerTest { + @Test + void testParallel() { + return Runner + .path("classpath:examples") + .hook(new ReportPortalHook()) + .outputCucumberJson(true) + .tags("~@ignore") + .parallel(1); + } +} ``` -## Execution -To publish test results to ReportPortal, the test project should run by `KarateReportPortalRunner` instead of Karate runner. -E.g.: - - ```java - class scenarioRunnerTest { - - @Test - void testParallel() { - KarateReportPortalRunner - .path("classpath:examples") - .outputCucumberJson(true) - .tags("~@ignore") - .parallel(1); - } - } - ``` +### Post-running + +Post-running publisher uploads Karate tests on ReportPortal after the test execution. It uses Karate result object to get data about tests. +It might be useful if your tests make heavy load both on ReportPortal server or on the running node. To publish test results in this case, +the test project should run by `KarateReportPortalRunner` instead of Karate runner. +E.G.: + +```java +import com.epam.reportportal.karate.KarateReportPortalRunner; + +class ScenarioRunnerTest { + @Test + void testParallel() { + KarateReportPortalRunner + .path("classpath:examples") + .outputCucumberJson(true) + .tags("~@ignore") + .parallel(1); + } +} +``` + +## Logging + +Karate uses `slf4j` as Logging library, so you are free to choose any Logging Framework. + +ReportPortal provides its own logger implementations for major logging frameworks like *Log4j* and *Logback*. It also +provides additional formatting features for popular client and test libraries like: *Selenide*, *Apache HttpComponents*, +*Rest Assured*, etc. + +Here is the list of supported loggers and setup documentation links. + +**Logging frameworks:** + +| **Library name** | **Documentation link** | +|------------------|-----------------------------------------------------| +| Log4j | https://github.com/reportportal/logger-java-log4j | +| Logback | https://github.com/reportportal/logger-java-logback | + +**HTTP clients:** + +| **Library name** | **Documentation link** | +|-----------------------|------------------------------------------------------------| +| OkHttp3 | https://github.com/reportportal/logger-java-okhttp3 | +| Apache HttpComponents | https://github.com/reportportal/logger-java-httpcomponents | + +## Running tests + +We are set. To run tests we just need to execute corresponding command in our build system. + +#### Maven + +`mvn test` or `mvnw test` if you are using Maven wrapper + +#### Gradle + +`gradle test` or `gradlew test` if you are using Gradle wrapper From f9d52d25c2050846cb20ecbea60c9f14455fe5de Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 16 Jan 2024 16:24:08 +0300 Subject: [PATCH 76/76] Update release branch --- .github/workflows/release.yml | 2 +- build.gradle | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 24d8eec..6b1aae4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,7 @@ name: Release on: push: branches: - - master + - main paths-ignore: - '.github/**' - README.md diff --git a/build.gradle b/build.gradle index 016f87b..a90e645 100644 --- a/build.gradle +++ b/build.gradle @@ -85,4 +85,10 @@ processResources { } } +release { + git { + requireBranch = 'main' + } +} + build.dependsOn jacocoTestReport