Search in sources :

Example 6 with ReportPortalClient

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

the class CallbackReportingIntegrationTest method initMocks.

@BeforeEach
@SuppressWarnings("unchecked")
public void initMocks() {
    ReportPortalClient reportPortalClient = mock(ReportPortalClient.class);
    when(reportPortalClient.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS("launchUuid", 1L)));
    Maybe<ItemCreatedRS> suiteMaybe = Maybe.just(new ItemCreatedRS(suitedUuid, suitedUuid));
    when(reportPortalClient.startTestItem(any())).thenReturn(suiteMaybe);
    Maybe<ItemCreatedRS> testClassMaybe = Maybe.just(new ItemCreatedRS(testClassUuid, testClassUuid));
    when(reportPortalClient.startTestItem(eq(suiteMaybe.blockingGet().getId()), any())).thenReturn(testClassMaybe);
    Maybe<ItemCreatedRS> testMethodMaybe = Maybe.just(new ItemCreatedRS(testMethodUuid, testMethodUuid));
    when(reportPortalClient.startTestItem(eq(testClassMaybe.blockingGet().getId()), any())).thenReturn(testMethodMaybe);
    Maybe<OperationCompletionRS> finishResponse = Maybe.just(new OperationCompletionRS("finished"));
    when(reportPortalClient.finishTestItem(eq(testMethodUuid), any())).thenReturn(finishResponse);
    when(reportPortalClient.log(any(List.class))).thenReturn(Maybe.just(new BatchSaveOperatingRS()));
    when(reportPortalClient.log(any(SaveLogRQ.class))).thenReturn(Maybe.just(new EntryCreatedAsyncRS("logId")));
    ListenerParameters params = standardParameters();
    params.setCallbackReportingEnabled(true);
    final ReportPortal reportPortal = ReportPortal.create(reportPortalClient, params);
    CallbackReportingListener.initReportPortal(reportPortal);
}
Also used : StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) SaveLogRQ(com.epam.ta.reportportal.ws.model.log.SaveLogRQ) ListenerParameters(com.epam.reportportal.listeners.ListenerParameters) ReportPortal(com.epam.reportportal.service.ReportPortal) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) ReportPortalClient(com.epam.reportportal.service.ReportPortalClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with ReportPortalClient

use of com.epam.reportportal.service.ReportPortalClient in project agent-java-testNG 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 -> Maybe.just(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 -> Maybe.just(new OperationCompletionRS())));
}
Also used : ReportPortalClient(com.epam.reportportal.service.ReportPortalClient) java.util(java.util) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) ArgumentMatchers(org.mockito.ArgumentMatchers) ListenerParameters(com.epam.reportportal.listeners.ListenerParameters) Launch(com.epam.reportportal.service.Launch) Maybe(io.reactivex.Maybe) ITestNGListener(org.testng.ITestNGListener) CommonUtils(com.epam.reportportal.util.test.CommonUtils) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Answer(org.mockito.stubbing.Answer) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) ArgumentCaptor(org.mockito.ArgumentCaptor) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) Pair(org.apache.commons.lang3.tuple.Pair) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) TestNG(org.testng.TestNG) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) 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)

Example 8 with ReportPortalClient

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

the class TestUtils method mockLaunch.

@SuppressWarnings("unchecked")
public static void mockLaunch(ReportPortalClient client, String launchUuid, String suiteUuid, String testClassUuid, Collection<String> testMethodUuidList) {
    when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launchUuid, 1L)));
    Maybe<ItemCreatedRS> suiteMaybe = Maybe.just(new ItemCreatedRS(suiteUuid, suiteUuid));
    when(client.startTestItem(any())).thenReturn(suiteMaybe);
    Maybe<ItemCreatedRS> testClassMaybe = Maybe.just(new ItemCreatedRS(testClassUuid, testClassUuid));
    when(client.startTestItem(eq(suiteUuid), any())).thenReturn(testClassMaybe);
    List<Maybe<ItemCreatedRS>> responses = testMethodUuidList.stream().map(uuid -> Maybe.just(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(eq(testClassUuid), any())).thenReturn(first, other);
    new HashSet<>(testMethodUuidList).forEach(testMethodUuid -> when(client.finishTestItem(eq(testMethodUuid), any())).thenReturn(Maybe.just(new OperationCompletionRS())));
    Maybe<OperationCompletionRS> testClassFinishMaybe = Maybe.just(new OperationCompletionRS());
    when(client.finishTestItem(eq(testClassUuid), any())).thenReturn(testClassFinishMaybe);
    Maybe<OperationCompletionRS> suiteFinishMaybe = Maybe.just(new OperationCompletionRS());
    when(client.finishTestItem(eq(suiteUuid), any())).thenReturn(suiteFinishMaybe);
    when(client.finishLaunch(eq(launchUuid), any())).thenReturn(Maybe.just(new OperationCompletionRS()));
}
Also used : ReportPortalClient(com.epam.reportportal.service.ReportPortalClient) java.util(java.util) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) ArgumentMatchers(org.mockito.ArgumentMatchers) ListenerParameters(com.epam.reportportal.listeners.ListenerParameters) Launch(com.epam.reportportal.service.Launch) Maybe(io.reactivex.Maybe) ITestNGListener(org.testng.ITestNGListener) CommonUtils(com.epam.reportportal.util.test.CommonUtils) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Answer(org.mockito.stubbing.Answer) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) ArgumentCaptor(org.mockito.ArgumentCaptor) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) Pair(org.apache.commons.lang3.tuple.Pair) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) TestNG(org.testng.TestNG) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) Maybe(io.reactivex.Maybe) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 9 with ReportPortalClient

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

the class CallbackTest method afterClass.

@AfterClass
public static void afterClass() {
    ReportPortalClient client = ReportPortalListener.getReportPortal().getClient();
    TestItemTree itemTree = ParallelRunningContext.getCurrent().getItemTree();
    attachLog(client, itemTree);
    changeStatus(client, itemTree);
}
Also used : TestItemTree(com.epam.reportportal.service.tree.TestItemTree) ReportPortalClient(com.epam.reportportal.service.ReportPortalClient) AfterClass(org.junit.AfterClass)

Example 10 with ReportPortalClient

use of com.epam.reportportal.service.ReportPortalClient in project agent-java-junit5 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 -> Maybe.just(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 -> Maybe.just(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) Launch(com.epam.reportportal.service.Launch) Maybe(io.reactivex.Maybe) Answer(org.mockito.stubbing.Answer) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) BatchSaveOperatingRS(com.epam.ta.reportportal.ws.model.BatchSaveOperatingRS) ArgumentCaptor(org.mockito.ArgumentCaptor) Pair(org.apache.commons.lang3.tuple.Pair) LauncherFactory(org.junit.platform.launcher.core.LauncherFactory) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) DiscoverySelectors(org.junit.platform.engine.discovery.DiscoverySelectors) CommonUtils.createMaybeUuid(com.epam.reportportal.util.test.CommonUtils.createMaybeUuid) ReportPortalClient(com.epam.reportportal.service.ReportPortalClient) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) CommonUtils(com.epam.reportportal.util.test.CommonUtils) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) LauncherConfig(org.junit.platform.launcher.core.LauncherConfig) Stream(java.util.stream.Stream) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) LauncherDiscoveryRequestBuilder(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) ClassSelector(org.junit.platform.engine.discovery.ClassSelector) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) Mockito.mock(org.mockito.Mockito.mock) 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