Skip to content

Commit

Permalink
Client version update
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Jan 23, 2024
1 parent a62075d commit d972a55
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 85 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## [Unreleased]
### Changed
- Client version updated on [5.2.1](https://github.com/reportportal/client-java/releases/tag/5.2.1), by @HardNorth
- Spock dependency marked as `implementation` to force users specify their own versions, by @HardNorth
### Removed
- Unused code, by @HardNorth

## [5.1.4]
### Changed
Expand Down
11 changes: 6 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,30 @@ repositories {
}

dependencies {
api "com.epam.reportportal:client-java:5.1.24"
api "com.epam.reportportal:client-java:5.2.1"
api "com.epam.reportportal:commons-model:5.0.0"
api "org.spockframework:spock-core:${spock_version}"
api 'com.google.code.findbugs:jsr305:3.0.2'

implementation "org.spockframework:spock-core:${spock_version}"
implementation 'org.slf4j:slf4j-api:2.0.7'

testImplementation 'org.codehaus.groovy:groovy:2.5.14'

testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.2'

testImplementation 'org.aspectj:aspectjweaver:1.9.19'
testImplementation 'org.hamcrest:hamcrest-core:2.2'
testImplementation "org.mockito:mockito-core:${mockito_version}"
testImplementation "org.mockito:mockito-inline:${mockito_version}"
testImplementation "org.mockito:mockito-junit-jupiter:${mockito_version}"
testImplementation 'ch.qos.logback:logback-classic:1.3.8'
testImplementation 'com.epam.reportportal:logger-java-logback:5.1.6'
testImplementation 'ch.qos.logback:logback-classic:1.3.12'
testImplementation 'com.epam.reportportal:logger-java-logback:5.2.0'
testImplementation ("org.junit.platform:junit-platform-runner:${junit5_launcher_version}") {
exclude module: 'junit'
}
testImplementation "org.junit.jupiter:junit-jupiter-api:${junit5_version}"
testImplementation "org.junit.jupiter:junit-jupiter-params:${junit5_version}"
testImplementation "org.junit.jupiter:junit-jupiter-engine:${junit5_version}"
testImplementation 'com.squareup.okhttp3:okhttp:4.12.0'
}

test {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/epam/reportportal/spock/LaunchContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
package com.epam.reportportal.spock;

import com.google.common.collect.Lists;
import io.reactivex.Maybe;
import org.spockframework.runtime.model.FeatureInfo;
import org.spockframework.runtime.model.IterationInfo;
import org.spockframework.runtime.model.SpecInfo;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -93,24 +93,24 @@ public NodeFootprint<IterationInfo> findIterationFootprint(IterationInfo iterati
}

@Override
public Iterable<Iteration> findIterationFootprints(final FeatureInfo featureInfo) {
Iterable<Iteration> findIterationFootprints(final FeatureInfo featureInfo) {
return ofNullable(findSpecFootprint(featureInfo.getSpec())).map(s -> s.getFeature(featureInfo))
.map(Feature::getAllTrackedIteration)
.orElse(null);
}

@Override
public Specification findSpecFootprint(final SpecInfo specInfo) {
Specification findSpecFootprint(final SpecInfo specInfo) {
return findValueInRegistry(specFootprintsRegistry, specInfo);
}

@Override
public Iterable<Specification> findAllUnpublishedSpecFootprints() {
Iterable<Specification> findAllUnpublishedSpecFootprints() {
return specFootprintsRegistry.values().stream().filter(IS_NOT_PUBLISHED).collect(Collectors.toList());
}

@Override
public RuntimePointer getRuntimePointerForSpec(SpecInfo specInfo) {
RuntimePointer getRuntimePointerForSpec(SpecInfo specInfo) {
return findValueInRegistry(runtimePointersRegistry, specInfo);
}

Expand All @@ -131,7 +131,7 @@ private static class Specification extends NodeFootprint<SpecInfo> {

private List<Feature> features;

Specification(SpecInfo nodeInfo, Maybe<String> id) {
Specification(@Nonnull SpecInfo nodeInfo, Maybe<String> id) {
super(nodeInfo, id);
}

Expand All @@ -154,7 +154,7 @@ private Feature getFeature(final FeatureInfo featureInfo) {

private List<Feature> getAllTrackedFeatures() {
if (features == null) {
features = Lists.newArrayList();
features = new ArrayList<>();
}
return features;
}
Expand All @@ -174,7 +174,7 @@ boolean hasDescendants() {

private List<Iteration> getAllTrackedIteration() {
if (iterations == null) {
iterations = Lists.newArrayList();
iterations = new ArrayList<>();
}
return iterations;
}
Expand Down
27 changes: 7 additions & 20 deletions src/main/java/com/epam/reportportal/spock/NodeFootprint.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,25 @@
import org.spockframework.runtime.model.MethodInfo;
import org.spockframework.runtime.model.NodeInfo;

import javax.annotation.Nonnull;
import java.lang.reflect.AnnotatedElement;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.function.Predicate;

import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.newArrayListWithCapacity;

/**
* Abstract entity for the representation of the metadata for the reportable
* <i>Spock</i> test item (specification, iteration, etc.)
*
* @author Dzmitry Mikhievich
*/
public abstract class NodeFootprint<T extends NodeInfo> extends ReportableItemFootprint<T> {

/*
* Approximate fixtures count, which should match most cases. This is
* a kind of "happy medium" between memory consumption and potential
* performance drawback on arrays coping
*/
private static final int APPROXIMATE_CAPACITY = 4;

public abstract class NodeFootprint<T extends NodeInfo<?, ? extends AnnotatedElement>> extends ReportableItemFootprint<T> {
private final List<ReportableItemFootprint<MethodInfo>> fixtures;

NodeFootprint(T nodeInfo, Maybe<String> id) {
NodeFootprint(@Nonnull T nodeInfo, Maybe<String> id) {
super(nodeInfo, id);
fixtures = newArrayListWithCapacity(APPROXIMATE_CAPACITY);
}

ReportableItemFootprint<MethodInfo> findFixtureFootprint(final MethodInfo fixture) {
Predicate<ReportableItemFootprint<MethodInfo>> criteria = createFixtureMatchPredicate(fixture);
return getFixtures().stream().filter(criteria).findAny().orElseThrow(NoSuchElementException::new);
fixtures = new ArrayList<>();
}

/**
Expand All @@ -70,7 +57,7 @@ void addFixtureFootprint(FixtureFootprint footprint) {
}

List<ReportableItemFootprint<MethodInfo>> getFixtures() {
return newArrayList(fixtures);
return new ArrayList<>(fixtures);
}

private static Predicate<ReportableItemFootprint<MethodInfo>> createFixtureMatchPredicate(final MethodInfo fixture) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
final class NodeInfoUtils {
static final String INHERITED_FIXTURE_NAME_TEMPLATE = "%s:%s";
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private static final String LINE_SEPARATOR = System.lineSeparator();
private static final String BLOCK_SPLITTER = ": ";
private static final String CONJUNCTION_KEYWORD = "And";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ public ReportPortalSpockExtension(ReportPortalSpockListener listener) {
reportingRunListener = listener;
}

@SuppressWarnings("unused")
public ReportPortalSpockExtension() {
this(new ReportPortalSpockListener());
}

@Override
public void start() {
LOGGER.info("\"LAUNCHING\" the test run");
//noinspection ReactiveStreamsUnusedPublisher
reportingRunListener.startLaunch();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import com.epam.ta.reportportal.ws.model.StartTestItemRQ;
import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ;
import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
import io.reactivex.Maybe;
import org.apache.commons.lang3.tuple.Pair;
import org.codehaus.groovy.runtime.StackTraceUtils;
Expand All @@ -54,8 +52,8 @@
import static com.epam.reportportal.listeners.ItemStatus.*;
import static com.epam.reportportal.spock.NodeInfoUtils.*;
import static com.epam.reportportal.spock.ReportableItemFootprint.IS_NOT_PUBLISHED;
import static com.google.common.base.Strings.isNullOrEmpty;
import static java.util.Optional.ofNullable;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.spockframework.runtime.model.MethodKind.*;

/**
Expand All @@ -70,24 +68,22 @@ public class ReportPortalSpockListener extends AbstractRunListener {
private static final Method DISPLAY_NAME_METHOD = Arrays.stream(ITERATION_METHODS)
.filter(m -> "getDisplayName".equals(m.getName()))
.findAny()
.orElseGet(
() -> Arrays.stream(ITERATION_METHODS)
.filter(m -> "getName".equals(m.getName()))
.findAny()
.orElseThrow(() -> new IllegalStateException("Unknown Spock version."))
);
.orElseGet(() -> Arrays.stream(ITERATION_METHODS)
.filter(m -> "getName".equals(m.getName()))
.findAny()
.orElseThrow(() -> new IllegalStateException("Unknown Spock version.")));

private final MemoizingSupplier<Launch> launch;

// stores the bindings of Spock method kinds to the RP-specific notation
private static final Map<MethodKind, String> ITEM_TYPES_REGISTRY = ImmutableMap.<MethodKind, String>builder()
.put(SPEC_EXECUTION, "TEST")
.put(SETUP_SPEC, "BEFORE_CLASS")
.put(SETUP, "BEFORE_METHOD")
.put(FEATURE, "STEP")
.put(CLEANUP, "AFTER_METHOD")
.put(CLEANUP_SPEC, "AFTER_CLASS")
.build();
private static final Map<MethodKind, String> ITEM_TYPES_REGISTRY = Collections.unmodifiableMap(new HashMap<MethodKind, String>() {{
put(SPEC_EXECUTION, "TEST");
put(SETUP_SPEC, "BEFORE_CLASS");
put(SETUP, "BEFORE_METHOD");
put(FEATURE, "STEP");
put(CLEANUP, "AFTER_METHOD");
put(CLEANUP_SPEC, "AFTER_CLASS");
}});

private ListenerParameters launchParameters;
private final AbstractLaunchContext launchContext;
Expand All @@ -96,7 +92,7 @@ public class ReportPortalSpockListener extends AbstractRunListener {
protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) {
StartLaunchRQ startLaunchRQ = new StartLaunchRQ();
startLaunchRQ.setName(parameters.getLaunchName());
if (!isNullOrEmpty(parameters.getDescription())) {
if (isNotBlank(parameters.getDescription())) {
startLaunchRQ.setDescription(parameters.getDescription());
}
startLaunchRQ.setStartTime(Calendar.getInstance().getTime());
Expand Down Expand Up @@ -131,6 +127,10 @@ public ReportPortalSpockListener(@Nonnull Supplier<Launch> launch) {
this(launch, new LaunchContextImpl());
}

void handleRpException(ReportPortalException rpException, String message) {
LOGGER.error(message, rpException);
}

public Maybe<String> startLaunch() {
if (launchContext.tryStartLaunch()) {
try {
Expand Down Expand Up @@ -394,7 +394,7 @@ protected void reportFeatureStart(@Nonnull Maybe<String> parentId, @Nonnull Feat
}

public void reportFixtureError(@Nonnull SpecInfo spec, @Nullable FeatureInfo feature, @Nullable IterationInfo iteration,
@Nonnull ErrorInfo error) {
@Nonnull ErrorInfo error) {
MethodInfo method = error.getMethod();
NodeFootprint<?> ownerFootprint = findFixtureOwner(spec, feature, iteration, error.getMethod());
MethodKind kind = method.getKind();
Expand Down Expand Up @@ -483,29 +483,9 @@ public void finishLaunch() {
}
}

void handleRpException(ReportPortalException rpException, String message) {
handleException(rpException, message);
}

/**
* Logs error in case of {@link ReportPortalException} or propagates exception exactly as-is, if
* and only if it is an instance of {@link RuntimeException} or {@link Error}.
*/
private void handleException(Exception exception, String message) {
if (exception instanceof ReportPortalException) {
if (LOGGER != null) {
LOGGER.error(message, exception);
} else {
System.out.println(exception.getMessage());
}
} else {
Throwables.throwIfUnchecked(exception);
}
}

@SuppressWarnings("rawtypes")
protected NodeFootprint<? extends NodeInfo> findFixtureOwner(SpecInfo spec, FeatureInfo feature, IterationInfo iteration,
MethodInfo fixture) {
MethodInfo fixture) {
MethodKind kind = fixture.getKind();
if (kind.isSpecScopedFixtureMethod()) {
return launchContext.findSpecFootprint(spec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
import io.reactivex.Maybe;
import org.spockframework.runtime.model.NodeInfo;

import javax.annotation.Nonnull;
import java.util.Optional;
import java.util.function.Predicate;

import static com.google.common.base.Preconditions.checkArgument;

/**
* Base entity which stores the reporting metadata for the <i>Spock</i> test elements
*
* @author Dzmitry Mikhievich
*/
@SuppressWarnings("rawtypes")
public abstract class ReportableItemFootprint<T extends NodeInfo> {

static final Predicate<ReportableItemFootprint> IS_NOT_PUBLISHED = input -> input != null && !input.isPublished();
Expand All @@ -39,8 +39,7 @@ public abstract class ReportableItemFootprint<T extends NodeInfo> {
private ItemStatus status;
private boolean published = false;

ReportableItemFootprint(T item, Maybe<String> id) {
checkArgument(item != null, "Node info shouldn't be null");
ReportableItemFootprint(@Nonnull T item, Maybe<String> id) {
this.id = id;
this.item = item;
}
Expand Down Expand Up @@ -69,9 +68,5 @@ boolean isPublished() {
return published;
}

String getItemName() {
return getItem().getName();
}

abstract boolean hasDescendants();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class SystemAttributesFetcher {
private static final String PROPS_FILE = "agent.properties";

private SystemAttributesFetcher() {
// static only
throw new RuntimeException("No instances should exist for the class!");
}

private static ItemAttributesRQ skippedIssue(Boolean skippedAnIssue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.epam.reportportal.spock;

import com.google.common.collect.Lists;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -114,6 +113,7 @@ private static Iterable<Object[]> parametersForFixtureDescription() {
when(inheritedFixtureInfo.getName()).thenReturn(inheritedFixtureName);
SpecInfo parent = mock(SpecInfo.class);
when(inheritedFixtureInfo.getParent()).thenReturn(parent);
//noinspection rawtypes
when(parent.getReflection()).thenReturn(((Class) FixtureSource.class));
String expectedInheritedName = format(INHERITED_FIXTURE_NAME_TEMPLATE, FixtureSource.class.getSimpleName(), inheritedFixtureName);

Expand All @@ -137,6 +137,7 @@ public void getFixtureDisplayName_fixtureIsNull() {
public void getSpecIdentifier_specInfoIsNotNull() {
Class<?> bearingClass = getClass();
SpecInfo specInfoMock = mock(SpecInfo.class);
//noinspection rawtypes
when((Class) specInfoMock.getReflection()).thenReturn(bearingClass);

String identifier = NodeInfoUtils.getSpecIdentifier(specInfoMock);
Expand All @@ -154,7 +155,7 @@ private static final class FixtureSource {
}

private static Collection<String> generateBlockTexts(int count) {
Collection<String> texts = Lists.newArrayListWithCapacity(count);
Collection<String> texts = new ArrayList<>();
for (int i = 0; i < count; i++) {
texts.add(RandomStringUtils.randomAlphabetic(40));
}
Expand Down

0 comments on commit d972a55

Please sign in to comment.