|
| 1 | +/* |
| 2 | + * Copyright 2024 EPAM Systems |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.epam.reportportal.karate.call; |
| 18 | + |
| 19 | +import com.epam.reportportal.karate.utils.TestUtils; |
| 20 | +import com.epam.reportportal.service.ReportPortal; |
| 21 | +import com.epam.reportportal.service.ReportPortalClient; |
| 22 | +import com.epam.reportportal.util.test.CommonUtils; |
| 23 | +import com.epam.ta.reportportal.ws.model.StartTestItemRQ; |
| 24 | +import com.intuit.karate.Results; |
| 25 | +import org.apache.commons.lang3.tuple.Pair; |
| 26 | +import org.junit.jupiter.api.BeforeEach; |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | +import org.junit.jupiter.api.Timeout; |
| 29 | +import org.mockito.ArgumentCaptor; |
| 30 | + |
| 31 | +import java.util.Arrays; |
| 32 | +import java.util.Collection; |
| 33 | +import java.util.Collections; |
| 34 | +import java.util.List; |
| 35 | +import java.util.stream.Collectors; |
| 36 | +import java.util.stream.Stream; |
| 37 | + |
| 38 | +import static com.epam.reportportal.karate.utils.TestUtils.*; |
| 39 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 40 | +import static org.hamcrest.Matchers.*; |
| 41 | +import static org.mockito.Mockito.*; |
| 42 | + |
| 43 | +public class CallTheSameFeatureWithParametersHookTest { |
| 44 | + private static final String TEST_FEATURE = "classpath:feature/call_same_feature.feature"; |
| 45 | + private final String featureId = CommonUtils.namedId("feature_"); |
| 46 | + private final String scenarioId = CommonUtils.namedId("scenario_"); |
| 47 | + private final String innerFeatureId = CommonUtils.namedId("feature_step_"); |
| 48 | + private final List<String> stepIds = Arrays.asList(CommonUtils.namedId("step_"), CommonUtils.namedId("step_"), |
| 49 | + CommonUtils.namedId("step_"), innerFeatureId); |
| 50 | + private final String innerScenarioId = CommonUtils.namedId("scenario_step_"); |
| 51 | + private final List<String> innerStepIds = Stream.generate(() -> CommonUtils.namedId("inner_step_")) |
| 52 | + .limit(4) |
| 53 | + .collect(Collectors.toList()); |
| 54 | + |
| 55 | + private final List<Pair<String, Collection<Pair<String, List<String>>>>> features = Stream.of(Pair.of(featureId, |
| 56 | + (Collection<Pair<String, List<String>>>) Collections.singletonList(Pair.of(scenarioId, stepIds)) |
| 57 | + )) |
| 58 | + .collect(Collectors.toList()); |
| 59 | + private final List<Pair<String, String>> nestedSteps = Stream.concat( |
| 60 | + Stream.of(Pair.of(innerFeatureId, innerScenarioId)), |
| 61 | + innerStepIds.stream().map(id -> Pair.of(innerScenarioId, id)) |
| 62 | + ).collect(Collectors.toList()); |
| 63 | + |
| 64 | + private final ReportPortalClient client = mock(ReportPortalClient.class); |
| 65 | + private final ReportPortal rp = ReportPortal.create(client, standardParameters(), testExecutor()); |
| 66 | + |
| 67 | + @BeforeEach |
| 68 | + public void setupMock() { |
| 69 | + mockLaunch(client, null); |
| 70 | + mockFeatures(client, features); |
| 71 | + mockNestedSteps(client, nestedSteps); |
| 72 | + mockBatchLogging(client); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + @Timeout(value = 30, threadMode = Timeout.ThreadMode.SEPARATE_THREAD) |
| 77 | + public void test_call_feature_with_parameters_hook_reporting() { |
| 78 | + Results results = TestUtils.runAsHook(rp, TEST_FEATURE); |
| 79 | + assertThat(results.getFailCount(), equalTo(0)); |
| 80 | + |
| 81 | + ArgumentCaptor<StartTestItemRQ> featureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); |
| 82 | + verify(client, times(1)).startTestItem(featureCaptor.capture()); |
| 83 | + ArgumentCaptor<StartTestItemRQ> scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); |
| 84 | + verify(client).startTestItem(same(featureId), scenarioCaptor.capture()); |
| 85 | + ArgumentCaptor<StartTestItemRQ> stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); |
| 86 | + verify(client, times(4)).startTestItem(same(scenarioId), stepCaptor.capture()); |
| 87 | + ArgumentCaptor<StartTestItemRQ> innerScenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); |
| 88 | + verify(client).startTestItem(same(innerFeatureId), innerScenarioCaptor.capture()); |
| 89 | + ArgumentCaptor<StartTestItemRQ> innerStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); |
| 90 | + verify(client, times(4)).startTestItem(same(innerScenarioId), innerStepCaptor.capture()); |
| 91 | + } |
| 92 | +} |
0 commit comments