From 44915ab5c77f22a80e10bf1bf1d3d913f95ff672 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 30 Jan 2024 14:57:58 +0300 Subject: [PATCH] Fix tests --- .../jbehave/gherkin/ScenarioOutlineTest.java | 69 +++++++++++-------- .../features/ScenarioOutline.feature | 4 +- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/test/java/com/epam/reportportal/jbehave/gherkin/ScenarioOutlineTest.java b/src/test/java/com/epam/reportportal/jbehave/gherkin/ScenarioOutlineTest.java index f6c0dbf..1c02c5d 100644 --- a/src/test/java/com/epam/reportportal/jbehave/gherkin/ScenarioOutlineTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/gherkin/ScenarioOutlineTest.java @@ -23,6 +23,7 @@ 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 org.apache.commons.lang3.tuple.Pair; import org.jbehave.core.parsers.gherkin.GherkinStoryParser; @@ -35,6 +36,7 @@ import java.util.stream.IntStream; import java.util.stream.Stream; +import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.mockito.Mockito.any; @@ -43,11 +45,9 @@ public class ScenarioOutlineTest extends BaseTest { private final String storyId = CommonUtils.namedId("story_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(3).collect(Collectors.toList()); - - private final List> stepIds = exampleIds.stream() - .flatMap(e -> Stream.generate(() -> Pair.of(e, CommonUtils.namedId("step_"))).limit(3)) + private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")).limit(3).collect(Collectors.toList()); + private final List>> stepIds = scenarioIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()))) .collect(Collectors.toList()); private final ReportPortalClient client = mock(ReportPortalClient.class); @@ -58,37 +58,48 @@ public class ScenarioOutlineTest extends BaseTest { @BeforeEach public void setupMock() { - mockLaunch(client, null, storyId, scenarioId, exampleIds); - mockNestedSteps(client, stepIds); + mockLaunch(client, null, storyId, stepIds); mockBatchLogging(client); } - private static final List EXAMPLE_NAMES = Arrays.asList("Example: [str: \"first\"; parameters: 123]", - "Example: [str: \"second\"; parameters: 12345]", - "Example: [str: \"third\"; parameters: 12345678]" + private static final String EXAMPLE_NAME = "Test with different parameters"; + //@formatter:off + private static final String PARAMETERS_PREFIX = + "Parameters:\n\n" + + MarkdownUtils.TABLE_INDENT + "|\u00A0\u00A0\u00A0str\u00A0\u00A0\u00A0|\u00A0parameters\u00A0|\n" + + MarkdownUtils.TABLE_INDENT + "|---------|------------|\n" + + MarkdownUtils.TABLE_INDENT; + //@formatter:on + private static final List EXAMPLE_DESCRIPTIONS = asList( + PARAMETERS_PREFIX + + "|\u00A0\"first\"\u00A0|\u00A0\u00A0\u00A0\u00A0123\u00A0\u00A0\u00A0\u00A0\u00A0|", + PARAMETERS_PREFIX + + "|\u00A0\"scond\"\u00A0|\u00A0\u00A0\u00A0\u00A0321\u00A0\u00A0\u00A0\u00A0\u00A0|", + PARAMETERS_PREFIX + + "|\u00A0\"third\"\u00A0|\u00A0\u00A0\u00A0\u00A0213\u00A0\u00A0\u00A0\u00A0\u00A0|" ); private static final List> OUTLINE_PARAMETERS = Arrays.asList(new HashMap() {{ put("str", "\"first\""); put("parameters", "123"); }}, new HashMap() {{ - put("str", "\"second\""); - put("parameters", "12345"); + put("str", "\"scond\""); + put("parameters", "321"); }}, new HashMap() {{ put("str", "\"third\""); - put("parameters", "12345678"); + put("parameters", "213"); }}); private static final List STEP_NAMES = Arrays.asList("Given It is test with parameters", "When I have parameter \"first\"", "Then I emit number 123 on level info", "Given It is test with parameters", - "When I have parameter \"second\"", - "Then I emit number 12345 on level info", + "When I have parameter \"scond\"", + "Then I emit number 321 on level info", "Given It is test with parameters", "When I have parameter \"third\"", - "Then I emit number 12345678 on level info" + "Then I emit number 213 on level info" ); private static final List> STEP_PARAMETERS = Arrays.asList(new HashMap<>(), new HashMap() {{ @@ -96,13 +107,13 @@ public void setupMock() { }}, new HashMap() {{ put("parameters", "123"); }}, new HashMap<>(), new HashMap() {{ - put("str", "\"second\""); + put("str", "\"scond\""); }}, new HashMap() {{ - put("parameters", "12345"); + put("parameters", "321"); }}, new HashMap<>(), new HashMap() {{ put("str", "\"third\""); }}, new HashMap() {{ - put("parameters", "12345678"); + put("parameters", "213"); }}); @Test @@ -110,25 +121,25 @@ public void verify_story_with_scenario_outline_names_types_and_parameters() { run(format, Collections.singletonList("features/ScenarioOutline.feature"), new GherkinStoryParser(), new ParameterizedSteps()); verify(client, times(1)).startTestItem(any()); - verify(client, times(1)).startTestItem(same(storyId), any()); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioId), startCaptor.capture()); - verify(client, times(3)).startTestItem(same(exampleIds.get(0)), startCaptor.capture()); - verify(client, times(3)).startTestItem(same(exampleIds.get(1)), startCaptor.capture()); - verify(client, times(3)).startTestItem(same(exampleIds.get(2)), startCaptor.capture()); + ArgumentCaptor exampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(storyId), exampleCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioIds.get(0)), stepCaptor.capture()); + verify(client, times(3)).startTestItem(same(scenarioIds.get(1)), stepCaptor.capture()); + verify(client, times(3)).startTestItem(same(scenarioIds.get(2)), stepCaptor.capture()); // Start items verification - List startItems = startCaptor.getAllValues(); - List examples = startItems.subList(0, 3); + List examples = exampleCaptor.getAllValues(); IntStream.range(0, examples.size()).forEach(i -> { StartTestItemRQ rq = examples.get(i); - assertThat(rq.getName(), equalTo(EXAMPLE_NAMES.get(i))); + assertThat(rq.getName(), equalTo(EXAMPLE_NAME)); + assertThat(rq.getDescription(), equalTo(EXAMPLE_DESCRIPTIONS.get(i))); assertThat(rq.getType(), equalTo(ItemType.TEST.name())); assertThat(rq.getParameters(), hasSize(OUTLINE_PARAMETERS.get(i).size())); rq.getParameters().forEach(p -> assertThat(OUTLINE_PARAMETERS.get(i), hasEntry(p.getKey(), p.getValue()))); }); - List steps = startItems.subList(3, 3 + 9); + List steps = stepCaptor.getAllValues(); IntStream.range(0, steps.size()).forEach(i -> { StartTestItemRQ rq = steps.get(i); assertThat(rq.getName(), equalTo(STEP_NAMES.get(i))); diff --git a/src/test/resources/features/ScenarioOutline.feature b/src/test/resources/features/ScenarioOutline.feature index 6913cbe..008f636 100644 --- a/src/test/resources/features/ScenarioOutline.feature +++ b/src/test/resources/features/ScenarioOutline.feature @@ -8,5 +8,5 @@ Feature: Basic test with parameters Examples: | str | parameters | | "first" | 123 | - | "second" | 12345 | - | "third" | 12345678 | + | "scond" | 321 | + | "third" | 213 |