From 582a6f7394f4e6e50d88901de0b2f1db4ea03192 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 8 Apr 2024 12:17:30 +0300 Subject: [PATCH 1/6] Dependencies update --- CHANGELOG.md | 2 ++ build.gradle | 38 +++++++++++----------- gradle.properties | 8 ++--- src/test/resources/reportportal.properties | 8 ++--- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ab1250..8e32476 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## [Unreleased] +### Changed +- Client version updated on [5.2.13](https://github.com/reportportal/client-java/releases/tag/5.2.13), by @HardNorth ## [5.0.4] ### Removed diff --git a/build.gradle b/build.gradle index 3a505f2..7a24fea 100644 --- a/build.gradle +++ b/build.gradle @@ -17,11 +17,11 @@ apply plugin: 'java-library' 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" +apply from: "${scripts_url}/${scripts_branch}/release-commons.gradle" +apply from: "${scripts_url}/${scripts_branch}/signing.gradle" +apply from: "${scripts_url}/${scripts_branch}/jacoco.gradle" -project.ext.limits = [ +ext.limits = [ 'instruction': 70, 'branch' : 53, 'line' : 75, @@ -42,21 +42,21 @@ repositories { } dependencies { - api "com.epam.reportportal:client-java:${project.client_java_version}" + api "com.epam.reportportal:client-java:${client_version}" - compileOnly "com.intuit.karate:karate-core:${project.karate_version}" - implementation "org.slf4j:slf4j-api:${project.slf4j_api_version}" + compileOnly "com.intuit.karate:karate-core:${karate_version}" + implementation "org.slf4j:slf4j-api:${slf4j_api_version}" - testImplementation "com.intuit.karate:karate-core:${project.karate_version}" - testImplementation "com.epam.reportportal:logger-java-logback:${project.logger_java_logback_version}" - testImplementation "com.epam.reportportal:agent-java-test-utils:${project.agent_java_test_utils_version}" - 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:${project.hamcrest_core_version}" - testImplementation "com.squareup.okhttp3:okhttp:${project.okhttp_version}" + testImplementation "com.intuit.karate:karate-core:${karate_version}" + testImplementation "com.epam.reportportal:logger-java-logback:${logger_version}" + testImplementation "com.epam.reportportal:agent-java-test-utils:${test_utils_version}" + testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_version}" + testImplementation "org.junit.jupiter:junit-jupiter-engine:${junit_version}" + testImplementation "org.junit.jupiter:junit-jupiter-params:${junit_version}" + testImplementation "org.mockito:mockito-core:${mockito_version}" + testImplementation "org.mockito:mockito-junit-jupiter:${mockito_version}" + testImplementation "org.hamcrest:hamcrest-core:${hamcrest_version}" + testImplementation "com.squareup.okhttp3:okhttp:${okhttp_version}" } test { @@ -80,12 +80,12 @@ test { } wrapper { - gradleVersion = "${project.gradle_version}" + gradleVersion = "${gradle_version}" } processResources { filesMatching('agent.properties') { - expand(project.properties) + expand(properties) } } diff --git a/gradle.properties b/gradle.properties index 6edd679..309d05d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,11 +5,11 @@ gradle_version=8.2 karate_version=1.4.1 junit_version=5.10.1 mockito_version=5.4.0 -agent_java_test_utils_version=0.0.3 -client_java_version=5.2.5 +test_utils_version=0.0.3 +client_version=5.2.13 slf4j_api_version=2.0.7 -logger_java_logback_version=5.2.1 -hamcrest_core_version=2.2 +logger_version=5.2.2 +hamcrest_version=2.2 okhttp_version=4.12.0 scripts_url=https://raw.githubusercontent.com/reportportal/gradle-scripts scripts_branch=develop diff --git a/src/test/resources/reportportal.properties b/src/test/resources/reportportal.properties index 4e3b746..068e0ed 100644 --- a/src/test/resources/reportportal.properties +++ b/src/test/resources/reportportal.properties @@ -1,7 +1,7 @@ -# rp.endpoint= -# rp.api.key= -# rp.launch= -# rp.project= +rp.endpoint=http://docker.local:8080/ +rp.api.key=test_1gabUh5lRhWDsL-HRERZ-0BXtn3HoH9d43vQ9JAAk-pZ6XFnEruFqm1Si90AiCJV +rp.launch=Karate +rp.project=default_personal ## OPTIONAL PARAMETERS # rp.reporting.async=true # rp.reporting.callback=true From 606116b978da6bfd3ff6b9a12f2c94848cf18429 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 8 Apr 2024 15:17:44 +0300 Subject: [PATCH 2/6] Revert --- 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 068e0ed..4e3b746 100644 --- a/src/test/resources/reportportal.properties +++ b/src/test/resources/reportportal.properties @@ -1,7 +1,7 @@ -rp.endpoint=http://docker.local:8080/ -rp.api.key=test_1gabUh5lRhWDsL-HRERZ-0BXtn3HoH9d43vQ9JAAk-pZ6XFnEruFqm1Si90AiCJV -rp.launch=Karate -rp.project=default_personal +# rp.endpoint= +# rp.api.key= +# rp.launch= +# rp.project= ## OPTIONAL PARAMETERS # rp.reporting.async=true # rp.reporting.callback=true From ad3c5056dd4b190c88705cae3d62fd7dcf1c9b28 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 8 Apr 2024 15:22:30 +0300 Subject: [PATCH 3/6] Fix build --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 7a24fea..8049ffb 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ apply from: "${scripts_url}/${scripts_branch}/release-commons.gradle" apply from: "${scripts_url}/${scripts_branch}/signing.gradle" apply from: "${scripts_url}/${scripts_branch}/jacoco.gradle" -ext.limits = [ +project.ext.limits = [ 'instruction': 70, 'branch' : 53, 'line' : 75, @@ -85,7 +85,7 @@ wrapper { processResources { filesMatching('agent.properties') { - expand(properties) + expand(project.properties) } } From 3a5365ce72e8cb8b32df89721b15600cd22f1b82 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 8 Apr 2024 15:29:16 +0300 Subject: [PATCH 4/6] Trailing EOLs --- jitpack.yml | 2 -- src/main/resources/agent.properties | 2 +- src/test/resources/agent.properties | 2 +- src/test/resources/reportportal.properties | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) delete mode 100644 jitpack.yml diff --git a/jitpack.yml b/jitpack.yml deleted file mode 100644 index 46c8529..0000000 --- a/jitpack.yml +++ /dev/null @@ -1,2 +0,0 @@ -jdk: - - openjdk11 \ No newline at end of file diff --git a/src/main/resources/agent.properties b/src/main/resources/agent.properties index d4082ab..c257470 100644 --- a/src/main/resources/agent.properties +++ b/src/main/resources/agent.properties @@ -1,2 +1,2 @@ agent.name=${name} -agent.version=${version} \ No newline at end of file +agent.version=${version} diff --git a/src/test/resources/agent.properties b/src/test/resources/agent.properties index 2629967..bc01e4a 100644 --- a/src/test/resources/agent.properties +++ b/src/test/resources/agent.properties @@ -1,2 +1,2 @@ agent.name=karate-test-agent -agent.version=test-1.0 \ No newline at end of file +agent.version=test-1.0 diff --git a/src/test/resources/reportportal.properties b/src/test/resources/reportportal.properties index 4e3b746..6c3b023 100644 --- a/src/test/resources/reportportal.properties +++ b/src/test/resources/reportportal.properties @@ -15,4 +15,4 @@ # rp.skipped.issue=true # rp.batch.size.logs=20 # rp.keystore.resource= -# rp.keystore.password= \ No newline at end of file +# rp.keystore.password= From dbe00f20803da994d6ddb844f94e3f71ccae4af9 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 8 Apr 2024 15:54:51 +0300 Subject: [PATCH 5/6] Fixes #30 --- .../reportportal/karate/ReportPortalHook.java | 32 ++++-- .../karate/tags/SimpleTagInclusionTest.java | 107 ++++++++++++++++++ .../reportportal/karate/utils/TestUtils.java | 13 ++- .../feature/http_request_tag.feature | 17 +++ 4 files changed, 155 insertions(+), 14 deletions(-) create mode 100644 src/test/java/com/epam/reportportal/karate/tags/SimpleTagInclusionTest.java create mode 100644 src/test/resources/feature/http_request_tag.feature diff --git a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java index 6254647..6c51607 100644 --- a/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java +++ b/src/main/java/com/epam/reportportal/karate/ReportPortalHook.java @@ -42,6 +42,7 @@ import java.util.Calendar; import java.util.Date; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; @@ -57,7 +58,7 @@ public class ReportPortalHook implements RuntimeHook { private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalHook.class); protected final MemoizingSupplier launch; - private final BlockingConcurrentHashMap> featureIdMap = new BlockingConcurrentHashMap<>(); + private final BlockingConcurrentHashMap>> featureIdMap = new BlockingConcurrentHashMap<>(); private final Map> scenarioIdMap = new ConcurrentHashMap<>(); private final Map> backgroundIdMap = new ConcurrentHashMap<>(); private final Map backgroundStatusMap = new ConcurrentHashMap<>(); @@ -162,7 +163,9 @@ protected StartTestItemRQ buildStartFeatureRq(@Nonnull FeatureRuntime fr) { @Override public boolean beforeFeature(FeatureRuntime fr) { - featureIdMap.computeIfAbsent(fr.featureCall.feature.getNameForReport(), f -> launch.get().startTestItem(buildStartFeatureRq(fr))); + featureIdMap.computeIfAbsent(fr.featureCall.feature.getNameForReport(), + f -> new MemoizingSupplier<>(() -> launch.get().startTestItem(buildStartFeatureRq(fr))) + ); return true; } @@ -179,13 +182,14 @@ protected FinishTestItemRQ buildFinishFeatureRq(@Nonnull FeatureRuntime fr) { @Override public void afterFeature(FeatureRuntime fr) { - Maybe featureId = featureIdMap.remove(fr.featureCall.feature.getNameForReport()); - if (featureId == null) { + Optional> optionalId = ofNullable(featureIdMap.remove(fr.featureCall.feature.getNameForReport())).map(Supplier::get); + if (optionalId.isEmpty()) { LOGGER.error("ERROR: Trying to finish unspecified feature."); } - FinishTestItemRQ rq = buildFinishFeatureRq(fr); - //noinspection ReactiveStreamsUnusedPublisher - launch.get().finishTestItem(featureId, rq); + optionalId.ifPresent(featureId -> { + //noinspection ReactiveStreamsUnusedPublisher + launch.get().finishTestItem(featureId, buildFinishFeatureRq(fr)); + }); } /** @@ -201,10 +205,15 @@ protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioRuntime sr) { @Override public boolean beforeScenario(ScenarioRuntime sr) { - Maybe featureId = featureIdMap.get(sr.featureRuntime.featureCall.feature.getNameForReport()); - StartTestItemRQ rq = buildStartScenarioRq(sr); - Maybe scenarioId = launch.get().startTestItem(featureId, rq); - scenarioIdMap.put(sr.scenario.getUniqueId(), scenarioId); + Optional> optionalId = ofNullable(featureIdMap.get(sr.featureRuntime.featureCall.feature.getNameForReport())).map(Supplier::get); + if (optionalId.isEmpty()) { + LOGGER.error("ERROR: Trying to post unspecified feature."); + } + optionalId.ifPresent(featureId -> { + StartTestItemRQ rq = buildStartScenarioRq(sr); + Maybe scenarioId = launch.get().startTestItem(featureId, rq); + scenarioIdMap.put(sr.scenario.getUniqueId(), scenarioId); + }); return true; } @@ -257,7 +266,6 @@ public Maybe startBackground(@Nonnull Step step, @Nonnull ScenarioRuntim @SuppressWarnings("unused") protected FinishTestItemRQ buildFinishBackgroundRq(@Nullable StepResult stepResult, @Nonnull ScenarioRuntime sr) { return buildFinishTestItemRq(Calendar.getInstance().getTime(), backgroundStatusMap.remove(sr.scenario.getUniqueId())); - } /** diff --git a/src/test/java/com/epam/reportportal/karate/tags/SimpleTagInclusionTest.java b/src/test/java/com/epam/reportportal/karate/tags/SimpleTagInclusionTest.java new file mode 100644 index 0000000..48e7b7d --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/tags/SimpleTagInclusionTest.java @@ -0,0 +1,107 @@ +/* + * 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.tags; + +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 com.epam.ta.reportportal.ws.model.StartTestItemRQ; +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.Collections; +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 SimpleTagInclusionTest { + private static final String[] TEST_FEATURES = new String[] { "classpath:feature/tags.feature", + "classpath:feature/http_request_tag.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_simple_all_passed(boolean report) { + List tagsToRun = Collections.singletonList("scope=smoke"); + Results results; + if (report) { + results = TestUtils.runAsReport(rp, tagsToRun, TEST_FEATURES); + } else { + results = TestUtils.runAsHook(rp, tagsToRun, TEST_FEATURES); + } + 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 featureFinishCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(client).finishTestItem(same(featureId), featureFinishCaptor.capture()); + ArgumentCaptor scenarioFinishCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); + verify(client).finishTestItem(same(scenarioId), scenarioFinishCaptor.capture()); + List> stepFinishCaptors = 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)), stepFinishCaptors.get(i).capture())); + + FinishTestItemRQ featureRq = featureFinishCaptor.getValue(); + FinishTestItemRQ scenarioRq = scenarioFinishCaptor.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()); + + stepFinishCaptors.forEach(stepFinishCaptor -> { + FinishTestItemRQ step = stepFinishCaptor.getValue(); + assertThat(step.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name()))); + assertThat(step.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid))); + assertThat(step.getEndTime(), notNullValue()); + }); + } +} 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 520bacc..3e0e73f 100644 --- a/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java +++ b/src/test/java/com/epam/reportportal/karate/utils/TestUtils.java @@ -65,12 +65,21 @@ public static ExecutorService testExecutor() { }); } + public static Results runAsReport(ReportPortal reportPortal, List tags, String... paths) { + return KarateReportPortalRunner.path(paths).withReportPortal(reportPortal).outputCucumberJson(false).tags(tags).parallel(1); + } + public static Results runAsReport(ReportPortal reportPortal, String... paths) { - return KarateReportPortalRunner.path(paths).withReportPortal(reportPortal).outputCucumberJson(false).parallel(1); + return runAsReport(reportPortal, Collections.emptyList(), paths); + } + + public static Results runAsHook(ReportPortal reportPortal, List tags, String... paths) { + Runner.Builder path = Runner.path(paths).hook(new ReportPortalHook(reportPortal)).outputCucumberJson(false); + return path.tags(tags).parallel(1); } public static Results runAsHook(ReportPortal reportPortal, String... paths) { - return Runner.path(paths).hook(new ReportPortalHook(reportPortal)).outputCucumberJson(false).parallel(1); + return runAsHook(reportPortal, Collections.emptyList(), paths); } public static ListenerParameters standardParameters() { diff --git a/src/test/resources/feature/http_request_tag.feature b/src/test/resources/feature/http_request_tag.feature new file mode 100644 index 0000000..d5c353f --- /dev/null +++ b/src/test/resources/feature/http_request_tag.feature @@ -0,0 +1,17 @@ +Feature: verify basic HTTP request + + @scope=regression + 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 c24d61433a3016e9bff4b31bb21359bae717a23e Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 8 Apr 2024 15:58:41 +0300 Subject: [PATCH 6/6] CHANGELOG.md update --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e32476..5293d07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## [Unreleased] ### Changed - Client version updated on [5.2.13](https://github.com/reportportal/client-java/releases/tag/5.2.13), by @HardNorth +### Fixed +- Issue [#30](https://github.com/reportportal/agent-java-karate/issues/30) Empty interrupted features in case of scenarios tag skip, by @HardNorth ## [5.0.4] ### Removed