From 9d95aed094cacb0668000fd30a8c9e42a84d5ee4 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 13 Sep 2024 19:12:00 +0300 Subject: [PATCH] Add test for issue #32 --- ...lTheSameFeatureWithParametersHookTest.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/test/java/com/epam/reportportal/karate/call/CallTheSameFeatureWithParametersHookTest.java diff --git a/src/test/java/com/epam/reportportal/karate/call/CallTheSameFeatureWithParametersHookTest.java b/src/test/java/com/epam/reportportal/karate/call/CallTheSameFeatureWithParametersHookTest.java new file mode 100644 index 0000000..d3b9040 --- /dev/null +++ b/src/test/java/com/epam/reportportal/karate/call/CallTheSameFeatureWithParametersHookTest.java @@ -0,0 +1,92 @@ +/* + * 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.call; + +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.apache.commons.lang3.tuple.Pair; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.mockito.ArgumentCaptor; + +import java.util.Arrays; +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.*; +import static org.mockito.Mockito.*; + +public class CallTheSameFeatureWithParametersHookTest { + private static final String TEST_FEATURE = "classpath:feature/call_same_feature.feature"; + 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 stepIds = Arrays.asList(CommonUtils.namedId("step_"), CommonUtils.namedId("step_"), + CommonUtils.namedId("step_"), innerFeatureId); + private final String innerScenarioId = CommonUtils.namedId("scenario_step_"); + private final List innerStepIds = Stream.generate(() -> CommonUtils.namedId("inner_step_")) + .limit(4) + .collect(Collectors.toList()); + + private final List>>>> features = Stream.of(Pair.of(featureId, + (Collection>>) Collections.singletonList(Pair.of(scenarioId, stepIds)) + )) + .collect(Collectors.toList()); + private final List> 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); + } + + @Test + @Timeout(value = 30, threadMode = Timeout.ThreadMode.SEPARATE_THREAD) + public void test_call_feature_with_parameters_hook_reporting() { + Results results = TestUtils.runAsHook(rp, TEST_FEATURE); + assertThat(results.getFailCount(), equalTo(0)); + + ArgumentCaptor featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(1)).startTestItem(featureCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(scenarioId), stepCaptor.capture()); + ArgumentCaptor innerScenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(innerFeatureId), innerScenarioCaptor.capture()); + ArgumentCaptor innerStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(innerScenarioId), innerStepCaptor.capture()); + } +}