diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6464b07..18b080c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 04fc1a9..132ac50 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index de93cb1..a222bc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/build.gradle b/build.gradle index aee5837..a5b7589 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } diff --git a/gradle.properties b/gradle.properties index b45e18d..2073cf6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/com/epam/reportportal/spock/FixtureInterceptor.java b/src/main/java/com/epam/reportportal/spock/FixtureInterceptor.java index d8f45ac..bb95e8e 100644 --- a/src/main/java/com/epam/reportportal/spock/FixtureInterceptor.java +++ b/src/main/java/com/epam/reportportal/spock/FixtureInterceptor.java @@ -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 @@ -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) diff --git a/src/main/java/com/epam/reportportal/spock/LaunchContextImpl.java b/src/main/java/com/epam/reportportal/spock/LaunchContextImpl.java index f967aeb..0f1e5d9 100644 --- a/src/main/java/com/epam/reportportal/spock/LaunchContextImpl.java +++ b/src/main/java/com/epam/reportportal/spock/LaunchContextImpl.java @@ -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; @@ -77,7 +77,7 @@ public void addRunningIteration(Maybe id, IterationInfo iterationInfo) { @Override @Nullable public NodeFootprint 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 diff --git a/src/main/java/com/epam/reportportal/spock/NodeFootprint.java b/src/main/java/com/epam/reportportal/spock/NodeFootprint.java index 4e24d7e..7e1ff3c 100644 --- a/src/main/java/com/epam/reportportal/spock/NodeFootprint.java +++ b/src/main/java/com/epam/reportportal/spock/NodeFootprint.java @@ -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; diff --git a/src/main/java/com/epam/reportportal/spock/NodeInfoUtils.java b/src/main/java/com/epam/reportportal/spock/NodeInfoUtils.java index 7efe68c..7b9e120 100644 --- a/src/main/java/com/epam/reportportal/spock/NodeInfoUtils.java +++ b/src/main/java/com/epam/reportportal/spock/NodeInfoUtils.java @@ -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()); } } @@ -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); + } + ); } } diff --git a/src/main/java/com/epam/reportportal/spock/ReportPortalSpockListener.java b/src/main/java/com/epam/reportportal/spock/ReportPortalSpockListener.java index 8469db1..5ef5a08 100644 --- a/src/main/java/com/epam/reportportal/spock/ReportPortalSpockListener.java +++ b/src/main/java/com/epam/reportportal/spock/ReportPortalSpockListener.java @@ -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; @@ -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; @@ -81,14 +82,20 @@ public class ReportPortalSpockListener extends AbstractRunListener { private final Map, Pair> errorDescriptionMap = new ConcurrentHashMap<>(); // stores the bindings of Spock method kinds to the RP-specific notation - private static final Map ITEM_TYPES_REGISTRY = Collections.unmodifiableMap(new HashMap() {{ - 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 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; @@ -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 attributes = new HashSet<>(); attributes.addAll(parameters.getAttributes()); attributes.addAll(SystemAttributesFetcher.collectSystemAttributes(parameters.getSkippedAnIssue())); @@ -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; @@ -314,7 +321,7 @@ public void registerIteration(@Nonnull IterationInfo iteration) { protected FinishTestItemRQ buildFinishTestItemRq(@Nonnull Maybe 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())) { @@ -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 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 startFinishDescriptions = Pair.of( startDescriptions, ExceptionUtils.getStackTrace(error.getException(), new Throwable()) @@ -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; } diff --git a/src/main/java/com/epam/reportportal/spock/ReportableItemFootprint.java b/src/main/java/com/epam/reportportal/spock/ReportableItemFootprint.java index dbc49a1..b34dd82 100644 --- a/src/main/java/com/epam/reportportal/spock/ReportableItemFootprint.java +++ b/src/main/java/com/epam/reportportal/spock/ReportableItemFootprint.java @@ -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; diff --git a/src/main/java/com/epam/reportportal/spock/utils/SystemAttributesFetcher.java b/src/main/java/com/epam/reportportal/spock/utils/SystemAttributesFetcher.java index 7877ea1..25d023f 100644 --- a/src/main/java/com/epam/reportportal/spock/utils/SystemAttributesFetcher.java +++ b/src/main/java/com/epam/reportportal/spock/utils/SystemAttributesFetcher.java @@ -39,7 +39,8 @@ private static ItemAttributesRQ skippedIssue(Boolean skippedAnIssue) { } public static Set collectSystemAttributes(Boolean skippedAnIssue) { - Set systemAttributes = SystemAttributesExtractor.extract(PROPS_FILE, + Set systemAttributes = SystemAttributesExtractor.extract( + PROPS_FILE, SystemAttributesFetcher.class.getClassLoader() ); systemAttributes.add(skippedIssue(skippedAnIssue)); diff --git a/src/test/groovy/com/epam/reportportal/spock/bugs/NullPointerOnSetupTest.java b/src/test/groovy/com/epam/reportportal/spock/bugs/NullPointerOnSetupTest.java new file mode 100644 index 0000000..7c706ff --- /dev/null +++ b/src/test/groovy/com/epam/reportportal/spock/bugs/NullPointerOnSetupTest.java @@ -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")); + } +} diff --git a/src/test/groovy/com/epam/reportportal/spock/fail/TestFailsWithAnnotationFailed.java b/src/test/groovy/com/epam/reportportal/spock/fail/TestFailsWithAnnotationFailed.java index 9329fab..e6cc24b 100644 --- a/src/test/groovy/com/epam/reportportal/spock/fail/TestFailsWithAnnotationFailed.java +++ b/src/test/groovy/com/epam/reportportal/spock/fail/TestFailsWithAnnotationFailed.java @@ -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 startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client).startTestItem(any(StartTestItemRQ.class)); diff --git a/src/test/groovy/com/epam/reportportal/spock/fail/TestFailsWithStackTrace.java b/src/test/groovy/com/epam/reportportal/spock/fail/TestFailsWithStackTrace.java index 99f0ea0..32b2868 100644 --- a/src/test/groovy/com/epam/reportportal/spock/fail/TestFailsWithStackTrace.java +++ b/src/test/groovy/com/epam/reportportal/spock/fail/TestFailsWithStackTrace.java @@ -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 startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client).startTestItem(any(StartTestItemRQ.class)); diff --git a/src/test/groovy/com/epam/reportportal/spock/fail/ThreeStepsOneFailedTest.java b/src/test/groovy/com/epam/reportportal/spock/fail/ThreeStepsOneFailedTest.java index cb92d41..0102e5c 100644 --- a/src/test/groovy/com/epam/reportportal/spock/fail/ThreeStepsOneFailedTest.java +++ b/src/test/groovy/com/epam/reportportal/spock/fail/ThreeStepsOneFailedTest.java @@ -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 startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client).startTestItem(any(StartTestItemRQ.class)); diff --git a/src/test/groovy/com/epam/reportportal/spock/features/bugs/NullPointerOnSetupSpec.groovy b/src/test/groovy/com/epam/reportportal/spock/features/bugs/NullPointerOnSetupSpec.groovy new file mode 100644 index 0000000..846497a --- /dev/null +++ b/src/test/groovy/com/epam/reportportal/spock/features/bugs/NullPointerOnSetupSpec.groovy @@ -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 + } +} diff --git a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupFixtureFailureIntegrity.java b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupFixtureFailureIntegrity.java index 1e8e317..6a11f4e 100644 --- a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupFixtureFailureIntegrity.java +++ b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupFixtureFailureIntegrity.java @@ -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 startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupFixtureIntegrity.java b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupFixtureIntegrity.java index 8da2ba3..d130d35 100644 --- a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupFixtureIntegrity.java +++ b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupFixtureIntegrity.java @@ -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 startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupSpecFixtureFailureIntegrity.java b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupSpecFixtureFailureIntegrity.java index e5d8d3b..350113d 100644 --- a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupSpecFixtureFailureIntegrity.java +++ b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupSpecFixtureFailureIntegrity.java @@ -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 startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupSpecFixtureIntegrity.java b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupSpecFixtureIntegrity.java index 669e302..8d14075 100644 --- a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupSpecFixtureIntegrity.java +++ b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestCleanupSpecFixtureIntegrity.java @@ -64,6 +64,7 @@ public void verify_spec_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 startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestParametersSetupFixtureFailureIntegrity.java b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestParametersSetupFixtureFailureIntegrity.java index 9ceffa6..fac102f 100644 --- a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestParametersSetupFixtureFailureIntegrity.java +++ b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestParametersSetupFixtureFailureIntegrity.java @@ -71,6 +71,7 @@ public void verify_setup_fixture_failure_correct_reporting_parameterized_feature assertThat(result.getTotalFailureCount(), equalTo(1L)); verify(client).getProjectSettings(); + verify(client).getApiInfo(); verify(client).startLaunch(any()); verify(client).startTestItem(any(StartTestItemRQ.class)); verify(client).startTestItem(same(classId), any(StartTestItemRQ.class)); diff --git a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupFixtureFailureIntegrity.java b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupFixtureFailureIntegrity.java index 0de0d8c..d543594 100644 --- a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupFixtureFailureIntegrity.java +++ b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupFixtureFailureIntegrity.java @@ -65,6 +65,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 startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupFixtureIntegrity.java b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupFixtureIntegrity.java index e99e99e..e46d8e6 100644 --- a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupFixtureIntegrity.java +++ b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupFixtureIntegrity.java @@ -64,6 +64,7 @@ public void verify_setup_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 startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupSpecFixtureFailureIntegrity.java b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupSpecFixtureFailureIntegrity.java index 785adf5..3fa1e91 100644 --- a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupSpecFixtureFailureIntegrity.java +++ b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupSpecFixtureFailureIntegrity.java @@ -65,6 +65,7 @@ public void verify_setup_spec_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 startFeatureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupSpecFixtureFailureParametersUnrollIntegrity.java b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupSpecFixtureFailureParametersUnrollIntegrity.java index 4945f8c..4acb4ec 100644 --- a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupSpecFixtureFailureParametersUnrollIntegrity.java +++ b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupSpecFixtureFailureParametersUnrollIntegrity.java @@ -65,6 +65,7 @@ public void verify_setup_spec_failure_parameters_unroll_correct_reporting() { assertThat(result.getTotalFailureCount(), equalTo(1L)); verify(client).getProjectSettings(); + verify(client).getApiInfo(); verify(client).startLaunch(any()); verify(client).startTestItem(any(StartTestItemRQ.class)); ArgumentCaptor startFeatureCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupSpecFixtureIntegrity.java b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupSpecFixtureIntegrity.java index 8ed22cc..4bb6d2f 100644 --- a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupSpecFixtureIntegrity.java +++ b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestSetupSpecFixtureIntegrity.java @@ -64,6 +64,7 @@ public void verify_setup_spec_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 startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestUnrollParametersSetupFixtureFailureIntegrity.java b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestUnrollParametersSetupFixtureFailureIntegrity.java index 568afed..e4d5242 100644 --- a/src/test/groovy/com/epam/reportportal/spock/fixtures/TestUnrollParametersSetupFixtureFailureIntegrity.java +++ b/src/test/groovy/com/epam/reportportal/spock/fixtures/TestUnrollParametersSetupFixtureFailureIntegrity.java @@ -65,6 +65,7 @@ public void verify_setup_fixture_failure_correct_reporting_unrolled_feature() { assertThat(result.getTotalFailureCount(), equalTo(3L)); verify(client).getProjectSettings(); + verify(client).getApiInfo(); verify(client).startLaunch(any()); verify(client).startTestItem(any(StartTestItemRQ.class)); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/groovy/com/epam/reportportal/spock/ignore/TestIgnoreFeatureIntegrity.java b/src/test/groovy/com/epam/reportportal/spock/ignore/TestIgnoreFeatureIntegrity.java index e546b3f..10d0a52 100644 --- a/src/test/groovy/com/epam/reportportal/spock/ignore/TestIgnoreFeatureIntegrity.java +++ b/src/test/groovy/com/epam/reportportal/spock/ignore/TestIgnoreFeatureIntegrity.java @@ -62,6 +62,7 @@ public void verify_ignored_feature_correct_reporting() { assertThat(result.getTotalFailureCount(), equalTo(0L)); verify(client).getProjectSettings(); + verify(client).getApiInfo(); verify(client).startLaunch(any()); verify(client).startTestItem(any(StartTestItemRQ.class)); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/groovy/com/epam/reportportal/spock/ignore/TestIgnoreOtherFeaturesIntegrity.java b/src/test/groovy/com/epam/reportportal/spock/ignore/TestIgnoreOtherFeaturesIntegrity.java index b9d4402..bc4bfcf 100644 --- a/src/test/groovy/com/epam/reportportal/spock/ignore/TestIgnoreOtherFeaturesIntegrity.java +++ b/src/test/groovy/com/epam/reportportal/spock/ignore/TestIgnoreOtherFeaturesIntegrity.java @@ -62,6 +62,7 @@ public void verify_ignored_feature_correct_reporting() { assertThat(result.getTotalFailureCount(), equalTo(0L)); verify(client).getProjectSettings(); + verify(client).getApiInfo(); verify(client).startLaunch(any()); verify(client).startTestItem(any(StartTestItemRQ.class)); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); diff --git a/src/test/groovy/com/epam/reportportal/spock/nestedsteps/TestNoNestedStepsWhenNoParameters.java b/src/test/groovy/com/epam/reportportal/spock/nestedsteps/TestNoNestedStepsWhenNoParameters.java index 38bf9ce..d232b63 100644 --- a/src/test/groovy/com/epam/reportportal/spock/nestedsteps/TestNoNestedStepsWhenNoParameters.java +++ b/src/test/groovy/com/epam/reportportal/spock/nestedsteps/TestNoNestedStepsWhenNoParameters.java @@ -58,6 +58,7 @@ public void verify_no_nested_steps_reported() { assertThat(result.getTotalFailureCount(), equalTo(0L)); verify(client).getProjectSettings(); + verify(client).getApiInfo(); verify(client).startLaunch(any()); verify(client).startTestItem(any(StartTestItemRQ.class)); verify(client).startTestItem(same(classId), any(StartTestItemRQ.class)); diff --git a/src/test/groovy/com/epam/reportportal/spock/nestedsteps/ThreeNestedStepsOneFailedTest.java b/src/test/groovy/com/epam/reportportal/spock/nestedsteps/ThreeNestedStepsOneFailedTest.java index e7e9556..7b2aaa2 100644 --- a/src/test/groovy/com/epam/reportportal/spock/nestedsteps/ThreeNestedStepsOneFailedTest.java +++ b/src/test/groovy/com/epam/reportportal/spock/nestedsteps/ThreeNestedStepsOneFailedTest.java @@ -71,6 +71,8 @@ public void verify_one_failed_nested_step_reporting() { assertThat(result.getTotalFailureCount(), equalTo(1L)); + verify(client).getProjectSettings(); + verify(client).getApiInfo(); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client).startTestItem(any(StartTestItemRQ.class)); verify(client).startTestItem(same(classId), any(StartTestItemRQ.class)); diff --git a/src/test/groovy/com/epam/reportportal/spock/nestedsteps/ThreePassedNestedStepsTest.java b/src/test/groovy/com/epam/reportportal/spock/nestedsteps/ThreePassedNestedStepsTest.java index b5069ad..5fd61a3 100644 --- a/src/test/groovy/com/epam/reportportal/spock/nestedsteps/ThreePassedNestedStepsTest.java +++ b/src/test/groovy/com/epam/reportportal/spock/nestedsteps/ThreePassedNestedStepsTest.java @@ -69,6 +69,8 @@ public void verify_passed_nested_step_reporting() { assertThat(result.getTotalFailureCount(), equalTo(0L)); + verify(client).getProjectSettings(); + verify(client).getApiInfo(); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client).startTestItem(any(StartTestItemRQ.class)); verify(client).startTestItem(same(classId), any(StartTestItemRQ.class)); diff --git a/src/test/groovy/com/epam/reportportal/spock/utils/TestUtils.java b/src/test/groovy/com/epam/reportportal/spock/utils/TestUtils.java index 3e3656a..89107bf 100644 --- a/src/test/groovy/com/epam/reportportal/spock/utils/TestUtils.java +++ b/src/test/groovy/com/epam/reportportal/spock/utils/TestUtils.java @@ -17,18 +17,18 @@ package com.epam.reportportal.spock.utils; import com.epam.reportportal.listeners.ListenerParameters; +import com.epam.reportportal.service.LaunchImpl; import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; import com.epam.reportportal.utils.http.HttpRequestUtils; -import com.epam.ta.reportportal.ws.model.BatchSaveOperatingRS; -import com.epam.ta.reportportal.ws.model.Constants; -import com.epam.ta.reportportal.ws.model.EntryCreatedAsyncRS; -import com.epam.ta.reportportal.ws.model.OperationCompletionRS; +import com.epam.ta.reportportal.ws.model.*; import com.epam.ta.reportportal.ws.model.item.ItemCreatedRS; import com.epam.ta.reportportal.ws.model.launch.StartLaunchRS; import com.epam.ta.reportportal.ws.model.log.SaveLogRQ; import com.fasterxml.jackson.core.type.TypeReference; import io.reactivex.Maybe; +import jakarta.annotation.Nonnull; +import jakarta.annotation.Nullable; import okhttp3.MultipartBody; import okio.Buffer; import org.apache.commons.lang3.tuple.Pair; @@ -42,8 +42,6 @@ import org.junit.platform.launcher.listeners.TestExecutionSummary; import org.mockito.stubbing.Answer; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.io.IOException; import java.util.*; import java.util.concurrent.ExecutorService; @@ -98,6 +96,13 @@ public static > void mockLaunch(@Nonnull final Repo @Nullable final String launchUuid, @Nonnull final Collection> testSteps) { String launch = ofNullable(launchUuid).orElse(CommonUtils.namedId("launch_")); when(client.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS(launch, 1L))); + when(client.getApiInfo()).thenAnswer(invocation -> { + ApiInfo apiInfo = new ApiInfo(); + ApiInfo.Build build = new ApiInfo.Build(); + build.setVersion(LaunchImpl.MICROSECONDS_MIN_VERSION); + apiInfo.setBuild(build); + return Maybe.just(apiInfo); + }); List> testResponses = testSteps.stream() .map(Pair::getKey) @@ -130,10 +135,6 @@ public static void mockBatchLogging(final ReportPortalClient client) { when(client.log(any(List.class))).thenReturn(Maybe.just(new BatchSaveOperatingRS())); } - public static void mockSingleLogging(final ReportPortalClient client) { - when(client.log(any(SaveLogRQ.class))).thenReturn(Maybe.just(new EntryCreatedAsyncRS())); - } - @SuppressWarnings("unchecked") public static void mockNestedSteps(final ReportPortalClient client, final List> parentNestedPairs) { Map> responseOrders = parentNestedPairs.stream() @@ -171,7 +172,7 @@ public static List toSaveLogRQ(List> rqs) { .map(b -> { try { return HttpRequestUtils.MAPPER.readValue( - b, new TypeReference>() { + b, new TypeReference<>() { } ); } catch (IOException e) { diff --git a/src/test/java/com/epam/reportportal/spock/NodeInfoUtilsTest.java b/src/test/java/com/epam/reportportal/spock/NodeInfoUtilsTest.java index ebedba1..601e171 100644 --- a/src/test/java/com/epam/reportportal/spock/NodeInfoUtilsTest.java +++ b/src/test/java/com/epam/reportportal/spock/NodeInfoUtilsTest.java @@ -30,7 +30,8 @@ import static java.util.Collections.singletonList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import static org.spockframework.runtime.model.BlockKind.*; /** @@ -52,7 +53,8 @@ private static Iterable featureDescription_whereBlockIgnoring() { Collection generatedTexts = generateBlockTexts(expectedTextBlocksCount); Iterator generatedTextsIterator = generatedTexts.iterator(); - List blocks = asList(createBlockInfo(EXPECT, singletonList(generatedTextsIterator.next())), + List blocks = asList( + createBlockInfo(EXPECT, singletonList(generatedTextsIterator.next())), createBlockInfo(WHERE, singletonList(null)), createBlockInfo(WHERE, singletonList("")) ); @@ -71,7 +73,8 @@ private static Iterable featureDescription_singleTextInBlock() { Collection generatedTexts = generateBlockTexts(expectedTextBlocksCount); Iterator generatedTextsIterator = generatedTexts.iterator(); - List blocks = asList(createBlockInfo(SETUP, singletonList(generatedTextsIterator.next())), + List blocks = asList( + createBlockInfo(SETUP, singletonList(generatedTextsIterator.next())), createBlockInfo(WHEN, singletonList(generatedTextsIterator.next())), createBlockInfo(THEN, singletonList(generatedTextsIterator.next())), createBlockInfo(EXPECT, singletonList(generatedTextsIterator.next())), @@ -79,7 +82,8 @@ private static Iterable featureDescription_singleTextInBlock() { createBlockInfo(WHERE, singletonList(generatedTextsIterator.next())) ); - String expectedDescription = String.format("Setup: %s%nWhen: %s%nThen: %s%nExpect: %s%nCleanup: %s%nWhere: %s", + String expectedDescription = String.format( + "Setup: %s%nWhen: %s%nThen: %s%nExpect: %s%nCleanup: %s%nWhere: %s", generatedTexts.toArray() ); @@ -121,7 +125,8 @@ private static Iterable parametersForFixtureDescription() { String plainFixtureName = "inherited"; when(plainFixtureInfo.getName()).thenReturn(plainFixtureName); - return Arrays.asList(new Object[] { plainFixtureInfo, false, plainFixtureName }, + return Arrays.asList( + new Object[] { plainFixtureInfo, false, plainFixtureName }, new Object[] { inheritedFixtureInfo, true, expectedInheritedName } ); }