Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Release #31

Merged
merged 6 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Unreleased]
### Changed
- Client version updated on [5.2.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
Expand Down
34 changes: 17 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
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 = [
'instruction': 70,
Expand All @@ -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 {
Expand All @@ -80,7 +80,7 @@ test {
}

wrapper {
gradleVersion = "${project.gradle_version}"
gradleVersion = "${gradle_version}"
}

processResources {
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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://github.com/raw/reportportal/gradle-scripts
scripts_branch=develop
Expand Down
2 changes: 0 additions & 2 deletions jitpack.yml

This file was deleted.

32 changes: 20 additions & 12 deletions src/main/java/com/epam/reportportal/karate/ReportPortalHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -57,7 +58,7 @@
public class ReportPortalHook implements RuntimeHook {
private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalHook.class);
protected final MemoizingSupplier<Launch> launch;
private final BlockingConcurrentHashMap<String, Maybe<String>> featureIdMap = new BlockingConcurrentHashMap<>();
private final BlockingConcurrentHashMap<String, Supplier<Maybe<String>>> featureIdMap = new BlockingConcurrentHashMap<>();
private final Map<String, Maybe<String>> scenarioIdMap = new ConcurrentHashMap<>();
private final Map<String, Maybe<String>> backgroundIdMap = new ConcurrentHashMap<>();
private final Map<String, ItemStatus> backgroundStatusMap = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -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;
}

Expand All @@ -179,13 +182,14 @@ protected FinishTestItemRQ buildFinishFeatureRq(@Nonnull FeatureRuntime fr) {

@Override
public void afterFeature(FeatureRuntime fr) {
Maybe<String> featureId = featureIdMap.remove(fr.featureCall.feature.getNameForReport());
if (featureId == null) {
Optional<Maybe<String>> 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));
});
}

/**
Expand All @@ -201,10 +205,15 @@ protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioRuntime sr) {

@Override
public boolean beforeScenario(ScenarioRuntime sr) {
Maybe<String> featureId = featureIdMap.get(sr.featureRuntime.featureCall.feature.getNameForReport());
StartTestItemRQ rq = buildStartScenarioRq(sr);
Maybe<String> scenarioId = launch.get().startTestItem(featureId, rq);
scenarioIdMap.put(sr.scenario.getUniqueId(), scenarioId);
Optional<Maybe<String>> 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<String> scenarioId = launch.get().startTestItem(featureId, rq);
scenarioIdMap.put(sr.scenario.getUniqueId(), scenarioId);
});
return true;
}

Expand Down Expand Up @@ -257,7 +266,6 @@ public Maybe<String> 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()));

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/agent.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
agent.name=${name}
agent.version=${version}
agent.version=${version}
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> 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<StartTestItemRQ> featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
verify(client).startTestItem(featureCaptor.capture());
ArgumentCaptor<StartTestItemRQ> scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
verify(client).startTestItem(same(featureId), scenarioCaptor.capture());
ArgumentCaptor<StartTestItemRQ> stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
verify(client, times(3)).startTestItem(same(scenarioId), stepCaptor.capture());

ArgumentCaptor<FinishTestItemRQ> featureFinishCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class);
verify(client).finishTestItem(same(featureId), featureFinishCaptor.capture());
ArgumentCaptor<FinishTestItemRQ> scenarioFinishCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class);
verify(client).finishTestItem(same(scenarioId), scenarioFinishCaptor.capture());
List<ArgumentCaptor<FinishTestItemRQ>> 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());
});
}
}
13 changes: 11 additions & 2 deletions src/test/java/com/epam/reportportal/karate/utils/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,21 @@ public static ExecutorService testExecutor() {
});
}

public static Results runAsReport(ReportPortal reportPortal, List<String> 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<String> 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() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/agent.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
agent.name=karate-test-agent
agent.version=test-1.0
agent.version=test-1.0
17 changes: 17 additions & 0 deletions src/test/resources/feature/http_request_tag.feature
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/test/resources/reportportal.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# rp.skipped.issue=true
# rp.batch.size.logs=20
# rp.keystore.resource=<PATH_TO_YOUR_KEYSTORE>
# rp.keystore.password=<PASSWORD_OF_YOUR_KEYSTORE>
# rp.keystore.password=<PASSWORD_OF_YOUR_KEYSTORE>