Skip to content

Commit b780386

Browse files
authored
Merge pull request #142 from reportportal/develop
Release
2 parents 0b45947 + b222620 commit b780386

File tree

66 files changed

+717
-636
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+717
-636
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ jobs:
3737
- name: Checkout repository
3838
uses: actions/checkout@v4
3939

40-
- name: Set up JDK 1.8
40+
- name: Set up JDK 11
4141
uses: actions/setup-java@v4
4242
with:
4343
distribution: 'temurin'
44-
java-version: '8'
44+
java-version: '11'
4545

4646
- name: Build with Gradle
4747
run: ./gradlew build

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ jobs:
4949
version-file: ${{ env.VERSION_FILE }}
5050
version-file-extraction-pattern: ${{ env.VERSION_EXTRACT_PATTERN }}
5151

52-
- name: Set up JDK 1.8
52+
- name: Set up JDK 11
5353
uses: actions/setup-java@v4
5454
with:
5555
distribution: 'temurin'
56-
java-version: '8'
56+
java-version: '11'
5757

5858
- name: Setup git credentials
5959
uses: oleksiyrudenko/gha-git-credentials@v2-latest

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Changed
5+
- Client version updated to [5.4.1](https://github.com/reportportal/client-java/releases/tag/5.4.1), by @HardNorth
6+
- Switch on use of `Instant` class instead of `Date` to get more timestamp precision, by @HardNorth
7+
- Replace "jsr305" annotations with "jakarta.annotation-api", by @HardNorth
8+
### Removed
9+
- Java 8-10 support, by @HardNorth
410

511
## [5.4.2]
612
### Changed

build.gradle

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,29 @@ project.ext.limits = [
2929
'class' : 87
3030
]
3131

32-
sourceCompatibility = JavaVersion.VERSION_1_8
33-
targetCompatibility = JavaVersion.VERSION_1_8
32+
sourceCompatibility = JavaVersion.VERSION_11
33+
targetCompatibility = JavaVersion.VERSION_11
3434

3535
repositories {
3636
mavenCentral()
3737
}
3838

3939
dependencies {
40-
api 'com.epam.reportportal:client-java:5.3.17'
40+
api 'com.epam.reportportal:client-java:5.4.1'
4141

4242
compileOnly "org.junit.jupiter:junit-jupiter-api:${junit_version}"
4343
implementation 'org.slf4j:slf4j-api:2.0.7'
44+
implementation 'org.apache.commons:commons-lang3:3.19.0'
4445

45-
testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.13'
46+
testImplementation 'com.epam.reportportal:agent-java-test-utils:0.1.0'
4647
testImplementation "org.junit.platform:junit-platform-runner:${junit_runner_version}" // We need runner for JUnit 4 compatibility tests
4748
testImplementation "org.junit.jupiter:junit-jupiter-engine:${junit_version}" // Required for tests to run
4849
testImplementation "org.junit.jupiter:junit-jupiter-params:${junit_version}"
4950
testImplementation 'org.aspectj:aspectjweaver:1.9.19'
5051
testImplementation 'org.hamcrest:hamcrest:2.2'
5152
testImplementation 'org.mockito:mockito-core:3.3.3'
52-
testImplementation 'ch.qos.logback:logback-classic:1.3.15'
53-
testImplementation 'com.epam.reportportal:logger-java-logback:5.2.3'
53+
testImplementation 'ch.qos.logback:logback-classic:1.5.18'
54+
testImplementation 'com.epam.reportportal:logger-java-logback:5.4.0'
5455
testImplementation 'org.assertj:assertj-core:3.23.1'
5556
testImplementation 'com.squareup.okhttp3:okhttp:4.12.0'
5657
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=5.4.3-SNAPSHOT
1+
version=5.5.0-SNAPSHOT
22
description=JUnit5 integration for ReportPortal
33
junit_version=5.9.3
44
# We need runner for JUnit 4 compatibility tests

src/main/java/com/epam/reportportal/junit5/ReportPortalExtension.java

Lines changed: 68 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,21 @@
3333
import com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ;
3434
import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ;
3535
import io.reactivex.Maybe;
36+
import jakarta.annotation.Nonnull;
37+
import jakarta.annotation.Nullable;
3638
import org.apache.commons.lang3.StringUtils;
37-
import org.junit.jupiter.api.DisplayName;
3839
import org.junit.jupiter.api.*;
40+
import org.junit.jupiter.api.DisplayName;
3941
import org.junit.jupiter.api.extension.*;
4042
import org.opentest4j.TestAbortedException;
4143
import org.slf4j.Logger;
4244
import org.slf4j.LoggerFactory;
4345

44-
import javax.annotation.Nonnull;
45-
import javax.annotation.Nullable;
4646
import java.lang.reflect.AnnotatedElement;
4747
import java.lang.reflect.Constructor;
4848
import java.lang.reflect.Method;
49+
import java.time.Instant;
50+
import java.time.temporal.ChronoUnit;
4951
import java.util.*;
5052
import java.util.concurrent.ConcurrentHashMap;
5153
import java.util.function.Predicate;
@@ -65,11 +67,12 @@
6567
*/
6668
public class ReportPortalExtension
6769
implements Extension, BeforeAllCallback, BeforeEachCallback, InvocationInterceptor, AfterTestExecutionCallback, AfterAllCallback,
68-
TestWatcher {
70+
TestWatcher {
6971

7072
private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalExtension.class);
7173

72-
private static final Set<String> ASSUMPTION_CLASSES = new HashSet<>(Arrays.asList(TestAbortedException.class.getCanonicalName(),
74+
private static final Set<String> ASSUMPTION_CLASSES = new HashSet<>(Arrays.asList(
75+
TestAbortedException.class.getCanonicalName(),
7376
"org.junit.AssumptionViolatedException"
7477
));
7578

@@ -112,7 +115,7 @@ private void finish(String id) {
112115

113116
private static void finish(Launch launch) {
114117
FinishExecutionRQ rq = new FinishExecutionRQ();
115-
rq.setEndTime(Calendar.getInstance().getTime());
118+
rq.setEndTime(Instant.now());
116119
launch.finish(rq);
117120
}
118121

@@ -134,7 +137,7 @@ protected StartLaunchRQ buildStartLaunchRq(ListenerParameters parameters) {
134137
Set<ItemAttributesRQ> attributes = new HashSet<>(parameters.getAttributes());
135138
attributes.addAll(collectSystemAttributes(parameters.getSkippedAnIssue()));
136139
rq.setAttributes(attributes);
137-
rq.setStartTime(Calendar.getInstance().getTime());
140+
rq.setStartTime(Instant.now());
138141
rq.setRerun(parameters.isRerun());
139142
rq.setRerunOf(StringUtils.isNotBlank(parameters.getRerunOf()) ? parameters.getRerunOf() : null);
140143
return rq;
@@ -164,19 +167,21 @@ protected String getLaunchId(ExtensionContext context) {
164167
* @return represents current launch
165168
*/
166169
protected Launch getLaunch(ExtensionContext context) {
167-
return launchMap.computeIfAbsent(getLaunchId(context), id -> {
168-
ReportPortal rp = getReporter();
169-
ListenerParameters params = rp.getParameters();
170-
StartLaunchRQ rq = buildStartLaunchRq(params);
171-
172-
Launch launch = rp.newLaunch(rq);
173-
Runtime.getRuntime().addShutdownHook(getShutdownHook(id));
174-
Maybe<String> launchIdResponse = launch.start();
175-
if (params.isCallbackReportingEnabled()) {
176-
TEST_ITEM_TREE.setLaunchId(launchIdResponse);
177-
}
178-
return launch;
179-
});
170+
return launchMap.computeIfAbsent(
171+
getLaunchId(context), id -> {
172+
ReportPortal rp = getReporter();
173+
ListenerParameters params = rp.getParameters();
174+
StartLaunchRQ rq = buildStartLaunchRq(params);
175+
176+
Launch launch = rp.newLaunch(rq);
177+
Runtime.getRuntime().addShutdownHook(getShutdownHook(id));
178+
Maybe<String> launchIdResponse = launch.start();
179+
if (params.isCallbackReportingEnabled()) {
180+
TEST_ITEM_TREE.setLaunchId(launchIdResponse);
181+
}
182+
return launch;
183+
}
184+
);
180185
}
181186

182187
@Override
@@ -377,7 +382,7 @@ public void testFailed(ExtensionContext context, Throwable cause) {
377382
*/
378383
protected void finishBeforeAll(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
379384
ExtensionContext context, Maybe<String> id) throws Throwable {
380-
Date startTime = Calendar.getInstance().getTime();
385+
Instant startTime = Instant.now();
381386
try {
382387
finishBeforeAfter(invocation, context, id);
383388
} catch (Throwable throwable) {
@@ -398,7 +403,7 @@ protected void finishBeforeAll(Invocation<Void> invocation, ReflectiveInvocation
398403
*/
399404
protected void finishBeforeEach(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
400405
ExtensionContext context, Maybe<String> id) throws Throwable {
401-
Date startTime = Calendar.getInstance().getTime();
406+
Instant startTime = Instant.now();
402407
try {
403408
finishBeforeAfter(invocation, context, id);
404409
} catch (Throwable throwable) {
@@ -465,29 +470,31 @@ protected void startTestItem(ExtensionContext context, List<Object> arguments, I
465470
* @param startTime a start time of the item
466471
*/
467472
protected void startTestItem(@Nonnull final ExtensionContext context, @Nonnull final List<Object> arguments,
468-
@Nonnull final ItemType itemType, @Nullable final String description, @Nullable final Date startTime) {
469-
idMapping.computeIfAbsent(context, c -> {
470-
StartTestItemRQ rq = buildStartStepRq(c, arguments, itemType, description, startTime);
471-
Launch launch = getLaunch(c);
472-
473-
Maybe<String> parentId = c.getParent().flatMap(parent -> Optional.ofNullable(idMapping.get(parent))).orElse(null);
474-
Maybe<String> itemId;
475-
TestItemTree.TestItemLeaf leaf;
476-
if (parentId == null) {
477-
itemId = launch.startTestItem(rq);
478-
leaf = createTestItemLeaf(itemId);
479-
} else {
480-
itemId = launch.startTestItem(parentId, rq);
481-
leaf = createTestItemLeaf(parentId, itemId);
482-
}
483-
if (getReporter().getParameters().isCallbackReportingEnabled()) {
484-
TEST_ITEM_TREE.getTestItems().put(createItemTreeKey(rq.getName()), leaf);
485-
}
486-
if (TEMPLATE == itemType) {
487-
testTemplates.put(c, itemId);
488-
}
489-
return itemId;
490-
});
473+
@Nonnull final ItemType itemType, @Nullable final String description, @Nullable final Instant startTime) {
474+
idMapping.computeIfAbsent(
475+
context, c -> {
476+
StartTestItemRQ rq = buildStartStepRq(c, arguments, itemType, description, startTime);
477+
Launch launch = getLaunch(c);
478+
479+
Maybe<String> parentId = c.getParent().flatMap(parent -> Optional.ofNullable(idMapping.get(parent))).orElse(null);
480+
Maybe<String> itemId;
481+
TestItemTree.TestItemLeaf leaf;
482+
if (parentId == null) {
483+
itemId = launch.startTestItem(rq);
484+
leaf = createTestItemLeaf(itemId);
485+
} else {
486+
itemId = launch.startTestItem(parentId, rq);
487+
leaf = createTestItemLeaf(parentId, itemId);
488+
}
489+
if (getReporter().getParameters().isCallbackReportingEnabled()) {
490+
TEST_ITEM_TREE.getTestItems().put(createItemTreeKey(rq.getName()), leaf);
491+
}
492+
if (TEMPLATE == itemType) {
493+
testTemplates.put(c, itemId);
494+
}
495+
return itemId;
496+
}
497+
);
491498
}
492499

493500
/**
@@ -648,10 +655,10 @@ protected Optional<Method> getTestMethod(ExtensionContext context) {
648655

649656
private Optional<Method> getOptionalTestMethod(ExtensionContext context) {
650657
Optional<Method> optionalMethod = context.getTestMethod();
651-
if (!optionalMethod.isPresent()) {
658+
if (optionalMethod.isEmpty()) {
652659
//if not present means that we are in the dynamic test, in this case we need to move to the parent context
653660
Optional<ExtensionContext> parentContext = context.getParent();
654-
if (!parentContext.isPresent()) {
661+
if (parentContext.isEmpty()) {
655662
return Optional.empty();
656663
}
657664
return parentContext.get().getTestMethod();
@@ -679,7 +686,7 @@ protected String createStepName(ExtensionContext context, ItemType itemType) {
679686
}
680687

681688
Optional<Method> optionalMethod = getOptionalTestMethod(context);
682-
if (!optionalMethod.isPresent()) {
689+
if (optionalMethod.isEmpty()) {
683690
return defaultValue;
684691
}
685692
Method method = optionalMethod.get();
@@ -710,9 +717,9 @@ protected String createStepName(ExtensionContext context, ItemType itemType) {
710717
*/
711718
@Nonnull
712719
protected StartTestItemRQ buildStartStepRq(@Nonnull final ExtensionContext context, @Nonnull final List<Object> arguments,
713-
@Nonnull final ItemType itemType, @Nullable final String description, @Nullable final Date startTime) {
720+
@Nonnull final ItemType itemType, @Nullable final String description, @Nullable final Instant startTime) {
714721
StartTestItemRQ rq = new StartTestItemRQ();
715-
rq.setStartTime(ofNullable(startTime).orElseGet(Calendar.getInstance()::getTime));
722+
rq.setStartTime(ofNullable(startTime).orElseGet(Instant::now));
716723
rq.setName(createStepName(context, itemType));
717724
rq.setDescription(ofNullable(description).orElseGet(() -> createStepDescription(context, itemType)));
718725
rq.setType(itemType == TEMPLATE ? SUITE.name() : itemType.name());
@@ -750,7 +757,7 @@ protected StartTestItemRQ buildStartStepRq(@Nonnull final ExtensionContext conte
750757
protected StartTestItemRQ buildStartConfigurationRq(@Nonnull Method method, @Nonnull ExtensionContext parentContext,
751758
@Nonnull ExtensionContext context, @Nonnull ItemType itemType) {
752759
StartTestItemRQ rq = new StartTestItemRQ();
753-
rq.setStartTime(Calendar.getInstance().getTime());
760+
rq.setStartTime(Instant.now());
754761
Optional<Class<?>> testClass = context.getTestClass();
755762
if (testClass.isPresent()) {
756763
rq.setName(createConfigurationName(testClass.get(), method));
@@ -805,15 +812,16 @@ protected FinishTestItemRQ buildFinishTestRq(@Nonnull ExtensionContext context,
805812
}
806813
rq.setIssue(getIssue(context));
807814
ofNullable(status).ifPresent(s -> rq.setStatus(s.name()));
808-
rq.setEndTime(Calendar.getInstance().getTime());
815+
rq.setEndTime(Instant.now());
809816
return rq;
810817
}
811818

812819
@Nullable
813820
protected com.epam.ta.reportportal.ws.model.issue.Issue getIssue(@Nonnull ExtensionContext context) {
814821
String stepName = createStepName(context, STEP);
815822
List<ParameterResource> parameters = testParameters.containsKey(context) ? testParameters.remove(context) : Collections.emptyList();
816-
return getOptionalTestMethod(context).map(m -> ofNullable(m.getAnnotation(Issues.class)).map(i -> IssueUtils.createIssue(i,
823+
return getOptionalTestMethod(context).map(m -> ofNullable(m.getAnnotation(Issues.class)).map(i -> IssueUtils.createIssue(
824+
i,
817825
stepName,
818826
parameters
819827
)).orElseGet(() -> IssueUtils.createIssue(m.getAnnotation(Issue.class), stepName, parameters)))
@@ -832,7 +840,7 @@ protected com.epam.ta.reportportal.ws.model.issue.Issue getIssue(@Nonnull Extens
832840
protected FinishTestItemRQ buildFinishTestItemRq(@Nonnull ExtensionContext context, @Nullable ItemStatus status) {
833841
FinishTestItemRQ rq = new FinishTestItemRQ();
834842
ofNullable(status).ifPresent(s -> rq.setStatus(s.name()));
835-
rq.setEndTime(Calendar.getInstance().getTime());
843+
rq.setEndTime(Instant.now());
836844
return rq;
837845
}
838846

@@ -879,7 +887,7 @@ protected String createStepDescription(ExtensionContext context, final ItemType
879887
return defaultValue;
880888
}
881889
Optional<Method> optionalMethod = getOptionalTestMethod(context);
882-
if (!optionalMethod.isPresent()) {
890+
if (optionalMethod.isEmpty()) {
883891
return defaultValue;
884892
}
885893
Method method = optionalMethod.get();
@@ -918,11 +926,11 @@ protected String createConfigurationDescription(Class<?> testClass, Method metho
918926
* @param eventTime <code>@BeforeEach</code> start time
919927
*/
920928
protected void reportSkippedStep(ReflectiveInvocationContext<Method> invocationContext, ExtensionContext context, Throwable throwable,
921-
Date eventTime) {
922-
Date skipStartTime = Calendar.getInstance().getTime();
923-
if (skipStartTime.after(eventTime)) {
929+
Instant eventTime) {
930+
Instant skipStartTime = Instant.now();
931+
if (skipStartTime.compareTo(eventTime) > 0) {
924932
// to fix item ordering when @AfterEach starts in the same millisecond as skipped test
925-
skipStartTime = new Date(skipStartTime.getTime() - 1);
933+
skipStartTime = skipStartTime.minus(1, ChronoUnit.MILLIS);
926934
}
927935
final ItemType itemType = STEP;
928936
startTestItem(context, invocationContext.getArguments(), itemType, createStepDescription(context, itemType), skipStartTime);
@@ -941,6 +949,6 @@ protected void reportSkippedStep(ReflectiveInvocationContext<Method> invocationC
941949
*/
942950
@SuppressWarnings("unused")
943951
protected void reportSkippedClassTests(ReflectiveInvocationContext<Method> invocationContext, ExtensionContext context,
944-
Date eventTime) {
952+
Instant eventTime) {
945953
}
946954
}

src/test/java/com/epam/reportportal/junit5/AssumptionsTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,12 @@ public void setupMock() {
6161
Launch launch = AssumptionsTestExtension.LAUNCH;
6262
when(launch.getStepReporter()).thenReturn(StepReporter.NOOP_STEP_REPORTER);
6363
when(launch.startTestItem(any())).thenAnswer((Answer<Maybe<String>>) invocation -> CommonUtils.createMaybeUuid());
64-
when(launch.startTestItem(
65-
any(),
66-
any()
67-
)).thenAnswer((Answer<Maybe<String>>) invocation -> CommonUtils.createMaybeUuid());
64+
when(launch.startTestItem(any(), any())).thenAnswer((Answer<Maybe<String>>) invocation -> CommonUtils.createMaybeUuid());
6865
}
6966

7067
@ParameterizedTest
71-
@ValueSource(classes = {AssumptionFailedTest.class, Junit4AssumptionFailedTest.class,
72-
AssertJAssumptionFailedTest.class, Junit4ExtendedAssumptionFailedTest.class})
68+
@ValueSource(classes = { AssumptionFailedTest.class, Junit4AssumptionFailedTest.class, AssertJAssumptionFailedTest.class,
69+
Junit4ExtendedAssumptionFailedTest.class })
7370
public void verify_assumption_failure_marks_test_as_skipped(Class<?> testClass) {
7471
TestUtils.runClasses(testClass);
7572

src/test/java/com/epam/reportportal/junit5/AttributesTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ protected Launch getLaunch(ExtensionContext context) {
3838
public void setupMock() {
3939
AttributesTestExtension.LAUNCH = mock(Launch.class);
4040
when(AttributesTestExtension.LAUNCH.startTestItem(any())).thenAnswer((Answer<Maybe<String>>) invocation -> CommonUtils.createMaybeUuid());
41-
when(AttributesTestExtension.LAUNCH.startTestItem(any(),
42-
any()
43-
)).thenAnswer((Answer<Maybe<String>>) invocation -> CommonUtils.createMaybeUuid());
44-
when(AttributesTestExtension.LAUNCH.finishTestItem(
41+
when(AttributesTestExtension.LAUNCH.startTestItem(
4542
any(),
4643
any()
47-
)).thenAnswer(invocation -> Maybe.just(new OperationCompletionRS()));
44+
)).thenAnswer((Answer<Maybe<String>>) invocation -> CommonUtils.createMaybeUuid());
45+
when(AttributesTestExtension.LAUNCH.finishTestItem(any(), any())).thenAnswer(invocation -> Maybe.just(new OperationCompletionRS()));
4846
}
4947

5048
@Test

src/test/java/com/epam/reportportal/junit5/CodeReferenceTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ protected Launch getLaunch(ExtensionContext context) {
3737
public void setupMock() {
3838
CodeReferenceTestExtension.LAUNCH = mock(Launch.class);
3939
when(CodeReferenceTestExtension.LAUNCH.startTestItem(any())).thenAnswer((Answer<Maybe<String>>) invocation -> CommonUtils.createMaybeUuid());
40-
when(CodeReferenceTestExtension.LAUNCH.startTestItem(any(),
40+
when(CodeReferenceTestExtension.LAUNCH.startTestItem(
41+
any(),
4142
any()
4243
)).thenAnswer((Answer<Maybe<String>>) invocation -> CommonUtils.createMaybeUuid());
4344
}

0 commit comments

Comments
 (0)