From 19288ba9591b12269f62f907db8262af150c0082 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 31 Jul 2023 12:32:33 +0300 Subject: [PATCH 01/15] Documentation fix --- README.md | 6 +++--- README_TEMPLATE.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9be1b62..bb34d8f 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ folder `src/main/resources` or `src/test/resources` (depending on where your tes ``` rp.endpoint = http://localhost:8080 -rp.uuid = e0e541d8-b1cd-426a-ae18-b771173c545a +rp.api.key = e0e541d8-b1cd-426a-ae18-b771173c545a rp.launch = JBehave Tests rp.project = default_personal ``` @@ -73,7 +73,7 @@ rp.project = default_personal UTF-8 1.8 1.8 - 4.8.1 + 5.1.1 **/*Stories.java -skip @@ -151,7 +151,7 @@ repositories { mavenCentral() } -def jbehaveVersion = '4.8.1' +def jbehaveVersion = '5.1.1' dependencies { testCompile "org.jbehave:jbehave-core:${jbehaveVersion}" testCompile "org.jbehave:jbehave-navigator:${jbehaveVersion}" diff --git a/README_TEMPLATE.md b/README_TEMPLATE.md index 6df9552..e9e7226 100644 --- a/README_TEMPLATE.md +++ b/README_TEMPLATE.md @@ -44,7 +44,7 @@ folder `src/main/resources` or `src/test/resources` (depending on where your tes ``` rp.endpoint = http://localhost:8080 -rp.uuid = e0e541d8-b1cd-426a-ae18-b771173c545a +rp.api.key = e0e541d8-b1cd-426a-ae18-b771173c545a rp.launch = JBehave Tests rp.project = default_personal ``` @@ -73,7 +73,7 @@ rp.project = default_personal UTF-8 1.8 1.8 - 4.8.1 + 5.1.1 **/*Stories.java -skip @@ -151,7 +151,7 @@ repositories { mavenCentral() } -def jbehaveVersion = '4.8.1' +def jbehaveVersion = '5.1.1' dependencies { testCompile "org.jbehave:jbehave-core:${jbehaveVersion}" testCompile "org.jbehave:jbehave-navigator:${jbehaveVersion}" From 1ae4e5c79ccd78c34b395e7978cc2ad9d46fd104 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 31 Jul 2023 12:44:41 +0300 Subject: [PATCH 02/15] Documentation fix --- README.md | 3 +++ README_TEMPLATE.md | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index bb34d8f..6144ca2 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,9 @@ rp.project = default_personal projects. * `rp.launch` - a user-selected identifier of test launches. +The full list of supported properties is located here in client-java library documentation (a common library for all +Java agents): https://github.com/reportportal/client-java + ### Build system configuration #### Maven diff --git a/README_TEMPLATE.md b/README_TEMPLATE.md index e9e7226..9a29b2e 100644 --- a/README_TEMPLATE.md +++ b/README_TEMPLATE.md @@ -58,6 +58,10 @@ rp.project = default_personal projects. * `rp.launch` - a user-selected identifier of test launches. +The full list of supported properties is located here in client-java library documentation (a common library for all +Java agents): https://github.com/reportportal/client-java + + ### Build system configuration #### Maven From a5c6d24941ff04d5241fd8f59ca6992dad28bc2c Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 4 Aug 2023 15:46:30 +0300 Subject: [PATCH 03/15] Maven link update --- README.md | 2 +- README_TEMPLATE.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6144ca2..2dadd9a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ > and their versions after a successful launch start. This information might help us to improve both ReportPortal > backend and client sides. It is used by the ReportPortal team only and is not supposed for sharing with 3rd parties. -[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/agent-java-jbehave.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22agent-java-jbehave%22) +[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/agent-java-jbehave.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.epam.reportportal/agent-java-jbehave) [![CI Build](https://github.com/reportportal/agent-java-jbehave/actions/workflows/ci.yml/badge.svg)](https://github.com/reportportal/agent-java-jbehave/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/reportportal/agent-java-jbehave/branch/develop/graph/badge.svg?token=BCglguEcoR)](https://codecov.io/gh/reportportal/agent-java-jbehave) [![Join Slack chat!](https://slack.epmrpp.reportportal.io/badge.svg)](https://slack.epmrpp.reportportal.io/) diff --git a/README_TEMPLATE.md b/README_TEMPLATE.md index 9a29b2e..c1e508e 100644 --- a/README_TEMPLATE.md +++ b/README_TEMPLATE.md @@ -4,7 +4,7 @@ > and their versions after a successful launch start. This information might help us to improve both ReportPortal > backend and client sides. It is used by the ReportPortal team only and is not supposed for sharing with 3rd parties. -[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/agent-java-jbehave.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.epam.reportportal%22%20AND%20a:%22agent-java-jbehave%22) +[![Maven Central](https://img.shields.io/maven-central/v/com.epam.reportportal/agent-java-jbehave.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/com.epam.reportportal/agent-java-jbehave) [![CI Build](https://github.com/reportportal/agent-java-jbehave/actions/workflows/ci.yml/badge.svg)](https://github.com/reportportal/agent-java-jbehave/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/reportportal/agent-java-jbehave/branch/develop/graph/badge.svg?token=BCglguEcoR)](https://codecov.io/gh/reportportal/agent-java-jbehave) [![Join Slack chat!](https://slack.epmrpp.reportportal.io/badge.svg)](https://slack.epmrpp.reportportal.io/) From 3d21958606fe43edb63d5eb5cacc7d93c9679ad4 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 12 Dec 2023 15:24:39 +0300 Subject: [PATCH 04/15] Reformat --- .../epam/reportportal/jbehave/BaseTest.java | 67 ++++++++++++------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/src/test/java/com/epam/reportportal/jbehave/BaseTest.java b/src/test/java/com/epam/reportportal/jbehave/BaseTest.java index c1f1a74..37e6520 100644 --- a/src/test/java/com/epam/reportportal/jbehave/BaseTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/BaseTest.java @@ -67,8 +67,9 @@ import static org.mockito.Mockito.when; /** - * This class shouldn't be like that, since it goes against inheritance philosophy. But this is my try to workaround Mockito context - * collision issues on virtual environments. Basically, if I made everything right, I will get test failures sporadically. + * This class shouldn't be like that, since it goes against inheritance philosophy. But this is my try to workaround + * Mockito context collision issues on virtual environments. Basically, if I make everything right, I will get test + * failures sporadically. */ public class BaseTest { public static final String ROOT_SUITE_PREFIX = "root_"; @@ -85,8 +86,9 @@ public static ExecutorService testExecutor() { }); } - public static void run(@Nonnull final Class clazz, @Nonnull final Format format, @Nonnull final List stories, - @Nonnull final StoryParser parser, @Nullable final Object... steps) { + public static void run(@Nonnull final Class clazz, @Nonnull final Format format, + @Nonnull final List stories, @Nonnull final StoryParser parser, + @Nullable final Object... steps) { Properties viewResources = new Properties(); Embedder embedder = new Embedder(); @@ -116,12 +118,13 @@ public static void run(@Nonnull final Class clazz, @Nonnull final Format form embedder.runStoriesAsPaths(stories); } - public void run(@Nonnull final Format format, @Nonnull final List stories, @Nonnull final StoryParser parser, - @Nullable final Object... steps) { + public void run(@Nonnull final Format format, @Nonnull final List stories, + @Nonnull final StoryParser parser, @Nullable final Object... steps) { run(getClass(), format, stories, parser, steps); } - public void run(@Nonnull final Format format, @Nonnull final List stories, @Nullable final Object... steps) { + public void run(@Nonnull final Format format, @Nonnull final List stories, + @Nullable final Object... steps) { run(format, stories, new RegexStoryParser(), steps); } @@ -130,17 +133,21 @@ public void run(@Nonnull final Format format, @Nonnull final String story, @Null } public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid, - @Nullable final String storyUuid, @Nonnull String testClassUuid, @Nonnull String stepUuid) { + @Nullable final String storyUuid, @Nonnull String testClassUuid, + @Nonnull String stepUuid) { mockLaunch(client, launchUuid, storyUuid, testClassUuid, Collections.singleton(stepUuid)); } public static void mockLaunch(@Nonnull final ReportPortalClient client, @Nullable final String launchUuid, - @Nullable final String storyUuid, @Nonnull String testClassUuid, @Nonnull Collection stepList) { + @Nullable final String storyUuid, @Nonnull String testClassUuid, + @Nonnull Collection stepList) { mockLaunch(client, launchUuid, storyUuid, Collections.singletonList(Pair.of(testClassUuid, stepList))); } public static > void mockLaunch(@Nonnull final ReportPortalClient client, - @Nullable final String launchUuid, @Nullable final String storyUuid, @Nonnull final Collection> testSteps) { + @Nullable final String launchUuid, + @Nullable final String storyUuid, + @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.finishLaunch(eq(launch), any())).thenReturn(Maybe.just(new OperationCompletionRS())); @@ -148,14 +155,16 @@ public static > void mockLaunch(@Nonnull final Repo mockStory(client, storyUuid, testSteps); } - public static > void mockStory(@Nonnull final ReportPortalClient client, @Nullable final String storyUuid, - @Nonnull final Collection> testSteps) { + public static > void mockStory(@Nonnull final ReportPortalClient client, + @Nullable final String storyUuid, + @Nonnull final Collection> testSteps) { String rootItemId = ofNullable(storyUuid).orElseGet(() -> CommonUtils.namedId(ROOT_SUITE_PREFIX)); mockStories(client, Collections.singletonList(Pair.of(rootItemId, testSteps))); } @SuppressWarnings("unchecked") - public static > void mockStories(@Nonnull final ReportPortalClient client, + public static > void mockStories( + @Nonnull final ReportPortalClient client, @Nonnull final List>>> stories) { if (stories.isEmpty()) { return; @@ -177,8 +186,9 @@ public static > void mockStories(@Nonnull final Rep } @SuppressWarnings("unchecked") - public static > void mockScenario(@Nonnull final ReportPortalClient client, - @Nonnull final String storyUuid, @Nonnull final Collection> testSteps) { + public static > void mockScenario( + @Nonnull final ReportPortalClient client, @Nonnull final String storyUuid, + @Nonnull final Collection> testSteps) { List> testResponses = testSteps.stream() .map(Pair::getKey) .map(uuid -> Maybe.just(new ItemCreatedRS(uuid, uuid))) @@ -199,9 +209,10 @@ public static > void mockScenario(@Nonnull final Re Maybe myFirst = stepResponses.get(0); Maybe[] myOther = stepResponses.subList(1, stepResponses.size()).toArray(new Maybe[0]); when(client.startTestItem(same(testClassUuid), any())).thenReturn(myFirst, myOther); - new HashSet<>(test.getValue()).forEach(testMethodUuid -> when(client.finishTestItem(same(testMethodUuid), - any() - )).thenReturn(Maybe.just(new OperationCompletionRS()))); + new HashSet<>(test.getValue()).forEach(testMethodUuid -> when( + client.finishTestItem(same(testMethodUuid), + any() + )).thenReturn(Maybe.just(new OperationCompletionRS()))); } }); } @@ -216,7 +227,8 @@ public static void mockNestedSteps(final ReportPortalClient client, final Pair> parentNestedPairs) { + public static void mockNestedSteps(final ReportPortalClient client, + final List> parentNestedPairs) { Map> responseOrders = parentNestedPairs.stream() .collect(Collectors.groupingBy(Pair::getKey, Collectors.mapping(Pair::getValue, Collectors.toList()))); responseOrders.forEach((k, v) -> { @@ -270,12 +282,19 @@ public static List extractJsonParts(List parts) { .collect(Collectors.toList()); } - public static List filterLogs(ArgumentCaptor> logCaptor, Predicate filter) { - return logCaptor.getAllValues().stream().flatMap(l -> extractJsonParts(l).stream()).filter(filter).collect(Collectors.toList()); + public static List filterLogs(ArgumentCaptor> logCaptor, + Predicate filter) { + return logCaptor + .getAllValues() + .stream() + .flatMap(l -> extractJsonParts(l).stream()) + .filter(filter) + .collect(Collectors.toList()); } - public static void verifyLogged(@Nonnull final ArgumentCaptor> logCaptor, @Nullable final String itemId, - @Nonnull final LogLevel level, @Nonnull final String message) { + public static void verifyLogged(@Nonnull final ArgumentCaptor> logCaptor, + @Nullable final String itemId, @Nonnull final LogLevel level, + @Nonnull final String message) { List expectedErrorList = filterLogs(logCaptor, l -> level.name().equals(l.getLevel()) && l.getMessage() != null && l.getMessage().contains(message) ); @@ -289,6 +308,6 @@ protected static ParameterResource parameterOf(String key, String value) { ParameterResource parameterResource = new ParameterResource(); parameterResource.setKey(key); parameterResource.setValue(value); - return parameterResource; + return parameterResource; } } From 07f33d7d566aa55d5fb4b2cf7ad911c3a5bdaac6 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 15 Dec 2023 11:59:14 +0300 Subject: [PATCH 05/15] Client version update --- CHANGELOG.md | 2 ++ build.gradle | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d8ea71..b08e147 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## [Unreleased] +### Changed +- Client version updated on [5.1.24](https://github.com/reportportal/client-java/releases/tag/5.1.24), by @HardNorth ## [5.2.2] ### Changed diff --git a/build.gradle b/build.gradle index 40f43cb..5d10ce0 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ repositories { } dependencies { - api 'com.epam.reportportal:client-java:5.1.22' + api 'com.epam.reportportal:client-java:5.1.24' api 'com.epam.reportportal:commons-model:5.0.0' api ("org.jbehave:jbehave-core:${project.jbehave_version}") { exclude group: 'junit' From dbb2e070560427c621be6e517675ad2df98e7df6 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 25 Jan 2024 15:25:12 +0300 Subject: [PATCH 06/15] Update version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 6901c9f..4bdc8a4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -version=5.2.3-SNAPSHOT +version=5.3.0-SNAPSHOT description=JBehave reporters for Report Portal jbehave_version=5.1.1 junit5_version=5.8.2 From 8aaa4a9a4d4dcd3c9d3f72464ac2d57bb30fca83 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 25 Jan 2024 15:27:53 +0300 Subject: [PATCH 07/15] Dependency versions update --- CHANGELOG.md | 3 +++ build.gradle | 11 ++++++----- gradle.properties | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b08e147..671fe00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +### Changed +- Client version updated on [5.2.1](https://github.com/reportportal/client-java/releases/tag/5.2.1), by @HardNorth +- JBehave dependency marked as `implementation` to force users specify their own versions, by @HardNorth ## [Unreleased] ### Changed diff --git a/build.gradle b/build.gradle index 5d10ce0..3283574 100644 --- a/build.gradle +++ b/build.gradle @@ -38,13 +38,13 @@ repositories { } dependencies { - api 'com.epam.reportportal:client-java:5.1.24' + api 'com.epam.reportportal:client-java:5.2.1' api 'com.epam.reportportal:commons-model:5.0.0' - api ("org.jbehave:jbehave-core:${project.jbehave_version}") { + api 'com.google.code.findbugs:jsr305:3.0.2' + implementation ("org.jbehave:jbehave-core:${project.jbehave_version}") { exclude group: 'junit' exclude group: 'org.junit.vintage' } - api 'com.google.code.findbugs:jsr305:3.0.2' implementation 'org.slf4j:slf4j-api:2.0.7' testImplementation 'com.epam.reportportal:agent-java-test-utils:0.0.2' @@ -52,8 +52,8 @@ dependencies { testImplementation 'org.hamcrest:hamcrest-core:2.2' testImplementation "org.mockito:mockito-core:${project.mockito_version}" testImplementation "org.mockito:mockito-junit-jupiter:${project.mockito_version}" - testImplementation 'ch.qos.logback:logback-classic:1.3.8' - testImplementation 'com.epam.reportportal:logger-java-logback:5.1.6' + testImplementation 'ch.qos.logback:logback-classic:1.3.12' + testImplementation 'com.epam.reportportal:logger-java-logback:5.2.0' testImplementation ("org.junit.platform:junit-platform-runner:${project.junit5_launcher_version}") { exclude group: 'junit' } @@ -65,6 +65,7 @@ dependencies { exclude group: 'junit' exclude group: 'org.junit.vintage' } + testImplementation 'com.squareup.okhttp3:okhttp:4.12.0' } test { diff --git a/gradle.properties b/gradle.properties index 4bdc8a4..141742a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ # version=5.3.0-SNAPSHOT description=JBehave reporters for Report Portal -jbehave_version=5.1.1 +jbehave_version=5.2.0 junit5_version=5.8.2 junit5_launcher_version=1.8.2 mockito_version=3.3.3 From 469418bf13a66bb6b756b49168c764539b19604d Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 25 Jan 2024 15:38:50 +0300 Subject: [PATCH 08/15] Deprecate step reporter --- .../com/epam/reportportal/jbehave/ReportPortalStepFormat.java | 2 ++ .../reportportal/jbehave/ReportPortalStepStoryReporter.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStepFormat.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStepFormat.java index af11ffb..cb6bacc 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStepFormat.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStepFormat.java @@ -24,7 +24,9 @@ * Scenarios will not have it. * * @author Vadzim Hushchanskou + * @deprecated Use {@link ReportPortalScenarioFormat}, since the semantic of this class is completely broken and will be removed */ +@Deprecated public class ReportPortalStepFormat extends ReportPortalFormat { public static final ReportPortalStepFormat INSTANCE = new ReportPortalStepFormat(); diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStepStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStepStoryReporter.java index b2f9f74..4e5fffd 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStepStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStepStoryReporter.java @@ -25,7 +25,9 @@ * statistic. * * @author Vadzim Hushchanskou + * @deprecated Use {@link ReportPortalScenarioStoryReporter}, since the semantic of this class is completely broken and will be removed */ +@Deprecated public class ReportPortalStepStoryReporter extends ReportPortalStoryReporter { public ReportPortalStepStoryReporter(final Supplier launchSupplier, TestItemTree testItemTree) { super(launchSupplier, testItemTree); From 0beaae0bc134de025c86eb3075ba5b81e98ba18f Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 30 Jan 2024 10:12:11 +0300 Subject: [PATCH 09/15] Examples are not reported in their own separate suite now --- CHANGELOG.md | 3 +- build.gradle | 3 +- .../ReportPortalScenarioStoryReporter.java | 12 ++- .../jbehave/ReportPortalStoryReporter.java | 77 +++++++++++-------- .../scenario/ExamplesScenarioFormatTest.java | 17 ++-- 5 files changed, 61 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 671fe00..4dc13d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ### Changed -- Client version updated on [5.2.1](https://github.com/reportportal/client-java/releases/tag/5.2.1), by @HardNorth +- Examples are not reported in their own separate suite now, they are reported as separate scenarios instead, to conform other BDD framework implementation, by @HardNorth +- Client version updated on [5.2.2](https://github.com/reportportal/client-java/releases/tag/5.2.2), by @HardNorth - JBehave dependency marked as `implementation` to force users specify their own versions, by @HardNorth ## [Unreleased] diff --git a/build.gradle b/build.gradle index 3283574..a3d5512 100644 --- a/build.gradle +++ b/build.gradle @@ -34,11 +34,12 @@ sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 repositories { + mavenLocal() mavenCentral() } dependencies { - api 'com.epam.reportportal:client-java:5.2.1' + api 'com.epam.reportportal:client-java:5.2.2' api 'com.epam.reportportal:commons-model:5.0.0' api 'com.google.code.findbugs:jsr305:3.0.2' implementation ("org.jbehave:jbehave-core:${project.jbehave_version}") { diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalScenarioStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalScenarioStoryReporter.java index e29bbb6..626a4f3 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalScenarioStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalScenarioStoryReporter.java @@ -32,7 +32,7 @@ /** * JBehave Reporter for reporting results into ReportPortal. Reports each Story Scenario as a separate test. That means each Scenario - * has it's own statistic and each Scenario Step is reported as nested step and does not add test count. + * has its own statistic and each Scenario Step is reported as nested step and does not add test count. * * @author Vadzim Hushchanskou */ @@ -46,9 +46,9 @@ public ReportPortalScenarioStoryReporter(final Supplier launchSupplier, * {@inheritDoc} */ @Nonnull - protected StartTestItemRQ buildStartExampleRq(@Nonnull final Map example, @Nonnull String codeRef, + protected StartTestItemRQ buildStartExampleRq(@Nonnull Scenario scenario, @Nonnull Map example, @Nonnull String codeRef, @Nullable final Date startTime) { - StartTestItemRQ rq = super.buildStartExampleRq(example, codeRef, startTime); + StartTestItemRQ rq = super.buildStartExampleRq(scenario, example, codeRef, startTime); rq.setType(ItemType.STEP.name()); rq.setTestCaseId(ofNullable(getTestCaseId(codeRef, null)).map(TestCaseIdEntry::getId).orElse(null)); return rq; @@ -61,10 +61,8 @@ protected StartTestItemRQ buildStartExampleRq(@Nonnull final Map @Nonnull protected StartTestItemRQ buildStartScenarioRq(@Nonnull Scenario scenario, @Nonnull String codeRef, @Nullable final Date startTime) { StartTestItemRQ rq = super.buildStartScenarioRq(scenario, codeRef, startTime); - if (!scenario.hasExamplesTable() || scenario.getExamplesTable().getRows().isEmpty()) { - rq.setTestCaseId(ofNullable(getTestCaseId(codeRef, null)).map(TestCaseIdEntry::getId).orElse(null)); - rq.setType(ItemType.STEP.name()); - } + rq.setTestCaseId(ofNullable(getTestCaseId(codeRef, null)).map(TestCaseIdEntry::getId).orElse(null)); + rq.setType(ItemType.STEP.name()); return rq; } diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java index d6e4667..4d9beec 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java @@ -25,6 +25,7 @@ import com.epam.reportportal.service.tree.TestItemTree; import com.epam.reportportal.utils.StatusEvaluation; import com.epam.reportportal.utils.TestCaseIdUtils; +import com.epam.reportportal.utils.markdown.MarkdownUtils; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.OperationCompletionRS; import com.epam.ta.reportportal.ws.model.ParameterResource; @@ -38,7 +39,10 @@ import org.apache.commons.lang3.tuple.Pair; import org.jbehave.core.model.*; import org.jbehave.core.reporters.NullStoryReporter; +import org.jbehave.core.steps.StepCreator; import org.jbehave.core.steps.Timing; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -58,6 +62,8 @@ * @author Vadzim Hushchanskou */ public abstract class ReportPortalStoryReporter extends NullStoryReporter { + private static final Logger LOGGER = LoggerFactory.getLogger(ReportPortalStoryReporter.class); + public static final String CODE_REF = "CODE_REF"; public static final String START_TIME = "START_TIME"; public static final String PARAMETERS = "PARAMETERS"; @@ -67,30 +73,27 @@ public abstract class ReportPortalStoryReporter extends NullStoryReporter { private static final String CODE_REFERENCE_DELIMITER = "/"; private static final String CODE_REFERENCE_ITEM_TYPE_DELIMITER = ":"; - private static final String PARAMETER_ITEMS_DELIMITER = ";"; private static final String CODE_REFERENCE_ITEM_START = "["; private static final String CODE_REFERENCE_ITEM_END = "]"; - private static final String EXAMPLE_PATTERN = "Example: %s"; private static final String EXAMPLE_VALUE_PATTERN = "<%s>"; private static final Pattern EXAMPLE_VALUE_MATCH = Pattern.compile("<([^>]*)>"); private static final String EXAMPLE = "EXAMPLE"; private static final String LIFECYCLE = "LIFECYCLE"; - private static final String EXAMPLE_PARAMETER_DELIMITER = PARAMETER_ITEMS_DELIMITER + " "; - private static final String EXAMPLE_KEY_VALUE_DELIMITER = CODE_REFERENCE_ITEM_TYPE_DELIMITER + " "; private static final String NO_NAME = "No name"; private static final String BEFORE_STORIES = "BeforeStories"; private static final String AFTER_STORIES = "AfterStories"; private static final String BEFORE_STORY = "BeforeStory"; private static final String AFTER_STORY = "AfterStory"; + private static final String PARAMETERS_PATTERN = "Parameters:\n\n%s"; private final Deque> structure = new LinkedList<>(); private final Deque stepStack = new LinkedList<>(); private final Supplier launch; private final TestItemTree itemTree; - private volatile TestItemTree.TestItemLeaf lastStep; + private TestItemTree.TestItemLeaf lastStep; private static volatile ItemType currentLifecycleTopItemType; - private volatile ItemType currentLifecycleItemType; + private ItemType currentLifecycleItemType; public ReportPortalStoryReporter(final Supplier launchSupplier, TestItemTree testItemTree) { launch = launchSupplier; @@ -243,24 +246,6 @@ protected StartTestItemRQ buildStartScenarioRq(@Nonnull Scenario scenario, @Nonn return rq; } - /** - * Extension point to customize example names - * - * @param example a map of variable name -> variable value - * @return a name of the given example - */ - protected String formatExampleName(@Nonnull final Map example) { - return String.format(EXAMPLE_PATTERN, - example.entrySet() - .stream() - .map(e -> e.getKey() + EXAMPLE_KEY_VALUE_DELIMITER + e.getValue()) - .collect(Collectors.joining(EXAMPLE_PARAMETER_DELIMITER, - CODE_REFERENCE_ITEM_START, - CODE_REFERENCE_ITEM_END - )) - ); - } - /** * Converts parameters map into Report Portal's {@link ParameterResource} list ready to use in a request to Report Portal * @@ -285,20 +270,22 @@ private ParameterResource parameterOf(String key, String value) { /** * Extension point to customize test creation event/request * + * @param scenario JBehave scenario object * @param example an example map * @param codeRef a step code reference * @param startTime a step start time which will be passed to RP * @return Request to ReportPortal */ @Nonnull - protected StartTestItemRQ buildStartExampleRq(@Nonnull final Map example, @Nonnull String codeRef, + protected StartTestItemRQ buildStartExampleRq(@Nonnull Scenario scenario, @Nonnull Map example, @Nonnull String codeRef, @Nullable final Date startTime) { StartTestItemRQ rq = new StartTestItemRQ(); - rq.setName(formatExampleName(example)); + rq.setName(getScenarioName(scenario)); rq.setCodeRef(codeRef); rq.setStartTime(ofNullable(startTime).orElseGet(() -> Calendar.getInstance().getTime())); rq.setType(ItemType.TEST.name()); rq.setParameters(getStepParameters(example)); + rq.setDescription(String.format(PARAMETERS_PATTERN, MarkdownUtils.formatDataTable(example))); return rq; } @@ -486,6 +473,7 @@ protected Date getItemDate(@Nullable final TestItemTree.TestItemLeaf parent) { @Nullable protected TestItemTree.TestItemLeaf retrieveLeaf() { final List> leafChain = new ArrayList<>(); + Entity parentEntity = null; for (Entity entity : structure) { final ItemType itemType = entity.type(); final Optional> parent = leafChain.isEmpty() ? @@ -509,6 +497,10 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { break; case SCENARIO: Scenario scenario = (Scenario) entity.get(); + if (scenario.hasExamplesTable() || !scenario.getExamplesTable().getRows().isEmpty()) { + // Each Example has its own scenario node, no need to wrap them into suite once again + break; + } TestItemTree.ItemTreeKey scenarioKey = ItemTreeUtils.createKey(getScenarioName(scenario)); leafChain.add(ImmutablePair.of(scenarioKey, children.computeIfAbsent(scenarioKey, k -> createLeaf( ItemType.SCENARIO, @@ -517,11 +509,19 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { )))); break; case SUITE: // type SUITE == an Example + if (parentEntity == null) { + LOGGER.error("Unable to locate Scenario item for Example, this is not something which is supposed to happen," + + " skipping reporting"); + break; + } + Scenario parentScenario = (Scenario) parentEntity.get(); Map example = (Map) entity.get(); + TestItemTree.ItemTreeKey parentScenarioKey = ItemTreeUtils.createKey(getScenarioName(parentScenario)); TestItemTree.ItemTreeKey exampleKey = ItemTreeUtils.createKey(example); leafChain.add(ImmutablePair.of(exampleKey, children.computeIfAbsent(exampleKey, k -> { + String parentScenarioCodeRef = getCodeRef(parentCodeRef, parentScenarioKey, ItemType.SCENARIO); TestItemTree.TestItemLeaf leaf = createLeaf(ItemType.SUITE, - buildStartExampleRq(example, getCodeRef(parentCodeRef, k, ItemType.SUITE), itemDate), + buildStartExampleRq(parentScenario, example, getCodeRef(parentScenarioCodeRef, k, ItemType.SUITE), itemDate), parentLeaf ); leaf.setAttribute(PARAMETERS, example); @@ -542,6 +542,7 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { )); break; } + parentEntity = entity; } return leafChain.isEmpty() ? null : leafChain.get(leafChain.size() - 1).getValue(); } @@ -573,7 +574,12 @@ protected TestItemTree.TestItemLeaf getLeaf() { leafChain.add(ImmutablePair.of(storyKey, children.get(storyKey))); break; case SCENARIO: - TestItemTree.ItemTreeKey scenarioKey = ItemTreeUtils.createKey(getScenarioName((Scenario) entity.get())); + Scenario scenario = (Scenario) entity.get(); + if (scenario.hasExamplesTable() || !scenario.getExamplesTable().getRows().isEmpty()) { + // Each Example has its own scenario node, no need to wrap them into suite once again + continue; + } + TestItemTree.ItemTreeKey scenarioKey = ItemTreeUtils.createKey(getScenarioName(scenario)); leafChain.add(ImmutablePair.of(scenarioKey, children.get(scenarioKey))); break; case SUITE: // type SUITE == an Example @@ -695,6 +701,14 @@ protected ItemStatus evaluateStatus(@Nullable final ItemStatus currentStatus, */ protected void evaluateAndFinishLastItem() { TestItemTree.TestItemLeaf item = getLeaf(); + Entity entity = structure.pollLast(); + if (entity != null && ItemType.SCENARIO == entity.type()) { + Scenario scenario = (Scenario) entity.get(); + if (scenario.hasExamplesTable() || !scenario.getExamplesTable().getRows().isEmpty()) { + // Each Example has its own scenario node, no need to wrap them into suite once again + return; + } + } ofNullable(item).ifPresent(i -> { ItemStatus status = i.getStatus(); for (Map.Entry entry : i.getChildItems().entrySet()) { @@ -706,7 +720,6 @@ protected void evaluateAndFinishLastItem() { i.setStatus(status); finishItem(i, status); }); - structure.pollLast(); } /** @@ -814,7 +827,7 @@ protected void simulateStep(@Nonnull String step) { * Starts story (test suite level) in ReportPortal * * @param story JBehave story object - * @param givenStory whether or not this story is given + * @param givenStory whether this story is given * @see Given Stories */ @Override @@ -1004,9 +1017,9 @@ public void notPerformed(String step) { } @Override - public void pending(String step) { + public void pending(StepCreator.PendingStep step) { ofNullable(stepStack.pollLast()).ifPresent(i -> { - createPendingSteps(step, i); + createPendingSteps(step.stepAsString(), i); finishStep(i, ItemStatus.SKIPPED); finishBeforeAfterSuites(i); }); diff --git a/src/test/java/com/epam/reportportal/jbehave/scenario/ExamplesScenarioFormatTest.java b/src/test/java/com/epam/reportportal/jbehave/scenario/ExamplesScenarioFormatTest.java index bfc4a3b..7fb63c1 100644 --- a/src/test/java/com/epam/reportportal/jbehave/scenario/ExamplesScenarioFormatTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/scenario/ExamplesScenarioFormatTest.java @@ -44,11 +44,10 @@ public class ExamplesScenarioFormatTest extends BaseTest { public static final int STEPS_QUANTITY = 4; private final String storyId = CommonUtils.namedId("story_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2).collect(Collectors.toList()); + private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")).limit(2).collect(Collectors.toList()); - private final List> stepIds = exampleIds.stream() - .flatMap(e -> Stream.generate(() -> Pair.of(e, CommonUtils.namedId("step_"))).limit(3)) + private final List>> stepIds = scenarioIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")).limit(4).collect(Collectors.toList()))) .collect(Collectors.toList()); private final ReportPortalClient client = mock(ReportPortalClient.class); @@ -59,8 +58,7 @@ public class ExamplesScenarioFormatTest extends BaseTest { @BeforeEach public void setupMock() { - mockLaunch(client, null, storyId, scenarioId, exampleIds); - mockNestedSteps(client, stepIds); + mockLaunch(client, null, storyId, stepIds); mockBatchLogging(client); } @@ -81,12 +79,11 @@ public void verify_story_with_examples_scenario_reporter() { run(format, EXAMPLES_STORY, new StockSteps()); verify(client, times(1)).startTestItem(any()); - verify(client, times(1)).startTestItem(same(storyId), any()); ArgumentCaptor exampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(scenarioId), exampleCaptor.capture()); + verify(client, times(2)).startTestItem(same(storyId), exampleCaptor.capture()); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(STEPS_QUANTITY)).startTestItem(same(exampleIds.get(0)), startCaptor.capture()); - verify(client, times(STEPS_QUANTITY)).startTestItem(same(exampleIds.get(1)), startCaptor.capture()); + verify(client, times(STEPS_QUANTITY)).startTestItem(same(scenarioIds.get(0)), startCaptor.capture()); + verify(client, times(STEPS_QUANTITY)).startTestItem(same(scenarioIds.get(1)), startCaptor.capture()); String scenarioCodeRef = EXAMPLES_STORY + "/[SCENARIO:Stock trade alert]"; From 9f103e12fba2580e8e5095de85e69347a53cdf06 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 30 Jan 2024 12:04:23 +0300 Subject: [PATCH 10/15] Fix tests --- .../reportportal/jbehave/ReportPortalStoryReporter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java index 4d9beec..1732cf5 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java @@ -497,7 +497,7 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { break; case SCENARIO: Scenario scenario = (Scenario) entity.get(); - if (scenario.hasExamplesTable() || !scenario.getExamplesTable().getRows().isEmpty()) { + if (scenario.hasExamplesTable() && !scenario.getExamplesTable().getRows().isEmpty()) { // Each Example has its own scenario node, no need to wrap them into suite once again break; } @@ -575,7 +575,7 @@ protected TestItemTree.TestItemLeaf getLeaf() { break; case SCENARIO: Scenario scenario = (Scenario) entity.get(); - if (scenario.hasExamplesTable() || !scenario.getExamplesTable().getRows().isEmpty()) { + if (scenario.hasExamplesTable() && !scenario.getExamplesTable().getRows().isEmpty()) { // Each Example has its own scenario node, no need to wrap them into suite once again continue; } @@ -704,7 +704,7 @@ protected void evaluateAndFinishLastItem() { Entity entity = structure.pollLast(); if (entity != null && ItemType.SCENARIO == entity.type()) { Scenario scenario = (Scenario) entity.get(); - if (scenario.hasExamplesTable() || !scenario.getExamplesTable().getRows().isEmpty()) { + if (scenario.hasExamplesTable() && !scenario.getExamplesTable().getRows().isEmpty()) { // Each Example has its own scenario node, no need to wrap them into suite once again return; } From c0d66c71125a2b7325ef2c0d12390f9a142a0c17 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 30 Jan 2024 12:12:10 +0300 Subject: [PATCH 11/15] Fix tests --- .../jbehave/id/TestCaseIdExamplesTest.java | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/test/java/com/epam/reportportal/jbehave/id/TestCaseIdExamplesTest.java b/src/test/java/com/epam/reportportal/jbehave/id/TestCaseIdExamplesTest.java index 0a50202..b41a5b8 100644 --- a/src/test/java/com/epam/reportportal/jbehave/id/TestCaseIdExamplesTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/id/TestCaseIdExamplesTest.java @@ -29,7 +29,9 @@ import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; @@ -45,11 +47,10 @@ public class TestCaseIdExamplesTest extends BaseTest { public static final int STEPS_QUANTITY = 4; private final String storyId = CommonUtils.namedId("story_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2).collect(Collectors.toList()); + private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")).limit(2).collect(Collectors.toList()); - private final List> stepIds = exampleIds.stream() - .flatMap(e -> Stream.generate(() -> Pair.of(e, CommonUtils.namedId("step_"))).limit(STEPS_QUANTITY)) + private final List>> stepIds = scenarioIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")).limit(STEPS_QUANTITY).collect(Collectors.toList()))) .collect(Collectors.toList()); private final ReportPortalClient client = mock(ReportPortalClient.class); @@ -60,8 +61,7 @@ public class TestCaseIdExamplesTest extends BaseTest { @BeforeEach public void setupMock() { - mockLaunch(client, null, storyId, scenarioId, exampleIds); - mockNestedSteps(client, stepIds); + mockLaunch(client, null, storyId, stepIds); mockBatchLogging(client); } @@ -82,8 +82,10 @@ public void setupMock() { "When I have first parameter and second parameter " ); - private static final List> STEP_PARAMETERS = asList( - asList(parameterOf("symbol", "STK1$"), parameterOf("threshold", "10.0")), + private static final List> STEP_PARAMETERS = asList(asList( + parameterOf("symbol", "STK1$"), + parameterOf("threshold", "10.0") + ), asList(parameterOf("price", "5.0")), asList(parameterOf("status", "OFF")), asList(parameterOf("symbol", "STK1$"), parameterOf("symbol", "STK1$")), @@ -100,11 +102,10 @@ public void verify_test_case_id_with_examples() { run(format, EXAMPLES_STORY, new StockSteps()); verify(client, times(1)).startTestItem(any()); - verify(client, times(1)).startTestItem(same(storyId), any()); - verify(client, times(2)).startTestItem(same(scenarioId), any()); + verify(client, times(2)).startTestItem(same(storyId), any()); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(STEPS_QUANTITY)).startTestItem(same(exampleIds.get(0)), startCaptor.capture()); - verify(client, times(STEPS_QUANTITY)).startTestItem(same(exampleIds.get(1)), startCaptor.capture()); + verify(client, times(STEPS_QUANTITY)).startTestItem(same(scenarioIds.get(0)), startCaptor.capture()); + verify(client, times(STEPS_QUANTITY)).startTestItem(same(scenarioIds.get(1)), startCaptor.capture()); String scenarioCodeRef = EXAMPLES_STORY + "/[SCENARIO:Stock trade alert]"; @@ -115,8 +116,12 @@ public void verify_test_case_id_with_examples() { StartTestItemRQ rq = steps.get(i); String exampleCodeRef = scenarioCodeRef + "/" + EXAMPLE_NODES.get(i); String stepCodeRef = exampleCodeRef + "/" + String.format("[STEP:%s]", STEP_NAMES.get(i)); - assertThat(rq.getTestCaseId(), equalTo(stepCodeRef + STEP_PARAMETERS.get(i).stream() - .map(ParameterResource::getValue).collect(Collectors.joining(",", "[", "]"))) + assertThat( + rq.getTestCaseId(), + equalTo(stepCodeRef + STEP_PARAMETERS.get(i) + .stream() + .map(ParameterResource::getValue) + .collect(Collectors.joining(",", "[", "]"))) ); }); } From f67f19b03244a077bcd4c16195cb924f70f36f2e Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 30 Jan 2024 12:40:52 +0300 Subject: [PATCH 12/15] Fix tests --- .../jbehave/steps/CompositeStepsTest.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/test/java/com/epam/reportportal/jbehave/steps/CompositeStepsTest.java b/src/test/java/com/epam/reportportal/jbehave/steps/CompositeStepsTest.java index 1795b45..1021971 100644 --- a/src/test/java/com/epam/reportportal/jbehave/steps/CompositeStepsTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/steps/CompositeStepsTest.java @@ -28,7 +28,6 @@ import com.epam.reportportal.util.test.CommonUtils; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; - import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -48,12 +47,10 @@ public class CompositeStepsTest extends BaseTest { private final String storyId = CommonUtils.namedId("story_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(1).collect( - Collectors.toList()); - - private final List> stepIds = exampleIds.stream().flatMap( - e -> Stream.generate(() -> Pair.of(e, CommonUtils.namedId("step_"))).limit(6)).collect(Collectors.toList()); + private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")).limit(1).collect(Collectors.toList()); + private final List>> stepIds = scenarioIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")).limit(6).collect(Collectors.toList()))) + .collect(Collectors.toList()); private final ReportPortalClient client = mock(ReportPortalClient.class); private final ReportPortalStepFormat format = new ReportPortalStepFormat(ReportPortal.create(client, @@ -63,15 +60,13 @@ public class CompositeStepsTest extends BaseTest { @BeforeEach public void setupMock() { - mockLaunch(client, null, storyId, scenarioId, exampleIds); - mockNestedSteps(client, stepIds); + mockLaunch(client, null, storyId, stepIds); mockBatchLogging(client); } private static final String STORY = "stories/composite/CompositeSteps.story"; - private static final List STEP_NAMES = Arrays.asList( - "Given composite step", + private static final List STEP_NAMES = Arrays.asList("Given composite step", "Given I have empty step", "Then I have another empty step", "When parametrized with a string step", @@ -86,10 +81,8 @@ public void verify_story_with_composite_steps_passed() { ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client).startTestItem(any()); verify(client).startTestItem(same(storyId), any()); - verify(client).startTestItem(same(scenarioId), startCaptor.capture()); - verify(client, times(6)).startTestItem(same(exampleIds.get(0)), startCaptor.capture()); + verify(client, times(6)).startTestItem(same(scenarioIds.get(0)), startCaptor.capture()); List startRequests = startCaptor.getAllValues(); - startRequests.remove(0); IntStream.range(0, startRequests.size()).forEach(i -> { StartTestItemRQ rq = startRequests.get(i); assertThat(rq.getName(), equalTo(STEP_NAMES.get(i))); @@ -97,7 +90,7 @@ public void verify_story_with_composite_steps_passed() { }); ArgumentCaptor finishCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - stepIds.forEach(id -> verify(client).finishTestItem(same(id.getValue()), finishCaptor.capture())); + stepIds.stream().flatMap(p -> p.getValue().stream()).forEach(id -> verify(client).finishTestItem(same(id), finishCaptor.capture())); finishCaptor.getAllValues().forEach(rq -> assertThat(rq.getStatus(), equalTo(ItemStatus.PASSED.name()))); } From ba6d665bc771cf6e69218cf62cab12e45fc27298 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 30 Jan 2024 13:31:34 +0300 Subject: [PATCH 13/15] Fix tests --- .../reportportal/jbehave/ExamplesTest.java | 77 +++++++++++-------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/src/test/java/com/epam/reportportal/jbehave/ExamplesTest.java b/src/test/java/com/epam/reportportal/jbehave/ExamplesTest.java index 6789063..d52c303 100644 --- a/src/test/java/com/epam/reportportal/jbehave/ExamplesTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/ExamplesTest.java @@ -23,6 +23,7 @@ import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; +import com.epam.reportportal.utils.markdown.MarkdownUtils; import com.epam.ta.reportportal.ws.model.FinishTestItemRQ; import com.epam.ta.reportportal.ws.model.ParameterResource; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; @@ -49,11 +50,9 @@ public class ExamplesTest extends BaseTest { public static final int STEPS_QUANTITY = 4; private final String storyId = CommonUtils.namedId("story_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2).collect(Collectors.toList()); - - private final List> stepIds = exampleIds.stream() - .flatMap(e -> Stream.generate(() -> Pair.of(e, CommonUtils.namedId("step_"))).limit(STEPS_QUANTITY)) + private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")).limit(2).collect(Collectors.toList()); + private final List>> stepIds = scenarioIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")).limit(STEPS_QUANTITY).collect(Collectors.toList()))) .collect(Collectors.toList()); private final ReportPortalClient client = mock(ReportPortalClient.class); @@ -64,15 +63,25 @@ public class ExamplesTest extends BaseTest { @BeforeEach public void setupMock() { - mockLaunch(client, null, storyId, scenarioId, exampleIds); - mockNestedSteps(client, stepIds); + mockLaunch(client, null, storyId, stepIds); mockBatchLogging(client); } - private static final List EXAMPLE_NAMES = asList( - "Example: [symbol: STK1$; threshold: 10.0; price: 5.0; status: OFF]", - "Example: [symbol: STK1$; threshold: 10.0; price: 11.0; status: ON]" + private static final String EXAMPLE_NAME = "Stock trade alert"; + //@formatter:off + private static final String PARAMETERS_PREFIX = + "Parameters:\n\n" + + MarkdownUtils.TABLE_INDENT + "|\u00A0symbol\u00A0|\u00A0threshold\u00A0|\u00A0price\u00A0|\u00A0status\u00A0|\n" + + MarkdownUtils.TABLE_INDENT + "|--------|-----------|-------|--------|\n" + + MarkdownUtils.TABLE_INDENT; + //@formatter:on + + private static final List EXAMPLE_DESCRIPTIONS = asList( + PARAMETERS_PREFIX + + "|\u00A0STK1$\u00A0\u00A0|\u00A0\u00A0\u00A010.0\u00A0\u00A0\u00A0\u00A0|\u00A0\u00A05.0\u00A0\u00A0|\u00A0\u00A0OFF\u00A0\u00A0\u00A0|", + PARAMETERS_PREFIX + + "|\u00A0STK1$\u00A0\u00A0|\u00A0\u00A0\u00A010.0\u00A0\u00A0\u00A0\u00A0|\u00A011.0\u00A0\u00A0|\u00A0\u00A0\u00A0ON\u00A0\u00A0\u00A0|" ); private static final List> EXAMPLE_PARAMETERS = asList(new HashMap() {{ @@ -87,8 +96,7 @@ public void setupMock() { put("status", "ON"); }}); - private static final List STEP_NAMES = asList( - "Given a stock of symbol STK1$ and a threshold 10.0", + private static final List STEP_NAMES = asList("Given a stock of symbol STK1$ and a threshold 10.0", "When the stock is traded at price 5.0", "Then the alert status should be status OFF", "When I have first parameter STK1$ and second parameter STK1$", @@ -98,15 +106,17 @@ public void setupMock() { "When I have first parameter STK1$ and second parameter STK1$" ); - private static final List> STEP_PARAMETERS = asList( - asList(parameterOf("symbol", "STK1$"), parameterOf("threshold", "10.0")), - asList(parameterOf("price", "5.0")), - asList(parameterOf("status", "OFF")), - asList(parameterOf("symbol", "STK1$"), parameterOf("symbol", "STK1$")), - asList(parameterOf("symbol", "STK1$"), parameterOf("threshold", "10.0")), - asList(parameterOf("price", "11.0")), - asList(parameterOf("status", "ON")), - asList(parameterOf("symbol", "STK1$"), parameterOf("symbol", "STK1$")) + private static final List> STEP_PARAMETERS = asList(asList( + parameterOf("symbol", "STK1$"), + parameterOf("threshold", "10.0") + ), + asList(parameterOf("price", "5.0")), + asList(parameterOf("status", "OFF")), + asList(parameterOf("symbol", "STK1$"), parameterOf("symbol", "STK1$")), + asList(parameterOf("symbol", "STK1$"), parameterOf("threshold", "10.0")), + asList(parameterOf("price", "11.0")), + asList(parameterOf("status", "ON")), + asList(parameterOf("symbol", "STK1$"), parameterOf("symbol", "STK1$")) ); @Test @@ -114,24 +124,24 @@ public void verify_story_with_examples_names_types_and_parameters() { run(format, "stories/Examples.story", new StockSteps(), new ParameterizedSteps()); verify(client, times(1)).startTestItem(any()); - verify(client, times(1)).startTestItem(same(storyId), any()); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(scenarioId), startCaptor.capture()); - verify(client, times(STEPS_QUANTITY)).startTestItem(same(exampleIds.get(0)), startCaptor.capture()); - verify(client, times(STEPS_QUANTITY)).startTestItem(same(exampleIds.get(1)), startCaptor.capture()); + ArgumentCaptor exampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(storyId), exampleCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(STEPS_QUANTITY)).startTestItem(same(scenarioIds.get(0)), stepCaptor.capture()); + verify(client, times(STEPS_QUANTITY)).startTestItem(same(scenarioIds.get(1)), stepCaptor.capture()); // Start items verification - List startItems = startCaptor.getAllValues(); - List examples = startItems.subList(0, 2); + List examples = exampleCaptor.getAllValues(); IntStream.range(0, examples.size()).forEach(i -> { StartTestItemRQ rq = examples.get(i); - assertThat(rq.getName(), equalTo(EXAMPLE_NAMES.get(i))); + assertThat(rq.getName(), equalTo(EXAMPLE_NAME)); + assertThat(rq.getDescription(), equalTo(EXAMPLE_DESCRIPTIONS.get(i))); assertThat(rq.getType(), equalTo(ItemType.TEST.name())); assertThat(rq.getParameters(), hasSize(STEPS_QUANTITY)); rq.getParameters().forEach(p -> assertThat(EXAMPLE_PARAMETERS.get(i), hasEntry(p.getKey(), p.getValue()))); }); - List steps = startItems.subList(2, 2 + 2 * STEPS_QUANTITY); + List steps = stepCaptor.getAllValues(); IntStream.range(0, steps.size()).forEach(i -> { StartTestItemRQ rq = steps.get(i); assertThat(rq.getName(), equalTo(STEP_NAMES.get(i))); @@ -141,18 +151,19 @@ public void verify_story_with_examples_names_types_and_parameters() { // Finish items verification ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - stepIds.forEach(s -> verify(client, times(1)).finishTestItem(same(s.getValue()), finishStepCaptor.capture())); + stepIds.stream() + .flatMap(p -> p.getValue().stream()) + .forEach(s -> verify(client, times(1)).finishTestItem(same(s), finishStepCaptor.capture())); List finishSteps = finishStepCaptor.getAllValues(); assertThat(finishSteps, hasSize(2 * STEPS_QUANTITY)); finishSteps.forEach(rq -> assertThat(rq.getStatus(), equalTo(ItemStatus.PASSED.name()))); ArgumentCaptor finishExampleCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - exampleIds.forEach(s -> verify(client, times(1)).finishTestItem(same(s), finishExampleCaptor.capture())); + scenarioIds.forEach(s -> verify(client, times(1)).finishTestItem(same(s), finishExampleCaptor.capture())); finishExampleCaptor.getAllValues().forEach(rq -> assertThat(rq.getStatus(), equalTo(ItemStatus.PASSED.name()))); ArgumentCaptor finishCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - verify(client, times(1)).finishTestItem(same(scenarioId), finishCaptor.capture()); verify(client, times(1)).finishTestItem(same(storyId), finishCaptor.capture()); finishCaptor.getAllValues().forEach(rq -> assertThat(rq.getStatus(), equalTo(ItemStatus.PASSED.name()))); } From 1eaf3f07530d26387ae17fa70faefcdcda0fcb78 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 30 Jan 2024 13:39:10 +0300 Subject: [PATCH 14/15] Fix tests --- .../jbehave/coderef/ExamplesCodeRefTest.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/epam/reportportal/jbehave/coderef/ExamplesCodeRefTest.java b/src/test/java/com/epam/reportportal/jbehave/coderef/ExamplesCodeRefTest.java index 702197d..362ef4b 100644 --- a/src/test/java/com/epam/reportportal/jbehave/coderef/ExamplesCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/coderef/ExamplesCodeRefTest.java @@ -42,11 +42,9 @@ public class ExamplesCodeRefTest extends BaseTest { public static final int STEPS_QUANTITY = 4; private final String storyId = CommonUtils.namedId("story_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(2).collect(Collectors.toList()); - - private final List> stepIds = exampleIds.stream() - .flatMap(e -> Stream.generate(() -> Pair.of(e, CommonUtils.namedId("step_"))).limit(3)) + private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")).limit(2).collect(Collectors.toList()); + private final List>> stepIds = scenarioIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()))) .collect(Collectors.toList()); private final ReportPortalClient client = mock(ReportPortalClient.class); @@ -57,8 +55,7 @@ public class ExamplesCodeRefTest extends BaseTest { @BeforeEach public void setupMock() { - mockLaunch(client, null, storyId, scenarioId, exampleIds); - mockNestedSteps(client, stepIds); + mockLaunch(client, null, storyId, stepIds); mockBatchLogging(client); } @@ -79,12 +76,11 @@ public void verify_story_with_examples() { run(format, EXAMPLES_STORY, new StockSteps()); verify(client, times(1)).startTestItem(any()); - verify(client, times(1)).startTestItem(same(storyId), any()); + verify(client, times(2)).startTestItem(same(storyId), any()); ArgumentCaptor exampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(scenarioId), exampleCaptor.capture()); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(STEPS_QUANTITY)).startTestItem(same(exampleIds.get(0)), startCaptor.capture()); - verify(client, times(STEPS_QUANTITY)).startTestItem(same(exampleIds.get(1)), startCaptor.capture()); + verify(client, times(STEPS_QUANTITY)).startTestItem(same(scenarioIds.get(0)), startCaptor.capture()); + verify(client, times(STEPS_QUANTITY)).startTestItem(same(scenarioIds.get(1)), startCaptor.capture()); String scenarioCodeRef = EXAMPLES_STORY + "/[SCENARIO:Stock trade alert]"; From 44915ab5c77f22a80e10bf1bf1d3d913f95ff672 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 30 Jan 2024 14:57:58 +0300 Subject: [PATCH 15/15] Fix tests --- .../jbehave/gherkin/ScenarioOutlineTest.java | 69 +++++++++++-------- .../features/ScenarioOutline.feature | 4 +- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/test/java/com/epam/reportportal/jbehave/gherkin/ScenarioOutlineTest.java b/src/test/java/com/epam/reportportal/jbehave/gherkin/ScenarioOutlineTest.java index f6c0dbf..1c02c5d 100644 --- a/src/test/java/com/epam/reportportal/jbehave/gherkin/ScenarioOutlineTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/gherkin/ScenarioOutlineTest.java @@ -23,6 +23,7 @@ import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.ReportPortalClient; import com.epam.reportportal.util.test.CommonUtils; +import com.epam.reportportal.utils.markdown.MarkdownUtils; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import org.apache.commons.lang3.tuple.Pair; import org.jbehave.core.parsers.gherkin.GherkinStoryParser; @@ -35,6 +36,7 @@ import java.util.stream.IntStream; import java.util.stream.Stream; +import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.mockito.Mockito.any; @@ -43,11 +45,9 @@ public class ScenarioOutlineTest extends BaseTest { private final String storyId = CommonUtils.namedId("story_"); - private final String scenarioId = CommonUtils.namedId("scenario_"); - private final List exampleIds = Stream.generate(() -> CommonUtils.namedId("example_")).limit(3).collect(Collectors.toList()); - - private final List> stepIds = exampleIds.stream() - .flatMap(e -> Stream.generate(() -> Pair.of(e, CommonUtils.namedId("step_"))).limit(3)) + private final List scenarioIds = Stream.generate(() -> CommonUtils.namedId("scenario_")).limit(3).collect(Collectors.toList()); + private final List>> stepIds = scenarioIds.stream() + .map(e -> Pair.of(e, Stream.generate(() -> CommonUtils.namedId("step_")).limit(3).collect(Collectors.toList()))) .collect(Collectors.toList()); private final ReportPortalClient client = mock(ReportPortalClient.class); @@ -58,37 +58,48 @@ public class ScenarioOutlineTest extends BaseTest { @BeforeEach public void setupMock() { - mockLaunch(client, null, storyId, scenarioId, exampleIds); - mockNestedSteps(client, stepIds); + mockLaunch(client, null, storyId, stepIds); mockBatchLogging(client); } - private static final List EXAMPLE_NAMES = Arrays.asList("Example: [str: \"first\"; parameters: 123]", - "Example: [str: \"second\"; parameters: 12345]", - "Example: [str: \"third\"; parameters: 12345678]" + private static final String EXAMPLE_NAME = "Test with different parameters"; + //@formatter:off + private static final String PARAMETERS_PREFIX = + "Parameters:\n\n" + + MarkdownUtils.TABLE_INDENT + "|\u00A0\u00A0\u00A0str\u00A0\u00A0\u00A0|\u00A0parameters\u00A0|\n" + + MarkdownUtils.TABLE_INDENT + "|---------|------------|\n" + + MarkdownUtils.TABLE_INDENT; + //@formatter:on + private static final List EXAMPLE_DESCRIPTIONS = asList( + PARAMETERS_PREFIX + + "|\u00A0\"first\"\u00A0|\u00A0\u00A0\u00A0\u00A0123\u00A0\u00A0\u00A0\u00A0\u00A0|", + PARAMETERS_PREFIX + + "|\u00A0\"scond\"\u00A0|\u00A0\u00A0\u00A0\u00A0321\u00A0\u00A0\u00A0\u00A0\u00A0|", + PARAMETERS_PREFIX + + "|\u00A0\"third\"\u00A0|\u00A0\u00A0\u00A0\u00A0213\u00A0\u00A0\u00A0\u00A0\u00A0|" ); private static final List> OUTLINE_PARAMETERS = Arrays.asList(new HashMap() {{ put("str", "\"first\""); put("parameters", "123"); }}, new HashMap() {{ - put("str", "\"second\""); - put("parameters", "12345"); + put("str", "\"scond\""); + put("parameters", "321"); }}, new HashMap() {{ put("str", "\"third\""); - put("parameters", "12345678"); + put("parameters", "213"); }}); private static final List STEP_NAMES = Arrays.asList("Given It is test with parameters", "When I have parameter \"first\"", "Then I emit number 123 on level info", "Given It is test with parameters", - "When I have parameter \"second\"", - "Then I emit number 12345 on level info", + "When I have parameter \"scond\"", + "Then I emit number 321 on level info", "Given It is test with parameters", "When I have parameter \"third\"", - "Then I emit number 12345678 on level info" + "Then I emit number 213 on level info" ); private static final List> STEP_PARAMETERS = Arrays.asList(new HashMap<>(), new HashMap() {{ @@ -96,13 +107,13 @@ public void setupMock() { }}, new HashMap() {{ put("parameters", "123"); }}, new HashMap<>(), new HashMap() {{ - put("str", "\"second\""); + put("str", "\"scond\""); }}, new HashMap() {{ - put("parameters", "12345"); + put("parameters", "321"); }}, new HashMap<>(), new HashMap() {{ put("str", "\"third\""); }}, new HashMap() {{ - put("parameters", "12345678"); + put("parameters", "213"); }}); @Test @@ -110,25 +121,25 @@ public void verify_story_with_scenario_outline_names_types_and_parameters() { run(format, Collections.singletonList("features/ScenarioOutline.feature"), new GherkinStoryParser(), new ParameterizedSteps()); verify(client, times(1)).startTestItem(any()); - verify(client, times(1)).startTestItem(same(storyId), any()); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(scenarioId), startCaptor.capture()); - verify(client, times(3)).startTestItem(same(exampleIds.get(0)), startCaptor.capture()); - verify(client, times(3)).startTestItem(same(exampleIds.get(1)), startCaptor.capture()); - verify(client, times(3)).startTestItem(same(exampleIds.get(2)), startCaptor.capture()); + ArgumentCaptor exampleCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(storyId), exampleCaptor.capture()); + ArgumentCaptor stepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(scenarioIds.get(0)), stepCaptor.capture()); + verify(client, times(3)).startTestItem(same(scenarioIds.get(1)), stepCaptor.capture()); + verify(client, times(3)).startTestItem(same(scenarioIds.get(2)), stepCaptor.capture()); // Start items verification - List startItems = startCaptor.getAllValues(); - List examples = startItems.subList(0, 3); + List examples = exampleCaptor.getAllValues(); IntStream.range(0, examples.size()).forEach(i -> { StartTestItemRQ rq = examples.get(i); - assertThat(rq.getName(), equalTo(EXAMPLE_NAMES.get(i))); + assertThat(rq.getName(), equalTo(EXAMPLE_NAME)); + assertThat(rq.getDescription(), equalTo(EXAMPLE_DESCRIPTIONS.get(i))); assertThat(rq.getType(), equalTo(ItemType.TEST.name())); assertThat(rq.getParameters(), hasSize(OUTLINE_PARAMETERS.get(i).size())); rq.getParameters().forEach(p -> assertThat(OUTLINE_PARAMETERS.get(i), hasEntry(p.getKey(), p.getValue()))); }); - List steps = startItems.subList(3, 3 + 9); + List steps = stepCaptor.getAllValues(); IntStream.range(0, steps.size()).forEach(i -> { StartTestItemRQ rq = steps.get(i); assertThat(rq.getName(), equalTo(STEP_NAMES.get(i))); diff --git a/src/test/resources/features/ScenarioOutline.feature b/src/test/resources/features/ScenarioOutline.feature index 6913cbe..008f636 100644 --- a/src/test/resources/features/ScenarioOutline.feature +++ b/src/test/resources/features/ScenarioOutline.feature @@ -8,5 +8,5 @@ Feature: Basic test with parameters Examples: | str | parameters | | "first" | 123 | - | "second" | 12345 | - | "third" | 12345678 | + | "scond" | 321 | + | "third" | 213 |