Search in sources :

Example 11 with ReportPortalClient

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

the class TestUtils method mockLaunch.

@SuppressWarnings("unchecked")
public static void mockLaunch(ReportPortalClient client, String launchUuid, String testClassUuid, Collection<String> testMethodUuidList) {
    when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launchUuid, 1L)));
    Maybe<ItemCreatedRS> testClassMaybe = Maybe.just(new ItemCreatedRS(testClassUuid, testClassUuid));
    when(client.startTestItem(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);
    when(client.finishLaunch(eq(launchUuid), any())).thenReturn(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) 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 12 with ReportPortalClient

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

the class BaseTest method mockScenario.

@SuppressWarnings("unchecked")
public static <T extends Collection<String>> void mockScenario(@Nonnull final ReportPortalClient client, @Nonnull final String storyUuid, @Nonnull final Collection<Pair<String, T>> testSteps) {
    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(storyUuid), 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());
        when(client.finishTestItem(same(testClassUuid), any())).thenReturn(createMaybe(new OperationCompletionRS()));
        if (!stepResponses.isEmpty()) {
            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())));
        }
    });
}
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) InstanceStepsFactory(org.jbehave.core.steps.InstanceStepsFactory) ListenerParameters(com.epam.reportportal.listeners.ListenerParameters) Maybe(io.reactivex.Maybe) Format(org.jbehave.core.reporters.Format) Answer(org.mockito.stubbing.Answer) BatchSaveOperatingRS(com.epam.ta.reportportal.ws.model.BatchSaveOperatingRS) ArgumentCaptor(org.mockito.ArgumentCaptor) Pair(org.apache.commons.lang3.tuple.Pair) NullEmbedderMonitor(org.jbehave.core.embedder.NullEmbedderMonitor) Constants(com.epam.ta.reportportal.ws.model.Constants) Matchers.hasSize(org.hamcrest.Matchers.hasSize) RegexStoryParser(org.jbehave.core.parsers.RegexStoryParser) StoryParser(org.jbehave.core.parsers.StoryParser) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Nonnull(javax.annotation.Nonnull) Embedder(org.jbehave.core.embedder.Embedder) Nullable(javax.annotation.Nullable) 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) 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) UnderscoredCamelCaseResolver(org.jbehave.core.io.UnderscoredCamelCaseResolver) Collectors(java.util.stream.Collectors) FilePrintStreamFactory(org.jbehave.core.reporters.FilePrintStreamFactory) Executors(java.util.concurrent.Executors) EmbedderControls(org.jbehave.core.embedder.EmbedderControls) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) MultipartBody(okhttp3.MultipartBody) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) Matchers.equalTo(org.hamcrest.Matchers.equalTo) LogLevel(com.epam.reportportal.listeners.LogLevel) StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) HttpRequestUtils(com.epam.reportportal.utils.http.HttpRequestUtils) CommonUtils.createMaybe(com.epam.reportportal.util.test.CommonUtils.createMaybe) 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 13 with ReportPortalClient

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

the class BaseTest 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 -> 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(eq(k), any())).thenReturn(first, other);
    });
    parentNestedPairs.forEach(p -> when(client.finishTestItem(same(p.getValue()), any())).thenAnswer((Answer<Maybe<OperationCompletionRS>>) invocation -> 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) InstanceStepsFactory(org.jbehave.core.steps.InstanceStepsFactory) ListenerParameters(com.epam.reportportal.listeners.ListenerParameters) Maybe(io.reactivex.Maybe) Format(org.jbehave.core.reporters.Format) Answer(org.mockito.stubbing.Answer) BatchSaveOperatingRS(com.epam.ta.reportportal.ws.model.BatchSaveOperatingRS) ArgumentCaptor(org.mockito.ArgumentCaptor) Pair(org.apache.commons.lang3.tuple.Pair) NullEmbedderMonitor(org.jbehave.core.embedder.NullEmbedderMonitor) Constants(com.epam.ta.reportportal.ws.model.Constants) Matchers.hasSize(org.hamcrest.Matchers.hasSize) RegexStoryParser(org.jbehave.core.parsers.RegexStoryParser) StoryParser(org.jbehave.core.parsers.StoryParser) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Nonnull(javax.annotation.Nonnull) Embedder(org.jbehave.core.embedder.Embedder) Nullable(javax.annotation.Nullable) 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) 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) UnderscoredCamelCaseResolver(org.jbehave.core.io.UnderscoredCamelCaseResolver) Collectors(java.util.stream.Collectors) FilePrintStreamFactory(org.jbehave.core.reporters.FilePrintStreamFactory) Executors(java.util.concurrent.Executors) EmbedderControls(org.jbehave.core.embedder.EmbedderControls) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) MultipartBody(okhttp3.MultipartBody) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) Matchers.equalTo(org.hamcrest.Matchers.equalTo) LogLevel(com.epam.reportportal.listeners.LogLevel) StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) HttpRequestUtils(com.epam.reportportal.utils.http.HttpRequestUtils) Answer(org.mockito.stubbing.Answer) CommonUtils.createMaybe(com.epam.reportportal.util.test.CommonUtils.createMaybe) 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 14 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 -> 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(eq(k), any())).thenReturn(first, other);
    });
    parentNestedPairs.forEach(p -> when(client.finishTestItem(same(p.getValue()), any())).thenAnswer((Answer<Maybe<OperationCompletionRS>>) invocation -> 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) Answer(org.mockito.stubbing.Answer) CommonUtils.createMaybe(com.epam.reportportal.util.test.CommonUtils.createMaybe) 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 15 with ReportPortalClient

use of com.epam.reportportal.service.ReportPortalClient in project allure-java 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(TestUtils.createMaybe(new StartLaunchRS(launchUuid, 1L)));
    Maybe<ItemCreatedRS> suiteMaybe = TestUtils.createMaybe(new ItemCreatedRS(suiteUuid, suiteUuid));
    when(client.startTestItem(any())).thenReturn(suiteMaybe);
    Maybe<ItemCreatedRS> testClassMaybe = TestUtils.createMaybe(new ItemCreatedRS(testClassUuid, testClassUuid));
    when(client.startTestItem(eq(suiteUuid), any())).thenReturn(testClassMaybe);
    List<Maybe<ItemCreatedRS>> responses = testMethodUuidList.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(eq(testClassUuid), any())).thenReturn(first, other);
    new HashSet<>(testMethodUuidList).forEach(testMethodUuid -> when(client.finishTestItem(eq(testMethodUuid), any())).thenReturn(TestUtils.createMaybe(new OperationCompletionRS())));
    Maybe<OperationCompletionRS> testClassFinishMaybe = TestUtils.createMaybe(new OperationCompletionRS());
    when(client.finishTestItem(eq(testClassUuid), any())).thenReturn(testClassFinishMaybe);
    Maybe<OperationCompletionRS> suiteFinishMaybe = TestUtils.createMaybe(new OperationCompletionRS());
    when(client.finishTestItem(eq(suiteUuid), any())).thenReturn(suiteFinishMaybe);
    when(client.finishLaunch(eq(launchUuid), any())).thenReturn(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) 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)

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