Skip to content

Commit

Permalink
[agent-reportportal] Migrate to ReportPortal agent-java-jbehave 5.1.1…
Browse files Browse the repository at this point in the history
…; logger-java-log4j 5.1.3
  • Loading branch information
ikalinin1 authored and valfirst committed Dec 21, 2021
1 parent a0778b3 commit 7ab0b05
Show file tree
Hide file tree
Showing 16 changed files with 480 additions and 212 deletions.
1 change: 1 addition & 0 deletions docs/modules/integrations/nav.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.Integrations
* xref:azure-devops-exporter.adoc[Azure DevOps Exporter]
* xref:reportportal.adoc
* xref:xray-exporter.adoc[Xray Exporter]
* xref:zephyr-exporter.adoc[Zephyr Exporter]
* xref:docker.adoc[Docker]
64 changes: 64 additions & 0 deletions docs/modules/integrations/pages/reportportal.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
= Report Portal

https://reportportal.io/[ReportPortal] is a test automation analytics platform and real-time reporting, powered by Machine Learning.

== Installation

.build.gradle
[source,gradle,subs="attributes+"]
----
implementation(group: 'org.vividus', name: 'agent-reportportal', version: '{current-version}')
----

== Properties

NOTE: The properties marked with bold are mandatory.

[cols="4,3,2,6", options="header"]
|===
|Property Name
|Acceptable values
|Default
|Description

|*system.rp.enable*
|`true`/`false`
|`false`
|Enables reporting to the ReportPortal

|*system.rp.endpoint*
|URL
|none
|URL to the ReportPortal instance

|*system.rp.uuid*
|Access token from ReportPortal profile
|none
|Will be used to authenticate user

|*system.rp.project*
|Any string
|none
|Name of the project that will be used for launch reporting

|*system.rp.launch*
|Any string
|none
|The name of the launch, e.g. `SMOKE`

|system.rp.description
|Any string
|none
|Launch description

|system.rp.test-entity
|`SCENARIO`/`STEP`
|`SCENARIO`
|Defines what will be reported as a test case `SCENARIO` or `STEP`

|system.rp.attributes
|Semi-colon seprated values, e.g. `key:value; value;`
|none
|Attributes could be used for additional tagging of the launches

|===
5 changes: 3 additions & 2 deletions vividus-agent-reportportal/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
project.description = 'Vividus agent for Report Portal'

dependencies {
implementation project(':vividus-engine')
implementation project(':vividus-soft-assert')
implementation project(':vividus-reporter')
implementation(group: 'com.google.guava', name: 'guava', version: versions.guava)
implementation(group: 'org.springframework', name: 'spring-context', version: versions.spring)

// ReportPortal
implementation(group: 'com.epam.reportportal', name: 'logger-java-log4j', version: '4.0.2')
implementation(group: 'com.github.reportportal', name: 'agent-java-jbehave', version: '4.2.1') {
implementation(group: 'com.epam.reportportal', name: 'logger-java-log4j', version: '5.1.3')
implementation(group: 'com.epam.reportportal', name: 'agent-java-jbehave', version: '5.1.1') {
exclude module: 'jbehave-core'
}
implementation(group: 'org.slf4j', name: 'slf4j-api', version: versions.slf4j)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,27 @@

package org.vividus.reportportal.config;

import java.util.List;

import com.epam.reportportal.jbehave.ReportPortalViewGenerator;

import org.jbehave.core.reporters.StoryReporter;
import org.jbehave.core.reporters.ViewGenerator;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.vividus.ExtendedStoryReporterBuilder;
import org.vividus.reportportal.config.condition.ReportPortalEnableCondition;
import org.vividus.reportportal.jbehave.AdaptedReportPortalStoryReporter;
import org.vividus.reportportal.listener.AssertionFailureListener;
import org.vividus.reportportal.jbehave.AdaptedReportPortalFormat;

@Conditional(ReportPortalEnableCondition.class)
@Configuration
public class ReportPortalConfiguration implements InitializingBean
{
@Autowired
@Qualifier("storyReporters")
private List<StoryReporter> storyReporters;
private AdaptedReportPortalFormat adaptedReportPortalFormat;

@Autowired
private ExtendedStoryReporterBuilder storyReporterBuilder;

@Override
public void afterPropertiesSet()
{
storyReporters.add(new AdaptedReportPortalStoryReporter());
}

@Bean
public AssertionFailureListener assertionFailureListener()
{
return new AssertionFailureListener();
}

@Bean
public ViewGenerator reportPortalViewGenerator()
{
return new ReportPortalViewGenerator();
storyReporterBuilder.withFormats(adaptedReportPortalFormat);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright 2019-2021 the original author or authors.
*
* 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 org.vividus.reportportal.jbehave;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.function.Consumer;

import com.epam.reportportal.jbehave.ReportPortalStoryReporter;
import com.epam.reportportal.listeners.LogLevel;
import com.epam.reportportal.service.ReportPortal;
import com.epam.reportportal.service.tree.TestItemTree.TestItemLeaf;
import com.epam.ta.reportportal.ws.model.log.SaveLogRQ;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.jbehave.core.model.Scenario;
import org.jbehave.core.model.Step;
import org.jbehave.core.reporters.DelegatingStoryReporter;
import org.jbehave.core.steps.Timing;
import org.vividus.softassert.event.AssertionFailedEvent;

public class AdaptedDelegatingReportPortalStoryReporter extends DelegatingStoryReporter
{
private final ReportPortalStoryReporter reporter;
private final List<TestItemLeaf> failedSteps = new ArrayList<>();

public AdaptedDelegatingReportPortalStoryReporter(EventBus eventBus, ReportPortalStoryReporter reporter)
{
super(reporter);
this.reporter = reporter;
eventBus.register(this);
}

@Override
public void beforeStep(Step step)
{
runIfNotSystem(step.getStepAsString(), reporter::beforeStep);
}

@Override
public void successful(String step)
{
reporter.getLastStep()
.map(failedSteps::remove)
.filter(Boolean.TRUE::equals)
.ifPresentOrElse(e -> reporter.failed(step, null),
() -> runIfNotSystem(step, reporter::successful));
}

private void runIfNotSystem(String step, Consumer<String> toRun)
{
if (!step.contains("afterStories"))
{
toRun.accept(step);
}
}

@Override
public void afterScenario(Timing timing)
{
reporter.afterScenario();
}

@Override
public void scenarioExcluded(Scenario scenario, String filter)
{
reporter.scenarioNotAllowed(scenario, filter);
}

@Subscribe
public void onAssertionFailure(AssertionFailedEvent event)
{
reporter.getLastStep().ifPresent(s -> {
failedSteps.add(s);
ReportPortal.emitLog(s.getItemId(), itemUuid -> {
SaveLogRQ rq = new SaveLogRQ();
rq.setItemUuid(itemUuid);
rq.setLevel(LogLevel.ERROR.name());
rq.setLogTime(new Date());
rq.setMessage(ExceptionUtils.getStackTrace(event.getSoftAssertionError().getError()));
return rq;
});
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2019-2021 the original author or authors.
*
* 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 org.vividus.reportportal.jbehave;

import java.util.function.BiFunction;
import java.util.function.Supplier;

import com.epam.reportportal.jbehave.ReportPortalFormat;
import com.epam.reportportal.jbehave.ReportPortalScenarioStoryReporter;
import com.epam.reportportal.jbehave.ReportPortalStepStoryReporter;
import com.epam.reportportal.jbehave.ReportPortalStoryReporter;
import com.epam.reportportal.service.Launch;
import com.epam.reportportal.service.ReportPortal;
import com.epam.reportportal.service.tree.TestItemTree;
import com.google.common.eventbus.EventBus;

import org.jbehave.core.reporters.FilePrintStreamFactory;
import org.jbehave.core.reporters.StoryReporter;
import org.jbehave.core.reporters.StoryReporterBuilder;

public class AdaptedReportPortalFormat extends ReportPortalFormat
{
private final EventBus eventBus;
private TestEntity testEntity;

public AdaptedReportPortalFormat(EventBus eventBus)
{
super(ReportPortal.builder().build());
this.eventBus = eventBus;
}

@Override
public StoryReporter createStoryReporter(FilePrintStreamFactory factory, StoryReporterBuilder storyReporterBuilder)
{
return new AdaptedDelegatingReportPortalStoryReporter(eventBus, testEntity.buildReporter(launch, itemTree));
}

@Override
protected ReportPortalStoryReporter createReportPortalReporter(FilePrintStreamFactory factory,
StoryReporterBuilder storyReporterBuilder)
{
throw new UnsupportedOperationException();
}

public void setTestEntity(TestEntity testEntity)
{
this.testEntity = testEntity;
}

public enum TestEntity
{
STEP(ReportPortalStepStoryReporter::new),
SCENARIO(ReportPortalScenarioStoryReporter::new);

private final BiFunction<Supplier<Launch>, TestItemTree, ReportPortalStoryReporter> factory;

TestEntity(BiFunction<Supplier<Launch>, TestItemTree, ReportPortalStoryReporter> factory)
{
this.factory = factory;
}

ReportPortalStoryReporter buildReporter(Supplier<Launch> launch, TestItemTree itemTree)
{
return factory.apply(launch, itemTree);
}
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7ab0b05

Please # to comment.