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
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,13 @@ jobs:
body: ${{ steps.readChangelogEntry.outputs.changes }}

- name: Checkout develop branch
if: ${{ github.ref }} == 'master'
uses: actions/checkout@v4
with:
ref: 'develop'
fetch-depth: 0

- name: Merge release branch into develop
id: mergeIntoDevelop
if: ${{ github.ref }} == 'master'
run: |
git merge -m 'Merge master branch into develop after a release' origin/master
git status | (! grep -Fq 'both modified:') || git status | grep -F 'both modified:' \
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.1](https://github.com/reportportal/client-java/releases/tag/5.4.1), 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.5.2]
### Changed
Expand Down
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ repositories {
}

dependencies {
api 'com.epam.reportportal:client-java:5.3.17'
api 'com.epam.reportportal:client-java:5.4.1'

compileOnly "org.testng:testng:${testng_version}"
implementation 'org.slf4j:slf4j-api:2.0.7'
implementation 'org.apache.commons:commons-lang3:3.18.0'

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

testImplementation "org.testng:testng:${testng_version}"
testImplementation("org.junit.platform:junit-platform-runner:${junit5_runner_version}") {
Expand All @@ -58,9 +59,9 @@ dependencies {
testImplementation 'org.hamcrest:hamcrest-core:2.2'
testImplementation "org.mockito:mockito-core:${mockito_version}"
testImplementation "org.mockito:mockito-junit-jupiter:${mockito_version}"
testImplementation 'ch.qos.logback:logback-classic:1.4.14'
testImplementation 'ch.qos.logback:logback-classic:1.5.18'

testImplementation 'com.epam.reportportal:logger-java-logback:5.2.3'
testImplementation 'com.epam.reportportal:logger-java-logback:5.4.0'

testImplementation 'commons-io:commons-io:2.17.0'
testImplementation 'com.ibm.icu:icu4j:67.1'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=5.5.3-SNAPSHOT
version=5.6.0-SNAPSHOT
description=TestNG integration for ReportPortal
junit5_version=5.6.3
junit5_runner_version=1.6.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
public class ReportPortalTestNGListener extends BaseTestNGListener {

/* static instance with lazy init */
public static final Supplier<ITestNGService> SERVICE =
new MemoizingSupplier<>(() -> new TestNGService(ReportPortal.builder().build()));
public static final Supplier<ITestNGService> SERVICE = new MemoizingSupplier<>(() -> new TestNGService(ReportPortal.builder().build()));

public ReportPortalTestNGListener() {
super(SERVICE.get());
Expand Down
54 changes: 32 additions & 22 deletions src/main/java/com/epam/reportportal/testng/TestNGService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ;
import com.epam.ta.reportportal.ws.model.log.SaveLogRQ;
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.testng.*;
Expand All @@ -43,11 +45,10 @@
import org.testng.xml.XmlClass;
import org.testng.xml.XmlTest;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand All @@ -68,14 +69,16 @@
* TestNG service implements operations for interaction ReportPortal
*/
public class TestNGService implements ITestNGService {
private static final Set<TestMethodType> BEFORE_METHODS = Stream.of(TestMethodType.BEFORE_TEST,
private static final Set<TestMethodType> BEFORE_METHODS = Stream.of(
TestMethodType.BEFORE_TEST,
TestMethodType.BEFORE_SUITE,
TestMethodType.BEFORE_GROUPS,
TestMethodType.BEFORE_CLASS,
TestMethodType.BEFORE_METHOD
).collect(Collectors.toSet());
private static final String AGENT_PROPERTIES_FILE = "agent.properties";
private static final Set<String> TESTNG_INVOKERS = Stream.of("org.testng.internal.TestInvoker",
private static final Set<String> TESTNG_INVOKERS = Stream.of(
"org.testng.internal.TestInvoker",
"org.testng.internal.invokers.TestInvoker"
).collect(Collectors.toSet());
private static final Predicate<StackTraceElement> IS_RETRY_ELEMENT = e -> TESTNG_INVOKERS.contains(e.getClassName())
Expand Down Expand Up @@ -103,7 +106,7 @@ public class TestNGService implements ITestNGService {
private static Thread getShutdownHook(final Supplier<Launch> launch) {
return new Thread(() -> {
FinishExecutionRQ rq = new FinishExecutionRQ();
rq.setEndTime(Calendar.getInstance().getTime());
rq.setEndTime(Instant.now());
launch.get().finish(rq);
});
}
Expand All @@ -113,7 +116,7 @@ public TestNGService(@Nonnull final ReportPortal reportPortal) {
//this reads property, so we want to
//init ReportPortal object each time Launch object is going to be created
StartLaunchRQ startRq = buildStartLaunchRq(reportPortal.getParameters());
startRq.setStartTime(Calendar.getInstance().getTime());
startRq.setStartTime(Instant.now());
Launch newLaunch = reportPortal.newLaunch(startRq);
shutDownHook = getShutdownHook(() -> newLaunch);
Runtime.getRuntime().addShutdownHook(shutDownHook);
Expand Down Expand Up @@ -263,7 +266,7 @@ protected StartTestItemRQ buildStartConfigurationRq(@Nonnull ITestResult testRes
rq.setName(createConfigurationName(testResult));
rq.setCodeRef(testResult.getMethod().getQualifiedName());
rq.setDescription(createConfigurationDescription(testResult));
rq.setStartTime(new Date(testResult.getStartMillis()));
rq.setStartTime(Instant.ofEpochMilli(testResult.getStartMillis()));
rq.setType(type == null ? null : type.toString());
boolean retry = isRetry(testResult);
if (retry) {
Expand Down Expand Up @@ -323,7 +326,7 @@ protected StartTestItemRQ buildStartStepRq(final @Nonnull ITestResult testResult
rq.setAttributes(createStepAttributes(testResult));
rq.setDescription(createStepDescription(testResult));
rq.setParameters(createStepParameters(testResult));
rq.setStartTime(new Date(testResult.getStartMillis()));
rq.setStartTime(Instant.ofEpochMilli(testResult.getStartMillis()));
rq.setType(type.toString());
boolean retry = isRetry(testResult);
if (retry) {
Expand Down Expand Up @@ -379,7 +382,8 @@ public void startTestMethod(@Nonnull ITestResult testResult) {
*/
@Nullable
private String getLogMessage(@Nonnull ITestResult testResult) {
String error = ofNullable(testResult.getThrowable()).map(t -> String.format(DESCRIPTION_ERROR_FORMAT,
String error = ofNullable(testResult.getThrowable()).map(t -> String.format(
DESCRIPTION_ERROR_FORMAT,
getStackTrace(t, new Throwable())
)).orElse(null);
if (error == null) {
Expand All @@ -399,7 +403,7 @@ private String getLogMessage(@Nonnull ITestResult testResult) {
@Nonnull
protected FinishTestItemRQ buildFinishTestMethodRq(@Nonnull ItemStatus status, @Nonnull ITestResult testResult) {
FinishTestItemRQ rq = new FinishTestItemRQ();
rq.setEndTime(new Date(testResult.getEndMillis()));
rq.setEndTime(Instant.ofEpochMilli(testResult.getEndMillis()));
rq.setStatus(status.name());
if (!testResult.isSuccess() && ItemStatus.SKIPPED != status) {
rq.setDescription(getLogMessage(testResult));
Expand Down Expand Up @@ -507,8 +511,8 @@ public void finishTestMethod(ItemStatus status, ITestResult testResult) {
if (ItemStatus.FAILED == status && (TestMethodType.BEFORE_METHOD == type || TestMethodType.BEFORE_CLASS == type)) {
SKIPPED_STATUS_TRACKER.put(instance, Boolean.TRUE);
}
if (status == ItemStatus.SKIPPED && rq.getIssue() == null
&& (SKIPPED_STATUS_TRACKER.containsKey(instance) || (TestMethodType.BEFORE_METHOD == type && getAttribute(testResult, RP_RETRY) != null))) {
if (status == ItemStatus.SKIPPED && rq.getIssue() == null && (SKIPPED_STATUS_TRACKER.containsKey(instance) || (
TestMethodType.BEFORE_METHOD == type && getAttribute(testResult, RP_RETRY) != null))) {
rq.setIssue(Launch.NOT_ISSUE);
}
if (ItemStatus.SKIPPED == status && BEFORE_METHODS.contains(type) && testResult.getThrowable() != null) {
Expand All @@ -533,7 +537,7 @@ public void sendReportPortalMsg(final ITestResult result) {
rq.setLevel("ERROR");
rq.setMessage(ofNullable(result.getThrowable()).map(t -> getStackTrace(result.getThrowable(), new Throwable()))
.orElse("Test has failed without exception"));
rq.setLogTime(Calendar.getInstance().getTime());
rq.setLogTime(Instant.now());
return rq;
});
}
Expand All @@ -548,7 +552,7 @@ public void sendReportPortalMsg(final ITestResult result) {
protected StartTestItemRQ buildStartSuiteRq(ISuite suite) {
StartTestItemRQ rq = new StartTestItemRQ();
rq.setName(suite.getName());
rq.setStartTime(Calendar.getInstance().getTime());
rq.setStartTime(Instant.now());
rq.setType("SUITE");
return rq;
}
Expand All @@ -568,7 +572,7 @@ protected StartTestItemRQ buildStartTestItemRq(@Nonnull ITestContext testContext
.ifPresent(xmlClasses -> xmlClasses.forEach(xmlClass -> ofNullable(xmlClass.getSupportClass()).map(c -> c.getAnnotation(
Attributes.class)).ifPresent(a -> attributes.addAll(AttributeParser.retrieveAttributes(a)))));
rq.setName(testContext.getName());
rq.setStartTime(testContext.getStartDate());
rq.setStartTime(ofNullable(testContext.getStartDate()).map(java.util.Date::toInstant).orElseGet(Instant::now));
rq.setType("TEST");
return rq;
}
Expand All @@ -583,7 +587,7 @@ protected StartTestItemRQ buildStartTestItemRq(@Nonnull ITestContext testContext
protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) {
StartLaunchRQ rq = new StartLaunchRQ();
rq.setName(parameters.getLaunchName());
rq.setStartTime(Calendar.getInstance().getTime());
rq.setStartTime(Instant.now());
Set<ItemAttributesRQ> attributes = new HashSet<>(parameters.getAttributes());
rq.setAttributes(attributes);
rq.setMode(parameters.getLaunchRunningMode());
Expand Down Expand Up @@ -615,7 +619,7 @@ protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) {
@Nonnull
protected FinishExecutionRQ buildFinishLaunchRq(ListenerParameters parameters) {
FinishExecutionRQ rq = new FinishExecutionRQ();
rq.setEndTime(Calendar.getInstance().getTime());
rq.setEndTime(Instant.now());
return rq;
}

Expand All @@ -629,7 +633,7 @@ protected FinishExecutionRQ buildFinishLaunchRq(ListenerParameters parameters) {
@Nonnull
protected FinishTestItemRQ buildFinishTestSuiteRq(ISuite suite) {
/* 'real' end time */
Date now = Calendar.getInstance().getTime();
Instant now = Instant.now();
FinishTestItemRQ rq = new FinishTestItemRQ();
rq.setEndTime(now);
return rq;
Expand All @@ -644,7 +648,7 @@ protected FinishTestItemRQ buildFinishTestSuiteRq(ISuite suite) {
@Nonnull
protected FinishTestItemRQ buildFinishTestRq(ITestContext testContext) {
FinishTestItemRQ rq = new FinishTestItemRQ();
rq.setEndTime(testContext.getEndDate());
rq.setEndTime(ofNullable(testContext.getEndDate()).map(java.util.Date::toInstant).orElse(null));
return rq;
}

Expand Down Expand Up @@ -776,10 +780,16 @@ private TestCaseIdEntry getTestCaseId(@Nonnull String codeRef, @Nonnull ITestRes
Method method = getMethod(testResult);
Object instance = testResult.getInstance();
List<Object> parameters = ofNullable(testResult.getParameters()).map(Arrays::asList).orElse(null);
TestCaseIdEntry id = getMethodAnnotation(TestCaseId.class,
TestCaseIdEntry id = getMethodAnnotation(
TestCaseId.class,
testResult
).flatMap(a -> ofNullable(method).map(m -> TestCaseIdUtils.getTestCaseId(a, m, codeRef, parameters, instance)))
.orElse(TestCaseIdUtils.getTestCaseId(codeRef, parameters));
).flatMap(a -> ofNullable(method).map(m -> TestCaseIdUtils.getTestCaseId(
a,
m,
codeRef,
parameters,
instance
))).orElse(TestCaseIdUtils.getTestCaseId(codeRef, parameters));

return id == null ? null : id.getId().endsWith("[]") ? new TestCaseIdEntry(id.getId().substring(0, id.getId().length() - 2)) : id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public static Optional<TestItemTree.TestItemLeaf> retrieveLeaf(ITestContext test
}

public static Optional<TestItemTree.TestItemLeaf> retrieveLeaf(ITestResult testResult, TestItemTree testItemTree) {
Optional<TestItemTree.TestItemLeaf> testClassLeaf = retrieveLeaf(testResult.getTestContext(),
Optional<TestItemTree.TestItemLeaf> testClassLeaf = retrieveLeaf(
testResult.getTestContext(),
testResult.getTestClass(),
testItemTree
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.epam.reportportal.testng.util.internal;

import javax.annotation.Nonnull;
import jakarta.annotation.Nonnull;

import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand Down
22 changes: 11 additions & 11 deletions src/test/java/com/epam/reportportal/testng/BuildStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@

package com.epam.reportportal.testng;

import com.epam.reportportal.annotations.Description;
import com.epam.reportportal.annotations.DisplayName;
import com.epam.reportportal.annotations.ParameterKey;
import com.epam.reportportal.annotations.TestCaseId;
import com.epam.reportportal.annotations.TestCaseIdKey;
import com.epam.reportportal.annotations.*;
import com.epam.reportportal.listeners.ItemStatus;
import com.epam.reportportal.service.Launch;
import com.epam.reportportal.utils.MemoizingSupplier;
Expand All @@ -37,15 +33,19 @@
import org.testng.internal.ConstructorOrMethod;

import java.lang.reflect.Method;
import java.util.*;
import java.time.Instant;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Iterator;
import java.util.Optional;

import static com.epam.reportportal.testng.Constants.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.when;

/**
* @author Pavel Bortnik
Expand Down Expand Up @@ -195,7 +195,7 @@ public void testStartTime() {
instance.setTimeInMillis(DEFAULT_TIME);
when(testResult.getStartMillis()).thenReturn(instance.getTimeInMillis());
StartTestItemRQ rq = testNGService.buildStartStepRq(testResult);
assertThat("Incorrect start time", rq.getStartTime(), is(instance.getTime()));
assertThat("Incorrect start time", rq.getStartTime(), is(Instant.ofEpochMilli(instance.getTimeInMillis())));
}

@Test
Expand Down Expand Up @@ -231,7 +231,7 @@ public void testBuildFinishRQ() {
when(testResult.getEndMillis()).thenReturn(DEFAULT_TIME);
when(testResult.isSuccess()).thenReturn(true);
FinishTestItemRQ rq = testNGService.buildFinishTestMethodRq(ItemStatus.PASSED, testResult);
assertThat("Incorrect end time", rq.getEndTime().getTime(), is(DEFAULT_TIME));
assertThat("Incorrect end time", rq.getEndTime(), is(Instant.ofEpochMilli(DEFAULT_TIME)));
assertThat("Incorrect status", rq.getStatus(), is(ItemStatus.PASSED.name()));
assertThat("Incorrect issue", rq.getIssue(), nullValue());
}
Expand All @@ -247,7 +247,7 @@ public void testStartConfigurationRq() {

assertThat("Incorrect method name", rq.getName(), is(DEFAULT_NAME));
assertThat("Incorrect method description", rq.getDescription(), is(DEFAULT_DESCRIPTION));
assertThat("Incorrect start time", rq.getStartTime(), is(new Date(DEFAULT_TIME)));
assertThat("Incorrect start time", rq.getStartTime(), is(Instant.ofEpochMilli(DEFAULT_TIME)));
assertThat("Incorrect test method type", rq.getType(), is(TestMethodType.BEFORE_TEST.name()));
}

Expand Down Expand Up @@ -339,7 +339,7 @@ public void testCaseId_fromAnnotationParametrized() {
assertEquals(expectedParam, request.getTestCaseId());
}

private Method getTestMethodsExampleByName(String methodName){
private Method getTestMethodsExampleByName(String methodName) {
Optional<Method> methodOptional = Arrays.stream(TestMethodsExamples.class.getDeclaredMethods())
.filter(it -> it.getName().equals(methodName))
.findFirst();
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/com/epam/reportportal/testng/BuildTestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@

import com.epam.reportportal.listeners.ListenerParameters;
import com.epam.reportportal.service.Launch;
import com.epam.reportportal.utils.MemoizingSupplier;
import com.epam.ta.reportportal.ws.model.FinishTestItemRQ;
import com.epam.ta.reportportal.ws.model.StartTestItemRQ;
import com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource;
import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ;
import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ;
import org.hamcrest.Matchers;
import com.epam.reportportal.utils.MemoizingSupplier;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.testng.*;
import org.testng.ISuite;
import org.testng.ITestContext;

import java.util.*;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -149,7 +150,7 @@ public void testStartTestRq() {
StartTestItemRQ rq = testNGService.buildStartTestItemRq(testContext);
assertThat("Incorrect test item type", rq.getType(), is("TEST"));
assertThat("Incorrect test item name", rq.getName(), is(DEFAULT_NAME));
assertThat("Incorrect suite start time", rq.getStartTime(), is(instance.getTime()));
assertThat("Incorrect suite start time", rq.getStartTime(), is(instance.getTime().toInstant()));
}

@Test
Expand All @@ -158,7 +159,7 @@ public void testFinishTestRqPassed() {
when(testContext.getEndDate()).thenReturn(endTime);

FinishTestItemRQ rq = testNGService.buildFinishTestRq(testContext);
assertThat("Incorrect end time", rq.getEndTime(), is(endTime));
assertThat("Incorrect end time", rq.getEndTime(), is(endTime.toInstant()));
}

private ListenerParameters defaultListenerParameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.mockito.Mock;
import org.testng.ISuite;


import static com.epam.reportportal.testng.TestNGService.ITEM_TREE;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
Expand Down
Loading