Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Jan 30, 2024
1 parent 1eaf3f0 commit 44915ab
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<String> exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(3).collect(Collectors.toList());

private final List<Pair<String, String>> stepIds = exampleIds.stream()
.flatMap(e -> Stream.generate(() -> Pair.of(e, CommonUtils.namedId("step_"))).limit(3))
private final List<String> scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")).limit(3).collect(Collectors.toList());
private final List<Pair<String, List<String>>> 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);
Expand All @@ -58,77 +58,88 @@ 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<String> 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<String> 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<Map<String, String>> OUTLINE_PARAMETERS = Arrays.asList(new HashMap<String, String>() {{
put("str", "\"first\"");
put("parameters", "123");
}}, new HashMap<String, String>() {{
put("str", "\"second\"");
put("parameters", "12345");
put("str", "\"scond\"");
put("parameters", "321");
}}, new HashMap<String, String>() {{
put("str", "\"third\"");
put("parameters", "12345678");
put("parameters", "213");
}});

private static final List<String> 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<Map<String, String>> STEP_PARAMETERS = Arrays.asList(new HashMap<>(), new HashMap<String, String>() {{
put("str", "\"first\"");
}}, new HashMap<String, String>() {{
put("parameters", "123");
}}, new HashMap<>(), new HashMap<String, String>() {{
put("str", "\"second\"");
put("str", "\"scond\"");
}}, new HashMap<String, String>() {{
put("parameters", "12345");
put("parameters", "321");
}}, new HashMap<>(), new HashMap<String, String>() {{
put("str", "\"third\"");
}}, new HashMap<String, String>() {{
put("parameters", "12345678");
put("parameters", "213");
}});

@Test
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<StartTestItemRQ> 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<StartTestItemRQ> exampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
verify(client, times(3)).startTestItem(same(storyId), exampleCaptor.capture());
ArgumentCaptor<StartTestItemRQ> 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<StartTestItemRQ> startItems = startCaptor.getAllValues();
List<StartTestItemRQ> examples = startItems.subList(0, 3);
List<StartTestItemRQ> 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<StartTestItemRQ> steps = startItems.subList(3, 3 + 9);
List<StartTestItemRQ> steps = stepCaptor.getAllValues();
IntStream.range(0, steps.size()).forEach(i -> {
StartTestItemRQ rq = steps.get(i);
assertThat(rq.getName(), equalTo(STEP_NAMES.get(i)));
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/features/ScenarioOutline.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Feature: Basic test with parameters
Examples:
| str | parameters |
| "first" | 123 |
| "second" | 12345 |
| "third" | 12345678 |
| "scond" | 321 |
| "third" | 213 |

0 comments on commit 44915ab

Please sign in to comment.