Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Dec 26, 2023
1 parent e9a1f61 commit 2a12965
Showing 1 changed file with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2023 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.status;

import com.epam.reportportal.karate.utils.TestUtils;
import com.epam.reportportal.listeners.ItemStatus;
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.FinishTestItemRQ;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
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 SimpleAllPassedTest {
private final String launchUuid = CommonUtils.namedId("launch_");
private final String featureId = CommonUtils.namedId("feature_");
private final String scenarioId = CommonUtils.namedId("scenario_");
private final List<String> stepIds = Stream.generate(() -> CommonUtils.namedId("step_"))
.limit(3).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, launchUuid, featureId, scenarioId, stepIds);
mockBatchLogging(client);
}

@Test
public void test_simple_all_passed() {
var results = TestUtils.runAsReport(rp, "classpath:feature/simple.feature");
assertThat(results.getFailCount(), equalTo(0));

ArgumentCaptor<FinishTestItemRQ> featureCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class);
verify(client).finishTestItem(same(featureId), featureCaptor.capture());
ArgumentCaptor<FinishTestItemRQ> scenarioCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class);
verify(client).finishTestItem(same(scenarioId), scenarioCaptor.capture());
List<ArgumentCaptor<FinishTestItemRQ>> stepCaptors =
Stream.generate(() -> ArgumentCaptor.forClass(FinishTestItemRQ.class)).limit(stepIds.size()).collect(Collectors.toList());
IntStream.range(0, stepIds.size()).forEach(i -> verify(client).finishTestItem(same(stepIds.get(i)), stepCaptors.get(i).capture()));

FinishTestItemRQ featureRq = featureCaptor.getValue();
FinishTestItemRQ scenarioRq = scenarioCaptor.getValue();

assertThat(featureRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name())));
assertThat(featureRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid)));
assertThat(featureRq.getEndTime(), notNullValue());

assertThat(scenarioRq.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name())));
assertThat(scenarioRq.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid)));
assertThat(scenarioRq.getEndTime(), notNullValue());

stepCaptors.forEach(stepCaptor -> {
FinishTestItemRQ step = stepCaptor.getValue();
assertThat(step.getStatus(), allOf(notNullValue(), equalTo(ItemStatus.PASSED.name())));
assertThat(step.getLaunchUuid(), allOf(notNullValue(), equalTo(launchUuid)));
assertThat(step.getEndTime(), notNullValue());
});
}
}

0 comments on commit 2a12965

Please sign in to comment.