-
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
3 changed files
with
150 additions
and
3 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
68 changes: 68 additions & 0 deletions
68
src/test/java/com/epam/reportportal/karate/id/ExamplesTestCaseIdTest.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,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<String> exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2) | ||
.collect(Collectors.toList()); | ||
private final List<Pair<String, List<String>>> 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<StartTestItemRQ> 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<StartTestItemRQ> 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))); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/java/com/epam/reportportal/karate/id/ScenarioTestCaseIdTest.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,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<String> 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<StartTestItemRQ> 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<StartTestItemRQ> items = captor.getAllValues(); | ||
assertThat(items, hasSize(5)); | ||
|
||
StartTestItemRQ scenarioRq = items.get(1); | ||
assertThat(scenarioRq.getTestCaseId(), allOf(notNullValue(), equalTo(SIMPLE_TEST_CASE_ID))); | ||
} | ||
} |