Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up JDK 1.8
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '8'
java-version: '11'

- name: Build with Gradle
run: ./gradlew build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ jobs:
version-file: ${{ env.VERSION_FILE }}
version-file-extraction-pattern: ${{ env.VERSION_EXTRACT_PATTERN }}

- name: Set up JDK 1.8
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '8'
java-version: '11'

- name: Setup git credentials
uses: oleksiyrudenko/gha-git-credentials@v2-latest
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Unreleased]
### Changed
- Client version updated on [5.4.3](https://github.com/reportportal/client-java/releases/tag/5.4.3), by @HardNorth
- Replace "jsr305" annotations with "jakarta.annotation-api", by @HardNorth
- Switch on use of `Instant` class instead of `Date` to get more timestamp precision, by @HardNorth

## [5.3.2]
### Changed
Expand Down
13 changes: 7 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,31 @@ project.ext.limits = [
'class' : 40
]

sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
}

dependencies {
api "com.epam.reportportal:client-java:5.3.17"
api "com.epam.reportportal:client-java:5.4.3"

compileOnly "org.spockframework:spock-core:${spock_version}"
implementation 'org.slf4j:slf4j-api:2.0.7'
implementation 'org.apache.commons:commons-lang3:3.18.0'

testImplementation "org.spockframework:spock-core:${spock_version}"
testImplementation 'org.codehaus.groovy:groovy:2.5.14'
testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.13'
testImplementation 'com.epam.reportportal:agent-java-test-utils:0.1.0'

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.15'
testImplementation 'com.epam.reportportal:logger-java-logback:5.2.3'
testImplementation 'ch.qos.logback:logback-classic:1.5.18'
testImplementation 'com.epam.reportportal:logger-java-logback:5.4.0'
testImplementation ("org.junit.platform:junit-platform-runner:${junit5_launcher_version}") {
exclude module: 'junit'
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=agent-java-spock
version=5.3.3-SNAPSHOT
version=5.4.0-SNAPSHOT
description=Spock integration agent for Report Portal
spock_version=2.3-groovy-2.5
junit5_version=5.9.2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.epam.reportportal.spock;

import jakarta.annotation.Nonnull;
import org.spockframework.runtime.extension.IMethodInterceptor;
import org.spockframework.runtime.extension.IMethodInvocation;
import org.spockframework.runtime.model.ErrorInfo;

import javax.annotation.Nonnull;

/**
* Implementation of {@link org.spockframework.runtime.extension.IMethodInterceptor}, which allows to report
* fixture method execution
Expand All @@ -30,7 +29,8 @@ public void intercept(IMethodInvocation invocation) throws Throwable {
exception = ex;
// explicitly report exception to has an ability to track error
// before result publishing
spockService.reportFixtureError(invocation.getSpec(),
spockService.reportFixtureError(
invocation.getSpec(),
invocation.getFeature(),
invocation.getIteration(),
new ErrorInfo(invocation.getMethod(), ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
package com.epam.reportportal.spock;

import io.reactivex.Maybe;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
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;
Expand Down Expand Up @@ -77,7 +77,7 @@ public void addRunningIteration(Maybe<String> id, IterationInfo iterationInfo) {
@Override
@Nullable
public NodeFootprint<FeatureInfo> findFeatureFootprint(FeatureInfo featureInfo) {
return ofNullable(findSpecFootprint(featureInfo.getSpec())).map(s->s.getFeature(featureInfo)).orElse(null);
return ofNullable(findSpecFootprint(featureInfo.getSpec())).map(s -> s.getFeature(featureInfo)).orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package com.epam.reportportal.spock;

import io.reactivex.Maybe;
import jakarta.annotation.Nonnull;
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;
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/com/epam/reportportal/spock/NodeInfoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ private static void appendBlockInfo(StringBuilder featureDescription, BlockInfo
}
// append conjunction blocks
while (textsIterator.hasNext()) {
featureDescription.append(LINE_SEPARATOR)
.append(CONJUNCTION_KEYWORD)
.append(BLOCK_SPLITTER)
.append(textsIterator.next());
featureDescription.append(LINE_SEPARATOR).append(CONJUNCTION_KEYWORD).append(BLOCK_SPLITTER).append(textsIterator.next());
}
}

Expand All @@ -149,9 +146,11 @@ private static void appendBlockInfo(StringBuilder featureDescription, BlockInfo
* @return capitalized block kind name
*/
private static String formatBlockKind(BlockKind blockKind) {
return BLOCK_NAMES.computeIfAbsent(blockKind, b -> {
String blockName = b.name();
return blockName.charAt(0) + blockName.substring(1).toLowerCase(Locale.US);
});
return BLOCK_NAMES.computeIfAbsent(
blockKind, b -> {
String blockName = b.name();
return blockName.charAt(0) + blockName.substring(1).toLowerCase(Locale.US);
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ;
import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ;
import io.reactivex.Maybe;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.codehaus.groovy.runtime.StackTraceUtils;
Expand All @@ -41,11 +43,10 @@
import org.spockframework.runtime.AbstractRunListener;
import org.spockframework.runtime.model.*;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
Expand Down Expand Up @@ -81,14 +82,20 @@ public class ReportPortalSpockListener extends AbstractRunListener {
private final Map<Maybe<String>, Pair<String, String>> errorDescriptionMap = new ConcurrentHashMap<>();

// stores the bindings of Spock method kinds to the RP-specific notation
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 static final Map<MethodKind, String> ITEM_TYPES_REGISTRY = Map.of(
SPEC_EXECUTION,
"TEST",
SETUP_SPEC,
"BEFORE_CLASS",
SETUP,
"BEFORE_METHOD",
FEATURE,
"STEP",
CLEANUP,
"AFTER_METHOD",
CLEANUP_SPEC,
"AFTER_CLASS"
);

private ListenerParameters launchParameters;
private final AbstractLaunchContext launchContext;
Expand All @@ -100,7 +107,7 @@ protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) {
if (isNotBlank(parameters.getDescription())) {
startLaunchRQ.setDescription(parameters.getDescription());
}
startLaunchRQ.setStartTime(Calendar.getInstance().getTime());
startLaunchRQ.setStartTime(Instant.now());
Set<ItemAttributesRQ> attributes = new HashSet<>();
attributes.addAll(parameters.getAttributes());
attributes.addAll(SystemAttributesFetcher.collectSystemAttributes(parameters.getSkippedAnIssue()));
Expand Down Expand Up @@ -165,7 +172,7 @@ protected void setAttributes(@Nonnull StartTestItemRQ rq, @Nonnull AnnotatedElem
protected StartTestItemRQ buildBaseStartTestItemRq(@Nonnull String name, @Nonnull String type) {
StartTestItemRQ rq = new StartTestItemRQ();
rq.setName(name);
rq.setStartTime(Calendar.getInstance().getTime());
rq.setStartTime(Instant.now());
rq.setType(type);
rq.setLaunchUuid(launchContext.getLaunchId().blockingGet());
return rq;
Expand Down Expand Up @@ -314,7 +321,7 @@ public void registerIteration(@Nonnull IterationInfo iteration) {
protected FinishTestItemRQ buildFinishTestItemRq(@Nonnull Maybe<String> itemId, @Nullable ItemStatus status) {
FinishTestItemRQ rq = new FinishTestItemRQ();
ofNullable(status).ifPresent(s -> rq.setStatus(s.name()));
rq.setEndTime(Calendar.getInstance().getTime());
rq.setEndTime(Instant.now());
if (Objects.equals(status, ItemStatus.FAILED) && errorDescriptionMap.containsKey(itemId)) {
String formattedException = String.format("Error:\n%s", errorDescriptionMap.get(itemId).getRight());
if (StringUtils.isNotBlank(errorDescriptionMap.get(itemId).getLeft())) {
Expand Down Expand Up @@ -461,7 +468,7 @@ public void reportError(@Nonnull ErrorInfo error) {
ofNullable(launchContext.getRuntimePointerForSpec(method.getParent())
.getCurrentIteration()).map(launchContext::findIterationFootprint).ifPresent(i -> i.setStatus(FAILED));
Maybe<String> itemId = launchContext.findIterationFootprint(error.getMethod().getIteration()).getId();
String startDescriptions = errorDescriptionMap.get(itemId).getLeft();
String startDescriptions = ofNullable(errorDescriptionMap.get(itemId)).map(Pair::getLeft).orElse(null);
Pair<String, String> startFinishDescriptions = Pair.of(
startDescriptions,
ExceptionUtils.getStackTrace(error.getException(), new Throwable())
Expand Down Expand Up @@ -492,7 +499,7 @@ protected void trackSkippedFeature(FeatureInfo feature) {
@Nonnull
private FinishExecutionRQ buildFinishExecutionRq() {
FinishExecutionRQ rq = new FinishExecutionRQ();
rq.setEndTime(Calendar.getInstance().getTime());
rq.setEndTime(Instant.now());
return rq;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import com.epam.reportportal.listeners.ItemStatus;
import io.reactivex.Maybe;
import jakarta.annotation.Nonnull;
import org.spockframework.runtime.model.NodeInfo;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ private static ItemAttributesRQ skippedIssue(Boolean skippedAnIssue) {
}

public static Set<ItemAttributesRQ> collectSystemAttributes(Boolean skippedAnIssue) {
Set<ItemAttributesRQ> systemAttributes = SystemAttributesExtractor.extract(PROPS_FILE,
Set<ItemAttributesRQ> systemAttributes = SystemAttributesExtractor.extract(
PROPS_FILE,
SystemAttributesFetcher.class.getClassLoader()
);
systemAttributes.add(skippedIssue(skippedAnIssue));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.epam.reportportal.spock.bugs;

import com.epam.reportportal.listeners.ListenerParameters;
import com.epam.reportportal.service.ReportPortal;
import com.epam.reportportal.service.ReportPortalClient;
import com.epam.reportportal.spock.ReportPortalSpockListener;
import com.epam.reportportal.spock.features.bugs.NullPointerOnSetupSpec;
import com.epam.reportportal.spock.utils.TestExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.platform.launcher.listeners.TestExecutionSummary;

import static com.epam.reportportal.spock.utils.TestUtils.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.Mockito.mock;

public class NullPointerOnSetupTest {

private final ReportPortalClient client = mock(ReportPortalClient.class);

@BeforeEach
public void setupMock() {
ListenerParameters parameters = standardParameters();
parameters.setEnable(false);
TestExtension.listener = new ReportPortalSpockListener(ReportPortal.create(client, parameters, testExecutor()));
}

@Test
public void verify_no_null_pointer_on_setup() {
TestExecutionSummary result = runClasses(NullPointerOnSetupSpec.class);

assertThat(result.getTotalFailureCount(), equalTo(1L));
assertThat(result.getFailures().get(0).getException().getMessage(), equalTo("Cannot invoke method first() on null object"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void verify_fail_with_failed_reporting() {
assertThat(result.getTotalFailureCount(), equalTo(1L));

verify(client).getProjectSettings();
verify(client).getApiInfo();
verify(client).startLaunch(any());
ArgumentCaptor<StartTestItemRQ> startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
verify(client).startTestItem(any(StartTestItemRQ.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void verify_fail_with_failed_reporting() {
assertThat(result.getTotalFailureCount(), equalTo(1L));

verify(client).getProjectSettings();
verify(client).getApiInfo();
verify(client).startLaunch(any());
ArgumentCaptor<StartTestItemRQ> startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
verify(client).startTestItem(any(StartTestItemRQ.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void verify_one_failed_unrolled_step_reporting() {
assertThat(result.getTotalFailureCount(), equalTo(1L));

verify(client).getProjectSettings();
verify(client).getApiInfo();
verify(client).startLaunch(any());
ArgumentCaptor<StartTestItemRQ> startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
verify(client).startTestItem(any(StartTestItemRQ.class));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.epam.reportportal.spock.features.bugs

import spock.lang.Specification

class NullPointerOnSetupSpec extends Specification {
def setup() {
}

def "should add two numbers correctly"() {
given:
def a = null

when:
def b = a.first()

then:
assert true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void verify_setup_fixture_failure_correct_reporting() {
assertThat(result.getTotalFailureCount(), equalTo(1L));

verify(client).getProjectSettings();
verify(client).getApiInfo();
verify(client).startLaunch(any());
verify(client).startTestItem(any(StartTestItemRQ.class));
ArgumentCaptor<StartTestItemRQ> startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void verify_cleanup_fixture_correct_reporting() {
assertThat(result.getTotalFailureCount(), equalTo(0L));

verify(client).getProjectSettings();
verify(client).getApiInfo();
verify(client).startLaunch(any());
verify(client).startTestItem(any(StartTestItemRQ.class));
ArgumentCaptor<StartTestItemRQ> startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void verify_setup_fixture_failure_correct_reporting() {
assertThat(result.getTotalFailureCount(), equalTo(1L));

verify(client).getProjectSettings();
verify(client).getApiInfo();
verify(client).startLaunch(any());
verify(client).startTestItem(any(StartTestItemRQ.class));
ArgumentCaptor<StartTestItemRQ> startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class);
Expand Down
Loading