-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
182 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/test/java/com/epam/reportportal/karate/description/CallWithParametersHookTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> featureIds = Stream.generate(() -> CommonUtils.namedId("feature_")) | ||
.limit(2).collect(Collectors.toList()); | ||
private final List<String> scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")) | ||
.limit(2).collect(Collectors.toList()); | ||
private final List<String> stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) | ||
.limit(4).collect(Collectors.toList()); | ||
|
||
private final List<Pair<String, Collection<Pair<String, List<String>>>>> features = | ||
Stream.of( | ||
Pair.of(featureIds.get(0), (Collection<Pair<String, List<String>>>) Collections.singletonList(Pair.of(scenarioIds.get(0), Collections.singletonList(stepIds.get(0))))), | ||
Pair.of(featureIds.get(1), (Collection<Pair<String, List<String>>>) 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<StartTestItemRQ> featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client, times(2)).startTestItem(featureCaptor.capture()); | ||
ArgumentCaptor<StartTestItemRQ> scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client).startTestItem(same(featureIds.get(0)), scenarioCaptor.capture()); | ||
verify(client).startTestItem(same(featureIds.get(1)), scenarioCaptor.capture()); | ||
ArgumentCaptor<StartTestItemRQ> 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))); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/test/java/com/epam/reportportal/karate/description/CallWithParametersPublisherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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<StartTestItemRQ> captor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client).startTestItem(captor.capture()); | ||
verify(client).startTestItem(same(featureId), captor.capture()); | ||
ArgumentCaptor<StartTestItemRQ> stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); | ||
verify(client).startTestItem(same(scenarioId), stepCaptor.capture()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |