Skip to content

Commit e0242ca

Browse files
authored
Merge pull request #37 from reportportal/develop
Release
2 parents 37f211e + 9bd04d4 commit e0242ca

File tree

7 files changed

+139
-28
lines changed

7 files changed

+139
-28
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
java-version: '11'
4444

4545
- name: Build with Gradle
46+
timeout-minutes: 30
4647
run: ./gradlew build
4748

4849
- name: Codecov upload

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Fixed
5+
- Issue [#32](https://github.com/reportportal/agent-java-karate/issues/32): Handling of calling scenario in the same Feature file, by @HardNorth
46

57
## [5.1.0]
68
### Changed

src/main/java/com/epam/reportportal/karate/ReportPortalHook.java

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -162,30 +162,34 @@ protected StartTestItemRQ buildStartFeatureRq(@Nonnull FeatureRuntime fr) {
162162
return rq;
163163
}
164164

165+
private String getFeatureNameForReport(FeatureRuntime fr) {
166+
int callDepth = ofNullable(fr.caller).map(c -> c.depth).orElse(0);
167+
return callDepth + ":" + fr.featureCall.feature.getNameForReport();
168+
}
169+
165170
@Override
166171
public boolean beforeFeature(FeatureRuntime fr) {
167172
StartTestItemRQ rq = buildStartFeatureRq(fr);
168-
featureIdMap.computeIfAbsent(fr.featureCall.feature.getNameForReport(),
169-
f -> new MemoizingSupplier<>(() -> {
170-
if(fr.caller == null || fr.caller.depth == 0) {
171-
return launch.get().startTestItem(rq);
172-
} else {
173-
Maybe<String> scenarioId = scenarioIdMap.get(fr.caller.parentRuntime.scenario.getUniqueId());
174-
if (scenarioId == null) {
175-
LOGGER.error("ERROR: Trying to post unspecified scenario.");
176-
return launch.get().startTestItem(rq);
177-
}
178-
rq.setType(ItemType.STEP.name());
179-
rq.setHasStats(false);
180-
rq.setName(getInnerFeatureName(rq.getName()));
181-
Maybe<String> itemId = launch.get().startTestItem(scenarioId, rq);
182-
innerFeatures.add(itemId);
183-
if (StringUtils.isNotBlank(rq.getDescription())) {
184-
ReportPortalUtils.sendLog(itemId, rq.getDescription(), LogLevel.INFO, rq.getStartTime());
185-
}
186-
return itemId;
187-
}
188-
}));
173+
featureIdMap.computeIfAbsent(getFeatureNameForReport(fr), f -> new MemoizingSupplier<>(() -> {
174+
if (ofNullable(fr.caller).map(c -> c.depth).orElse(0) == 0) {
175+
return launch.get().startTestItem(rq);
176+
} else {
177+
Maybe<String> scenarioId = scenarioIdMap.get(fr.caller.parentRuntime.scenario.getUniqueId());
178+
if (scenarioId == null) {
179+
LOGGER.error("ERROR: Trying to post unspecified scenario.");
180+
return launch.get().startTestItem(rq);
181+
}
182+
rq.setType(ItemType.STEP.name());
183+
rq.setHasStats(false);
184+
rq.setName(getInnerFeatureName(rq.getName()));
185+
Maybe<String> itemId = launch.get().startTestItem(scenarioId, rq);
186+
innerFeatures.add(itemId);
187+
if (StringUtils.isNotBlank(rq.getDescription())) {
188+
ReportPortalUtils.sendLog(itemId, rq.getDescription(), LogLevel.INFO, rq.getStartTime());
189+
}
190+
return itemId;
191+
}
192+
}));
189193
return true;
190194
}
191195

@@ -202,7 +206,7 @@ protected FinishTestItemRQ buildFinishFeatureRq(@Nonnull FeatureRuntime fr) {
202206

203207
@Override
204208
public void afterFeature(FeatureRuntime fr) {
205-
Optional<Maybe<String>> optionalId = ofNullable(featureIdMap.remove(fr.featureCall.feature.getNameForReport())).map(Supplier::get);
209+
Optional<Maybe<String>> optionalId = ofNullable(featureIdMap.remove(getFeatureNameForReport(fr))).map(Supplier::get);
206210
if (optionalId.isEmpty()) {
207211
LOGGER.error("ERROR: Trying to finish unspecified feature.");
208212
}
@@ -222,8 +226,7 @@ public void afterFeature(FeatureRuntime fr) {
222226
@Nonnull
223227
protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioRuntime sr) {
224228
StartTestItemRQ rq = ReportPortalUtils.buildStartScenarioRq(sr.result);
225-
ofNullable(featureIdMap.get(sr.featureRuntime.featureCall.feature.getNameForReport()))
226-
.map(Supplier::get)
229+
ofNullable(featureIdMap.get(getFeatureNameForReport(sr.featureRuntime))).map(Supplier::get)
227230
.map(featureId -> innerFeatures.contains(featureId) ? featureId : null)
228231
.ifPresent(featureId -> {
229232
rq.setType(ItemType.STEP.name());
@@ -236,8 +239,8 @@ protected StartTestItemRQ buildStartScenarioRq(@Nonnull ScenarioRuntime sr) {
236239
@Override
237240
public boolean beforeScenario(ScenarioRuntime sr) {
238241
StartTestItemRQ rq = buildStartScenarioRq(sr);
239-
Optional<Maybe<String>> optionalId = ofNullable(featureIdMap.get(sr.featureRuntime.featureCall.feature.getNameForReport()))
240-
.map(Supplier::get);
242+
Optional<Maybe<String>> optionalId = ofNullable(featureIdMap.get(getFeatureNameForReport(sr.featureRuntime))).map(
243+
Supplier::get);
241244
if (optionalId.isEmpty()) {
242245
LOGGER.error("ERROR: Trying to post unspecified feature.");
243246
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2024 EPAM Systems
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.epam.reportportal.karate.call;
18+
19+
import com.epam.reportportal.karate.utils.TestUtils;
20+
import com.epam.reportportal.service.ReportPortal;
21+
import com.epam.reportportal.service.ReportPortalClient;
22+
import com.epam.reportportal.util.test.CommonUtils;
23+
import com.epam.ta.reportportal.ws.model.StartTestItemRQ;
24+
import com.intuit.karate.Results;
25+
import org.apache.commons.lang3.tuple.Pair;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.api.Timeout;
29+
import org.mockito.ArgumentCaptor;
30+
31+
import java.util.Arrays;
32+
import java.util.Collection;
33+
import java.util.Collections;
34+
import java.util.List;
35+
import java.util.stream.Collectors;
36+
import java.util.stream.Stream;
37+
38+
import static com.epam.reportportal.karate.utils.TestUtils.*;
39+
import static org.hamcrest.MatcherAssert.assertThat;
40+
import static org.hamcrest.Matchers.*;
41+
import static org.mockito.Mockito.*;
42+
43+
public class CallTheSameFeatureWithParametersHookTest {
44+
private static final String TEST_FEATURE = "classpath:feature/call_same_feature.feature";
45+
private final String featureId = CommonUtils.namedId("feature_");
46+
private final String scenarioId = CommonUtils.namedId("scenario_");
47+
private final String innerFeatureId = CommonUtils.namedId("feature_step_");
48+
private final List<String> stepIds = Arrays.asList(CommonUtils.namedId("step_"), CommonUtils.namedId("step_"),
49+
CommonUtils.namedId("step_"), innerFeatureId);
50+
private final String innerScenarioId = CommonUtils.namedId("scenario_step_");
51+
private final List<String> innerStepIds = Stream.generate(() -> CommonUtils.namedId("inner_step_"))
52+
.limit(4)
53+
.collect(Collectors.toList());
54+
55+
private final List<Pair<String, Collection<Pair<String, List<String>>>>> features = Stream.of(Pair.of(featureId,
56+
(Collection<Pair<String, List<String>>>) Collections.singletonList(Pair.of(scenarioId, stepIds))
57+
))
58+
.collect(Collectors.toList());
59+
private final List<Pair<String, String>> nestedSteps = Stream.concat(
60+
Stream.of(Pair.of(innerFeatureId, innerScenarioId)),
61+
innerStepIds.stream().map(id -> Pair.of(innerScenarioId, id))
62+
).collect(Collectors.toList());
63+
64+
private final ReportPortalClient client = mock(ReportPortalClient.class);
65+
private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor());
66+
67+
@BeforeEach
68+
public void setupMock() {
69+
mockLaunch(client, null);
70+
mockFeatures(client, features);
71+
mockNestedSteps(client, nestedSteps);
72+
mockBatchLogging(client);
73+
}
74+
75+
@Test
76+
@Timeout(value = 30, threadMode = Timeout.ThreadMode.SEPARATE_THREAD)
77+
public void test_call_feature_with_parameters_hook_reporting() {
78+
Results results = TestUtils.runAsHook(rp, TEST_FEATURE);
79+
assertThat(results.getFailCount(), equalTo(0));
80+
81+
ArgumentCaptor<StartTestItemRQ> featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
82+
verify(client, times(1)).startTestItem(featureCaptor.capture());
83+
ArgumentCaptor<StartTestItemRQ> scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
84+
verify(client).startTestItem(same(featureId), scenarioCaptor.capture());
85+
ArgumentCaptor<StartTestItemRQ> stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
86+
verify(client, times(4)).startTestItem(same(scenarioId), stepCaptor.capture());
87+
ArgumentCaptor<StartTestItemRQ> innerScenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
88+
verify(client).startTestItem(same(innerFeatureId), innerScenarioCaptor.capture());
89+
ArgumentCaptor<StartTestItemRQ> innerStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
90+
verify(client, times(4)).startTestItem(same(innerScenarioId), innerStepCaptor.capture());
91+
}
92+
}

src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java renamed to src/test/java/com/epam/reportportal/karate/call/CallWithParametersHookTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.epam.reportportal.karate.description;
17+
package com.epam.reportportal.karate.call;
1818

1919
import com.epam.reportportal.karate.utils.TestUtils;
2020
import com.epam.reportportal.service.ReportPortal;

src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java renamed to src/test/java/com/epam/reportportal/karate/call/CallWithParametersPublisherTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.epam.reportportal.karate.description;
17+
package com.epam.reportportal.karate.call;
1818

1919
import com.epam.reportportal.karate.utils.TestUtils;
2020
import com.epam.reportportal.service.ReportPortal;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Feature: the very basic test to run by Karate
2+
3+
@ignore @execute-test
4+
Scenario: Power of two
5+
* def expected = expectedValue
6+
* def powValue = testValue
7+
* def actual = powValue * powValue
8+
* assert actual == expected
9+
10+
Scenario: Verify math
11+
* def expectedValue = 4
12+
* def testValue = 2
13+
* call read('@execute-test') { expectedValue: #(expectedValue), testValue: #(testValue) }

0 commit comments

Comments
 (0)