diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebdafed..e50213a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,11 +39,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Set up JDK 1.8 + - name: Set up JDK 11 uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: '8' + java-version: '11' - name: Build with Gradle run: ./gradlew build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index af89118..f0e7819 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -49,11 +49,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@v3 with: distribution: 'temurin' - java-version: '8' + java-version: '11' - name: Setup git credentials uses: oleksiyrudenko/gha-git-credentials@v2.1.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index a67dbaa..c5ca27c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog ## [Unreleased] +### Changed +- Client version updated on [5.1.21](https://github.com/reportportal/client-java/releases/tag/5.1.21), by @HardNorth +- Slf4j version updated on version 2.0.4 to support newer versions of Logback with security fixes, by @HardNorth +### Removed +- Java 8 support, by @HardNorth +- Obsolete `UniqueID` annotation support, by @HardNorth +- Deprecated code, by @HardNorth ## [5.2.0] ### Fixed diff --git a/build.gradle b/build.gradle index 4f1768c..a9e10f9 100644 --- a/build.gradle +++ b/build.gradle @@ -29,8 +29,8 @@ project.ext.limits = [ 'class' : 83 ] -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 +sourceCompatibility = JavaVersion.VERSION_11 +targetCompatibility = JavaVersion.VERSION_11 repositories { mavenLocal() @@ -39,14 +39,14 @@ repositories { } dependencies { - api 'com.epam.reportportal:client-java:5.1.17' + api 'com.epam.reportportal:client-java:5.1.21' api 'com.google.code.findbugs:jsr305:3.0.2' api 'com.epam.reportportal:commons-model:5.0.0' - api 'org.testng:testng:7.5' // 7.5 - the last version which supports Java 1.8 + api 'org.testng:testng:7.7.0' - implementation 'org.slf4j:slf4j-api:1.7.36' + implementation 'org.slf4j:slf4j-api:2.0.4' - testImplementation('com.github.reportportal:agent-java-test-utils:236a68c') + testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.2' testImplementation("org.junit.platform:junit-platform-runner:${junit5_runner_version}") { exclude module: 'junit' @@ -54,14 +54,14 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter-params:${junit5_version}" testImplementation "org.junit.jupiter:junit-jupiter-engine:${junit5_version}" - testImplementation 'org.aspectj:aspectjweaver:1.9.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-junit-jupiter:${mockito_version}" - testImplementation 'ch.qos.logback:logback-classic:1.2.11' + testImplementation 'ch.qos.logback:logback-classic:1.4.5' - testImplementation 'com.epam.reportportal:logger-java-logback:5.1.3' + testImplementation 'com.epam.reportportal:logger-java-logback:5.1.5' testImplementation 'org.apache.commons:commons-io:1.3.2' testImplementation 'com.ibm.icu:icu4j:67.1' diff --git a/gradle.properties b/gradle.properties index 1d251cd..1d2e4d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=5.2.1-SNAPSHOT +version=5.3.0-SNAPSHOT description=TestNG integration for ReportPortal junit5_version=5.6.3 junit5_runner_version=1.6.3 diff --git a/src/main/java/com/epam/reportportal/testng/ReportPortalTestNGListener.java b/src/main/java/com/epam/reportportal/testng/ReportPortalTestNGListener.java index 34af47f..5680f5d 100644 --- a/src/main/java/com/epam/reportportal/testng/ReportPortalTestNGListener.java +++ b/src/main/java/com/epam/reportportal/testng/ReportPortalTestNGListener.java @@ -15,6 +15,7 @@ */ package com.epam.reportportal.testng; +import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.utils.MemoizingSupplier; import java.util.function.Supplier; @@ -27,7 +28,8 @@ public class ReportPortalTestNGListener extends BaseTestNGListener { /* static instance with lazy init */ - public static final Supplier SERVICE = new MemoizingSupplier<>(TestNGService::new); + public static final Supplier SERVICE = + new MemoizingSupplier<>(() -> new TestNGService(ReportPortal.builder().build())); public ReportPortalTestNGListener() { super(SERVICE.get()); diff --git a/src/main/java/com/epam/reportportal/testng/TestNGService.java b/src/main/java/com/epam/reportportal/testng/TestNGService.java index fbe98e4..4d8ffe8 100644 --- a/src/main/java/com/epam/reportportal/testng/TestNGService.java +++ b/src/main/java/com/epam/reportportal/testng/TestNGService.java @@ -17,7 +17,6 @@ import com.epam.reportportal.annotations.ParameterKey; import com.epam.reportportal.annotations.TestCaseId; -import com.epam.reportportal.annotations.UniqueID; import com.epam.reportportal.annotations.attribute.Attributes; import com.epam.reportportal.listeners.ItemStatus; import com.epam.reportportal.listeners.ListenerParameters; @@ -95,8 +94,6 @@ public class TestNGService implements ITestNGService { public static final String NULL_VALUE = "NULL"; public static final TestItemTree ITEM_TREE = new TestItemTree(); - private static volatile ReportPortal REPORT_PORTAL = ReportPortal.builder().build(); - private final Map, FinishTestItemRQ>>> BEFORE_METHOD_TRACKER = new ConcurrentHashMap<>(); private final Map RETRY_STATUS_TRACKER = new LimitedSizeConcurrentHashMap<>(MAXIMUM_HISTORY_SIZE); @@ -127,38 +124,12 @@ public TestNGService(@Nonnull final ReportPortal reportPortal) { }); } - public TestNGService() { - this(getReportPortal()); - } - public TestNGService(Supplier launchSupplier) { launch = new MemoizingSupplier<>(launchSupplier); shutDownHook = getShutdownHook(launch); Runtime.getRuntime().addShutdownHook(shutDownHook); } - /** - * Return current instance of {@link ReportPortal} class - * - * @return ReportPortal instance - * @deprecated use Launch.currentLaunch().getClient() - */ - @Deprecated - public static ReportPortal getReportPortal() { - return REPORT_PORTAL; - } - - /** - * Set current instance of {@link ReportPortal} class - * - * @param reportPortal class instance - * @deprecated use {@link TestNGService#TestNGService(com.epam.reportportal.service.ReportPortal)} - */ - @Deprecated - protected static void setReportPortal(ReportPortal reportPortal) { - REPORT_PORTAL = reportPortal; - } - @Override public void startLaunch() { Maybe launchId = launch.get().start(); @@ -338,7 +309,6 @@ protected StartTestItemRQ buildStartStepRq(final @Nonnull ITestResult testResult rq.setAttributes(createStepAttributes(testResult)); rq.setDescription(createStepDescription(testResult)); rq.setParameters(createStepParameters(testResult)); - rq.setUniqueId(extractUniqueID(testResult)); rq.setStartTime(new Date(testResult.getStartMillis())); rq.setType(type.toString()); boolean retry = isRetry(testResult); @@ -767,17 +737,6 @@ protected String createStepDescription(ITestResult testResult) { return testResult.getMethod().getDescription(); } - /** - * Returns test item ID from annotation if it provided. - * - * @param testResult Where to find - * @return test item ID or null - */ - @Nullable - private String extractUniqueID(@Nonnull ITestResult testResult) { - return getMethodAnnotation(UniqueID.class, testResult).map(UniqueID::value).orElse(null); - } - @Nullable private TestCaseIdEntry getTestCaseId(@Nonnull String codeRef, @Nonnull ITestResult testResult) { Method method = getMethod(testResult); diff --git a/src/test/java/com/epam/reportportal/testng/BuildStepTest.java b/src/test/java/com/epam/reportportal/testng/BuildStepTest.java index b1e1857..995ced2 100644 --- a/src/test/java/com/epam/reportportal/testng/BuildStepTest.java +++ b/src/test/java/com/epam/reportportal/testng/BuildStepTest.java @@ -19,7 +19,6 @@ import com.epam.reportportal.annotations.ParameterKey; import com.epam.reportportal.annotations.TestCaseId; import com.epam.reportportal.annotations.TestCaseIdKey; -import com.epam.reportportal.annotations.UniqueID; import com.epam.reportportal.listeners.ItemStatus; import com.epam.reportportal.service.Launch; import com.epam.reportportal.utils.MemoizingSupplier; @@ -171,25 +170,6 @@ public void testParametersNotSpecified() { assertThat("Incorrect test item parameters", rq.getParameters(), nullValue()); } - @Test - public void testUniqueId() { - when(testResult.getMethod()).thenReturn(testNGMethod); - when(testNGMethod.getConstructorOrMethod()).thenReturn(constructorOrMethod); - when(testNGMethod.isTest()).thenReturn(true); - Method[] methods = TestMethodsExamples.class.getDeclaredMethods(); - Method method = null; - for (Method m : methods) { - if (m.getName().contains("uniqueIdAnnotation")) { - method = m; - } - } - - when(constructorOrMethod.getMethod()).thenReturn(method); - StartTestItemRQ rq = testNGService.buildStartStepRq(testResult); - assertThat("Incorrect unique id", rq.getUniqueId(), is("ProvidedID")); - - } - @Test public void testUniqueIdNotSpecified() { when(testResult.getMethod()).thenReturn(testNGMethod); @@ -358,12 +338,6 @@ public void testCaseId_fromAnnotationParametrized() { } private static class TestMethodsExamples { - @UniqueID("ProvidedID") - @org.testng.annotations.Test - private void uniqueIdAnnotation() { - //just for testing providing unique id - } - @Ignore @org.testng.annotations.Test(dataProvider = "dp") private void dataProviderWithoutKey(String param_0, String param_1) { diff --git a/src/test/java/com/epam/reportportal/testng/ParametersBypassTest.java b/src/test/java/com/epam/reportportal/testng/ParametersBypassTest.java index 5dc3545..b91a613 100644 --- a/src/test/java/com/epam/reportportal/testng/ParametersBypassTest.java +++ b/src/test/java/com/epam/reportportal/testng/ParametersBypassTest.java @@ -1,16 +1,11 @@ package com.epam.reportportal.testng; -import com.epam.reportportal.listeners.ListenerParameters; -import com.epam.reportportal.service.Launch; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.testng.integration.feature.parameters.*; import com.epam.reportportal.testng.integration.util.TestUtils; -import com.epam.reportportal.utils.MemoizingSupplier; -import com.epam.reportportal.utils.properties.PropertiesLoader; import com.epam.ta.reportportal.ws.model.ParameterResource; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; -import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -18,7 +13,6 @@ import org.mockito.Mock; import java.util.Arrays; -import java.util.Calendar; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -38,28 +32,12 @@ public static class TestReportPortalListener extends BaseTestNGListener { public static final ThreadLocal REPORT_PORTAL_THREAD_LOCAL = new ThreadLocal<>(); public TestReportPortalListener() { - super(new TestNGServiceExtension( - new MemoizingSupplier<>(() -> getLaunch(REPORT_PORTAL_THREAD_LOCAL.get().getParameters())), - REPORT_PORTAL_THREAD_LOCAL.get() - )); + super(new TestNGService(REPORT_PORTAL_THREAD_LOCAL.get())); } public static void initReportPortal(ReportPortal reportPortal) { REPORT_PORTAL_THREAD_LOCAL.set(reportPortal); } - - private static Launch getLaunch(ListenerParameters parameters) { - - ReportPortal reportPortal = REPORT_PORTAL_THREAD_LOCAL.get(); - StartLaunchRQ rq = new StartLaunchRQ(); - rq.setName(parameters.getLaunchName()); - rq.setStartTime(Calendar.getInstance().getTime()); - rq.setMode(parameters.getLaunchRunningMode()); - rq.setStartTime(Calendar.getInstance().getTime()); - - return reportPortal.newLaunch(rq); - - } } private final String suitedUuid = namedUuid("suite"); diff --git a/src/test/java/com/epam/reportportal/testng/TestLaunchFinishShutdownHook.java b/src/test/java/com/epam/reportportal/testng/TestLaunchFinishShutdownHook.java index f1aa7ca..bf6b79a 100644 --- a/src/test/java/com/epam/reportportal/testng/TestLaunchFinishShutdownHook.java +++ b/src/test/java/com/epam/reportportal/testng/TestLaunchFinishShutdownHook.java @@ -12,6 +12,7 @@ import java.net.ServerSocket; import java.util.Collections; +import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; @@ -22,16 +23,16 @@ public class TestLaunchFinishShutdownHook { @ParameterizedTest - @ValueSource(classes = { LaunchFinishShutdownHookTest.class, LaunchFinishShutdownHookRemoveTest.class }) + @ValueSource(classes = {LaunchFinishShutdownHookTest.class, LaunchFinishShutdownHookRemoveTest.class}) public void test_shutdown_hook_finishes_launch_on_java_machine_exit(final Class clazz) throws Exception { ServerSocket ss = SocketUtils.getServerSocketOnFreePort(); SocketUtils.ServerCallable serverCallable = new SocketUtils.ServerCallable(ss, Collections.emptyMap(), "files/socket_response.txt"); Callable clientCallable = () -> ProcessUtils.buildProcess(true, clazz, Collections.singletonMap(StatisticsService.DISABLE_PROPERTY, "1"), String.valueOf(ss.getLocalPort())); - Pair startResult = SocketUtils.executeServerCallable(serverCallable, clientCallable); + Pair, Process> startResult = SocketUtils.executeServerCallable(serverCallable, clientCallable); assertThat(startResult.getValue(), notNullValue()); - assertThat("First request is a launch start", startResult.getKey(), startsWith("POST /api/v1/test-project/launch")); + assertThat("First request is a launch start", startResult.getKey().get(0), startsWith("POST /api/v1/test-project/launch")); Callable clientCallableResult = () -> { try { @@ -45,10 +46,10 @@ public void test_shutdown_hook_finishes_launch_on_java_machine_exit(final Class< return -2; } }; - Pair finishResult = SocketUtils.executeServerCallable(serverCallable, clientCallableResult); + Pair, Integer> finishResult = SocketUtils.executeServerCallable(serverCallable, clientCallableResult); assertThat("Second request is a launch finish", - finishResult.getKey(), + finishResult.getKey().get(0), startsWith("PUT /api/v1/test-project/launch/b7a79414-287c-452d-b157-c32fe6cb1c72/finish") ); assertThat("Exit code should be '0'", finishResult.getValue(), equalTo(0)); diff --git a/src/test/java/com/epam/reportportal/testng/TestNGServiceExtension.java b/src/test/java/com/epam/reportportal/testng/TestNGServiceExtension.java deleted file mode 100644 index 841f1b0..0000000 --- a/src/test/java/com/epam/reportportal/testng/TestNGServiceExtension.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.epam.reportportal.testng; - -import com.epam.reportportal.service.Launch; -import com.epam.reportportal.service.ReportPortal; - -import java.util.function.Supplier; - -/** - * @author Ivan Budayeu - */ -public class TestNGServiceExtension extends TestNGService { - - public TestNGServiceExtension(Supplier launch, ReportPortal reportPortal) { - super(launch); - setReportPortal(reportPortal); - } -} diff --git a/src/test/java/com/epam/reportportal/testng/integration/CallbackReportingListener.java b/src/test/java/com/epam/reportportal/testng/integration/CallbackReportingListener.java index aca8c10..10f285d 100644 --- a/src/test/java/com/epam/reportportal/testng/integration/CallbackReportingListener.java +++ b/src/test/java/com/epam/reportportal/testng/integration/CallbackReportingListener.java @@ -1,12 +1,8 @@ package com.epam.reportportal.testng.integration; -import com.epam.reportportal.listeners.ListenerParameters; -import com.epam.reportportal.service.Launch; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.testng.BaseTestNGListener; -import com.epam.reportportal.testng.TestNGServiceExtension; -import com.epam.reportportal.testng.integration.util.TestUtils; -import com.epam.reportportal.utils.MemoizingSupplier; +import com.epam.reportportal.testng.TestNGService; /** * @author Ivan Budayeu @@ -16,9 +12,7 @@ public class CallbackReportingListener extends BaseTestNGListener { public static final ThreadLocal REPORT_PORTAL_THREAD_LOCAL = new ThreadLocal<>(); public CallbackReportingListener() { - super(new TestNGServiceExtension(new MemoizingSupplier<>(() -> getLaunch(REPORT_PORTAL_THREAD_LOCAL.get().getParameters())), - REPORT_PORTAL_THREAD_LOCAL.get() - )); + super(new TestNGService(REPORT_PORTAL_THREAD_LOCAL.get())); } public static void initReportPortal(ReportPortal reportPortal) { @@ -28,9 +22,4 @@ public static void initReportPortal(ReportPortal reportPortal) { public static ReportPortal getReportPortal() { return REPORT_PORTAL_THREAD_LOCAL.get(); } - - private static Launch getLaunch(ListenerParameters parameters) { - ReportPortal reportPortal = REPORT_PORTAL_THREAD_LOCAL.get(); - return reportPortal.newLaunch(TestUtils.launchRQ(parameters)); - } } diff --git a/src/test/java/com/epam/reportportal/testng/integration/feature/callback/CallbackReportingTest.java b/src/test/java/com/epam/reportportal/testng/integration/feature/callback/CallbackReportingTest.java index 37040ae..325145b 100644 --- a/src/test/java/com/epam/reportportal/testng/integration/feature/callback/CallbackReportingTest.java +++ b/src/test/java/com/epam/reportportal/testng/integration/feature/callback/CallbackReportingTest.java @@ -3,7 +3,6 @@ import com.epam.reportportal.service.Launch; import com.epam.reportportal.service.tree.ItemTreeReporter; import com.epam.reportportal.service.tree.TestItemTree; -import com.epam.reportportal.testng.TestNGService; import com.epam.reportportal.testng.util.ItemTreeUtils; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import org.testng.ITestResult; @@ -51,9 +50,11 @@ private void sendFinishRequest(TestItemTree.TestItemLeaf testResultLeaf, String finishTestItemRQ.setDescription(description); finishTestItemRQ.setStatus(status); finishTestItemRQ.setEndTime(Calendar.getInstance().getTime()); - ItemTreeReporter.finishItem(TestNGService.getReportPortal().getClient(), finishTestItemRQ, ITEM_TREE.getLaunchId(), testResultLeaf) - .cache() - .blockingGet(); + //noinspection ResultOfMethodCallIgnored + ofNullable(Launch.currentLaunch()).ifPresent(l -> + ItemTreeReporter.finishItem(l.getClient(), finishTestItemRQ, ITEM_TREE.getLaunchId(), testResultLeaf) + .cache() + .blockingGet()); } private void attachLog(TestItemTree.TestItemLeaf testItemLeaf) {