Search in sources :

Example 1 with ReportPortalClient

use of com.epam.reportportal.service.ReportPortalClient in project agent-java-testNG by reportportal.

the class CallbackReportingIntegrationTest method callbackReportingTest.

@Test
public void callbackReportingTest() {
    ReportPortalClient client = CallbackReportingListener.getReportPortal().getClient();
    try {
        TestUtils.runTests(Collections.singletonList(CallbackReportingListener.class), CallbackReportingTest.class);
    } catch (Exception ex) {
        // do nothing
        ex.printStackTrace();
    }
    // Start parent suite
    verify(client, times(1)).startTestItem(any());
    ArgumentCaptor<FinishTestItemRQ> captor = ArgumentCaptor.forClass(FinishTestItemRQ.class);
    // Start test class and test method
    verify(client, times(6)).finishTestItem(eq(testMethodUuid), captor.capture());
    ArgumentCaptor<SaveLogRQ> saveLogRQArgumentCaptor = ArgumentCaptor.forClass(SaveLogRQ.class);
    verify(client, times(1)).log(saveLogRQArgumentCaptor.capture());
    Map<String, List<FinishTestItemRQ>> finishMapping = captor.getAllValues().stream().filter(it -> Objects.nonNull(it.getDescription())).collect(groupingBy(FinishExecutionRQ::getDescription));
    FinishTestItemRQ firstTestCallbackFinish = finishMapping.get("firstTest").get(0);
    FinishTestItemRQ secondTestCallbackFinish = finishMapping.get("secondTest").get(0);
    assertEquals("PASSED", firstTestCallbackFinish.getStatus());
    assertEquals("FAILED", secondTestCallbackFinish.getStatus());
    SaveLogRQ logRequest = saveLogRQArgumentCaptor.getValue();
    assertEquals("Error message", logRequest.getMessage());
    assertEquals("ERROR", logRequest.getLevel());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ReportPortalClient(com.epam.reportportal.service.ReportPortalClient) java.util(java.util) ListenerParameters(com.epam.reportportal.listeners.ListenerParameters) CallbackReportingTest(com.epam.reportportal.testng.integration.feature.callback.CallbackReportingTest) com.epam.ta.reportportal.ws.model(com.epam.ta.reportportal.ws.model) Maybe(io.reactivex.Maybe) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) ReportPortal(com.epam.reportportal.service.ReportPortal) SaveLogRQ(com.epam.ta.reportportal.ws.model.log.SaveLogRQ) Test(org.junit.jupiter.api.Test) TestUtils(com.epam.reportportal.testng.integration.util.TestUtils) Mockito(org.mockito.Mockito) CallbackReportingListener(com.epam.reportportal.testng.integration.CallbackReportingListener) ArgumentCaptor(org.mockito.ArgumentCaptor) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) TestUtils.standardParameters(com.epam.reportportal.testng.integration.util.TestUtils.standardParameters) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SaveLogRQ(com.epam.ta.reportportal.ws.model.log.SaveLogRQ) ReportPortalClient(com.epam.reportportal.service.ReportPortalClient) CallbackReportingListener(com.epam.reportportal.testng.integration.CallbackReportingListener) CallbackReportingTest(com.epam.reportportal.testng.integration.feature.callback.CallbackReportingTest) Test(org.junit.jupiter.api.Test)

Example 2 with ReportPortalClient

use of com.epam.reportportal.service.ReportPortalClient in project agent-java-junit5 by reportportal.

the class StepReporterTest method verify_failed_nested_step_not_fails_test_run.

@Test
public void verify_failed_nested_step_not_fails_test_run() {
    TestExtension.init();
    Listener listener = new Listener();
    runClasses(listener, ManualStepReporterFeatureTest.class);
    ReportPortalClient client = TestExtension.client.get();
    ArgumentCaptor<FinishTestItemRQ> finishNestedStep = ArgumentCaptor.forClass(FinishTestItemRQ.class);
    verify(client, timeout(1000)).finishTestItem(eq(TestExtension.stepUuidList.get(2)), finishNestedStep.capture());
    ArgumentCaptor<FinishTestItemRQ> finishTestStep = ArgumentCaptor.forClass(FinishTestItemRQ.class);
    verify(client, timeout(1000)).finishTestItem(eq(TestExtension.testMethodUuid), finishTestStep.capture());
    assertThat(finishNestedStep.getValue().getStatus(), equalTo(ItemStatus.FAILED.name()));
    assertThat(finishTestStep.getValue().getStatus(), equalTo(ItemStatus.FAILED.name()));
    assertThat(listener.results.remove().getStatus(), sameInstance(TestExecutionResult.Status.SUCCESSFUL));
}
Also used : TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) ReportPortalClient(com.epam.reportportal.service.ReportPortalClient) FinishTestItemRQ(com.epam.ta.reportportal.ws.model.FinishTestItemRQ) ManualStepReporterSimpleTest(com.epam.reportportal.junit5.features.step.ManualStepReporterSimpleTest) ManualStepReporterFeatureTest(com.epam.reportportal.junit5.features.step.ManualStepReporterFeatureTest) Test(org.junit.jupiter.api.Test)

Example 3 with ReportPortalClient

use of com.epam.reportportal.service.ReportPortalClient in project agent-java-junit5 by reportportal.

the class StepReporterTest method verify_listener_finishes_unfinished_step.

@Test
public void verify_listener_finishes_unfinished_step() {
    TestExtension.init();
    runClasses(ManualStepReporterSimpleTest.class);
    ReportPortalClient client = TestExtension.client.get();
    verify(client, timeout(1000)).finishTestItem(eq(TestExtension.stepUuidList.get(0)), any());
}
Also used : ReportPortalClient(com.epam.reportportal.service.ReportPortalClient) ManualStepReporterSimpleTest(com.epam.reportportal.junit5.features.step.ManualStepReporterSimpleTest) ManualStepReporterFeatureTest(com.epam.reportportal.junit5.features.step.ManualStepReporterFeatureTest) Test(org.junit.jupiter.api.Test)

Example 4 with ReportPortalClient

use of com.epam.reportportal.service.ReportPortalClient in project allure-java by reportportal.

the class TestUtils method mockLaunch.

@SuppressWarnings("unchecked")
public static <T extends Collection<String>> void mockLaunch(ReportPortalClient client, String launchUuid, String suiteUuid, Collection<Pair<String, T>> testSteps) {
    when(client.startLaunch(any())).thenReturn(createMaybe(new StartLaunchRS(launchUuid, 1L)));
    Maybe<ItemCreatedRS> suiteMaybe = createMaybe(new ItemCreatedRS(suiteUuid, suiteUuid));
    when(client.startTestItem(any())).thenReturn(suiteMaybe);
    List<Maybe<ItemCreatedRS>> testResponses = testSteps.stream().map(Pair::getKey).map(uuid -> createMaybe(new ItemCreatedRS(uuid, uuid))).collect(Collectors.toList());
    Maybe<ItemCreatedRS> first = testResponses.get(0);
    Maybe<ItemCreatedRS>[] other = testResponses.subList(1, testResponses.size()).toArray(new Maybe[0]);
    when(client.startTestItem(same(suiteUuid), any())).thenReturn(first, other);
    testSteps.forEach(test -> {
        String testClassUuid = test.getKey();
        List<Maybe<ItemCreatedRS>> stepResponses = test.getValue().stream().map(uuid -> createMaybe(new ItemCreatedRS(uuid, uuid))).collect(Collectors.toList());
        Maybe<ItemCreatedRS> myFirst = stepResponses.get(0);
        Maybe<ItemCreatedRS>[] myOther = stepResponses.subList(1, stepResponses.size()).toArray(new Maybe[0]);
        when(client.startTestItem(same(testClassUuid), any())).thenReturn(myFirst, myOther);
        new HashSet<>(test.getValue()).forEach(testMethodUuid -> when(client.finishTestItem(same(testMethodUuid), any())).thenReturn(createMaybe(new OperationCompletionRS())));
        when(client.finishTestItem(same(testClassUuid), any())).thenReturn(createMaybe(new OperationCompletionRS()));
    });
    Maybe<OperationCompletionRS> suiteFinishMaybe = createMaybe(new OperationCompletionRS());
    when(client.finishTestItem(eq(suiteUuid), any())).thenReturn(suiteFinishMaybe);
    when(client.finishLaunch(eq(launchUuid), any())).thenReturn(createMaybe(new OperationCompletionRS()));
}
Also used : CommonUtils.createMaybe(com.epam.reportportal.util.test.CommonUtils.createMaybe) java.util(java.util) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) ArgumentMatchers(org.mockito.ArgumentMatchers) ListenerParameters(com.epam.reportportal.listeners.ListenerParameters) Maybe(io.reactivex.Maybe) Answer(org.mockito.stubbing.Answer) BatchSaveOperatingRS(com.epam.ta.reportportal.ws.model.BatchSaveOperatingRS) ArgumentCaptor(org.mockito.ArgumentCaptor) Pair(org.apache.commons.lang3.tuple.Pair) Constants(com.epam.ta.reportportal.ws.model.Constants) TestNG(org.testng.TestNG) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ExecutorService(java.util.concurrent.ExecutorService) CommonUtils.generateUniqueId(com.epam.reportportal.util.test.CommonUtils.generateUniqueId) ReportPortalClient(com.epam.reportportal.service.ReportPortalClient) Buffer(okio.Buffer) Predicate(java.util.function.Predicate) Optional.ofNullable(java.util.Optional.ofNullable) IOException(java.io.IOException) SaveLogRQ(com.epam.ta.reportportal.ws.model.log.SaveLogRQ) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) MultipartBody(okhttp3.MultipartBody) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) HttpRequestUtils(com.epam.reportportal.utils.http.HttpRequestUtils) CommonUtils.createMaybe(com.epam.reportportal.util.test.CommonUtils.createMaybe) Maybe(io.reactivex.Maybe) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) Pair(org.apache.commons.lang3.tuple.Pair) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 5 with ReportPortalClient

use of com.epam.reportportal.service.ReportPortalClient in project allure-java by reportportal.

the class TestUtils method mockNestedSteps.

@SuppressWarnings("unchecked")
public static void mockNestedSteps(final ReportPortalClient client, final List<Pair<String, String>> parentNestedPairs) {
    Map<String, List<String>> responseOrders = parentNestedPairs.stream().collect(Collectors.groupingBy(Pair::getKey, Collectors.mapping(Pair::getValue, Collectors.toList())));
    responseOrders.forEach((k, v) -> {
        List<Maybe<ItemCreatedRS>> responses = v.stream().map(uuid -> TestUtils.createMaybe(new ItemCreatedRS(uuid, uuid))).collect(Collectors.toList());
        Maybe<ItemCreatedRS> first = responses.get(0);
        Maybe<ItemCreatedRS>[] other = responses.subList(1, responses.size()).toArray(new Maybe[0]);
        when(client.startTestItem(same(k), any())).thenReturn(first, other);
    });
    parentNestedPairs.forEach(p -> when(client.finishTestItem(same(p.getValue()), any())).thenAnswer((Answer<Maybe<OperationCompletionRS>>) invocation -> TestUtils.createMaybe(new OperationCompletionRS())));
}
Also used : java.util(java.util) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) ArgumentMatchers(org.mockito.ArgumentMatchers) ListenerParameters(com.epam.reportportal.listeners.ListenerParameters) Maybe(io.reactivex.Maybe) Answer(org.mockito.stubbing.Answer) BatchSaveOperatingRS(com.epam.ta.reportportal.ws.model.BatchSaveOperatingRS) ArgumentCaptor(org.mockito.ArgumentCaptor) Pair(org.apache.commons.lang3.tuple.Pair) Constants(com.epam.ta.reportportal.ws.model.Constants) TestNG(org.testng.TestNG) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Triple(org.apache.commons.lang3.tuple.Triple) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ReportPortalClient(com.epam.reportportal.service.ReportPortalClient) Buffer(okio.Buffer) Predicate(java.util.function.Predicate) Optional.ofNullable(java.util.Optional.ofNullable) ITestNGListener(org.testng.ITestNGListener) CommonUtils(com.epam.reportportal.util.test.CommonUtils) IOException(java.io.IOException) SaveLogRQ(com.epam.ta.reportportal.ws.model.log.SaveLogRQ) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) MultipartBody(okhttp3.MultipartBody) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) LogLevel(com.epam.reportportal.listeners.LogLevel) HttpRequestUtils(com.epam.reportportal.utils.http.HttpRequestUtils) Answer(org.mockito.stubbing.Answer) Maybe(io.reactivex.Maybe) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) Pair(org.apache.commons.lang3.tuple.Pair) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

ReportPortalClient (com.epam.reportportal.service.ReportPortalClient)15 ListenerParameters (com.epam.reportportal.listeners.ListenerParameters)12 ItemCreatedRS (com.epam.ta.reportportal.ws.model.item.ItemCreatedRS)12 StartLaunchRS (com.epam.ta.reportportal.ws.model.launch.StartLaunchRS)12 Maybe (io.reactivex.Maybe)11 java.util (java.util)11 ArgumentCaptor (org.mockito.ArgumentCaptor)11 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)10 Collectors (java.util.stream.Collectors)10 Pair (org.apache.commons.lang3.tuple.Pair)10 ArgumentMatchers (org.mockito.ArgumentMatchers)10 Mockito.when (org.mockito.Mockito.when)10 Answer (org.mockito.stubbing.Answer)10 CommonUtils (com.epam.reportportal.util.test.CommonUtils)8 BatchSaveOperatingRS (com.epam.ta.reportportal.ws.model.BatchSaveOperatingRS)8 SaveLogRQ (com.epam.ta.reportportal.ws.model.log.SaveLogRQ)8 HttpRequestUtils (com.epam.reportportal.utils.http.HttpRequestUtils)6 Constants (com.epam.ta.reportportal.ws.model.Constants)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)6 IOException (java.io.IOException)6