Skip to content

Commit

Permalink
Call logic fix: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Sep 12, 2024
1 parent 743ea58 commit 2b81cae
Showing 1 changed file with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand All @@ -44,33 +45,36 @@
public class CallWithParametersHookTest {
private static final String TEST_FEATURE = "classpath:feature/call.feature";
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 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())
))
)
"Parameters:\n\n" + MarkdownUtils.TABLE_INDENT + "|\u00A0vara\u00A0|\u00A0result\u00A0|\n" + MarkdownUtils.TABLE_INDENT
+ "|------|--------|\n" + MarkdownUtils.TABLE_INDENT
+ "|\u00A0\u00A02\u00A0\u00A0\u00A0|\u00A0\u00A0\u00A04\u00A0\u00A0\u00A0\u00A0|\n\n"
+ MarkdownUtils.TABLE_ROW_SEPARATOR;
private final String featureId = CommonUtils.namedId("feature_");
private final String scenarioId = CommonUtils.namedId("scenario_");
private final String innerFeatureId = CommonUtils.namedId("feature_step_");
private final List<String> stepIds = Arrays.asList(CommonUtils.namedId("step_"), innerFeatureId);
private final String innerScenarioId = CommonUtils.namedId("scenario_step_");
private final List<String> innerStepIds = Stream.generate(() -> CommonUtils.namedId("inner_step_"))
.limit(3)
.collect(Collectors.toList());

private final List<Pair<String, Collection<Pair<String, List<String>>>>> features = Stream.of(Pair.of(featureId,
(Collection<Pair<String, List<String>>>) Collections.singletonList(Pair.of(scenarioId, stepIds))
))
.collect(Collectors.toList());
private final List<Pair<String, String>> nestedSteps = Stream.concat(
Stream.of(Pair.of(innerFeatureId, innerScenarioId)),
innerStepIds.stream().map(id -> Pair.of(innerScenarioId, id))
).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);
mockFeatures(client, features);
mockNestedSteps(client, nestedSteps);
mockBatchLogging(client);
}

Expand All @@ -80,15 +84,17 @@ public void test_call_feature_with_parameters_hook_reporting() {
assertThat(results.getFailCount(), equalTo(0));

ArgumentCaptor<StartTestItemRQ> featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
verify(client, times(2)).startTestItem(featureCaptor.capture());
verify(client, times(1)).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());
verify(client).startTestItem(same(featureId), 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());
verify(client, times(2)).startTestItem(same(scenarioId), stepCaptor.capture());
ArgumentCaptor<StartTestItemRQ> innerScenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
verify(client).startTestItem(same(innerFeatureId), innerScenarioCaptor.capture());
ArgumentCaptor<StartTestItemRQ> innerStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
verify(client, times(3)).startTestItem(same(innerScenarioId), innerStepCaptor.capture());

StartTestItemRQ calledFeature = featureCaptor.getAllValues()
StartTestItemRQ calledFeature = stepCaptor.getAllValues()
.stream()
.filter(rq -> "a feature which is called with parameters".equals(rq.getName()))
.findAny()
Expand Down

0 comments on commit 2b81cae

Please sign in to comment.