From 5d9c195f4c402efdcab56b7d3623ddbbd3ba8559 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 25 Oct 2022 14:44:24 +0300 Subject: [PATCH 01/32] Initial JBehave 5 support --- gradle.properties | 2 +- .../jbehave/ReportPortalStoryReporter.java | 132 +++++++++++++----- .../epam/reportportal/jbehave/BaseTest.java | 2 +- 3 files changed, 98 insertions(+), 38 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8e16d52..a1f3b92 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ # version=5.1.3-SNAPSHOT description=JBehave reporters for Report Portal -jbehave_version=4.8.3 +jbehave_version=5.0 junit5_version=5.6.3 junit5_launcher_version=1.6.3 mockito_version=3.3.3 diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java index e17e3e4..8804217 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java @@ -38,6 +38,7 @@ import org.apache.commons.lang3.tuple.Pair; import org.jbehave.core.model.*; import org.jbehave.core.reporters.NullStoryReporter; +import org.jbehave.core.steps.Timing; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -111,7 +112,8 @@ public Optional getLastStep() { * @param type an item type * @return a code reference string to identify every element of a story */ - private String getCodeRef(@Nullable final String parentCodeRef, @Nonnull final TestItemTree.ItemTreeKey key, ItemType type) { + private String getCodeRef(@Nullable final String parentCodeRef, @Nonnull final TestItemTree.ItemTreeKey key, + ItemType type) { StringBuilder sb = new StringBuilder(); if (isBlank(parentCodeRef)) { sb.append(key.getName()); @@ -173,7 +175,8 @@ protected Set getAttributes(@Nonnull final Story story) { * @return Request to ReportPortal */ @Nonnull - protected StartTestItemRQ buildStartStoryRq(@Nonnull Story story, @Nonnull String codeRef, @Nullable final Date startTime) { + protected StartTestItemRQ buildStartStoryRq(@Nonnull Story story, @Nonnull String codeRef, + @Nullable final Date startTime) { StartTestItemRQ rq = new StartTestItemRQ(); rq.setName(getStoryName(story)); rq.setCodeRef(codeRef); @@ -215,7 +218,8 @@ protected Set getAttributes(@Nonnull final Scenario scenario) * @return Request to ReportPortal */ @Nonnull - protected StartTestItemRQ buildStartScenarioRq(@Nonnull Scenario scenario, @Nonnull String codeRef, @Nullable final Date startTime) { + protected StartTestItemRQ buildStartScenarioRq(@Nonnull Scenario scenario, @Nonnull String codeRef, + @Nullable final Date startTime) { StartTestItemRQ rq = new StartTestItemRQ(); rq.setName(getScenarioName(scenario)); rq.setCodeRef(codeRef); @@ -236,7 +240,10 @@ protected String formatExampleName(@Nonnull final Map example) { 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)) + .collect(Collectors.joining(EXAMPLE_PARAMETER_DELIMITER, + CODE_REFERENCE_ITEM_START, + CODE_REFERENCE_ITEM_END + )) ); } @@ -311,7 +318,9 @@ protected String formatExampleStep(@Nonnull final String step, @Nullable final M } String result = step; for (Map.Entry e : example.entrySet()) { - result = result.replaceAll(String.format(EXAMPLE_VALUE_PATTERN, e.getKey()), Matcher.quoteReplacement(e.getValue())); + result = result.replaceAll(String.format(EXAMPLE_VALUE_PATTERN, e.getKey()), + Matcher.quoteReplacement(e.getValue()) + ); } return result; } @@ -351,7 +360,8 @@ protected StartTestItemRQ buildStartStepRq(@Nonnull final String step, @Nonnull .collect(Collectors.toList())); usedParams.ifPresent(rq::setParameters); rq.setTestCaseId(ofNullable(getTestCaseId(codeRef, - usedParams.map(p -> p.stream().map(ParameterResource::getValue).collect(Collectors.toList())).orElse(null) + usedParams.map(p -> p.stream().map(ParameterResource::getValue).collect(Collectors.toList())) + .orElse(null) )).map(TestCaseIdEntry::getId).orElse(null)); return rq; } @@ -464,23 +474,26 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { Optional.empty() : Optional.of(leafChain.get(leafChain.size() - 1)); final TestItemTree.TestItemLeaf parentLeaf = parent.map(Pair::getValue).orElse(null); - final Map children = parent.map(p -> p.getValue().getChildItems()) - .orElseGet(itemTree::getTestItems); + final Map children = parent.map(p -> p.getValue() + .getChildItems()).orElseGet(itemTree::getTestItems); final String parentCodeRef = parent.map(p -> (String) p.getValue().getAttribute(CODE_REF)).orElse(null); Date itemDate = getItemDate(parent.map(Pair::getValue).orElse(null)); switch (itemType) { case STORY: Story story = (Story) entity.get(); TestItemTree.ItemTreeKey storyKey = ItemTreeUtils.createKey(story); - leafChain.add(ImmutablePair.of(storyKey, children.computeIfAbsent(storyKey, k -> createLeaf(ItemType.STORY, - buildStartStoryRq(story, getCodeRef(parentCodeRef, k, ItemType.STORY), itemDate), - parentLeaf - )))); + leafChain.add(ImmutablePair.of(storyKey, + children.computeIfAbsent(storyKey, k -> createLeaf(ItemType.STORY, + buildStartStoryRq(story, getCodeRef(parentCodeRef, k, ItemType.STORY), itemDate), + parentLeaf + )) + )); break; case SCENARIO: Scenario scenario = (Scenario) entity.get(); TestItemTree.ItemTreeKey scenarioKey = ItemTreeUtils.createKey(getScenarioName(scenario)); - leafChain.add(ImmutablePair.of(scenarioKey, children.computeIfAbsent(scenarioKey, k -> createLeaf(ItemType.SCENARIO, + leafChain.add(ImmutablePair.of(scenarioKey, children.computeIfAbsent(scenarioKey, k -> createLeaf( + ItemType.SCENARIO, buildStartScenarioRq(scenario, getCodeRef(parentCodeRef, k, ItemType.SCENARIO), itemDate), parentLeaf )))); @@ -500,9 +513,14 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { case TEST: // type TEST == a lifecycle SUITE String lifecycleSuiteName = (String) entity.get(); TestItemTree.ItemTreeKey lifecycleSuiteKey = ItemTreeUtils.createKey(lifecycleSuiteName); - leafChain.add(ImmutablePair.of(lifecycleSuiteKey, children.computeIfAbsent(lifecycleSuiteKey, - k -> createLeaf(itemType, buildLifecycleSuiteStartRq(lifecycleSuiteName, itemDate), parentLeaf) - ))); + leafChain.add(ImmutablePair.of(lifecycleSuiteKey, + children.computeIfAbsent(lifecycleSuiteKey, + k -> createLeaf(itemType, + buildLifecycleSuiteStartRq(lifecycleSuiteName, itemDate), + parentLeaf + ) + ) + )); break; } } @@ -559,7 +577,8 @@ protected TestItemTree.TestItemLeaf getLeaf() { * @param parent a parent test item leaf * @return the step leaf */ - protected TestItemTree.TestItemLeaf startStep(@Nonnull final String name, @Nonnull final TestItemTree.TestItemLeaf parent) { + protected TestItemTree.TestItemLeaf startStep(@Nonnull final String name, + @Nonnull final TestItemTree.TestItemLeaf parent) { TestItemTree.ItemTreeKey key = ItemTreeUtils.createKey(name); TestItemTree.TestItemLeaf leaf = createLeaf(ItemType.STEP, buildStartStepRq(name, getCodeRef(parent.getAttribute(CODE_REF), key, ItemType.STEP), @@ -579,10 +598,13 @@ protected TestItemTree.TestItemLeaf startStep(@Nonnull final String name, @Nonnu * @return the step leaf */ @Nonnull - protected TestItemTree.TestItemLeaf startLifecycleMethod(@Nonnull final String name, @Nonnull final ItemType itemType, - @Nonnull final TestItemTree.TestItemLeaf parent) { + protected TestItemTree.TestItemLeaf startLifecycleMethod(@Nonnull final String name, + @Nonnull final ItemType itemType, @Nonnull final TestItemTree.TestItemLeaf parent) { TestItemTree.ItemTreeKey key = ItemTreeUtils.createKey(name); - TestItemTree.TestItemLeaf leaf = createLeaf(itemType, buildLifecycleMethodStartRq(itemType, name, getItemDate(parent)), parent); + TestItemTree.TestItemLeaf leaf = createLeaf(itemType, + buildLifecycleMethodStartRq(itemType, name, getItemDate(parent)), + parent + ); parent.getChildItems().put(key, leaf); return leaf; } @@ -597,8 +619,8 @@ protected TestItemTree.TestItemLeaf startLifecycleMethod(@Nonnull final String n */ @SuppressWarnings("unused") @Nonnull - protected FinishTestItemRQ buildFinishTestItemRequest(@Nonnull final Maybe id, @Nullable final ItemStatus status, - @Nullable Issue issue) { + protected FinishTestItemRQ buildFinishTestItemRequest(@Nonnull final Maybe id, + @Nullable final ItemStatus status, @Nullable Issue issue) { FinishTestItemRQ rq = new FinishTestItemRQ(); rq.setEndTime(Calendar.getInstance().getTime()); rq.setStatus(ofNullable(status).map(Enum::name).orElse(null)); @@ -643,7 +665,8 @@ protected void finishLastItem(@Nullable final ItemStatus status) { * @see StatusEvaluation#evaluateStatus(ItemStatus, ItemStatus) */ @Nullable - protected ItemStatus evaluateStatus(@Nullable final ItemStatus currentStatus, @Nullable final ItemStatus childStatus) { + protected ItemStatus evaluateStatus(@Nullable final ItemStatus currentStatus, + @Nullable final ItemStatus childStatus) { return StatusEvaluation.evaluateStatus(currentStatus, childStatus); } @@ -674,7 +697,8 @@ protected void evaluateAndFinishLastItem() { * @return a {@link SaveLogRQ} supplier {@link Function} */ @Nonnull - protected Function getLogSupplier(@Nonnull final LogLevel level, @Nullable final String message) { + protected Function getLogSupplier(@Nonnull final LogLevel level, + @Nullable final String message) { return itemUuid -> { SaveLogRQ rq = new SaveLogRQ(); rq.setItemUuid(itemUuid); @@ -693,7 +717,9 @@ protected Function getLogSupplier(@Nonnull final LogLevel lev * @param thrown {@link Throwable} object with details of the failure */ protected void sendStackTraceToRP(@Nonnull Maybe itemId, @Nullable final Throwable thrown) { - ofNullable(thrown).ifPresent(t -> ReportPortal.emitLog(itemId, getLogSupplier(LogLevel.ERROR, ExceptionUtils.getStackTrace(t)))); + ofNullable(thrown).ifPresent(t -> ReportPortal.emitLog(itemId, + getLogSupplier(LogLevel.ERROR, ExceptionUtils.getStackTrace(t)) + )); } /** @@ -703,12 +729,14 @@ protected void sendStackTraceToRP(@Nonnull Maybe itemId, @Nullable final * @param status a status of the item which will be set * @param issue an optional issue which will be set */ - protected void finishItem(final @Nonnull Maybe id, final @Nonnull ItemStatus status, @Nullable Issue issue) { + protected void finishItem(final @Nonnull Maybe id, final @Nonnull ItemStatus status, + @Nullable Issue issue) { FinishTestItemRQ rq = buildFinishTestItemRequest(id, status, issue); launch.get().finishTestItem(id, rq); } - private void finishStep(final @Nonnull TestItemTree.TestItemLeaf step, final @Nonnull ItemStatus status, @Nullable Issue issue) { + private void finishStep(final @Nonnull TestItemTree.TestItemLeaf step, final @Nonnull ItemStatus status, + @Nullable Issue issue) { finishItem(step.getItemId(), status, issue); step.setStatus(status); } @@ -809,8 +837,7 @@ public void beforeScenario(@Nonnull Scenario scenario) { /** * Finishes scenario in ReportPortal */ - @Override - public void afterScenario() { + public void afterScenario(Timing timing) { TestItemTree.TestItemLeaf previousItem = getLeaf(); if (previousItem != null && previousItem.getType() == ItemType.TEST) { evaluateAndFinishLastItem(); @@ -819,12 +846,32 @@ public void afterScenario() { evaluateAndFinishLastItem(); } + /** + * Finishes scenario in ReportPortal + * + * @deprecated use {@link #afterScenario(Timing)} along with JBehave 5.0 + */ + @Deprecated + public void afterScenario() { + afterScenario(null); + } + /** * Starts step in ReportPortal (TestStep level) * * @param step Step to be reported */ - @Override + public void beforeStep(@Nonnull Step step) { + beforeStep(step.getStepAsString()); + } + + /** + * Starts step in ReportPortal (TestStep level) + * + * @param step Step to be reported + * @deprecated use {@link #beforeStep(Step)} along with JBehave 5.0 + */ + @Deprecated public void beforeStep(@Nonnull String step) { TestItemTree.TestItemLeaf previousItem = getLeaf(); if (previousItem != null && previousItem.getType() == ItemType.TEST) { @@ -846,7 +893,8 @@ public void beforeExamples(List steps, ExamplesTable table) { @Override public void example(Map tableRow, int exampleIndex) { TestItemTree.TestItemLeaf previousItem = getLeaf(); - if (previousItem != null && (previousItem.getType() == ItemType.TEST || previousItem.getType() == ItemType.SUITE)) { + if (previousItem != null && (previousItem.getType() == ItemType.TEST + || previousItem.getType() == ItemType.SUITE)) { evaluateAndFinishLastItem(); } structure.add(new Entity<>(ItemType.SUITE, tableRow)); // type SUITE is used for Examples @@ -886,12 +934,17 @@ public void failed(String step, Throwable cause) { if (isLifecycleMethod) { if (item == null) { // failed @BeforeStories (annotated) methods - structure.add(new Entity<>(ItemType.TEST, currentLifecycleItemType == null ? BEFORE_STORIES : AFTER_STORIES)); + structure.add(new Entity<>(ItemType.TEST, + currentLifecycleItemType == null ? BEFORE_STORIES : AFTER_STORIES + )); } else if (item.getType() == ItemType.STORY) { // failed @BeforeStory, @BeforeScenario (annotated) methods - structure.add(new Entity<>(ItemType.TEST, currentLifecycleItemType == ItemType.BEFORE_SUITE ? BEFORE_STORY : AFTER_STORY)); + structure.add(new Entity<>(ItemType.TEST, + currentLifecycleItemType == ItemType.BEFORE_SUITE ? BEFORE_STORY : AFTER_STORY + )); } - stepStack.add(ofNullable(retrieveLeaf()).map(i -> startLifecycleMethod(step, currentLifecycleItemType, i)).orElse(null)); + stepStack.add(ofNullable(retrieveLeaf()).map(i -> startLifecycleMethod(step, currentLifecycleItemType, i)) + .orElse(null)); } ofNullable(stepStack.pollLast()).ifPresent(i -> { sendStackTraceToRP(i.getItemId(), cause); @@ -938,8 +991,7 @@ public void pending(String step) { }); } - @Override - public void scenarioNotAllowed(Scenario scenario, String filter) { + public void scenarioExcluded(Scenario scenario, String filter) { if (null != scenario.getExamplesTable() && scenario.getExamplesTable().getRowCount() > 0) { beforeExamples(scenario.getSteps(), scenario.getExamplesTable()); for (int i = 0; i < scenario.getExamplesTable().getRowCount(); i++) { @@ -956,6 +1008,14 @@ public void scenarioNotAllowed(Scenario scenario, String filter) { finishLastItem(ItemStatus.SKIPPED); } + /** + * @deprecated use {@link #scenarioExcluded(Scenario, String)} + */ + @Deprecated + public void scenarioNotAllowed(Scenario scenario, String filter) { + scenarioExcluded(scenario, filter); + } + protected static class Entity { private final ItemType type; diff --git a/src/test/java/com/epam/reportportal/jbehave/BaseTest.java b/src/test/java/com/epam/reportportal/jbehave/BaseTest.java index 82e4a00..1987f18 100644 --- a/src/test/java/com/epam/reportportal/jbehave/BaseTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/BaseTest.java @@ -108,7 +108,7 @@ public static void run(@Nonnull final Class clazz, @Nonnull final Format form final InjectableStepsFactory stepsFactory = new InstanceStepsFactory(embedder.configuration(), steps == null ? Collections.emptyList() : Arrays.asList(steps) ); - embedder.useCandidateSteps(stepsFactory.createCandidateSteps()); + embedder.useStepsFactory(stepsFactory); embedder.runStoriesAsPaths(stories); } From b7c2292dc3760f40a5943c5dbfc7fafad07685b5 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 3 Nov 2022 17:16:09 +0300 Subject: [PATCH 02/32] Revert "Changelog update" This reverts commit 17b6550eb083646175169504a3af4bd040930355. --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df4b0c8..8ec101b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,6 @@ # Changelog ## [Unreleased] - -## [5.1.4] ### Changed - Test new actions From 739e8331c06c2c0e0badf79920f3cb197d903b95 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 3 Nov 2022 17:16:10 +0300 Subject: [PATCH 03/32] Revert "Readme update" This reverts commit 55f5d613d32538bc609d674f7d6eef9d6707316a. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 83e0931..1977f29 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![stackoverflow](https://img.shields.io/badge/reportportal-stackoverflow-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/reportportal) [![Build with Love](https://img.shields.io/badge/build%20with-❤%EF%B8%8F%E2%80%8D-lightgrey.svg)](http://reportportal.io?style=flat) -The latest version: 5.1.4. Please use `Download` link above to get the agent. Minimal supported JBehave version: 4.8 +The latest version: 5.1.3. Please use `Download` link above to get the agent. Minimal supported JBehave version: 4.8 ## Overview: How to Add ReportPortal Logging to Your JBehave Java Project @@ -80,7 +80,7 @@ rp.project = default_personal com.epam.reportportal agent-java-jbehave - 5.1.4 + 5.1.3 @@ -153,7 +153,7 @@ def jbehaveVersion = '4.8.1' dependencies { testCompile "org.jbehave:jbehave-core:${jbehaveVersion}" testCompile "org.jbehave:jbehave-navigator:${jbehaveVersion}" - testCompile 'com.epam.reportportal:agent-java-jbehave:5.1.4' + testCompile 'com.epam.reportportal:agent-java-jbehave:5.1.3' testCompile 'com.epam.reportportal:logger-java-logback:5.1.1' } From d8eb9b922975aa89c26372e46d1a2176fb2efcef Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 3 Nov 2022 17:16:10 +0300 Subject: [PATCH 04/32] Revert "[Gradle Release Plugin] - new version commit: '5.1.5-SNAPSHOT'." This reverts commit 4ef3a64a55adfee13bb6d04a53c7f6d3e2776bed. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1ede057..e69d0ca 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.1.5-SNAPSHOT +version=5.1.4 description=JBehave reporters for Report Portal jbehave_version=4.8.3 junit5_version=5.6.3 From da06f16fe01226e7c0f19ab2fce3f2737f315f61 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 3 Nov 2022 17:16:10 +0300 Subject: [PATCH 05/32] Revert "[Gradle Release Plugin] - pre tag commit: '5.1.4'." This reverts commit 52ad037256913901de517061c0bfccbd863e8b77. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index e69d0ca..c9335e8 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.1.4 +version=5.1.4-SNAPSHOT description=JBehave reporters for Report Portal jbehave_version=4.8.3 junit5_version=5.6.3 From 0b76af849de6ff0b32e17dd9a6019f2d74ae048f Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 3 Nov 2022 17:40:42 +0300 Subject: [PATCH 06/32] Fix release changes publication --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2ec4bbd..6b39a0f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -104,7 +104,7 @@ jobs: with: tag: ${{ env.RELEASE_VERSION }} name: Release ${{ env.RELEASE_VERSION }} - body: ${{ steps.readChangelogEntry.outputs.log_entry }} + body: ${{ steps.readChangelogEntry.outputs.changes }} - name: Checkout develop branch if: ${{ github.ref }} == 'master' From d475f8493ad29ca85372080fbfc798dbf9d7b370 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 4 Nov 2022 16:42:43 +0300 Subject: [PATCH 07/32] JUnit 5 version update --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index af2b047..f66d83e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,8 +16,8 @@ version=5.1.4-SNAPSHOT description=JBehave reporters for Report Portal jbehave_version=5.0 -junit5_version=5.6.3 -junit5_launcher_version=1.6.3 +junit5_version=5.8.2 +junit5_launcher_version=1.8.2 mockito_version=3.3.3 scripts_url=https://raw.githubusercontent.com/reportportal/gradle-scripts scripts_branch=master From 986c113258aa1422c6783118396b788268357e33 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 4 Nov 2022 17:00:31 +0300 Subject: [PATCH 08/32] Fix test starting --- build.gradle | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a8aa4cc..3037fc6 100644 --- a/build.gradle +++ b/build.gradle @@ -44,6 +44,7 @@ dependencies { api ("org.jbehave:jbehave-core:${project.jbehave_version}") { exclude group: 'org.hamcrest' exclude group: 'junit' + exclude group: 'org.junit.vintage' } api 'com.google.code.findbugs:jsr305:3.0.2' implementation 'org.slf4j:slf4j-api:1.7.36' @@ -56,7 +57,7 @@ dependencies { testImplementation 'ch.qos.logback:logback-classic:1.2.11' testImplementation 'com.epam.reportportal:logger-java-logback:5.1.3' testImplementation ("org.junit.platform:junit-platform-runner:${project.junit5_launcher_version}") { - exclude module: 'junit' + exclude group: 'junit' } testImplementation "org.junit.jupiter:junit-jupiter-api:${project.junit5_version}" testImplementation "org.junit.jupiter:junit-jupiter-params:${project.junit5_version}" @@ -64,6 +65,7 @@ dependencies { testImplementation 'org.apache.commons:commons-io:1.3.2' testImplementation ("org.jbehave:jbehave-gherkin:${project.jbehave_version}") { exclude group: 'junit' + exclude group: 'org.junit.vintage' } } From e55e3a458154e1ec97f6cc9b96c96f135d4e9ad4 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 8 Nov 2022 18:40:53 +0300 Subject: [PATCH 09/32] Test fixes --- .../jbehave/ReportPortalStoryReporter.java | 31 ++++++++++++++++--- .../epam/reportportal/jbehave/BaseTest.java | 12 +++++++ .../reportportal/jbehave/ExamplesTest.java | 3 -- .../BeforeScenarioAnnotationFailedTest.java | 18 ++++++++--- 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java index 8804217..46bbf91 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java @@ -36,6 +36,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; +import org.apache.commons.text.StringEscapeUtils; import org.jbehave.core.model.*; import org.jbehave.core.reporters.NullStoryReporter; import org.jbehave.core.steps.Timing; @@ -514,7 +515,8 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { String lifecycleSuiteName = (String) entity.get(); TestItemTree.ItemTreeKey lifecycleSuiteKey = ItemTreeUtils.createKey(lifecycleSuiteName); leafChain.add(ImmutablePair.of(lifecycleSuiteKey, - children.computeIfAbsent(lifecycleSuiteKey, + children.computeIfAbsent( + lifecycleSuiteKey, k -> createLeaf(itemType, buildLifecycleSuiteStartRq(lifecycleSuiteName, itemDate), parentLeaf @@ -777,7 +779,8 @@ protected void createNotPerformedSteps(@Nullable String step, @Nonnull TestItemT @SuppressWarnings("unused") protected void createPendingSteps(@Nullable String step, @Nonnull TestItemTree.TestItemLeaf leaf) { ReportPortal.emitLog(leaf.getItemId(), - getLogSupplier(LogLevel.WARN, String.format("Unable to locate a step implementation: '%s'", step)) + getLogSupplier(LogLevel.WARN, String.format("Unable to locate a step implementation: '%s'", + StringEscapeUtils.escapeHtml4(step))) ); } @@ -930,6 +933,8 @@ public void successful(String step) { @Override public void failed(String step, Throwable cause) { TestItemTree.TestItemLeaf item = retrieveLeaf(); + + // The next if is legacy code for JBehave versions < 5.0, where startStep wasn't called for Lifecycle methods boolean isLifecycleMethod = item == null || stepStack.isEmpty(); if (isLifecycleMethod) { if (item == null) { @@ -943,7 +948,7 @@ public void failed(String step, Throwable cause) { currentLifecycleItemType == ItemType.BEFORE_SUITE ? BEFORE_STORY : AFTER_STORY )); } - stepStack.add(ofNullable(retrieveLeaf()).map(i -> startLifecycleMethod(step, currentLifecycleItemType, i)) + stepStack.add(ofNullable(item).map(i -> startLifecycleMethod(step, currentLifecycleItemType, i)) .orElse(null)); } ofNullable(stepStack.pollLast()).ifPresent(i -> { @@ -966,6 +971,20 @@ public void ignorable(String step) { }); } + private TestItemTree.TestItemLeaf getOrCreateStepLeaf(@Nonnull String step, + @Nonnull TestItemTree.TestItemLeaf parentLeaf) { + Maybe parent = parentLeaf.getItemId(); + TestItemTree.TestItemLeaf lastStepLeaf = stepStack.pollLast(); + Maybe lastStepParent = ofNullable(lastStepLeaf).map(TestItemTree.TestItemLeaf::getParentId) + .orElse(null); + boolean stepStarted = lastStepLeaf != null && lastStepParent == parent && parentLeaf.getChildItems() + .containsKey(ItemTreeUtils.createKey(step)); + if (!stepStarted) { + return startStep(step, parentLeaf); + } + return lastStepLeaf; + } + /** * Report a not performed step * @@ -975,7 +994,7 @@ public void ignorable(String step) { public void notPerformed(String step) { TestItemTree.TestItemLeaf item = retrieveLeaf(); ofNullable(item).ifPresent(i -> { - TestItemTree.TestItemLeaf leaf = startStep(step, i); + TestItemTree.TestItemLeaf leaf = getOrCreateStepLeaf(step, i); createNotPerformedSteps(step, leaf); finishStep(leaf, ItemStatus.SKIPPED, Launch.NOT_ISSUE); }); @@ -985,7 +1004,7 @@ public void notPerformed(String step) { public void pending(String step) { TestItemTree.TestItemLeaf item = retrieveLeaf(); ofNullable(item).ifPresent(i -> { - TestItemTree.TestItemLeaf leaf = startStep(step, i); + TestItemTree.TestItemLeaf leaf = getOrCreateStepLeaf(step, i); createPendingSteps(step, leaf); finishStep(leaf, ItemStatus.SKIPPED); }); @@ -1009,6 +1028,8 @@ public void scenarioExcluded(Scenario scenario, String filter) { } /** + * @param scenario - JBehave's Scenario Object + * @param filter - Scenario filter * @deprecated use {@link #scenarioExcluded(Scenario, String)} */ @Deprecated diff --git a/src/test/java/com/epam/reportportal/jbehave/BaseTest.java b/src/test/java/com/epam/reportportal/jbehave/BaseTest.java index 1987f18..76eb494 100644 --- a/src/test/java/com/epam/reportportal/jbehave/BaseTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/BaseTest.java @@ -73,6 +73,18 @@ public class BaseTest { public static final String ROOT_SUITE_PREFIX = "root_"; + public static final boolean IS_JBEHAVE_5; + static { + boolean isJbehave5; + try { + Class.forName("org.jbehave.core.model.Step"); + isJbehave5 = true; + } catch (ClassNotFoundException ignore) { + isJbehave5 = false; + } + IS_JBEHAVE_5 = isJbehave5; + } + public static ExecutorService testExecutor() { return Executors.newSingleThreadExecutor(r -> { Thread t = new Thread(r); diff --git a/src/test/java/com/epam/reportportal/jbehave/ExamplesTest.java b/src/test/java/com/epam/reportportal/jbehave/ExamplesTest.java index 996fd42..6789063 100644 --- a/src/test/java/com/epam/reportportal/jbehave/ExamplesTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/ExamplesTest.java @@ -27,12 +27,10 @@ import com.epam.ta.reportportal.ws.model.ParameterResource; import com.epam.ta.reportportal.ws.model.StartTestItemRQ; import org.apache.commons.lang3.tuple.Pair; -import org.jbehave.core.annotations.When; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -111,7 +109,6 @@ public void setupMock() { asList(parameterOf("symbol", "STK1$"), parameterOf("symbol", "STK1$")) ); - @Test public void verify_story_with_examples_names_types_and_parameters() { run(format, "stories/Examples.story", new StockSteps(), new ParameterizedSteps()); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java index a4ec620..2757ec4 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java @@ -68,6 +68,7 @@ public void setupMock() { private static final String STORY_PATH = "stories/NoScenario.story"; private static final String DEFAULT_SCENARIO_NAME = "No name"; + private static final String BEFORE_SCENARIO_METHOD_NAME = "beforeScenarioFailed"; private static final String STEP_NAME = "Given I have empty step"; @Test @@ -88,10 +89,19 @@ public void verify_before_scenario_annotation_failed_method_reporting() { assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); StartTestItemRQ beforeStep = startItems.get(1); - String beforeStepCodeRef = BeforeScenarioFailedSteps.class.getCanonicalName() + ".beforeScenarioFailed()"; - assertThat(beforeStep.getName(), equalTo(beforeStepCodeRef)); - assertThat(beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); - assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_TEST.name())); + + if (IS_JBEHAVE_5) { + String beforeStepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", BEFORE_SCENARIO_METHOD_NAME); + assertThat("BeforeScenario name invalid", beforeStep.getName(), equalTo(BEFORE_SCENARIO_METHOD_NAME)); + assertThat("BeforeScenario code reference invalid", beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); + assertThat(beforeStep.getType(), equalTo(ItemType.STEP.name())); + } else { + String beforeStepCodeRef = + BeforeScenarioFailedSteps.class.getCanonicalName() + "." + BEFORE_SCENARIO_METHOD_NAME + "()"; + assertThat("BeforeScenario name invalid", beforeStep.getName(), equalTo(beforeStepCodeRef)); + assertThat("BeforeScenario code reference invalid", beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); + assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_TEST.name())); + } StartTestItemRQ step = startItems.get(2); String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); From f588660f37d6ba3a6c7fe03005dc9a7c3a39b08b Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 8 Nov 2022 18:44:52 +0300 Subject: [PATCH 10/32] Commons-text exclusion --- build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index 3037fc6..959c552 100644 --- a/build.gradle +++ b/build.gradle @@ -45,9 +45,11 @@ dependencies { exclude group: 'org.hamcrest' exclude group: 'junit' exclude group: 'org.junit.vintage' + exclude group: 'org.apache.commons', module: 'commons-text' } api 'com.google.code.findbugs:jsr305:3.0.2' implementation 'org.slf4j:slf4j-api:1.7.36' + implementation 'org.apache.commons:commons-text:1.10.0' testImplementation 'com.github.reportportal:agent-java-test-utils:236a68c' testImplementation 'org.aspectj:aspectjweaver:1.9.2' From c726262d886c22ce98589a98aaae0742bc4e0c9d Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 8 Nov 2022 23:10:27 +0300 Subject: [PATCH 11/32] Callback test fix --- .../jbehave/CallbackReportingTest.java | 16 ++++++-- .../basic/CallbackReportingSteps.java | 41 +++++++++++++------ 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/test/java/com/epam/reportportal/jbehave/CallbackReportingTest.java b/src/test/java/com/epam/reportportal/jbehave/CallbackReportingTest.java index 8c30cef..f1c6961 100644 --- a/src/test/java/com/epam/reportportal/jbehave/CallbackReportingTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/CallbackReportingTest.java @@ -74,7 +74,11 @@ public void callback_reporting_test() { ArgumentCaptor idCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor rqCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - verify(client, times(7)).finishTestItem(idCaptor.capture(), rqCaptor.capture()); // Start test class and test method + if(IS_JBEHAVE_5) { + verify(client, times(9)).finishTestItem(idCaptor.capture(), rqCaptor.capture()); + } else { + verify(client, times(7)).finishTestItem(idCaptor.capture(), rqCaptor.capture()); + } ArgumentCaptor saveLogRQArgumentCaptor = ArgumentCaptor.forClass(SaveLogRQ.class); verify(client, times(1)).log(saveLogRQArgumentCaptor.capture()); @@ -93,9 +97,13 @@ public void callback_reporting_test() { List> secondScenarioIds = idRqs.stream() .filter(e -> stepIds.get(1).equals(e.getKey())) .collect(Collectors.toList()); - - assertThat(firstScenarioIds, hasSize(2)); - assertThat(secondScenarioIds, hasSize(2)); + if(IS_JBEHAVE_5) { + assertThat(firstScenarioIds, hasSize(3)); + assertThat(secondScenarioIds, hasSize(3)); + } else { + assertThat(firstScenarioIds, hasSize(2)); + assertThat(secondScenarioIds, hasSize(2)); + } List> failureUpdates = firstScenarioIds.stream() .filter(r -> "FAILED".equals(r.getValue().getStatus())) diff --git a/src/test/java/com/epam/reportportal/jbehave/integration/basic/CallbackReportingSteps.java b/src/test/java/com/epam/reportportal/jbehave/integration/basic/CallbackReportingSteps.java index f06bbd1..ebd53d5 100644 --- a/src/test/java/com/epam/reportportal/jbehave/integration/basic/CallbackReportingSteps.java +++ b/src/test/java/com/epam/reportportal/jbehave/integration/basic/CallbackReportingSteps.java @@ -16,10 +16,8 @@ package com.epam.reportportal.jbehave.integration.basic; -import com.epam.reportportal.jbehave.ReportPortalFormat; -import com.epam.reportportal.jbehave.ReportPortalStepFormat; -import com.epam.reportportal.jbehave.ReportPortalStepStoryReporter; -import com.epam.reportportal.jbehave.ReportPortalStoryReporter; +import com.epam.reportportal.jbehave.*; +import com.epam.reportportal.jbehave.util.ItemTreeUtils; import com.epam.reportportal.listeners.ItemStatus; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.tree.ItemTreeReporter; @@ -30,6 +28,7 @@ import org.jbehave.core.annotations.AfterScenario; import org.jbehave.core.annotations.Given; +import javax.annotation.Nonnull; import java.util.Calendar; import java.util.Optional; @@ -53,14 +52,27 @@ public void after() { reporter.flatMap(ReportPortalStoryReporter::getLastStep).ifPresent(itemLeaf -> { TestItemTree.TestItemLeaf scenario = itemLeaf.getAttribute(ReportPortalStepStoryReporter.PARENT); + TestItemTree.TestItemLeaf stepLeaf; + if (BaseTest.IS_JBEHAVE_5) { + // For JBehave 5 the item will be `after` method, so we need to find actual step + stepLeaf = ofNullable(scenario).map(TestItemTree.TestItemLeaf::getChildItems) + .map(c -> c.get(ItemTreeUtils.createKey("Given " + STEP_TEXT))) + .orElse(null); + } else { + stepLeaf = itemLeaf; + } if (ofNullable(scenario).isPresent()) { String scenarioName = ofNullable((StartTestItemRQ) scenario.getAttribute(ReportPortalStepStoryReporter.START_REQUEST)).map( - StartTestItemRQ::getName).orElseThrow(() -> new IllegalStateException("Unable to get start item request")); + StartTestItemRQ::getName) + .orElseThrow(() -> new IllegalStateException("Unable to get start item request")); + if (scenarioName.contains("failure")) { - finishWithStatus(rp, tree, "FAILED", itemLeaf); - attachLog(rp, tree, itemLeaf); + ofNullable(stepLeaf).ifPresent(l -> { + finishWithStatus(rp, tree, "FAILED", l); + attachLog(rp, tree, l); + }); } else { - finishWithStatus(rp, tree, "PASSED", itemLeaf); + ofNullable(stepLeaf).ifPresent(l -> finishWithStatus(rp, tree, "PASSED", stepLeaf)); } } else { throw new IllegalStateException("Unable to find parent item"); @@ -68,17 +80,22 @@ public void after() { }); } - private void finishWithStatus(ReportPortal rp, TestItemTree tree, String status, TestItemTree.TestItemLeaf testItemLeaf) { + private void finishWithStatus(@Nonnull ReportPortal rp, @Nonnull TestItemTree tree, @Nonnull String status, + @Nonnull TestItemTree.TestItemLeaf testItemLeaf) { FinishTestItemRQ finishTestItemRQ = new FinishTestItemRQ(); finishTestItemRQ.setStatus(status); finishTestItemRQ.setEndTime(Calendar.getInstance().getTime()); //noinspection ResultOfMethodCallIgnored - ItemTreeReporter.finishItem(rp.getClient(), finishTestItemRQ, tree.getLaunchId(), testItemLeaf).cache().blockingGet(); + ItemTreeReporter.finishItem(rp.getClient(), finishTestItemRQ, tree.getLaunchId(), testItemLeaf) + .cache() + .blockingGet(); testItemLeaf.setStatus(ItemStatus.valueOf(status)); } - private void attachLog(ReportPortal rp, TestItemTree tree, TestItemTree.TestItemLeaf testItemLeaf) { - ItemTreeReporter.sendLog(rp.getClient(), + private void attachLog(@Nonnull ReportPortal rp, @Nonnull TestItemTree tree, + @Nonnull TestItemTree.TestItemLeaf testItemLeaf) { + ItemTreeReporter.sendLog( + rp.getClient(), "ERROR", "Error message", Calendar.getInstance().getTime(), From fa6cab9701573f2c304be36416c8dcff6a3736ad Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 9 Nov 2022 15:41:16 +0300 Subject: [PATCH 12/32] Before Story test fix --- .../jbehave/ReportPortalStoryReporter.java | 31 +++++--- ...a => BeforeStoryAnnotationFailedTest.java} | 78 ++++++++++++------- 2 files changed, 70 insertions(+), 39 deletions(-) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyBeforeStoryAnnotationFailed.java => BeforeStoryAnnotationFailedTest.java} (63%) diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java index 46bbf91..18c3e0f 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java @@ -515,13 +515,10 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { String lifecycleSuiteName = (String) entity.get(); TestItemTree.ItemTreeKey lifecycleSuiteKey = ItemTreeUtils.createKey(lifecycleSuiteName); leafChain.add(ImmutablePair.of(lifecycleSuiteKey, - children.computeIfAbsent( - lifecycleSuiteKey, - k -> createLeaf(itemType, - buildLifecycleSuiteStartRq(lifecycleSuiteName, itemDate), - parentLeaf - ) - ) + children.computeIfAbsent(lifecycleSuiteKey, k -> createLeaf(itemType, + buildLifecycleSuiteStartRq(lifecycleSuiteName, itemDate), + parentLeaf + )) )); break; } @@ -582,11 +579,17 @@ protected TestItemTree.TestItemLeaf getLeaf() { protected TestItemTree.TestItemLeaf startStep(@Nonnull final String name, @Nonnull final TestItemTree.TestItemLeaf parent) { TestItemTree.ItemTreeKey key = ItemTreeUtils.createKey(name); - TestItemTree.TestItemLeaf leaf = createLeaf(ItemType.STEP, buildStartStepRq(name, + StartTestItemRQ rq = buildStartStepRq(name, getCodeRef(parent.getAttribute(CODE_REF), key, ItemType.STEP), parent.getAttribute(PARAMETERS), getItemDate(parent) - ), parent); + ); + // Workaround for JBehave 5 to report Lifecycle methods correctly + rq.setHasStats(ItemType.STORY.name() + .equals((ofNullable(parent.getAttribute(START_REQUEST)).map(r -> (StartTestItemRQ) r) + .map(StartTestItemRQ::getType) + .orElse(null)))); + TestItemTree.TestItemLeaf leaf = createLeaf(ItemType.STEP, rq, parent); parent.getChildItems().put(key, leaf); return leaf; } @@ -779,8 +782,12 @@ protected void createNotPerformedSteps(@Nullable String step, @Nonnull TestItemT @SuppressWarnings("unused") protected void createPendingSteps(@Nullable String step, @Nonnull TestItemTree.TestItemLeaf leaf) { ReportPortal.emitLog(leaf.getItemId(), - getLogSupplier(LogLevel.WARN, String.format("Unable to locate a step implementation: '%s'", - StringEscapeUtils.escapeHtml4(step))) + getLogSupplier( + LogLevel.WARN, + String.format("Unable to locate a step implementation: '%s'", + StringEscapeUtils.escapeHtml4(step) + ) + ) ); } @@ -1029,7 +1036,7 @@ public void scenarioExcluded(Scenario scenario, String filter) { /** * @param scenario - JBehave's Scenario Object - * @param filter - Scenario filter + * @param filter - Scenario filter * @deprecated use {@link #scenarioExcluded(Scenario, String)} */ @Deprecated diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryAnnotationFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryAnnotationFailedTest.java similarity index 63% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryAnnotationFailed.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryAnnotationFailedTest.java index e1cfb55..fbe33b2 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryAnnotationFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryAnnotationFailedTest.java @@ -42,7 +42,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyBeforeStoryAnnotationFailed extends BaseTest { +public class BeforeStoryAnnotationFailedTest extends BaseTest { private final String storyId = CommonUtils.namedId("story_"); private final String beforeStoryId = CommonUtils.namedId("before_story_"); @@ -50,7 +50,10 @@ public class VerifyBeforeStoryAnnotationFailed extends BaseTest { private final String scenarioId = CommonUtils.namedId("scenario_"); private final String stepId = CommonUtils.namedId("step_"); - private final List>> steps = Arrays.asList(Pair.of(beforeStoryId, Collections.singletonList(beforeStepId)), + private final List>> steps = Arrays.asList(Pair.of( + beforeStoryId, + Collections.singletonList(beforeStepId) + ), Pair.of(scenarioId, Collections.singletonList(stepId)) ); @@ -69,37 +72,53 @@ public void setupMock() { private static final String STORY_PATH = "stories/NoScenario.story"; private static final String DEFAULT_SCENARIO_NAME = "No name"; private static final String STEP_NAME = "Given I have empty step"; + private static final String BEFORE_STORY_NAME = "beforeStoryFailed"; @Test public void verify_before_story_annotation_failed_method_reporting() { run(format, STORY_PATH, new BeforeStoryFailedSteps(), new EmptySteps()); verify(client).startTestItem(any()); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(storyId), startCaptor.capture()); - verify(client).startTestItem(same(beforeStoryId), startCaptor.capture()); - verify(client).startTestItem(same(scenarioId), startCaptor.capture()); + ArgumentCaptor storyLevelCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(storyId), storyLevelCaptor.capture()); + ArgumentCaptor beforeLevelCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + if (!IS_JBEHAVE_5) { + verify(client).startTestItem(same(beforeStoryId), beforeLevelCaptor.capture()); + } + ArgumentCaptor scenarioLevelCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(scenarioId), scenarioLevelCaptor.capture()); // Start items verification - List startItems = startCaptor.getAllValues(); - StartTestItemRQ beforeStoryStart = startItems.get(0); - assertThat(beforeStoryStart.getName(), equalTo("BeforeStory")); - assertThat(beforeStoryStart.getCodeRef(), nullValue()); - assertThat(beforeStoryStart.getType(), equalTo(ItemType.TEST.name())); + List storyStartItems = storyLevelCaptor.getAllValues(); + StartTestItemRQ beforeStoryStart = storyStartItems.get(0); + if (IS_JBEHAVE_5) { + assertThat(beforeStoryStart.getName(), equalTo(BEFORE_STORY_NAME)); + assertThat( + beforeStoryStart.getCodeRef(), + equalTo(STORY_PATH + String.format("/[STEP:%s]", BEFORE_STORY_NAME)) + ); + assertThat(beforeStoryStart.getType(), equalTo(ItemType.STEP.name())); + } else { + assertThat(beforeStoryStart.getName(), equalTo("BeforeStory")); + assertThat(beforeStoryStart.getCodeRef(), nullValue()); + assertThat(beforeStoryStart.getType(), equalTo(ItemType.TEST.name())); + } String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME); - StartTestItemRQ scenarioStart = startItems.get(1); + StartTestItemRQ scenarioStart = storyStartItems.get(1); assertThat(scenarioStart.getName(), equalTo(DEFAULT_SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); - StartTestItemRQ beforeStep = startItems.get(2); - String beforeStepCodeRef = BeforeStoryFailedSteps.class.getCanonicalName() + ".beforeStoryFailed()"; - assertThat(beforeStep.getName(), equalTo(beforeStepCodeRef)); - assertThat(beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); - assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_SUITE.name())); + if(!IS_JBEHAVE_5) { + StartTestItemRQ beforeStep = beforeLevelCaptor.getValue(); + String beforeStepCodeRef = BeforeStoryFailedSteps.class.getCanonicalName() + ".beforeStoryFailed()"; + assertThat(beforeStep.getName(), equalTo(beforeStepCodeRef)); + assertThat(beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); + assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_SUITE.name())); + } - StartTestItemRQ step = startItems.get(3); + StartTestItemRQ step = scenarioLevelCaptor.getValue(); String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); @@ -107,27 +126,32 @@ public void verify_before_story_annotation_failed_method_reporting() { // Finish items verification ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - verify(client).finishTestItem(same(beforeStepId), finishStepCaptor.capture()); + if(!IS_JBEHAVE_5) { + verify(client).finishTestItem(same(beforeStepId), finishStepCaptor.capture()); + } verify(client).finishTestItem(same(stepId), finishStepCaptor.capture()); verify(client).finishTestItem(same(beforeStoryId), finishStepCaptor.capture()); verify(client).finishTestItem(same(scenarioId), finishStepCaptor.capture()); verify(client).finishTestItem(same(storyId), finishStepCaptor.capture()); List finishItems = finishStepCaptor.getAllValues(); - FinishTestItemRQ beforeStepFinish = finishItems.get(0); - assertThat(beforeStepFinish.getStatus(), equalTo(ItemStatus.FAILED.name())); - assertThat(beforeStepFinish.getIssue(), nullValue()); - - FinishTestItemRQ stepFinish = finishItems.get(1); + if(!IS_JBEHAVE_5) { + FinishTestItemRQ beforeStepFinish = finishItems.get(0); + assertThat(beforeStepFinish.getStatus(), equalTo(ItemStatus.FAILED.name())); + assertThat(beforeStepFinish.getIssue(), nullValue()); + finishItems = finishItems.subList(1, finishItems.size()); + } + + FinishTestItemRQ stepFinish = finishItems.get(0); assertThat(stepFinish.getStatus(), equalTo(ItemStatus.PASSED.name())); - FinishTestItemRQ beforeScenarioFinish = finishItems.get(2); + FinishTestItemRQ beforeScenarioFinish = finishItems.get(1); assertThat(beforeScenarioFinish.getStatus(), equalTo(ItemStatus.FAILED.name())); - FinishTestItemRQ scenarioFinish = finishItems.get(3); + FinishTestItemRQ scenarioFinish = finishItems.get(2); assertThat(scenarioFinish.getStatus(), equalTo(ItemStatus.PASSED.name())); - FinishTestItemRQ storyFinish = finishItems.get(4); + FinishTestItemRQ storyFinish = finishItems.get(3); assertThat(storyFinish.getStatus(), equalTo(ItemStatus.FAILED.name())); } } From 6c838cb9245d2aab29748e455f0a2bbe40ffc1a4 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 10 Nov 2022 16:54:16 +0300 Subject: [PATCH 13/32] Remove JBehave 4 support --- gradle.properties | 2 +- .../jbehave/ReportPortalStoryReporter.java | 196 ++++-------------- 2 files changed, 47 insertions(+), 151 deletions(-) diff --git a/gradle.properties b/gradle.properties index f66d83e..5205e1e 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.1.4-SNAPSHOT +version=5.2.0-SNAPSHOT description=JBehave reporters for Report Portal jbehave_version=5.0 junit5_version=5.8.2 diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java index 18c3e0f..5d53d51 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java @@ -36,7 +36,6 @@ import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; -import org.apache.commons.text.StringEscapeUtils; import org.jbehave.core.model.*; import org.jbehave.core.reporters.NullStoryReporter; import org.jbehave.core.steps.Timing; @@ -113,8 +112,7 @@ public Optional getLastStep() { * @param type an item type * @return a code reference string to identify every element of a story */ - private String getCodeRef(@Nullable final String parentCodeRef, @Nonnull final TestItemTree.ItemTreeKey key, - ItemType type) { + private String getCodeRef(@Nullable final String parentCodeRef, @Nonnull final TestItemTree.ItemTreeKey key, ItemType type) { StringBuilder sb = new StringBuilder(); if (isBlank(parentCodeRef)) { sb.append(key.getName()); @@ -176,8 +174,7 @@ protected Set getAttributes(@Nonnull final Story story) { * @return Request to ReportPortal */ @Nonnull - protected StartTestItemRQ buildStartStoryRq(@Nonnull Story story, @Nonnull String codeRef, - @Nullable final Date startTime) { + protected StartTestItemRQ buildStartStoryRq(@Nonnull Story story, @Nonnull String codeRef, @Nullable final Date startTime) { StartTestItemRQ rq = new StartTestItemRQ(); rq.setName(getStoryName(story)); rq.setCodeRef(codeRef); @@ -219,8 +216,7 @@ protected Set getAttributes(@Nonnull final Scenario scenario) * @return Request to ReportPortal */ @Nonnull - protected StartTestItemRQ buildStartScenarioRq(@Nonnull Scenario scenario, @Nonnull String codeRef, - @Nullable final Date startTime) { + protected StartTestItemRQ buildStartScenarioRq(@Nonnull Scenario scenario, @Nonnull String codeRef, @Nullable final Date startTime) { StartTestItemRQ rq = new StartTestItemRQ(); rq.setName(getScenarioName(scenario)); rq.setCodeRef(codeRef); @@ -241,10 +237,7 @@ protected String formatExampleName(@Nonnull final Map example) { 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 - )) + .collect(Collectors.joining(EXAMPLE_PARAMETER_DELIMITER, CODE_REFERENCE_ITEM_START, CODE_REFERENCE_ITEM_END)) ); } @@ -319,9 +312,7 @@ protected String formatExampleStep(@Nonnull final String step, @Nullable final M } String result = step; for (Map.Entry e : example.entrySet()) { - result = result.replaceAll(String.format(EXAMPLE_VALUE_PATTERN, e.getKey()), - Matcher.quoteReplacement(e.getValue()) - ); + result = result.replaceAll(String.format(EXAMPLE_VALUE_PATTERN, e.getKey()), Matcher.quoteReplacement(e.getValue())); } return result; } @@ -361,8 +352,7 @@ protected StartTestItemRQ buildStartStepRq(@Nonnull final String step, @Nonnull .collect(Collectors.toList())); usedParams.ifPresent(rq::setParameters); rq.setTestCaseId(ofNullable(getTestCaseId(codeRef, - usedParams.map(p -> p.stream().map(ParameterResource::getValue).collect(Collectors.toList())) - .orElse(null) + usedParams.map(p -> p.stream().map(ParameterResource::getValue).collect(Collectors.toList())).orElse(null) )).map(TestCaseIdEntry::getId).orElse(null)); return rq; } @@ -475,26 +465,23 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { Optional.empty() : Optional.of(leafChain.get(leafChain.size() - 1)); final TestItemTree.TestItemLeaf parentLeaf = parent.map(Pair::getValue).orElse(null); - final Map children = parent.map(p -> p.getValue() - .getChildItems()).orElseGet(itemTree::getTestItems); + final Map children = parent.map(p -> p.getValue().getChildItems()) + .orElseGet(itemTree::getTestItems); final String parentCodeRef = parent.map(p -> (String) p.getValue().getAttribute(CODE_REF)).orElse(null); Date itemDate = getItemDate(parent.map(Pair::getValue).orElse(null)); switch (itemType) { case STORY: Story story = (Story) entity.get(); TestItemTree.ItemTreeKey storyKey = ItemTreeUtils.createKey(story); - leafChain.add(ImmutablePair.of(storyKey, - children.computeIfAbsent(storyKey, k -> createLeaf(ItemType.STORY, - buildStartStoryRq(story, getCodeRef(parentCodeRef, k, ItemType.STORY), itemDate), - parentLeaf - )) - )); + leafChain.add(ImmutablePair.of(storyKey, children.computeIfAbsent(storyKey, k -> createLeaf(ItemType.STORY, + buildStartStoryRq(story, getCodeRef(parentCodeRef, k, ItemType.STORY), itemDate), + parentLeaf + )))); break; case SCENARIO: Scenario scenario = (Scenario) entity.get(); TestItemTree.ItemTreeKey scenarioKey = ItemTreeUtils.createKey(getScenarioName(scenario)); - leafChain.add(ImmutablePair.of(scenarioKey, children.computeIfAbsent(scenarioKey, k -> createLeaf( - ItemType.SCENARIO, + leafChain.add(ImmutablePair.of(scenarioKey, children.computeIfAbsent(scenarioKey, k -> createLeaf(ItemType.SCENARIO, buildStartScenarioRq(scenario, getCodeRef(parentCodeRef, k, ItemType.SCENARIO), itemDate), parentLeaf )))); @@ -514,16 +501,13 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { case TEST: // type TEST == a lifecycle SUITE String lifecycleSuiteName = (String) entity.get(); TestItemTree.ItemTreeKey lifecycleSuiteKey = ItemTreeUtils.createKey(lifecycleSuiteName); - leafChain.add(ImmutablePair.of(lifecycleSuiteKey, - children.computeIfAbsent(lifecycleSuiteKey, k -> createLeaf(itemType, - buildLifecycleSuiteStartRq(lifecycleSuiteName, itemDate), - parentLeaf - )) - )); + leafChain.add(ImmutablePair.of(lifecycleSuiteKey, children.computeIfAbsent(lifecycleSuiteKey, + k -> createLeaf(itemType, buildLifecycleSuiteStartRq(lifecycleSuiteName, itemDate), parentLeaf) + ))); break; } } - return leafChain.get(leafChain.size() - 1).getValue(); + return leafChain.isEmpty() ? null : leafChain.get(leafChain.size() - 1).getValue(); } /** @@ -576,20 +560,13 @@ protected TestItemTree.TestItemLeaf getLeaf() { * @param parent a parent test item leaf * @return the step leaf */ - protected TestItemTree.TestItemLeaf startStep(@Nonnull final String name, - @Nonnull final TestItemTree.TestItemLeaf parent) { + protected TestItemTree.TestItemLeaf startStep(@Nonnull final String name, @Nonnull final TestItemTree.TestItemLeaf parent) { TestItemTree.ItemTreeKey key = ItemTreeUtils.createKey(name); - StartTestItemRQ rq = buildStartStepRq(name, + TestItemTree.TestItemLeaf leaf = createLeaf(ItemType.STEP, buildStartStepRq(name, getCodeRef(parent.getAttribute(CODE_REF), key, ItemType.STEP), parent.getAttribute(PARAMETERS), getItemDate(parent) - ); - // Workaround for JBehave 5 to report Lifecycle methods correctly - rq.setHasStats(ItemType.STORY.name() - .equals((ofNullable(parent.getAttribute(START_REQUEST)).map(r -> (StartTestItemRQ) r) - .map(StartTestItemRQ::getType) - .orElse(null)))); - TestItemTree.TestItemLeaf leaf = createLeaf(ItemType.STEP, rq, parent); + ), parent); parent.getChildItems().put(key, leaf); return leaf; } @@ -603,13 +580,10 @@ protected TestItemTree.TestItemLeaf startStep(@Nonnull final String name, * @return the step leaf */ @Nonnull - protected TestItemTree.TestItemLeaf startLifecycleMethod(@Nonnull final String name, - @Nonnull final ItemType itemType, @Nonnull final TestItemTree.TestItemLeaf parent) { + protected TestItemTree.TestItemLeaf startLifecycleMethod(@Nonnull final String name, @Nonnull final ItemType itemType, + @Nonnull final TestItemTree.TestItemLeaf parent) { TestItemTree.ItemTreeKey key = ItemTreeUtils.createKey(name); - TestItemTree.TestItemLeaf leaf = createLeaf(itemType, - buildLifecycleMethodStartRq(itemType, name, getItemDate(parent)), - parent - ); + TestItemTree.TestItemLeaf leaf = createLeaf(itemType, buildLifecycleMethodStartRq(itemType, name, getItemDate(parent)), parent); parent.getChildItems().put(key, leaf); return leaf; } @@ -624,8 +598,8 @@ protected TestItemTree.TestItemLeaf startLifecycleMethod(@Nonnull final String n */ @SuppressWarnings("unused") @Nonnull - protected FinishTestItemRQ buildFinishTestItemRequest(@Nonnull final Maybe id, - @Nullable final ItemStatus status, @Nullable Issue issue) { + protected FinishTestItemRQ buildFinishTestItemRequest(@Nonnull final Maybe id, @Nullable final ItemStatus status, + @Nullable Issue issue) { FinishTestItemRQ rq = new FinishTestItemRQ(); rq.setEndTime(Calendar.getInstance().getTime()); rq.setStatus(ofNullable(status).map(Enum::name).orElse(null)); @@ -670,8 +644,7 @@ protected void finishLastItem(@Nullable final ItemStatus status) { * @see StatusEvaluation#evaluateStatus(ItemStatus, ItemStatus) */ @Nullable - protected ItemStatus evaluateStatus(@Nullable final ItemStatus currentStatus, - @Nullable final ItemStatus childStatus) { + protected ItemStatus evaluateStatus(@Nullable final ItemStatus currentStatus, @Nullable final ItemStatus childStatus) { return StatusEvaluation.evaluateStatus(currentStatus, childStatus); } @@ -702,8 +675,7 @@ protected void evaluateAndFinishLastItem() { * @return a {@link SaveLogRQ} supplier {@link Function} */ @Nonnull - protected Function getLogSupplier(@Nonnull final LogLevel level, - @Nullable final String message) { + protected Function getLogSupplier(@Nonnull final LogLevel level, @Nullable final String message) { return itemUuid -> { SaveLogRQ rq = new SaveLogRQ(); rq.setItemUuid(itemUuid); @@ -722,9 +694,7 @@ protected Function getLogSupplier(@Nonnull final LogLevel lev * @param thrown {@link Throwable} object with details of the failure */ protected void sendStackTraceToRP(@Nonnull Maybe itemId, @Nullable final Throwable thrown) { - ofNullable(thrown).ifPresent(t -> ReportPortal.emitLog(itemId, - getLogSupplier(LogLevel.ERROR, ExceptionUtils.getStackTrace(t)) - )); + ofNullable(thrown).ifPresent(t -> ReportPortal.emitLog(itemId, getLogSupplier(LogLevel.ERROR, ExceptionUtils.getStackTrace(t)))); } /** @@ -734,14 +704,12 @@ protected void sendStackTraceToRP(@Nonnull Maybe itemId, @Nullable final * @param status a status of the item which will be set * @param issue an optional issue which will be set */ - protected void finishItem(final @Nonnull Maybe id, final @Nonnull ItemStatus status, - @Nullable Issue issue) { + protected void finishItem(final @Nonnull Maybe id, final @Nonnull ItemStatus status, @Nullable Issue issue) { FinishTestItemRQ rq = buildFinishTestItemRequest(id, status, issue); launch.get().finishTestItem(id, rq); } - private void finishStep(final @Nonnull TestItemTree.TestItemLeaf step, final @Nonnull ItemStatus status, - @Nullable Issue issue) { + private void finishStep(final @Nonnull TestItemTree.TestItemLeaf step, final @Nonnull ItemStatus status, @Nullable Issue issue) { finishItem(step.getItemId(), status, issue); step.setStatus(status); } @@ -782,12 +750,7 @@ protected void createNotPerformedSteps(@Nullable String step, @Nonnull TestItemT @SuppressWarnings("unused") protected void createPendingSteps(@Nullable String step, @Nonnull TestItemTree.TestItemLeaf leaf) { ReportPortal.emitLog(leaf.getItemId(), - getLogSupplier( - LogLevel.WARN, - String.format("Unable to locate a step implementation: '%s'", - StringEscapeUtils.escapeHtml4(step) - ) - ) + getLogSupplier(LogLevel.WARN, String.format("Unable to locate a step implementation: '%s'", step)) ); } @@ -847,6 +810,7 @@ public void beforeScenario(@Nonnull Scenario scenario) { /** * Finishes scenario in ReportPortal */ + @Override public void afterScenario(Timing timing) { TestItemTree.TestItemLeaf previousItem = getLeaf(); if (previousItem != null && previousItem.getType() == ItemType.TEST) { @@ -856,39 +820,19 @@ public void afterScenario(Timing timing) { evaluateAndFinishLastItem(); } - /** - * Finishes scenario in ReportPortal - * - * @deprecated use {@link #afterScenario(Timing)} along with JBehave 5.0 - */ - @Deprecated - public void afterScenario() { - afterScenario(null); - } - /** * Starts step in ReportPortal (TestStep level) * * @param step Step to be reported */ + @Override public void beforeStep(@Nonnull Step step) { - beforeStep(step.getStepAsString()); - } - - /** - * Starts step in ReportPortal (TestStep level) - * - * @param step Step to be reported - * @deprecated use {@link #beforeStep(Step)} along with JBehave 5.0 - */ - @Deprecated - public void beforeStep(@Nonnull String step) { TestItemTree.TestItemLeaf previousItem = getLeaf(); if (previousItem != null && previousItem.getType() == ItemType.TEST) { evaluateAndFinishLastItem(); } currentLifecycleItemType = ItemType.BEFORE_METHOD; - TestItemTree.TestItemLeaf stepLeaf = ofNullable(retrieveLeaf()).map(l -> startStep(step, l)).orElse(null); + TestItemTree.TestItemLeaf stepLeaf = ofNullable(retrieveLeaf()).map(l -> startStep(step.getStepAsString(), l)).orElse(null); stepStack.add(stepLeaf); if (stepLeaf != null) { lastStep = stepLeaf; @@ -903,8 +847,7 @@ public void beforeExamples(List steps, ExamplesTable table) { @Override public void example(Map tableRow, int exampleIndex) { TestItemTree.TestItemLeaf previousItem = getLeaf(); - if (previousItem != null && (previousItem.getType() == ItemType.TEST - || previousItem.getType() == ItemType.SUITE)) { + if (previousItem != null && (previousItem.getType() == ItemType.TEST || previousItem.getType() == ItemType.SUITE)) { evaluateAndFinishLastItem(); } structure.add(new Entity<>(ItemType.SUITE, tableRow)); // type SUITE is used for Examples @@ -928,7 +871,7 @@ public void afterExamples() { @Override public void successful(String step) { currentLifecycleItemType = ItemType.AFTER_TEST; - ofNullable(stepStack.remove()).ifPresent(s -> finishStep(s, ItemStatus.PASSED)); + ofNullable(stepStack.pollLast()).ifPresent(s -> finishStep(s, ItemStatus.PASSED)); } /** @@ -939,25 +882,6 @@ public void successful(String step) { */ @Override public void failed(String step, Throwable cause) { - TestItemTree.TestItemLeaf item = retrieveLeaf(); - - // The next if is legacy code for JBehave versions < 5.0, where startStep wasn't called for Lifecycle methods - boolean isLifecycleMethod = item == null || stepStack.isEmpty(); - if (isLifecycleMethod) { - if (item == null) { - // failed @BeforeStories (annotated) methods - structure.add(new Entity<>(ItemType.TEST, - currentLifecycleItemType == null ? BEFORE_STORIES : AFTER_STORIES - )); - } else if (item.getType() == ItemType.STORY) { - // failed @BeforeStory, @BeforeScenario (annotated) methods - structure.add(new Entity<>(ItemType.TEST, - currentLifecycleItemType == ItemType.BEFORE_SUITE ? BEFORE_STORY : AFTER_STORY - )); - } - stepStack.add(ofNullable(item).map(i -> startLifecycleMethod(step, currentLifecycleItemType, i)) - .orElse(null)); - } ofNullable(stepStack.pollLast()).ifPresent(i -> { sendStackTraceToRP(i.getItemId(), cause); finishStep(i, ItemStatus.FAILED); @@ -971,27 +895,12 @@ public void failed(String step, Throwable cause) { */ @Override public void ignorable(String step) { - ofNullable(retrieveLeaf()).ifPresent(l -> { - TestItemTree.TestItemLeaf leaf = startStep(step, l); - createIgnoredSteps(step, leaf); - finishStep(leaf, ItemStatus.SKIPPED); + ofNullable(stepStack.pollLast()).ifPresent(i -> { + createIgnoredSteps(step, i); + finishStep(i, ItemStatus.SKIPPED); }); } - private TestItemTree.TestItemLeaf getOrCreateStepLeaf(@Nonnull String step, - @Nonnull TestItemTree.TestItemLeaf parentLeaf) { - Maybe parent = parentLeaf.getItemId(); - TestItemTree.TestItemLeaf lastStepLeaf = stepStack.pollLast(); - Maybe lastStepParent = ofNullable(lastStepLeaf).map(TestItemTree.TestItemLeaf::getParentId) - .orElse(null); - boolean stepStarted = lastStepLeaf != null && lastStepParent == parent && parentLeaf.getChildItems() - .containsKey(ItemTreeUtils.createKey(step)); - if (!stepStarted) { - return startStep(step, parentLeaf); - } - return lastStepLeaf; - } - /** * Report a not performed step * @@ -999,24 +908,21 @@ private TestItemTree.TestItemLeaf getOrCreateStepLeaf(@Nonnull String step, */ @Override public void notPerformed(String step) { - TestItemTree.TestItemLeaf item = retrieveLeaf(); - ofNullable(item).ifPresent(i -> { - TestItemTree.TestItemLeaf leaf = getOrCreateStepLeaf(step, i); - createNotPerformedSteps(step, leaf); - finishStep(leaf, ItemStatus.SKIPPED, Launch.NOT_ISSUE); + ofNullable(stepStack.pollLast()).ifPresent(i -> { + createNotPerformedSteps(step, i); + finishStep(i, ItemStatus.SKIPPED, Launch.NOT_ISSUE); }); } @Override public void pending(String step) { - TestItemTree.TestItemLeaf item = retrieveLeaf(); - ofNullable(item).ifPresent(i -> { - TestItemTree.TestItemLeaf leaf = getOrCreateStepLeaf(step, i); - createPendingSteps(step, leaf); - finishStep(leaf, ItemStatus.SKIPPED); + ofNullable(stepStack.pollLast()).ifPresent(i -> { + createPendingSteps(step, i); + finishStep(i, ItemStatus.SKIPPED); }); } + @Override public void scenarioExcluded(Scenario scenario, String filter) { if (null != scenario.getExamplesTable() && scenario.getExamplesTable().getRowCount() > 0) { beforeExamples(scenario.getSteps(), scenario.getExamplesTable()); @@ -1034,16 +940,6 @@ public void scenarioExcluded(Scenario scenario, String filter) { finishLastItem(ItemStatus.SKIPPED); } - /** - * @param scenario - JBehave's Scenario Object - * @param filter - Scenario filter - * @deprecated use {@link #scenarioExcluded(Scenario, String)} - */ - @Deprecated - public void scenarioNotAllowed(Scenario scenario, String filter) { - scenarioExcluded(scenario, filter); - } - protected static class Entity { private final ItemType type; From 5ac5dfe13ba09057813b88e47472a9904e8d3952 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Thu, 10 Nov 2022 17:05:03 +0300 Subject: [PATCH 14/32] Revert tests to update them again without JBehave 4 in mind --- .../epam/reportportal/jbehave/BaseTest.java | 12 --- .../jbehave/CallbackReportingTest.java | 16 +--- .../basic/CallbackReportingSteps.java | 41 +++------- .../basic/NestedStepsStepReporterSteps.java | 22 +++--- .../BeforeScenarioAnnotationFailedTest.java | 18 +---- ...=> VerifyBeforeStoryAnnotationFailed.java} | 78 +++++++------------ .../steps/NestedStepsStepReporterTest.java | 63 ++++++++++----- 7 files changed, 104 insertions(+), 146 deletions(-) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{BeforeStoryAnnotationFailedTest.java => VerifyBeforeStoryAnnotationFailed.java} (63%) diff --git a/src/test/java/com/epam/reportportal/jbehave/BaseTest.java b/src/test/java/com/epam/reportportal/jbehave/BaseTest.java index 76eb494..1987f18 100644 --- a/src/test/java/com/epam/reportportal/jbehave/BaseTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/BaseTest.java @@ -73,18 +73,6 @@ public class BaseTest { public static final String ROOT_SUITE_PREFIX = "root_"; - public static final boolean IS_JBEHAVE_5; - static { - boolean isJbehave5; - try { - Class.forName("org.jbehave.core.model.Step"); - isJbehave5 = true; - } catch (ClassNotFoundException ignore) { - isJbehave5 = false; - } - IS_JBEHAVE_5 = isJbehave5; - } - public static ExecutorService testExecutor() { return Executors.newSingleThreadExecutor(r -> { Thread t = new Thread(r); diff --git a/src/test/java/com/epam/reportportal/jbehave/CallbackReportingTest.java b/src/test/java/com/epam/reportportal/jbehave/CallbackReportingTest.java index f1c6961..8c30cef 100644 --- a/src/test/java/com/epam/reportportal/jbehave/CallbackReportingTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/CallbackReportingTest.java @@ -74,11 +74,7 @@ public void callback_reporting_test() { ArgumentCaptor idCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor rqCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - if(IS_JBEHAVE_5) { - verify(client, times(9)).finishTestItem(idCaptor.capture(), rqCaptor.capture()); - } else { - verify(client, times(7)).finishTestItem(idCaptor.capture(), rqCaptor.capture()); - } + verify(client, times(7)).finishTestItem(idCaptor.capture(), rqCaptor.capture()); // Start test class and test method ArgumentCaptor saveLogRQArgumentCaptor = ArgumentCaptor.forClass(SaveLogRQ.class); verify(client, times(1)).log(saveLogRQArgumentCaptor.capture()); @@ -97,13 +93,9 @@ public void callback_reporting_test() { List> secondScenarioIds = idRqs.stream() .filter(e -> stepIds.get(1).equals(e.getKey())) .collect(Collectors.toList()); - if(IS_JBEHAVE_5) { - assertThat(firstScenarioIds, hasSize(3)); - assertThat(secondScenarioIds, hasSize(3)); - } else { - assertThat(firstScenarioIds, hasSize(2)); - assertThat(secondScenarioIds, hasSize(2)); - } + + assertThat(firstScenarioIds, hasSize(2)); + assertThat(secondScenarioIds, hasSize(2)); List> failureUpdates = firstScenarioIds.stream() .filter(r -> "FAILED".equals(r.getValue().getStatus())) diff --git a/src/test/java/com/epam/reportportal/jbehave/integration/basic/CallbackReportingSteps.java b/src/test/java/com/epam/reportportal/jbehave/integration/basic/CallbackReportingSteps.java index ebd53d5..f06bbd1 100644 --- a/src/test/java/com/epam/reportportal/jbehave/integration/basic/CallbackReportingSteps.java +++ b/src/test/java/com/epam/reportportal/jbehave/integration/basic/CallbackReportingSteps.java @@ -16,8 +16,10 @@ package com.epam.reportportal.jbehave.integration.basic; -import com.epam.reportportal.jbehave.*; -import com.epam.reportportal.jbehave.util.ItemTreeUtils; +import com.epam.reportportal.jbehave.ReportPortalFormat; +import com.epam.reportportal.jbehave.ReportPortalStepFormat; +import com.epam.reportportal.jbehave.ReportPortalStepStoryReporter; +import com.epam.reportportal.jbehave.ReportPortalStoryReporter; import com.epam.reportportal.listeners.ItemStatus; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.tree.ItemTreeReporter; @@ -28,7 +30,6 @@ import org.jbehave.core.annotations.AfterScenario; import org.jbehave.core.annotations.Given; -import javax.annotation.Nonnull; import java.util.Calendar; import java.util.Optional; @@ -52,27 +53,14 @@ public void after() { reporter.flatMap(ReportPortalStoryReporter::getLastStep).ifPresent(itemLeaf -> { TestItemTree.TestItemLeaf scenario = itemLeaf.getAttribute(ReportPortalStepStoryReporter.PARENT); - TestItemTree.TestItemLeaf stepLeaf; - if (BaseTest.IS_JBEHAVE_5) { - // For JBehave 5 the item will be `after` method, so we need to find actual step - stepLeaf = ofNullable(scenario).map(TestItemTree.TestItemLeaf::getChildItems) - .map(c -> c.get(ItemTreeUtils.createKey("Given " + STEP_TEXT))) - .orElse(null); - } else { - stepLeaf = itemLeaf; - } if (ofNullable(scenario).isPresent()) { String scenarioName = ofNullable((StartTestItemRQ) scenario.getAttribute(ReportPortalStepStoryReporter.START_REQUEST)).map( - StartTestItemRQ::getName) - .orElseThrow(() -> new IllegalStateException("Unable to get start item request")); - + StartTestItemRQ::getName).orElseThrow(() -> new IllegalStateException("Unable to get start item request")); if (scenarioName.contains("failure")) { - ofNullable(stepLeaf).ifPresent(l -> { - finishWithStatus(rp, tree, "FAILED", l); - attachLog(rp, tree, l); - }); + finishWithStatus(rp, tree, "FAILED", itemLeaf); + attachLog(rp, tree, itemLeaf); } else { - ofNullable(stepLeaf).ifPresent(l -> finishWithStatus(rp, tree, "PASSED", stepLeaf)); + finishWithStatus(rp, tree, "PASSED", itemLeaf); } } else { throw new IllegalStateException("Unable to find parent item"); @@ -80,22 +68,17 @@ public void after() { }); } - private void finishWithStatus(@Nonnull ReportPortal rp, @Nonnull TestItemTree tree, @Nonnull String status, - @Nonnull TestItemTree.TestItemLeaf testItemLeaf) { + private void finishWithStatus(ReportPortal rp, TestItemTree tree, String status, TestItemTree.TestItemLeaf testItemLeaf) { FinishTestItemRQ finishTestItemRQ = new FinishTestItemRQ(); finishTestItemRQ.setStatus(status); finishTestItemRQ.setEndTime(Calendar.getInstance().getTime()); //noinspection ResultOfMethodCallIgnored - ItemTreeReporter.finishItem(rp.getClient(), finishTestItemRQ, tree.getLaunchId(), testItemLeaf) - .cache() - .blockingGet(); + ItemTreeReporter.finishItem(rp.getClient(), finishTestItemRQ, tree.getLaunchId(), testItemLeaf).cache().blockingGet(); testItemLeaf.setStatus(ItemStatus.valueOf(status)); } - private void attachLog(@Nonnull ReportPortal rp, @Nonnull TestItemTree tree, - @Nonnull TestItemTree.TestItemLeaf testItemLeaf) { - ItemTreeReporter.sendLog( - rp.getClient(), + private void attachLog(ReportPortal rp, TestItemTree tree, TestItemTree.TestItemLeaf testItemLeaf) { + ItemTreeReporter.sendLog(rp.getClient(), "ERROR", "Error message", Calendar.getInstance().getTime(), diff --git a/src/test/java/com/epam/reportportal/jbehave/integration/basic/NestedStepsStepReporterSteps.java b/src/test/java/com/epam/reportportal/jbehave/integration/basic/NestedStepsStepReporterSteps.java index dc06fc0..5073e64 100644 --- a/src/test/java/com/epam/reportportal/jbehave/integration/basic/NestedStepsStepReporterSteps.java +++ b/src/test/java/com/epam/reportportal/jbehave/integration/basic/NestedStepsStepReporterSteps.java @@ -19,7 +19,6 @@ import com.epam.reportportal.listeners.ItemStatus; import com.epam.reportportal.service.Launch; import com.epam.reportportal.service.step.StepReporter; -import com.epam.reportportal.util.test.CommonUtils; import org.jbehave.core.annotations.Given; import org.jbehave.core.annotations.Then; import org.slf4j.Logger; @@ -27,6 +26,8 @@ import java.io.File; +import static java.util.Optional.ofNullable; + public class NestedStepsStepReporterSteps { private static final Logger LOGGER = LoggerFactory.getLogger(NestedStepsStepReporterSteps.class); public static final String FIRST_NAME = "I am the first nested step"; @@ -37,28 +38,29 @@ public class NestedStepsStepReporterSteps { public static final String THIRD_NESTED_STEP_LOG = "Third error log of the second step"; public static final String DURING_SECOND_NESTED_STEP_LOG = "A log entry during the first nested step report"; + private static final IllegalStateException NO_LAUNCH_EXCEPTION = new IllegalStateException("Unable to get Launch"); + + @SuppressWarnings("unused") @Given("a step with a manual step") - public void i_have_a_step_with_a_manual_step() throws InterruptedException { - StepReporter stepReporter = Launch.currentLaunch().getStepReporter(); + public void i_have_a_step_with_a_manual_step() { + StepReporter stepReporter = ofNullable(Launch.currentLaunch()).map(Launch::getStepReporter) + .orElseThrow(() -> NO_LAUNCH_EXCEPTION); stepReporter.sendStep(FIRST_NAME); - Thread.sleep(CommonUtils.MINIMAL_TEST_PAUSE); LOGGER.info(FIRST_NESTED_STEP_LOG); - Thread.sleep(CommonUtils.MINIMAL_TEST_PAUSE); } + @SuppressWarnings("unused") @Then("a step with two manual steps") - public void i_have_a_step_with_two_manual_steps() throws InterruptedException { - StepReporter stepReporter = Launch.currentLaunch().getStepReporter(); + public void i_have_a_step_with_two_manual_steps() { + StepReporter stepReporter = ofNullable(Launch.currentLaunch()).map(Launch::getStepReporter) + .orElseThrow(() -> NO_LAUNCH_EXCEPTION); stepReporter.sendStep(SECOND_NAME, DURING_SECOND_NESTED_STEP_LOG); - Thread.sleep(CommonUtils.MINIMAL_TEST_PAUSE); LOGGER.info(SECOND_NESTED_STEP_LOG); stepReporter.sendStep(ItemStatus.FAILED, THIRD_NAME, new File("pug/unlucky.jpg")); - Thread.sleep(CommonUtils.MINIMAL_TEST_PAUSE); LOGGER.error(THIRD_NESTED_STEP_LOG); - Thread.sleep(CommonUtils.MINIMAL_TEST_PAUSE); } } diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java index 2757ec4..a4ec620 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java @@ -68,7 +68,6 @@ public void setupMock() { private static final String STORY_PATH = "stories/NoScenario.story"; private static final String DEFAULT_SCENARIO_NAME = "No name"; - private static final String BEFORE_SCENARIO_METHOD_NAME = "beforeScenarioFailed"; private static final String STEP_NAME = "Given I have empty step"; @Test @@ -89,19 +88,10 @@ public void verify_before_scenario_annotation_failed_method_reporting() { assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); StartTestItemRQ beforeStep = startItems.get(1); - - if (IS_JBEHAVE_5) { - String beforeStepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", BEFORE_SCENARIO_METHOD_NAME); - assertThat("BeforeScenario name invalid", beforeStep.getName(), equalTo(BEFORE_SCENARIO_METHOD_NAME)); - assertThat("BeforeScenario code reference invalid", beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); - assertThat(beforeStep.getType(), equalTo(ItemType.STEP.name())); - } else { - String beforeStepCodeRef = - BeforeScenarioFailedSteps.class.getCanonicalName() + "." + BEFORE_SCENARIO_METHOD_NAME + "()"; - assertThat("BeforeScenario name invalid", beforeStep.getName(), equalTo(beforeStepCodeRef)); - assertThat("BeforeScenario code reference invalid", beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); - assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_TEST.name())); - } + String beforeStepCodeRef = BeforeScenarioFailedSteps.class.getCanonicalName() + ".beforeScenarioFailed()"; + assertThat(beforeStep.getName(), equalTo(beforeStepCodeRef)); + assertThat(beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); + assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_TEST.name())); StartTestItemRQ step = startItems.get(2); String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryAnnotationFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryAnnotationFailed.java similarity index 63% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryAnnotationFailedTest.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryAnnotationFailed.java index fbe33b2..e1cfb55 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryAnnotationFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryAnnotationFailed.java @@ -42,7 +42,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class BeforeStoryAnnotationFailedTest extends BaseTest { +public class VerifyBeforeStoryAnnotationFailed extends BaseTest { private final String storyId = CommonUtils.namedId("story_"); private final String beforeStoryId = CommonUtils.namedId("before_story_"); @@ -50,10 +50,7 @@ public class BeforeStoryAnnotationFailedTest extends BaseTest { private final String scenarioId = CommonUtils.namedId("scenario_"); private final String stepId = CommonUtils.namedId("step_"); - private final List>> steps = Arrays.asList(Pair.of( - beforeStoryId, - Collections.singletonList(beforeStepId) - ), + private final List>> steps = Arrays.asList(Pair.of(beforeStoryId, Collections.singletonList(beforeStepId)), Pair.of(scenarioId, Collections.singletonList(stepId)) ); @@ -72,53 +69,37 @@ public void setupMock() { private static final String STORY_PATH = "stories/NoScenario.story"; private static final String DEFAULT_SCENARIO_NAME = "No name"; private static final String STEP_NAME = "Given I have empty step"; - private static final String BEFORE_STORY_NAME = "beforeStoryFailed"; @Test public void verify_before_story_annotation_failed_method_reporting() { run(format, STORY_PATH, new BeforeStoryFailedSteps(), new EmptySteps()); verify(client).startTestItem(any()); - ArgumentCaptor storyLevelCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(2)).startTestItem(same(storyId), storyLevelCaptor.capture()); - ArgumentCaptor beforeLevelCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - if (!IS_JBEHAVE_5) { - verify(client).startTestItem(same(beforeStoryId), beforeLevelCaptor.capture()); - } - ArgumentCaptor scenarioLevelCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client).startTestItem(same(scenarioId), scenarioLevelCaptor.capture()); + ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(2)).startTestItem(same(storyId), startCaptor.capture()); + verify(client).startTestItem(same(beforeStoryId), startCaptor.capture()); + verify(client).startTestItem(same(scenarioId), startCaptor.capture()); // Start items verification - List storyStartItems = storyLevelCaptor.getAllValues(); - StartTestItemRQ beforeStoryStart = storyStartItems.get(0); - if (IS_JBEHAVE_5) { - assertThat(beforeStoryStart.getName(), equalTo(BEFORE_STORY_NAME)); - assertThat( - beforeStoryStart.getCodeRef(), - equalTo(STORY_PATH + String.format("/[STEP:%s]", BEFORE_STORY_NAME)) - ); - assertThat(beforeStoryStart.getType(), equalTo(ItemType.STEP.name())); - } else { - assertThat(beforeStoryStart.getName(), equalTo("BeforeStory")); - assertThat(beforeStoryStart.getCodeRef(), nullValue()); - assertThat(beforeStoryStart.getType(), equalTo(ItemType.TEST.name())); - } + List startItems = startCaptor.getAllValues(); + StartTestItemRQ beforeStoryStart = startItems.get(0); + assertThat(beforeStoryStart.getName(), equalTo("BeforeStory")); + assertThat(beforeStoryStart.getCodeRef(), nullValue()); + assertThat(beforeStoryStart.getType(), equalTo(ItemType.TEST.name())); String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME); - StartTestItemRQ scenarioStart = storyStartItems.get(1); + StartTestItemRQ scenarioStart = startItems.get(1); assertThat(scenarioStart.getName(), equalTo(DEFAULT_SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); - if(!IS_JBEHAVE_5) { - StartTestItemRQ beforeStep = beforeLevelCaptor.getValue(); - String beforeStepCodeRef = BeforeStoryFailedSteps.class.getCanonicalName() + ".beforeStoryFailed()"; - assertThat(beforeStep.getName(), equalTo(beforeStepCodeRef)); - assertThat(beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); - assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_SUITE.name())); - } + StartTestItemRQ beforeStep = startItems.get(2); + String beforeStepCodeRef = BeforeStoryFailedSteps.class.getCanonicalName() + ".beforeStoryFailed()"; + assertThat(beforeStep.getName(), equalTo(beforeStepCodeRef)); + assertThat(beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); + assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_SUITE.name())); - StartTestItemRQ step = scenarioLevelCaptor.getValue(); + StartTestItemRQ step = startItems.get(3); String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); @@ -126,32 +107,27 @@ public void verify_before_story_annotation_failed_method_reporting() { // Finish items verification ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - if(!IS_JBEHAVE_5) { - verify(client).finishTestItem(same(beforeStepId), finishStepCaptor.capture()); - } + verify(client).finishTestItem(same(beforeStepId), finishStepCaptor.capture()); verify(client).finishTestItem(same(stepId), finishStepCaptor.capture()); verify(client).finishTestItem(same(beforeStoryId), finishStepCaptor.capture()); verify(client).finishTestItem(same(scenarioId), finishStepCaptor.capture()); verify(client).finishTestItem(same(storyId), finishStepCaptor.capture()); List finishItems = finishStepCaptor.getAllValues(); - if(!IS_JBEHAVE_5) { - FinishTestItemRQ beforeStepFinish = finishItems.get(0); - assertThat(beforeStepFinish.getStatus(), equalTo(ItemStatus.FAILED.name())); - assertThat(beforeStepFinish.getIssue(), nullValue()); - finishItems = finishItems.subList(1, finishItems.size()); - } - - FinishTestItemRQ stepFinish = finishItems.get(0); + FinishTestItemRQ beforeStepFinish = finishItems.get(0); + assertThat(beforeStepFinish.getStatus(), equalTo(ItemStatus.FAILED.name())); + assertThat(beforeStepFinish.getIssue(), nullValue()); + + FinishTestItemRQ stepFinish = finishItems.get(1); assertThat(stepFinish.getStatus(), equalTo(ItemStatus.PASSED.name())); - FinishTestItemRQ beforeScenarioFinish = finishItems.get(1); + FinishTestItemRQ beforeScenarioFinish = finishItems.get(2); assertThat(beforeScenarioFinish.getStatus(), equalTo(ItemStatus.FAILED.name())); - FinishTestItemRQ scenarioFinish = finishItems.get(2); + FinishTestItemRQ scenarioFinish = finishItems.get(3); assertThat(scenarioFinish.getStatus(), equalTo(ItemStatus.PASSED.name())); - FinishTestItemRQ storyFinish = finishItems.get(3); + FinishTestItemRQ storyFinish = finishItems.get(4); assertThat(storyFinish.getStatus(), equalTo(ItemStatus.FAILED.name())); } } diff --git a/src/test/java/com/epam/reportportal/jbehave/steps/NestedStepsStepReporterTest.java b/src/test/java/com/epam/reportportal/jbehave/steps/NestedStepsStepReporterTest.java index 2640c55..e81b866 100644 --- a/src/test/java/com/epam/reportportal/jbehave/steps/NestedStepsStepReporterTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/steps/NestedStepsStepReporterTest.java @@ -33,8 +33,10 @@ import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; +import java.util.Collection; import java.util.List; import java.util.concurrent.ExecutorService; +import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; @@ -49,14 +51,17 @@ public class NestedStepsStepReporterTest extends BaseTest { private final String launchId = CommonUtils.namedId("launch_"); private final String suiteId = CommonUtils.namedId("suite_"); private final String testId = CommonUtils.namedId("test_"); - private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(2).collect(Collectors.toList()); + private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")) + .limit(2) + .collect(Collectors.toList()); // Step reporter private final List stepNestedStepIds = Stream.generate(() -> CommonUtils.namedId("step_")) .limit(3) .collect(Collectors.toList()); - private final List> stepNestedSteps = Stream.concat( - Stream.of(Pair.of(stepIds.get(0), stepNestedStepIds.get(0))), + private final List> stepNestedSteps = Stream.concat(Stream.of(Pair.of(stepIds.get(0), + stepNestedStepIds.get(0) + )), stepNestedStepIds.stream().skip(1).map(s -> Pair.of(stepIds.get(1), s)) ).collect(Collectors.toList()); @@ -79,10 +84,23 @@ private static void verifyStepStart(StartTestItemRQ step, String stepName) { assertThat(step.getType(), equalTo("STEP")); } - private static void verifyLogEntry(SaveLogRQ firstStepLog, String stepId, String duringSecondNestedStepLog) { - assertThat(firstStepLog.getItemUuid(), equalTo(stepId)); - assertThat(firstStepLog.getMessage(), containsString(duringSecondNestedStepLog)); - assertThat(firstStepLog.getFile(), nullValue()); + private static SaveLogRQ verifyLogEntry(Collection logs, String stepId, + Predicate messagePredicate) { + List wantedLogs = logs.stream() + .filter(l -> l.getMessage() != null && messagePredicate.test(l.getMessage())) + .collect(Collectors.toList()); + assertThat(wantedLogs, hasSize(1)); + SaveLogRQ log = wantedLogs.get(0); + assertThat(log.getItemUuid(), equalTo(stepId)); + return log; + } + + private static void verifyTextLogEntry(Collection logs, String stepId, String message) { + assertThat(verifyLogEntry(logs, stepId, m -> m.contains(message)).getFile(), nullValue()); + } + + private static void verifyFileLogEntry(Collection logs, String stepId) { + assertThat(verifyLogEntry(logs, stepId, m -> m.equals("")).getFile(), notNullValue()); } private static final String STORY_PATH = "stories/ManualStepReporter.story"; @@ -99,31 +117,40 @@ public void verify_step_reporter_steps_integrity() { verify(client, atLeastOnce()).log(logCaptor.capture()); StartTestItemRQ firstStep = firstStepCaptor.getValue(); List logEntries = filterLogs(logCaptor, rq -> !LogLevel.DEBUG.name().equals(rq.getLevel())); - SaveLogRQ firstStepLog = logEntries.get(0); + String firstStepId = stepNestedStepIds.get(0); + List firstStepLogs = logEntries.stream() + .filter(l -> firstStepId.equals(l.getItemUuid())) + .collect(Collectors.toList()); assertThat(logEntries, hasSize(5)); verifyStepStart(firstStep, NestedStepsStepReporterSteps.FIRST_NAME); - verifyLogEntry(firstStepLog, stepNestedStepIds.get(0), NestedStepsStepReporterSteps.FIRST_NESTED_STEP_LOG); + assertThat(firstStepLogs, hasSize(1)); + verifyTextLogEntry(firstStepLogs, firstStepId, NestedStepsStepReporterSteps.FIRST_NESTED_STEP_LOG); ArgumentCaptor secondStepCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client, times(2)).startTestItem(same(stepIds.get(1)), secondStepCaptor.capture()); List secondSteps = secondStepCaptor.getAllValues(); - List secondStepLogs = logEntries.subList(1, logEntries.size()); StartTestItemRQ secondStep = secondSteps.get(0); verifyStepStart(secondStep, NestedStepsStepReporterSteps.SECOND_NAME); - verifyLogEntry(secondStepLogs.get(0), stepNestedStepIds.get(1), NestedStepsStepReporterSteps.DURING_SECOND_NESTED_STEP_LOG); - verifyLogEntry(secondStepLogs.get(1), stepNestedStepIds.get(1), NestedStepsStepReporterSteps.SECOND_NESTED_STEP_LOG); + String secondStepId = stepNestedStepIds.get(1); + List secondStepLogs = logEntries.stream() + .filter(l -> secondStepId.equals(l.getItemUuid())) + .collect(Collectors.toList()); + assertThat(secondStepLogs, hasSize(2)); + verifyTextLogEntry(secondStepLogs, secondStepId, NestedStepsStepReporterSteps.DURING_SECOND_NESTED_STEP_LOG); + verifyTextLogEntry(secondStepLogs, secondStepId, NestedStepsStepReporterSteps.SECOND_NESTED_STEP_LOG); StartTestItemRQ thirdStep = secondSteps.get(1); verifyStepStart(thirdStep, NestedStepsStepReporterSteps.THIRD_NAME); + String thirdStepId = stepNestedStepIds.get(2); + List thirdStepLogs = logEntries.stream() + .filter(l -> thirdStepId.equals(l.getItemUuid())) + .collect(Collectors.toList()); + assertThat(thirdStepLogs, hasSize(2)); - SaveLogRQ pugLog = secondStepLogs.get(2); - assertThat(pugLog.getItemUuid(), equalTo(stepNestedStepIds.get(2))); - assertThat(pugLog.getMessage(), emptyString()); - assertThat(pugLog.getFile(), notNullValue()); - - verifyLogEntry(secondStepLogs.get(3), stepNestedStepIds.get(2), NestedStepsStepReporterSteps.THIRD_NESTED_STEP_LOG); + verifyFileLogEntry(thirdStepLogs, thirdStepId); + verifyTextLogEntry(thirdStepLogs, thirdStepId, NestedStepsStepReporterSteps.THIRD_NESTED_STEP_LOG); ArgumentCaptor finishIdCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor finishRqCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); From 79cfce7c29dd68597dd15a6b4848345b0e2a7a29 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 11 Nov 2022 15:06:38 +0300 Subject: [PATCH 15/32] Fix AfterStoryAnnotationFailedTest --- .../jbehave/ReportPortalStoryReporter.java | 112 +++++++++++++----- ...va => AfterStoryAnnotationFailedTest.java} | 8 +- 2 files changed, 87 insertions(+), 33 deletions(-) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyAfterStoryAnnotationFailed.java => AfterStoryAnnotationFailedTest.java} (95%) diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java index 5d53d51..75680d7 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java @@ -112,7 +112,8 @@ public Optional getLastStep() { * @param type an item type * @return a code reference string to identify every element of a story */ - private String getCodeRef(@Nullable final String parentCodeRef, @Nonnull final TestItemTree.ItemTreeKey key, ItemType type) { + private String getCodeRef(@Nullable final String parentCodeRef, @Nonnull final TestItemTree.ItemTreeKey key, + ItemType type) { StringBuilder sb = new StringBuilder(); if (isBlank(parentCodeRef)) { sb.append(key.getName()); @@ -174,7 +175,8 @@ protected Set getAttributes(@Nonnull final Story story) { * @return Request to ReportPortal */ @Nonnull - protected StartTestItemRQ buildStartStoryRq(@Nonnull Story story, @Nonnull String codeRef, @Nullable final Date startTime) { + protected StartTestItemRQ buildStartStoryRq(@Nonnull Story story, @Nonnull String codeRef, + @Nullable final Date startTime) { StartTestItemRQ rq = new StartTestItemRQ(); rq.setName(getStoryName(story)); rq.setCodeRef(codeRef); @@ -216,7 +218,8 @@ protected Set getAttributes(@Nonnull final Scenario scenario) * @return Request to ReportPortal */ @Nonnull - protected StartTestItemRQ buildStartScenarioRq(@Nonnull Scenario scenario, @Nonnull String codeRef, @Nullable final Date startTime) { + protected StartTestItemRQ buildStartScenarioRq(@Nonnull Scenario scenario, @Nonnull String codeRef, + @Nullable final Date startTime) { StartTestItemRQ rq = new StartTestItemRQ(); rq.setName(getScenarioName(scenario)); rq.setCodeRef(codeRef); @@ -237,7 +240,10 @@ protected String formatExampleName(@Nonnull final Map example) { 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)) + .collect(Collectors.joining(EXAMPLE_PARAMETER_DELIMITER, + CODE_REFERENCE_ITEM_START, + CODE_REFERENCE_ITEM_END + )) ); } @@ -312,7 +318,10 @@ protected String formatExampleStep(@Nonnull final String step, @Nullable final M } String result = step; for (Map.Entry e : example.entrySet()) { - result = result.replaceAll(String.format(EXAMPLE_VALUE_PATTERN, e.getKey()), Matcher.quoteReplacement(e.getValue())); + result = result.replaceAll( + String.format(EXAMPLE_VALUE_PATTERN, e.getKey()), + Matcher.quoteReplacement(e.getValue()) + ); } return result; } @@ -352,7 +361,8 @@ protected StartTestItemRQ buildStartStepRq(@Nonnull final String step, @Nonnull .collect(Collectors.toList())); usedParams.ifPresent(rq::setParameters); rq.setTestCaseId(ofNullable(getTestCaseId(codeRef, - usedParams.map(p -> p.stream().map(ParameterResource::getValue).collect(Collectors.toList())).orElse(null) + usedParams.map(p -> p.stream().map(ParameterResource::getValue).collect(Collectors.toList())) + .orElse(null) )).map(TestCaseIdEntry::getId).orElse(null)); return rq; } @@ -383,10 +393,10 @@ protected StartTestItemRQ buildLifecycleSuiteStartRq(@Nonnull final String name, */ @Nonnull protected StartTestItemRQ buildLifecycleMethodStartRq(@Nonnull final ItemType type, @Nonnull final String name, - @Nullable final Date startTime) { + @Nullable final String codeRef, @Nullable final Date startTime) { StartTestItemRQ rq = new StartTestItemRQ(); rq.setName(name); - rq.setCodeRef(name); + rq.setCodeRef(codeRef); rq.setStartTime(ofNullable(startTime).orElseGet(() -> Calendar.getInstance().getTime())); rq.setType(type.name()); return rq; @@ -465,23 +475,26 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { Optional.empty() : Optional.of(leafChain.get(leafChain.size() - 1)); final TestItemTree.TestItemLeaf parentLeaf = parent.map(Pair::getValue).orElse(null); - final Map children = parent.map(p -> p.getValue().getChildItems()) - .orElseGet(itemTree::getTestItems); + final Map children = parent.map(p -> p.getValue() + .getChildItems()).orElseGet(itemTree::getTestItems); final String parentCodeRef = parent.map(p -> (String) p.getValue().getAttribute(CODE_REF)).orElse(null); Date itemDate = getItemDate(parent.map(Pair::getValue).orElse(null)); switch (itemType) { case STORY: Story story = (Story) entity.get(); TestItemTree.ItemTreeKey storyKey = ItemTreeUtils.createKey(story); - leafChain.add(ImmutablePair.of(storyKey, children.computeIfAbsent(storyKey, k -> createLeaf(ItemType.STORY, - buildStartStoryRq(story, getCodeRef(parentCodeRef, k, ItemType.STORY), itemDate), - parentLeaf - )))); + leafChain.add(ImmutablePair.of(storyKey, + children.computeIfAbsent(storyKey, k -> createLeaf(ItemType.STORY, + buildStartStoryRq(story, getCodeRef(parentCodeRef, k, ItemType.STORY), itemDate), + parentLeaf + )) + )); break; case SCENARIO: Scenario scenario = (Scenario) entity.get(); TestItemTree.ItemTreeKey scenarioKey = ItemTreeUtils.createKey(getScenarioName(scenario)); - leafChain.add(ImmutablePair.of(scenarioKey, children.computeIfAbsent(scenarioKey, k -> createLeaf(ItemType.SCENARIO, + leafChain.add(ImmutablePair.of(scenarioKey, children.computeIfAbsent(scenarioKey, k -> createLeaf( + ItemType.SCENARIO, buildStartScenarioRq(scenario, getCodeRef(parentCodeRef, k, ItemType.SCENARIO), itemDate), parentLeaf )))); @@ -502,7 +515,10 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { String lifecycleSuiteName = (String) entity.get(); TestItemTree.ItemTreeKey lifecycleSuiteKey = ItemTreeUtils.createKey(lifecycleSuiteName); leafChain.add(ImmutablePair.of(lifecycleSuiteKey, children.computeIfAbsent(lifecycleSuiteKey, - k -> createLeaf(itemType, buildLifecycleSuiteStartRq(lifecycleSuiteName, itemDate), parentLeaf) + k -> createLeaf(itemType, + buildLifecycleSuiteStartRq(lifecycleSuiteName, itemDate), + parentLeaf + ) ))); break; } @@ -560,7 +576,8 @@ protected TestItemTree.TestItemLeaf getLeaf() { * @param parent a parent test item leaf * @return the step leaf */ - protected TestItemTree.TestItemLeaf startStep(@Nonnull final String name, @Nonnull final TestItemTree.TestItemLeaf parent) { + protected TestItemTree.TestItemLeaf startStep(@Nonnull final String name, + @Nonnull final TestItemTree.TestItemLeaf parent) { TestItemTree.ItemTreeKey key = ItemTreeUtils.createKey(name); TestItemTree.TestItemLeaf leaf = createLeaf(ItemType.STEP, buildStartStepRq(name, getCodeRef(parent.getAttribute(CODE_REF), key, ItemType.STEP), @@ -580,10 +597,15 @@ protected TestItemTree.TestItemLeaf startStep(@Nonnull final String name, @Nonnu * @return the step leaf */ @Nonnull - protected TestItemTree.TestItemLeaf startLifecycleMethod(@Nonnull final String name, @Nonnull final ItemType itemType, - @Nonnull final TestItemTree.TestItemLeaf parent) { + protected TestItemTree.TestItemLeaf startLifecycleMethod(@Nonnull final String name, + @Nonnull final ItemType itemType, @Nonnull final TestItemTree.TestItemLeaf parent) { TestItemTree.ItemTreeKey key = ItemTreeUtils.createKey(name); - TestItemTree.TestItemLeaf leaf = createLeaf(itemType, buildLifecycleMethodStartRq(itemType, name, getItemDate(parent)), parent); + String codeRef = getCodeRef(parent.getAttribute(CODE_REF), key, itemType); + TestItemTree.TestItemLeaf leaf = createLeaf( + itemType, + buildLifecycleMethodStartRq(itemType, name, codeRef, getItemDate(parent)), + parent + ); parent.getChildItems().put(key, leaf); return leaf; } @@ -598,8 +620,8 @@ protected TestItemTree.TestItemLeaf startLifecycleMethod(@Nonnull final String n */ @SuppressWarnings("unused") @Nonnull - protected FinishTestItemRQ buildFinishTestItemRequest(@Nonnull final Maybe id, @Nullable final ItemStatus status, - @Nullable Issue issue) { + protected FinishTestItemRQ buildFinishTestItemRequest(@Nonnull final Maybe id, + @Nullable final ItemStatus status, @Nullable Issue issue) { FinishTestItemRQ rq = new FinishTestItemRQ(); rq.setEndTime(Calendar.getInstance().getTime()); rq.setStatus(ofNullable(status).map(Enum::name).orElse(null)); @@ -644,7 +666,8 @@ protected void finishLastItem(@Nullable final ItemStatus status) { * @see StatusEvaluation#evaluateStatus(ItemStatus, ItemStatus) */ @Nullable - protected ItemStatus evaluateStatus(@Nullable final ItemStatus currentStatus, @Nullable final ItemStatus childStatus) { + protected ItemStatus evaluateStatus(@Nullable final ItemStatus currentStatus, + @Nullable final ItemStatus childStatus) { return StatusEvaluation.evaluateStatus(currentStatus, childStatus); } @@ -675,7 +698,8 @@ protected void evaluateAndFinishLastItem() { * @return a {@link SaveLogRQ} supplier {@link Function} */ @Nonnull - protected Function getLogSupplier(@Nonnull final LogLevel level, @Nullable final String message) { + protected Function getLogSupplier(@Nonnull final LogLevel level, + @Nullable final String message) { return itemUuid -> { SaveLogRQ rq = new SaveLogRQ(); rq.setItemUuid(itemUuid); @@ -694,7 +718,10 @@ protected Function getLogSupplier(@Nonnull final LogLevel lev * @param thrown {@link Throwable} object with details of the failure */ protected void sendStackTraceToRP(@Nonnull Maybe itemId, @Nullable final Throwable thrown) { - ofNullable(thrown).ifPresent(t -> ReportPortal.emitLog(itemId, getLogSupplier(LogLevel.ERROR, ExceptionUtils.getStackTrace(t)))); + ofNullable(thrown).ifPresent(t -> ReportPortal.emitLog( + itemId, + getLogSupplier(LogLevel.ERROR, ExceptionUtils.getStackTrace(t)) + )); } /** @@ -704,12 +731,14 @@ protected void sendStackTraceToRP(@Nonnull Maybe itemId, @Nullable final * @param status a status of the item which will be set * @param issue an optional issue which will be set */ - protected void finishItem(final @Nonnull Maybe id, final @Nonnull ItemStatus status, @Nullable Issue issue) { + protected void finishItem(final @Nonnull Maybe id, final @Nonnull ItemStatus status, + @Nullable Issue issue) { FinishTestItemRQ rq = buildFinishTestItemRequest(id, status, issue); launch.get().finishTestItem(id, rq); } - private void finishStep(final @Nonnull TestItemTree.TestItemLeaf step, final @Nonnull ItemStatus status, @Nullable Issue issue) { + private void finishStep(final @Nonnull TestItemTree.TestItemLeaf step, final @Nonnull ItemStatus status, + @Nullable Issue issue) { finishItem(step.getItemId(), status, issue); step.setStatus(status); } @@ -829,10 +858,34 @@ public void afterScenario(Timing timing) { public void beforeStep(@Nonnull Step step) { TestItemTree.TestItemLeaf previousItem = getLeaf(); if (previousItem != null && previousItem.getType() == ItemType.TEST) { + // Finish Before/After methods evaluateAndFinishLastItem(); } + TestItemTree.TestItemLeaf parentItem = retrieveLeaf(); + if (parentItem == null) { + // Before Stories + structure.add(new Entity<>( + ItemType.TEST, + currentLifecycleItemType == null ? BEFORE_STORIES : AFTER_STORIES + )); + } else if (parentItem.getType() == ItemType.STORY) { + // Before Story + structure.add(new Entity<>( + ItemType.TEST, + currentLifecycleItemType == ItemType.BEFORE_SUITE ? BEFORE_STORY : AFTER_STORY + )); + } + if (parentItem == null || parentItem.getType() == ItemType.STORY) { + ofNullable(retrieveLeaf()).map(i -> startLifecycleMethod( + step.getStepAsString(), + currentLifecycleItemType, + i + )).ifPresent(stepStack::add); + return; + } currentLifecycleItemType = ItemType.BEFORE_METHOD; - TestItemTree.TestItemLeaf stepLeaf = ofNullable(retrieveLeaf()).map(l -> startStep(step.getStepAsString(), l)).orElse(null); + TestItemTree.TestItemLeaf stepLeaf = ofNullable(retrieveLeaf()).map(l -> startStep(step.getStepAsString(), l)) + .orElse(null); stepStack.add(stepLeaf); if (stepLeaf != null) { lastStep = stepLeaf; @@ -847,7 +900,8 @@ public void beforeExamples(List steps, ExamplesTable table) { @Override public void example(Map tableRow, int exampleIndex) { TestItemTree.TestItemLeaf previousItem = getLeaf(); - if (previousItem != null && (previousItem.getType() == ItemType.TEST || previousItem.getType() == ItemType.SUITE)) { + if (previousItem != null && (previousItem.getType() == ItemType.TEST + || previousItem.getType() == ItemType.SUITE)) { evaluateAndFinishLastItem(); } structure.add(new Entity<>(ItemType.SUITE, tableRow)); // type SUITE is used for Examples diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStoryAnnotationFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java similarity index 95% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStoryAnnotationFailed.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java index 3ae6b1b..8532eee 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStoryAnnotationFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java @@ -42,7 +42,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyAfterStoryAnnotationFailed extends BaseTest { +public class AfterStoryAnnotationFailedTest extends BaseTest { private final String storyId = CommonUtils.namedId("story_"); private final String afterStoryId = CommonUtils.namedId("after_scenario_"); @@ -69,6 +69,7 @@ public void setupMock() { private static final String STORY_PATH = "stories/NoScenario.story"; private static final String DEFAULT_SCENARIO_NAME = "No name"; private static final String STEP_NAME = "Given I have empty step"; + private static final String AFTER_STORY_NAME = "afterStoryFailed"; @Test public void verify_after_story_annotation_failed_method_reporting() { @@ -100,9 +101,8 @@ public void verify_after_story_annotation_failed_method_reporting() { assertThat(step.getType(), equalTo(ItemType.STEP.name())); StartTestItemRQ afterStep = startItems.get(3); - String beforeStepCodeRef = AfterStoryFailedSteps.class.getCanonicalName() + ".afterStoryFailed()"; - assertThat(afterStep.getName(), equalTo(beforeStepCodeRef)); - assertThat(afterStep.getCodeRef(), equalTo(beforeStepCodeRef)); + assertThat(afterStep.getName(), equalTo(AFTER_STORY_NAME)); + assertThat(afterStep.getCodeRef(), equalTo(AFTER_STORY_NAME)); assertThat(afterStep.getType(), equalTo(ItemType.AFTER_SUITE.name())); // Finish items verification From db92c33a4874d4d4ca421945bdd9a0516d8bc707 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Fri, 11 Nov 2022 15:59:53 +0300 Subject: [PATCH 16/32] Fix BeforeScenarioAnnotationFailedTest --- .../jbehave/ReportPortalStoryReporter.java | 1 - .../lifecycle/BeforeScenarioAnnotationFailedTest.java | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java index 75680d7..64f4bec 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java @@ -883,7 +883,6 @@ public void beforeStep(@Nonnull Step step) { )).ifPresent(stepStack::add); return; } - currentLifecycleItemType = ItemType.BEFORE_METHOD; TestItemTree.TestItemLeaf stepLeaf = ofNullable(retrieveLeaf()).map(l -> startStep(step.getStepAsString(), l)) .orElse(null); stepStack.add(stepLeaf); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java index a4ec620..8d2787e 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java @@ -70,6 +70,8 @@ public void setupMock() { private static final String DEFAULT_SCENARIO_NAME = "No name"; private static final String STEP_NAME = "Given I have empty step"; + private static final String BEFORE_SCENARIO_NAME = "beforeScenarioFailed"; + @Test public void verify_before_scenario_annotation_failed_method_reporting() { run(format, STORY_PATH, new BeforeScenarioFailedSteps(), new EmptySteps()); @@ -88,10 +90,10 @@ public void verify_before_scenario_annotation_failed_method_reporting() { assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); StartTestItemRQ beforeStep = startItems.get(1); - String beforeStepCodeRef = BeforeScenarioFailedSteps.class.getCanonicalName() + ".beforeScenarioFailed()"; - assertThat(beforeStep.getName(), equalTo(beforeStepCodeRef)); - assertThat(beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); - assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_TEST.name())); + assertThat(beforeStep.getName(), equalTo(BEFORE_SCENARIO_NAME)); + String beforeCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", BEFORE_SCENARIO_NAME); + assertThat(beforeStep.getCodeRef(), equalTo(beforeCodeRef)); + assertThat(beforeStep.getType(), equalTo(ItemType.STEP.name())); StartTestItemRQ step = startItems.get(2); String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); From b1ce4924e3fc273d8f5bd14703f2a79190c8148d Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 14 Nov 2022 15:13:06 +0300 Subject: [PATCH 17/32] Fix AfterStoriesAnnotationFailedTest --- .../jbehave/ReportPortalStoryReporter.java | 66 ++++++++++++------- ... => AfterStoriesAnnotationFailedTest.java} | 30 +++------ 2 files changed, 53 insertions(+), 43 deletions(-) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyAfterStoriesAnnotationFailed.java => AfterStoriesAnnotationFailedTest.java} (82%) diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java index 64f4bec..c5778db 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java @@ -86,8 +86,10 @@ public abstract class ReportPortalStoryReporter extends NullStoryReporter { private final Deque stepStack = new LinkedList<>(); private final Supplier launch; private final TestItemTree itemTree; - private volatile ItemType currentLifecycleItemType; + private volatile TestItemTree.TestItemLeaf lastStep; + private static volatile String currentLifecycleTopItemType; + private volatile ItemType currentLifecycleItemType; public ReportPortalStoryReporter(final Supplier launchSupplier, TestItemTree testItemTree) { launch = launchSupplier; @@ -318,8 +320,7 @@ protected String formatExampleStep(@Nonnull final String step, @Nullable final M } String result = step; for (Map.Entry e : example.entrySet()) { - result = result.replaceAll( - String.format(EXAMPLE_VALUE_PATTERN, e.getKey()), + result = result.replaceAll(String.format(EXAMPLE_VALUE_PATTERN, e.getKey()), Matcher.quoteReplacement(e.getValue()) ); } @@ -514,12 +515,15 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { case TEST: // type TEST == a lifecycle SUITE String lifecycleSuiteName = (String) entity.get(); TestItemTree.ItemTreeKey lifecycleSuiteKey = ItemTreeUtils.createKey(lifecycleSuiteName); - leafChain.add(ImmutablePair.of(lifecycleSuiteKey, children.computeIfAbsent(lifecycleSuiteKey, - k -> createLeaf(itemType, - buildLifecycleSuiteStartRq(lifecycleSuiteName, itemDate), - parentLeaf + leafChain.add(ImmutablePair.of(lifecycleSuiteKey, + children.computeIfAbsent( + lifecycleSuiteKey, + k -> createLeaf(itemType, + buildLifecycleSuiteStartRq(lifecycleSuiteName, itemDate), + parentLeaf + ) ) - ))); + )); break; } } @@ -601,8 +605,7 @@ protected TestItemTree.TestItemLeaf startLifecycleMethod(@Nonnull final String n @Nonnull final ItemType itemType, @Nonnull final TestItemTree.TestItemLeaf parent) { TestItemTree.ItemTreeKey key = ItemTreeUtils.createKey(name); String codeRef = getCodeRef(parent.getAttribute(CODE_REF), key, itemType); - TestItemTree.TestItemLeaf leaf = createLeaf( - itemType, + TestItemTree.TestItemLeaf leaf = createLeaf(itemType, buildLifecycleMethodStartRq(itemType, name, codeRef, getItemDate(parent)), parent ); @@ -718,8 +721,7 @@ protected Function getLogSupplier(@Nonnull final LogLevel lev * @param thrown {@link Throwable} object with details of the failure */ protected void sendStackTraceToRP(@Nonnull Maybe itemId, @Nullable final Throwable thrown) { - ofNullable(thrown).ifPresent(t -> ReportPortal.emitLog( - itemId, + ofNullable(thrown).ifPresent(t -> ReportPortal.emitLog(itemId, getLogSupplier(LogLevel.ERROR, ExceptionUtils.getStackTrace(t)) )); } @@ -734,6 +736,7 @@ protected void sendStackTraceToRP(@Nonnull Maybe itemId, @Nullable final protected void finishItem(final @Nonnull Maybe id, final @Nonnull ItemStatus status, @Nullable Issue issue) { FinishTestItemRQ rq = buildFinishTestItemRequest(id, status, issue); + //noinspection ReactiveStreamsUnusedPublisher launch.get().finishTestItem(id, rq); } @@ -800,7 +803,8 @@ protected void simulateStep(@Nonnull String step) { */ @Override public void beforeStory(@Nonnull Story story, boolean givenStory) { - currentLifecycleItemType = AFTER_STORIES.equals(story.getName()) ? ItemType.AFTER_SUITE : ItemType.BEFORE_SUITE; + currentLifecycleTopItemType = AFTER_STORIES; + currentLifecycleItemType = ItemType.BEFORE_SUITE; structure.add(new Entity<>(ItemType.STORY, story)); } @@ -864,25 +868,28 @@ public void beforeStep(@Nonnull Step step) { TestItemTree.TestItemLeaf parentItem = retrieveLeaf(); if (parentItem == null) { // Before Stories - structure.add(new Entity<>( - ItemType.TEST, - currentLifecycleItemType == null ? BEFORE_STORIES : AFTER_STORIES + structure.add(new Entity<>(ItemType.TEST, + currentLifecycleTopItemType == null ? BEFORE_STORIES : currentLifecycleTopItemType )); } else if (parentItem.getType() == ItemType.STORY) { // Before Story - structure.add(new Entity<>( - ItemType.TEST, + structure.add(new Entity<>(ItemType.TEST, currentLifecycleItemType == ItemType.BEFORE_SUITE ? BEFORE_STORY : AFTER_STORY )); } if (parentItem == null || parentItem.getType() == ItemType.STORY) { - ofNullable(retrieveLeaf()).map(i -> startLifecycleMethod( - step.getStepAsString(), - currentLifecycleItemType, + //noinspection StringEquality + ofNullable(retrieveLeaf()).map(i -> startLifecycleMethod(step.getStepAsString(), + parentItem == null ? + currentLifecycleTopItemType == BEFORE_STORIES ? + ItemType.BEFORE_GROUPS : + ItemType.AFTER_GROUPS : + ItemType.BEFORE_SUITE, i )).ifPresent(stepStack::add); return; } + currentLifecycleItemType = ItemType.BEFORE_METHOD; TestItemTree.TestItemLeaf stepLeaf = ofNullable(retrieveLeaf()).map(l -> startStep(step.getStepAsString(), l)) .orElse(null); stepStack.add(stepLeaf); @@ -918,13 +925,24 @@ public void afterExamples() { evaluateAndFinishLastItem(); } + private void finishAfterSuites(TestItemTree.TestItemLeaf item) { + if (item.getType() == ItemType.AFTER_GROUPS) { + Entity parentSuite = structure.getLast(); + evaluateAndFinishLastItem(); // Finish parent suite + structure.add(parentSuite); + } + } + /** * Finishes step in ReportPortal */ @Override public void successful(String step) { currentLifecycleItemType = ItemType.AFTER_TEST; - ofNullable(stepStack.pollLast()).ifPresent(s -> finishStep(s, ItemStatus.PASSED)); + ofNullable(stepStack.pollLast()).ifPresent(s -> { + finishStep(s, ItemStatus.PASSED); + finishAfterSuites(s); + }); } /** @@ -938,6 +956,7 @@ public void failed(String step, Throwable cause) { ofNullable(stepStack.pollLast()).ifPresent(i -> { sendStackTraceToRP(i.getItemId(), cause); finishStep(i, ItemStatus.FAILED); + finishAfterSuites(i); }); } @@ -951,6 +970,7 @@ public void ignorable(String step) { ofNullable(stepStack.pollLast()).ifPresent(i -> { createIgnoredSteps(step, i); finishStep(i, ItemStatus.SKIPPED); + finishAfterSuites(i); }); } @@ -964,6 +984,7 @@ public void notPerformed(String step) { ofNullable(stepStack.pollLast()).ifPresent(i -> { createNotPerformedSteps(step, i); finishStep(i, ItemStatus.SKIPPED, Launch.NOT_ISSUE); + finishAfterSuites(i); }); } @@ -972,6 +993,7 @@ public void pending(String step) { ofNullable(stepStack.pollLast()).ifPresent(i -> { createPendingSteps(step, i); finishStep(i, ItemStatus.SKIPPED); + finishAfterSuites(i); }); } diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStoriesAnnotationFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java similarity index 82% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStoriesAnnotationFailed.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java index 22d104c..0d03083 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStoriesAnnotationFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java @@ -41,20 +41,19 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyAfterStoriesAnnotationFailed extends BaseTest { +public class AfterStoriesAnnotationFailedTest extends BaseTest { private final String storyId = CommonUtils.namedId("story_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final String stepId = CommonUtils.namedId("step_"); private final String afterStoriesId = CommonUtils.namedId("after_stories_"); - private final String afterStoryId = CommonUtils.namedId("after_story_"); private final String afterStepId = CommonUtils.namedId("after_story_step_"); private final List>> steps = Collections.singletonList(Pair.of(scenarioId, Collections.singletonList(stepId) )); - private final List>> afterSteps = Collections.singletonList(Pair.of(afterStoryId, + private final List>> afterSteps = Collections.singletonList(Pair.of(afterStoriesId, Collections.singletonList(afterStepId) )); @@ -75,6 +74,8 @@ public void setupMock() { private static final String DEFAULT_SCENARIO_NAME = "No name"; private static final String STEP_NAME = "Given I have empty step"; + private static final String AFTER_STORY_NAME = "afterStoriesFailed"; + @Test public void verify_before_story_annotation_failed_method_reporting() { run(format, STORY_PATH, new AfterStoriesFailedSteps(), new EmptySteps()); @@ -84,7 +85,6 @@ public void verify_before_story_annotation_failed_method_reporting() { verify(client).startTestItem(same(storyId), startCaptor.capture()); verify(client).startTestItem(same(scenarioId), startCaptor.capture()); verify(client).startTestItem(same(afterStoriesId), startCaptor.capture()); - verify(client).startTestItem(same(afterStoryId), startCaptor.capture()); // Start items verification List startItems = startCaptor.getAllValues(); @@ -95,8 +95,7 @@ public void verify_before_story_annotation_failed_method_reporting() { StartTestItemRQ afterStoriesStart = startItems.get(1); assertThat(afterStoriesStart.getName(), equalTo("AfterStories")); - assertThat(afterStoriesStart.getCodeRef(), equalTo("AfterStories")); - assertThat(afterStoriesStart.getType(), equalTo(ItemType.STORY.name())); + assertThat(afterStoriesStart.getType(), equalTo(ItemType.TEST.name())); String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME); StartTestItemRQ scenarioStart = startItems.get(2); @@ -110,16 +109,10 @@ public void verify_before_story_annotation_failed_method_reporting() { assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ afterStoryStart = startItems.get(4); - assertThat(afterStoryStart.getName(), equalTo("AfterStory")); - assertThat(afterStoryStart.getCodeRef(), nullValue()); - assertThat(afterStoryStart.getType(), equalTo(ItemType.TEST.name())); - - StartTestItemRQ afterStep = startItems.get(5); - String beforeStepCodeRef = AfterStoriesFailedSteps.class.getCanonicalName() + ".afterStoriesFailed()"; - assertThat(afterStep.getName(), equalTo(beforeStepCodeRef)); - assertThat(afterStep.getCodeRef(), equalTo(beforeStepCodeRef)); - assertThat(afterStep.getType(), equalTo(ItemType.AFTER_SUITE.name())); + StartTestItemRQ afterStep = startItems.get(4); + assertThat(afterStep.getName(), equalTo(AFTER_STORY_NAME)); + assertThat(afterStep.getCodeRef(), equalTo(AFTER_STORY_NAME)); + assertThat(afterStep.getType(), equalTo(ItemType.AFTER_GROUPS.name())); // Finish items verification ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); @@ -127,7 +120,6 @@ public void verify_before_story_annotation_failed_method_reporting() { verify(client).finishTestItem(same(scenarioId), finishStepCaptor.capture()); verify(client).finishTestItem(same(storyId), finishStepCaptor.capture()); verify(client).finishTestItem(same(afterStepId), finishStepCaptor.capture()); - verify(client).finishTestItem(same(afterStoryId), finishStepCaptor.capture()); verify(client).finishTestItem(same(afterStoriesId), finishStepCaptor.capture()); List finishItems = finishStepCaptor.getAllValues(); @@ -147,9 +139,5 @@ public void verify_before_story_annotation_failed_method_reporting() { FinishTestItemRQ beforeStoryFinish = finishItems.get(4); assertThat(beforeStoryFinish.getStatus(), equalTo(ItemStatus.FAILED.name())); assertThat(beforeStoryFinish.getIssue(), nullValue()); - - FinishTestItemRQ beforeStoriesFinish = finishItems.get(5); - assertThat(beforeStoriesFinish.getStatus(), equalTo(ItemStatus.FAILED.name())); - assertThat(beforeStoriesFinish.getIssue(), nullValue()); } } From 75430f2f410fe61186f3122c3bf7a8a7eec8d49d Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 14 Nov 2022 15:32:51 +0300 Subject: [PATCH 18/32] Fix AfterStoryAnnotationFailedTest --- .../jbehave/ReportPortalStoryReporter.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java index c5778db..252b5f3 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java @@ -88,7 +88,7 @@ public abstract class ReportPortalStoryReporter extends NullStoryReporter { private final TestItemTree itemTree; private volatile TestItemTree.TestItemLeaf lastStep; - private static volatile String currentLifecycleTopItemType; + private static volatile ItemType currentLifecycleTopItemType; private volatile ItemType currentLifecycleItemType; public ReportPortalStoryReporter(final Supplier launchSupplier, TestItemTree testItemTree) { @@ -389,6 +389,7 @@ protected StartTestItemRQ buildLifecycleSuiteStartRq(@Nonnull final String name, * * @param type item type * @param name a lifecycle method name + * @param codeRef method's code reference * @param startTime item start time * @return Request to ReportPortal */ @@ -803,7 +804,7 @@ protected void simulateStep(@Nonnull String step) { */ @Override public void beforeStory(@Nonnull Story story, boolean givenStory) { - currentLifecycleTopItemType = AFTER_STORIES; + currentLifecycleTopItemType = ItemType.AFTER_GROUPS; currentLifecycleItemType = ItemType.BEFORE_SUITE; structure.add(new Entity<>(ItemType.STORY, story)); } @@ -869,8 +870,11 @@ public void beforeStep(@Nonnull Step step) { if (parentItem == null) { // Before Stories structure.add(new Entity<>(ItemType.TEST, - currentLifecycleTopItemType == null ? BEFORE_STORIES : currentLifecycleTopItemType + currentLifecycleTopItemType == null ? BEFORE_STORIES : AFTER_STORIES )); + if (currentLifecycleTopItemType == null) { + currentLifecycleTopItemType = ItemType.BEFORE_GROUPS; + } } else if (parentItem.getType() == ItemType.STORY) { // Before Story structure.add(new Entity<>(ItemType.TEST, @@ -878,15 +882,9 @@ public void beforeStep(@Nonnull Step step) { )); } if (parentItem == null || parentItem.getType() == ItemType.STORY) { - //noinspection StringEquality - ofNullable(retrieveLeaf()).map(i -> startLifecycleMethod(step.getStepAsString(), - parentItem == null ? - currentLifecycleTopItemType == BEFORE_STORIES ? - ItemType.BEFORE_GROUPS : - ItemType.AFTER_GROUPS : - ItemType.BEFORE_SUITE, - i - )).ifPresent(stepStack::add); + ItemType itemType = parentItem == null ? currentLifecycleTopItemType : currentLifecycleItemType; + ofNullable(retrieveLeaf()).map(i -> startLifecycleMethod(step.getStepAsString(), itemType, i)) + .ifPresent(stepStack::add); return; } currentLifecycleItemType = ItemType.BEFORE_METHOD; From f0abeeacc16ebdedeb5f6a88b027e1a9c2dfaaea Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 14 Nov 2022 15:52:29 +0300 Subject: [PATCH 19/32] Fix BeforeStoriesAnnotationFailedTest --- .../jbehave/ReportPortalStoryReporter.java | 25 +++++------- ...=> BeforeStoriesAnnotationFailedTest.java} | 40 +++++++------------ 2 files changed, 25 insertions(+), 40 deletions(-) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyBeforeStoriesAnnotationFailed.java => BeforeStoriesAnnotationFailedTest.java} (78%) diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java index 252b5f3..4a79e86 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java @@ -517,13 +517,10 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { String lifecycleSuiteName = (String) entity.get(); TestItemTree.ItemTreeKey lifecycleSuiteKey = ItemTreeUtils.createKey(lifecycleSuiteName); leafChain.add(ImmutablePair.of(lifecycleSuiteKey, - children.computeIfAbsent( - lifecycleSuiteKey, - k -> createLeaf(itemType, - buildLifecycleSuiteStartRq(lifecycleSuiteName, itemDate), - parentLeaf - ) - ) + children.computeIfAbsent(lifecycleSuiteKey, k -> createLeaf(itemType, + buildLifecycleSuiteStartRq(lifecycleSuiteName, itemDate), + parentLeaf + )) )); break; } @@ -923,8 +920,8 @@ public void afterExamples() { evaluateAndFinishLastItem(); } - private void finishAfterSuites(TestItemTree.TestItemLeaf item) { - if (item.getType() == ItemType.AFTER_GROUPS) { + private void finishBeforeAfterSuites(TestItemTree.TestItemLeaf item) { + if (item.getType() == ItemType.BEFORE_GROUPS || item.getType() == ItemType.AFTER_GROUPS) { Entity parentSuite = structure.getLast(); evaluateAndFinishLastItem(); // Finish parent suite structure.add(parentSuite); @@ -939,7 +936,7 @@ public void successful(String step) { currentLifecycleItemType = ItemType.AFTER_TEST; ofNullable(stepStack.pollLast()).ifPresent(s -> { finishStep(s, ItemStatus.PASSED); - finishAfterSuites(s); + finishBeforeAfterSuites(s); }); } @@ -954,7 +951,7 @@ public void failed(String step, Throwable cause) { ofNullable(stepStack.pollLast()).ifPresent(i -> { sendStackTraceToRP(i.getItemId(), cause); finishStep(i, ItemStatus.FAILED); - finishAfterSuites(i); + finishBeforeAfterSuites(i); }); } @@ -968,7 +965,7 @@ public void ignorable(String step) { ofNullable(stepStack.pollLast()).ifPresent(i -> { createIgnoredSteps(step, i); finishStep(i, ItemStatus.SKIPPED); - finishAfterSuites(i); + finishBeforeAfterSuites(i); }); } @@ -982,7 +979,7 @@ public void notPerformed(String step) { ofNullable(stepStack.pollLast()).ifPresent(i -> { createNotPerformedSteps(step, i); finishStep(i, ItemStatus.SKIPPED, Launch.NOT_ISSUE); - finishAfterSuites(i); + finishBeforeAfterSuites(i); }); } @@ -991,7 +988,7 @@ public void pending(String step) { ofNullable(stepStack.pollLast()).ifPresent(i -> { createPendingSteps(step, i); finishStep(i, ItemStatus.SKIPPED); - finishAfterSuites(i); + finishBeforeAfterSuites(i); }); } diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoriesAnnotationFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java similarity index 78% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoriesAnnotationFailed.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java index 5e6225d..def25ec 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoriesAnnotationFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java @@ -41,16 +41,15 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyBeforeStoriesAnnotationFailed extends BaseTest { +public class BeforeStoriesAnnotationFailedTest extends BaseTest { private final String beforeStoriesId = CommonUtils.namedId("before_stories_"); - private final String beforeStoryId = CommonUtils.namedId("before_story_"); private final String beforeStepId = CommonUtils.namedId("before_story_step_"); private final String storyId = CommonUtils.namedId("story_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final String stepId = CommonUtils.namedId("step_"); - private final List>> beforeSteps = Collections.singletonList(Pair.of(beforeStoryId, + private final List>> beforeSteps = Collections.singletonList(Pair.of(beforeStoriesId, Collections.singletonList(beforeStepId) )); @@ -75,6 +74,8 @@ public void setupMock() { private static final String DEFAULT_SCENARIO_NAME = "No name"; private static final String STEP_NAME = "Given I have empty step"; + private static final String AFTER_STORY_NAME = "beforeStoriesFailed"; + @Test public void verify_before_story_annotation_failed_method_reporting() { run(format, STORY_PATH, new BeforeStoriesFailedSteps(), new EmptySteps()); @@ -82,7 +83,6 @@ public void verify_before_story_annotation_failed_method_reporting() { ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client, times(2)).startTestItem(startCaptor.capture()); verify(client).startTestItem(same(beforeStoriesId), startCaptor.capture()); - verify(client).startTestItem(same(beforeStoryId), startCaptor.capture()); verify(client).startTestItem(same(storyId), startCaptor.capture()); verify(client).startTestItem(same(scenarioId), startCaptor.capture()); @@ -90,31 +90,24 @@ public void verify_before_story_annotation_failed_method_reporting() { List startItems = startCaptor.getAllValues(); StartTestItemRQ beforeStoriesStart = startItems.get(0); assertThat(beforeStoriesStart.getName(), equalTo("BeforeStories")); - assertThat(beforeStoriesStart.getCodeRef(), equalTo("BeforeStories")); - assertThat(beforeStoriesStart.getType(), equalTo(ItemType.STORY.name())); + assertThat(beforeStoriesStart.getType(), equalTo(ItemType.TEST.name())); StartTestItemRQ storyStart = startItems.get(1); assertThat(storyStart.getCodeRef(), allOf(notNullValue(), equalTo(STORY_PATH))); assertThat(storyStart.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); - StartTestItemRQ beforeStoryStart = startItems.get(2); - assertThat(beforeStoryStart.getName(), equalTo("BeforeStory")); - assertThat(beforeStoryStart.getCodeRef(), nullValue()); - assertThat(beforeStoryStart.getType(), equalTo(ItemType.TEST.name())); - - StartTestItemRQ beforeStep = startItems.get(3); - String beforeStepCodeRef = BeforeStoriesFailedSteps.class.getCanonicalName() + ".beforeStoriesFailed()"; - assertThat(beforeStep.getName(), equalTo(beforeStepCodeRef)); - assertThat(beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); - assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_SUITE.name())); + StartTestItemRQ beforeStep = startItems.get(2); + assertThat(beforeStep.getName(), equalTo(AFTER_STORY_NAME)); + assertThat(beforeStep.getCodeRef(), equalTo(AFTER_STORY_NAME)); + assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_GROUPS.name())); String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME); - StartTestItemRQ scenarioStart = startItems.get(4); + StartTestItemRQ scenarioStart = startItems.get(3); assertThat(scenarioStart.getName(), equalTo(DEFAULT_SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); - StartTestItemRQ step = startItems.get(5); + StartTestItemRQ step = startItems.get(4); String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); @@ -123,7 +116,6 @@ public void verify_before_story_annotation_failed_method_reporting() { // Finish items verification ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); verify(client).finishTestItem(same(beforeStepId), finishStepCaptor.capture()); - verify(client).finishTestItem(same(beforeStoryId), finishStepCaptor.capture()); verify(client).finishTestItem(same(beforeStoriesId), finishStepCaptor.capture()); verify(client).finishTestItem(same(stepId), finishStepCaptor.capture()); verify(client).finishTestItem(same(scenarioId), finishStepCaptor.capture()); @@ -138,17 +130,13 @@ public void verify_before_story_annotation_failed_method_reporting() { assertThat(beforeStoryFinish.getStatus(), equalTo(ItemStatus.FAILED.name())); assertThat(beforeStoryFinish.getIssue(), nullValue()); - FinishTestItemRQ beforeStoriesFinish = finishItems.get(2); - assertThat(beforeStoriesFinish.getStatus(), equalTo(ItemStatus.FAILED.name())); - assertThat(beforeStoriesFinish.getIssue(), nullValue()); - - FinishTestItemRQ stepFinish = finishItems.get(3); + FinishTestItemRQ stepFinish = finishItems.get(2); assertThat(stepFinish.getStatus(), equalTo(ItemStatus.PASSED.name())); - FinishTestItemRQ scenarioFinish = finishItems.get(4); + FinishTestItemRQ scenarioFinish = finishItems.get(3); assertThat(scenarioFinish.getStatus(), equalTo(ItemStatus.PASSED.name())); - FinishTestItemRQ storyFinish = finishItems.get(5); + FinishTestItemRQ storyFinish = finishItems.get(4); assertThat(storyFinish.getStatus(), equalTo(ItemStatus.PASSED.name())); } } From c58a5e9a40da7b95b328593a3e75c231098c0cf6 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 14 Nov 2022 16:53:11 +0300 Subject: [PATCH 20/32] Fix BeforeStoryTest --- .../jbehave/ReportPortalStoryReporter.java | 35 ++++++++++++++----- ...yBeforeStory.java => BeforeStoryTest.java} | 30 ++++++++++++---- 2 files changed, 50 insertions(+), 15 deletions(-) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyBeforeStory.java => BeforeStoryTest.java} (78%) diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java index 4a79e86..5b4249a 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java @@ -74,6 +74,7 @@ public abstract class ReportPortalStoryReporter extends NullStoryReporter { 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"; @@ -115,15 +116,26 @@ public Optional getLastStep() { * @return a code reference string to identify every element of a story */ private String getCodeRef(@Nullable final String parentCodeRef, @Nonnull final TestItemTree.ItemTreeKey key, - ItemType type) { + @Nonnull ItemType type) { StringBuilder sb = new StringBuilder(); if (isBlank(parentCodeRef)) { sb.append(key.getName()); } else { + String typeName; + switch (type) { + case SUITE: + typeName = EXAMPLE; + break; + case TEST: + typeName = LIFECYCLE; + break; + default: + typeName = type.name(); + } sb.append(parentCodeRef) .append(CODE_REFERENCE_DELIMITER) .append(CODE_REFERENCE_ITEM_START) - .append(type != ItemType.SUITE ? type.name() : EXAMPLE) + .append(typeName) .append(CODE_REFERENCE_ITEM_TYPE_DELIMITER) .append(key.getName().replace("\n", "").replace("\r", "")) .append(CODE_REFERENCE_ITEM_END); @@ -376,9 +388,11 @@ protected StartTestItemRQ buildStartStepRq(@Nonnull final String step, @Nonnull * @return Request to ReportPortal */ @Nonnull - protected StartTestItemRQ buildLifecycleSuiteStartRq(@Nonnull final String name, @Nullable final Date startTime) { + protected StartTestItemRQ buildLifecycleSuiteStartRq(@Nonnull final String name, @Nullable String codeRef, + @Nullable final Date startTime) { StartTestItemRQ rq = new StartTestItemRQ(); rq.setName(name); + rq.setCodeRef(codeRef); rq.setStartTime(ofNullable(startTime).orElseGet(() -> Calendar.getInstance().getTime())); rq.setType(ItemType.TEST.name()); return rq; @@ -518,7 +532,10 @@ protected TestItemTree.TestItemLeaf retrieveLeaf() { TestItemTree.ItemTreeKey lifecycleSuiteKey = ItemTreeUtils.createKey(lifecycleSuiteName); leafChain.add(ImmutablePair.of(lifecycleSuiteKey, children.computeIfAbsent(lifecycleSuiteKey, k -> createLeaf(itemType, - buildLifecycleSuiteStartRq(lifecycleSuiteName, itemDate), + buildLifecycleSuiteStartRq(lifecycleSuiteName, + getCodeRef(parentCodeRef, k, ItemType.TEST), + itemDate + ), parentLeaf )) )); @@ -878,10 +895,12 @@ public void beforeStep(@Nonnull Step step) { currentLifecycleItemType == ItemType.BEFORE_SUITE ? BEFORE_STORY : AFTER_STORY )); } - if (parentItem == null || parentItem.getType() == ItemType.STORY) { - ItemType itemType = parentItem == null ? currentLifecycleTopItemType : currentLifecycleItemType; - ofNullable(retrieveLeaf()).map(i -> startLifecycleMethod(step.getStepAsString(), itemType, i)) - .ifPresent(stepStack::add); + if (parentItem == null) { + ofNullable(retrieveLeaf()).map(i -> startLifecycleMethod( + step.getStepAsString(), + currentLifecycleTopItemType, + i + )).ifPresent(stepStack::add); return; } currentLifecycleItemType = ItemType.BEFORE_METHOD; diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStory.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryTest.java similarity index 78% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStory.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryTest.java index 0e073b4..35c21ea 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStory.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryTest.java @@ -40,14 +40,17 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyBeforeStory extends BaseTest { +public class BeforeStoryTest extends BaseTest { private final String storyId = CommonUtils.namedId("story_"); - private final String beforeStepId = CommonUtils.namedId("before_story_step_"); + private final String beforeSuiteId = CommonUtils.namedId("before_story_suite_"); private final String scenarioId = CommonUtils.namedId("scenario_"); + private final String beforeStepId = CommonUtils.namedId("before_story_step_"); private final String stepId = CommonUtils.namedId("step_"); - private final List>> steps = Arrays.asList(Pair.of(beforeStepId, Collections.emptyList()), + private final List>> steps = Arrays.asList(Pair.of(beforeSuiteId, + Collections.singletonList(beforeStepId) + ), Pair.of(scenarioId, Collections.singletonList(stepId)) ); @@ -66,6 +69,7 @@ public void setupMock() { private static final String STORY_PATH = "stories/lifecycle/BeforeStory.story"; private static final String SCENARIO_NAME = "The scenario"; private static final String STEP_NAME = "Given I have empty step"; + private static final String LIFECYCLE_SUITE_NAME = "BeforeStory"; private static final String LIFECYCLE_STEP_NAME = "Then I have another empty step"; @Test @@ -75,13 +79,25 @@ public void verify_before_story_lifecycle_step_reporting() { verify(client).startTestItem(any()); ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client, times(2)).startTestItem(same(storyId), startCaptor.capture()); - verify(client).startTestItem(same(scenarioId), startCaptor.capture()); + ArgumentCaptor beforeCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(beforeSuiteId), beforeCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(scenarioId), scenarioCaptor.capture()); // Start items verification List startItems = startCaptor.getAllValues(); - StartTestItemRQ beforeStoryStart = startItems.get(0); + StartTestItemRQ beforeStorySuiteStart = startItems.get(0); + assertThat(beforeStorySuiteStart.getName(), equalTo(LIFECYCLE_SUITE_NAME)); + String beforeSuiteCodeRef = STORY_PATH + String.format("/[LIFECYCLE:%s]", LIFECYCLE_SUITE_NAME); + assertThat(beforeStorySuiteStart.getCodeRef(), + equalTo(beforeSuiteCodeRef) + ); + + StartTestItemRQ beforeStoryStart = beforeCaptor.getValue(); assertThat(beforeStoryStart.getName(), equalTo(LIFECYCLE_STEP_NAME)); - assertThat(beforeStoryStart.getCodeRef(), equalTo(STORY_PATH + String.format("/[STEP:%s]", LIFECYCLE_STEP_NAME))); + assertThat(beforeStoryStart.getCodeRef(), + equalTo(beforeSuiteCodeRef + String.format("/[STEP:%s]", LIFECYCLE_STEP_NAME)) + ); assertThat(beforeStoryStart.getType(), equalTo(ItemType.STEP.name())); String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAME); @@ -90,7 +106,7 @@ public void verify_before_story_lifecycle_step_reporting() { assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); - StartTestItemRQ step = startItems.get(2); + StartTestItemRQ step = scenarioCaptor.getValue(); String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); From 9d6ffc0b589496b7c27760a98c66acbcf2ab2ef4 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 14 Nov 2022 17:25:57 +0300 Subject: [PATCH 21/32] CodeRef fixes --- .../lifecycle/AfterStoriesAnnotationFailedTest.java | 6 ++++-- .../lifecycle/AfterStoryAnnotationFailedTest.java | 7 ++++--- .../lifecycle/BeforeStoriesAnnotationFailedTest.java | 9 +++++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java index 0d03083..60ef8f7 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java @@ -94,7 +94,9 @@ public void verify_before_story_annotation_failed_method_reporting() { assertThat(storyStart.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); StartTestItemRQ afterStoriesStart = startItems.get(1); - assertThat(afterStoriesStart.getName(), equalTo("AfterStories")); + String afterStoriesCodeRef = "AfterStories"; + assertThat(afterStoriesStart.getName(), equalTo(afterStoriesCodeRef)); + assertThat(afterStoriesStart.getCodeRef(), equalTo(afterStoriesCodeRef)); assertThat(afterStoriesStart.getType(), equalTo(ItemType.TEST.name())); String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME); @@ -111,7 +113,7 @@ public void verify_before_story_annotation_failed_method_reporting() { StartTestItemRQ afterStep = startItems.get(4); assertThat(afterStep.getName(), equalTo(AFTER_STORY_NAME)); - assertThat(afterStep.getCodeRef(), equalTo(AFTER_STORY_NAME)); + assertThat(afterStep.getCodeRef(), equalTo(afterStoriesCodeRef + String.format("/[AFTER_GROUPS:%s]", AFTER_STORY_NAME))); assertThat(afterStep.getType(), equalTo(ItemType.AFTER_GROUPS.name())); // Finish items verification diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java index 8532eee..ee75ca5 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java @@ -91,7 +91,8 @@ public void verify_after_story_annotation_failed_method_reporting() { StartTestItemRQ beforeStoryStart = startItems.get(1); assertThat(beforeStoryStart.getName(), equalTo("AfterStory")); - assertThat(beforeStoryStart.getCodeRef(), nullValue()); + String afterStoryCodeRef = STORY_PATH + String.format("/[LIFECYCLE:%s]", "AfterStory"); + assertThat(beforeStoryStart.getCodeRef(), equalTo(afterStoryCodeRef)); assertThat(beforeStoryStart.getType(), equalTo(ItemType.TEST.name())); StartTestItemRQ step = startItems.get(2); @@ -102,8 +103,8 @@ public void verify_after_story_annotation_failed_method_reporting() { StartTestItemRQ afterStep = startItems.get(3); assertThat(afterStep.getName(), equalTo(AFTER_STORY_NAME)); - assertThat(afterStep.getCodeRef(), equalTo(AFTER_STORY_NAME)); - assertThat(afterStep.getType(), equalTo(ItemType.AFTER_SUITE.name())); + assertThat(afterStep.getCodeRef(), equalTo(afterStoryCodeRef + String.format("/[STEP:%s]", AFTER_STORY_NAME))); + assertThat(afterStep.getType(), equalTo(ItemType.STEP.name())); // Finish items verification ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java index def25ec..d5b5eb9 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java @@ -89,7 +89,9 @@ public void verify_before_story_annotation_failed_method_reporting() { // Start items verification List startItems = startCaptor.getAllValues(); StartTestItemRQ beforeStoriesStart = startItems.get(0); - assertThat(beforeStoriesStart.getName(), equalTo("BeforeStories")); + String beforeStoriesCodeRef = "BeforeStories"; + assertThat(beforeStoriesStart.getName(), equalTo(beforeStoriesCodeRef)); + assertThat(beforeStoriesStart.getCodeRef(), equalTo(beforeStoriesCodeRef)); assertThat(beforeStoriesStart.getType(), equalTo(ItemType.TEST.name())); StartTestItemRQ storyStart = startItems.get(1); @@ -98,7 +100,10 @@ public void verify_before_story_annotation_failed_method_reporting() { StartTestItemRQ beforeStep = startItems.get(2); assertThat(beforeStep.getName(), equalTo(AFTER_STORY_NAME)); - assertThat(beforeStep.getCodeRef(), equalTo(AFTER_STORY_NAME)); + assertThat( + beforeStep.getCodeRef(), + equalTo(beforeStoriesCodeRef + String.format("/[BEFORE_GROUPS:%s]", AFTER_STORY_NAME)) + ); assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_GROUPS.name())); String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME); From 08fde6f0dbc8414f54af8ad6fc89edc865c8925e Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 14 Nov 2022 18:34:22 +0300 Subject: [PATCH 22/32] BeforeStoryFailedTest fix and refactoring --- .../epam/reportportal/jbehave/BaseTest.java | 4 + .../reportportal/jbehave/NoScenarioTest.java | 4 +- .../jbehave/TabularParametersTest.java | 4 - .../coderef/FailedPassedStepCodeRefTest.java | 2 +- .../coderef/GivenStoryCodeRefTest.java | 6 +- .../jbehave/coderef/SimpleCodeRefTest.java | 2 +- .../jbehave/gherkin/SimpleGherkinTest.java | 4 - .../jbehave/id/TestCaseIdSimpleTest.java | 2 +- .../AfterStoriesAnnotationFailedTest.java | 4 +- .../AfterStoryAnnotationFailedTest.java | 8 +- .../BeforeScenarioAnnotationFailedTest.java | 6 +- .../BeforeStoriesAnnotationFailedTest.java | 4 +- ...Failed.java => BeforeStoryFailedTest.java} | 76 ++++++++++++------- .../jbehave/lifecycle/BeforeStoryTest.java | 8 +- .../lifecycle/VerifyAfterScenario.java | 6 +- .../VerifyAfterScenarioAnnotationFailed.java | 4 +- .../jbehave/lifecycle/VerifyAfterStep.java | 6 +- .../jbehave/lifecycle/VerifyAfterStory.java | 6 +- .../lifecycle/VerifyAfterStoryFailed.java | 3 +- .../lifecycle/VerifyBeforeScenario.java | 6 +- .../lifecycle/VerifyBeforeScenarioFailed.java | 4 +- .../jbehave/lifecycle/VerifyBeforeStep.java | 6 +- .../lifecycle/VerifyBeforeStepFailed.java | 3 +- .../VerifyBeforeStoryAnnotationFailed.java | 4 +- .../scenario/SimpleScenarioFormatTest.java | 2 +- 25 files changed, 100 insertions(+), 84 deletions(-) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyBeforeStoryFailed.java => BeforeStoryFailedTest.java} (64%) diff --git a/src/test/java/com/epam/reportportal/jbehave/BaseTest.java b/src/test/java/com/epam/reportportal/jbehave/BaseTest.java index 1987f18..c1f1a74 100644 --- a/src/test/java/com/epam/reportportal/jbehave/BaseTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/BaseTest.java @@ -73,6 +73,10 @@ public class BaseTest { public static final String ROOT_SUITE_PREFIX = "root_"; + public static final String STEP_PATTERN = "/[STEP:%s]"; + public static final String LIFECYCLE_PATTERN = "/[LIFECYCLE:%s]"; + public static final String SCENARIO_PATTERN = "/[SCENARIO:%s]"; + public static ExecutorService testExecutor() { return Executors.newSingleThreadExecutor(r -> { Thread t = new Thread(r); diff --git a/src/test/java/com/epam/reportportal/jbehave/NoScenarioTest.java b/src/test/java/com/epam/reportportal/jbehave/NoScenarioTest.java index b585e03..6295ce8 100644 --- a/src/test/java/com/epam/reportportal/jbehave/NoScenarioTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/NoScenarioTest.java @@ -79,12 +79,12 @@ public void verify_a_story_without_scenario() { assertThat(startStory.getCodeRef(), equalTo(STORY_PATH)); StartTestItemRQ startScenario = startItems.get(1); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, DEFAULT_SCENARIO_NAME); assertThat(startScenario.getName(), equalTo(DEFAULT_SCENARIO_NAME)); assertThat(startScenario.getCodeRef(), equalTo(scenarioCodeRef)); StartTestItemRQ startStep = startItems.get(2); - String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); + String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); assertThat(startStep.getName(), equalTo(STEP_NAME)); assertThat(startStep.getCodeRef(), equalTo(stepCodeRef)); diff --git a/src/test/java/com/epam/reportportal/jbehave/TabularParametersTest.java b/src/test/java/com/epam/reportportal/jbehave/TabularParametersTest.java index 76d570d..d3eb56e 100644 --- a/src/test/java/com/epam/reportportal/jbehave/TabularParametersTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/TabularParametersTest.java @@ -35,10 +35,6 @@ import static org.mockito.Mockito.verify; public class TabularParametersTest extends BaseTest { - - public static final String SCENARIO_PATTERN = "/[SCENARIO:%s]"; - public static final String STEP_PATTERN = "/[STEP:%s]"; - private final String storyId = CommonUtils.namedId("story_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final String stepId = CommonUtils.namedId("step_"); diff --git a/src/test/java/com/epam/reportportal/jbehave/coderef/FailedPassedStepCodeRefTest.java b/src/test/java/com/epam/reportportal/jbehave/coderef/FailedPassedStepCodeRefTest.java index 8957c7f..5ea2a31 100644 --- a/src/test/java/com/epam/reportportal/jbehave/coderef/FailedPassedStepCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/coderef/FailedPassedStepCodeRefTest.java @@ -89,7 +89,7 @@ public void verify_code_reference_generation() { List stepRqs = items.subList(2, items.size()); IntStream.range(0, stepRqs.size()).forEach(i -> { StartTestItemRQ step = stepRqs.get(i); - String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", SCENARIO_STEPS.get(i)); + String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, SCENARIO_STEPS.get(i)); assertThat(step.getCodeRef(), allOf(notNullValue(), equalTo(stepCodeRef))); assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); }); diff --git a/src/test/java/com/epam/reportportal/jbehave/coderef/GivenStoryCodeRefTest.java b/src/test/java/com/epam/reportportal/jbehave/coderef/GivenStoryCodeRefTest.java index e10cafa..bb31fae 100644 --- a/src/test/java/com/epam/reportportal/jbehave/coderef/GivenStoryCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/coderef/GivenStoryCodeRefTest.java @@ -129,7 +129,7 @@ public void verify_code_reference_generation_given_stories() { List outerScenarioSteps = items.subList(4, 6); IntStream.range(0, outerScenarioSteps.size()).forEach(i -> { StartTestItemRQ rq = outerScenarioSteps.get(i); - String outerScenarioStepCodeRef = outerScenarioCodeRef + String.format("/[STEP:%s]", DUMMY_SCENARIO_STEPS.get(i)); + String outerScenarioStepCodeRef = outerScenarioCodeRef + String.format(STEP_PATTERN, DUMMY_SCENARIO_STEPS.get(i)); assertThat(rq.getCodeRef(), equalTo(outerScenarioStepCodeRef)); assertThat(rq.getType(), equalTo(ItemType.STEP.name())); }); @@ -140,7 +140,7 @@ public void verify_code_reference_generation_given_stories() { assertThat(innerStory.getType(), equalTo(ItemType.STORY.name())); StartTestItemRQ rootStep = items.get(7); - String rootStepCodeRef = rootScenarioCodeRef + String.format("/[STEP:%s]", GIVEN_STORY_STEP); + String rootStepCodeRef = rootScenarioCodeRef + String.format(STEP_PATTERN, GIVEN_STORY_STEP); assertThat(rootStep.getCodeRef(), equalTo(rootStepCodeRef)); assertThat(rootStep.getType(), equalTo(ItemType.STEP.name())); @@ -152,7 +152,7 @@ public void verify_code_reference_generation_given_stories() { List innerScenarioSteps = items.subList(9, 11); IntStream.range(0, innerScenarioSteps.size()).forEach(i -> { StartTestItemRQ rq = innerScenarioSteps.get(i); - String innerStepCodeRef = innerScenarioCodeRef + String.format("/[STEP:%s]", INLINE_PARAMETERS_STEPS.get(i)); + String innerStepCodeRef = innerScenarioCodeRef + String.format(STEP_PATTERN, INLINE_PARAMETERS_STEPS.get(i)); assertThat(rq.getCodeRef(), equalTo(innerStepCodeRef)); assertThat(rq.getType(), equalTo(ItemType.STEP.name())); }); diff --git a/src/test/java/com/epam/reportportal/jbehave/coderef/SimpleCodeRefTest.java b/src/test/java/com/epam/reportportal/jbehave/coderef/SimpleCodeRefTest.java index 5d65255..822a34f 100644 --- a/src/test/java/com/epam/reportportal/jbehave/coderef/SimpleCodeRefTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/coderef/SimpleCodeRefTest.java @@ -85,7 +85,7 @@ public void verify_code_reference_generation() { List stepRqs = items.subList(2, items.size()); IntStream.range(0, stepRqs.size()).forEach(i -> { StartTestItemRQ step = stepRqs.get(i); - String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", DUMMY_SCENARIO_STEPS.get(i)); + String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, DUMMY_SCENARIO_STEPS.get(i)); assertThat(step.getCodeRef(), allOf(notNullValue(), equalTo(stepCodeRef))); assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); }); diff --git a/src/test/java/com/epam/reportportal/jbehave/gherkin/SimpleGherkinTest.java b/src/test/java/com/epam/reportportal/jbehave/gherkin/SimpleGherkinTest.java index f45d47c..4a35047 100644 --- a/src/test/java/com/epam/reportportal/jbehave/gherkin/SimpleGherkinTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/gherkin/SimpleGherkinTest.java @@ -42,10 +42,6 @@ import static org.mockito.Mockito.*; public class SimpleGherkinTest extends BaseTest { - - public static final String SCENARIO_PATTERN = "/[SCENARIO:%s]"; - public static final String STEP_PATTERN = "/[STEP:%s]"; - private final String storyId = CommonUtils.namedId("story_"); private final String scenarioId = CommonUtils.namedId("scenario_"); private final List stepIds = Stream.generate(() -> CommonUtils.namedId("step_")).limit(2).collect(Collectors.toList()); diff --git a/src/test/java/com/epam/reportportal/jbehave/id/TestCaseIdSimpleTest.java b/src/test/java/com/epam/reportportal/jbehave/id/TestCaseIdSimpleTest.java index 3c7d348..bb4fcea 100644 --- a/src/test/java/com/epam/reportportal/jbehave/id/TestCaseIdSimpleTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/id/TestCaseIdSimpleTest.java @@ -69,7 +69,7 @@ public void verify_test_case_id_for_a_simple_scenario() { // Start items verification StartTestItemRQ startStep = startCaptor.getValue(); - String stepCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME) + String.format("/[STEP:%s]", STEP_NAME); + String stepCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, DEFAULT_SCENARIO_NAME) + String.format(STEP_PATTERN, STEP_NAME); assertThat(startStep.getTestCaseId(), equalTo(stepCodeRef)); } } diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java index 60ef8f7..4d0d290 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java @@ -99,14 +99,14 @@ public void verify_before_story_annotation_failed_method_reporting() { assertThat(afterStoriesStart.getCodeRef(), equalTo(afterStoriesCodeRef)); assertThat(afterStoriesStart.getType(), equalTo(ItemType.TEST.name())); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, DEFAULT_SCENARIO_NAME); StartTestItemRQ scenarioStart = startItems.get(2); assertThat(scenarioStart.getName(), equalTo(DEFAULT_SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); StartTestItemRQ step = startItems.get(3); - String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); + String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java index ee75ca5..6e8f27f 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java @@ -83,7 +83,7 @@ public void verify_after_story_annotation_failed_method_reporting() { // Start items verification List startItems = startCaptor.getAllValues(); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, DEFAULT_SCENARIO_NAME); StartTestItemRQ scenarioStart = startItems.get(0); assertThat(scenarioStart.getName(), equalTo(DEFAULT_SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); @@ -91,19 +91,19 @@ public void verify_after_story_annotation_failed_method_reporting() { StartTestItemRQ beforeStoryStart = startItems.get(1); assertThat(beforeStoryStart.getName(), equalTo("AfterStory")); - String afterStoryCodeRef = STORY_PATH + String.format("/[LIFECYCLE:%s]", "AfterStory"); + String afterStoryCodeRef = STORY_PATH + String.format(LIFECYCLE_PATTERN, "AfterStory"); assertThat(beforeStoryStart.getCodeRef(), equalTo(afterStoryCodeRef)); assertThat(beforeStoryStart.getType(), equalTo(ItemType.TEST.name())); StartTestItemRQ step = startItems.get(2); - String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); + String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); StartTestItemRQ afterStep = startItems.get(3); assertThat(afterStep.getName(), equalTo(AFTER_STORY_NAME)); - assertThat(afterStep.getCodeRef(), equalTo(afterStoryCodeRef + String.format("/[STEP:%s]", AFTER_STORY_NAME))); + assertThat(afterStep.getCodeRef(), equalTo(afterStoryCodeRef + String.format(STEP_PATTERN, AFTER_STORY_NAME))); assertThat(afterStep.getType(), equalTo(ItemType.STEP.name())); // Finish items verification diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java index 8d2787e..5080519 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioAnnotationFailedTest.java @@ -83,7 +83,7 @@ public void verify_before_scenario_annotation_failed_method_reporting() { // Start items verification List startItems = startCaptor.getAllValues(); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, DEFAULT_SCENARIO_NAME); StartTestItemRQ scenarioStart = startItems.get(0); assertThat(scenarioStart.getName(), equalTo(DEFAULT_SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); @@ -91,12 +91,12 @@ public void verify_before_scenario_annotation_failed_method_reporting() { StartTestItemRQ beforeStep = startItems.get(1); assertThat(beforeStep.getName(), equalTo(BEFORE_SCENARIO_NAME)); - String beforeCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", BEFORE_SCENARIO_NAME); + String beforeCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, BEFORE_SCENARIO_NAME); assertThat(beforeStep.getCodeRef(), equalTo(beforeCodeRef)); assertThat(beforeStep.getType(), equalTo(ItemType.STEP.name())); StartTestItemRQ step = startItems.get(2); - String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); + String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java index d5b5eb9..969ef7e 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java @@ -106,14 +106,14 @@ public void verify_before_story_annotation_failed_method_reporting() { ); assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_GROUPS.name())); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, DEFAULT_SCENARIO_NAME); StartTestItemRQ scenarioStart = startItems.get(3); assertThat(scenarioStart.getName(), equalTo(DEFAULT_SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); StartTestItemRQ step = startItems.get(4); - String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); + String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryFailedTest.java similarity index 64% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryFailed.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryFailedTest.java index 457844e..8995373 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryFailedTest.java @@ -44,10 +44,10 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyBeforeStoryFailed extends BaseTest { - - public static final String STEP_PATTERN = "/[STEP:%s]"; +public class BeforeStoryFailedTest extends BaseTest { private final String storyId = namedId("story_"); + private final String beforeStoryId = namedId("before_story_"); + private final String afterStoryId = namedId("after_story_"); private final List lifecycleStepIds = Arrays.asList(namedId("before_story_"), namedId("before_scenario_"), namedId("before_step_"), @@ -58,11 +58,13 @@ public class VerifyBeforeStoryFailed extends BaseTest { private final String scenarioId = namedId("scenario_"); private final String stepId = namedId("step_"); - private final List>> steps = Arrays.asList(Pair.of(lifecycleStepIds.get(0), Collections.emptyList()), + private final List>> steps = Arrays.asList(Pair.of(beforeStoryId, + Collections.singletonList(lifecycleStepIds.get(0)) + ), Pair.of(scenarioId, Stream.concat(Stream.concat(lifecycleStepIds.subList(1, 3).stream(), Stream.of(stepId)), lifecycleStepIds.subList(3, lifecycleStepIds.size() - 1).stream() ).collect(Collectors.toList())), - Pair.of(lifecycleStepIds.get(lifecycleStepIds.size() - 1), Collections.emptyList()) + Pair.of(afterStoryId, Collections.singletonList(lifecycleStepIds.get(lifecycleStepIds.size() - 1))) ); private final ReportPortalClient client = mock(ReportPortalClient.class); @@ -80,68 +82,90 @@ public void setupMock() { private static final String STORY_PATH = "stories/lifecycle/BeforeStoryFailed.story"; private static final String SCENARIO_NAME = "The scenario"; private static final String STEP_NAME = "Given I have empty step"; - private static final String[] LIFECYCLE_STEP_NAMES = new String[] { "Given I have a failed step", "Then I have another empty step", - "Given It is test with parameters", "When I have parameter test", "Then I have another empty step", - "Given It is a step with an integer parameter 42" }; + private static final String[] LIFECYCLE_SUITES_NAMES = new String[] { "BeforeStory", "AfterStory" }; + private static final String[] LIFECYCLE_STEP_NAMES = new String[] { "Given I have a failed step", + "Then I have another empty step", "Given It is test with parameters", "When I have parameter test", + "Then I have another empty step", "Given It is a step with an integer parameter 42" }; @Test public void verify_before_story_lifecycle_step_failure_reporting() { run(format, STORY_PATH, new EmptySteps(), new ParameterizedSteps(), new FailedSteps()); verify(client).startTestItem(any()); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(storyId), startCaptor.capture()); - verify(client, times(5)).startTestItem(same(scenarioId), startCaptor.capture()); + ArgumentCaptor storyCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(storyId), storyCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(5)).startTestItem(same(scenarioId), scenarioCaptor.capture()); + ArgumentCaptor beforeCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(beforeStoryId), beforeCaptor.capture()); + ArgumentCaptor afterCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(afterStoryId), afterCaptor.capture()); // Start items verification - List startItems = startCaptor.getAllValues(); + List storyStartItems = storyCaptor.getAllValues(); + + StartTestItemRQ beforeStorySuiteStart = storyStartItems.get(0); + assertThat(beforeStorySuiteStart.getName(), equalTo(LIFECYCLE_SUITES_NAMES[0])); + String beforeSuiteCodeRef = STORY_PATH + String.format(LIFECYCLE_PATTERN, LIFECYCLE_SUITES_NAMES[0]); + assertThat(beforeStorySuiteStart.getCodeRef(), equalTo(beforeSuiteCodeRef)); + assertThat(beforeStorySuiteStart.getType(), equalTo(ItemType.TEST.name())); - StartTestItemRQ beforeStoryStart = startItems.get(0); + StartTestItemRQ beforeStoryStart = beforeCaptor.getValue(); assertThat(beforeStoryStart.getName(), equalTo(LIFECYCLE_STEP_NAMES[0])); - assertThat(beforeStoryStart.getCodeRef(), equalTo(STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[0]))); + assertThat(beforeStoryStart.getCodeRef(), + equalTo(beforeSuiteCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[0])) + ); assertThat(beforeStoryStart.getType(), equalTo(ItemType.STEP.name())); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAME); - StartTestItemRQ scenarioStart = startItems.get(1); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAME); + StartTestItemRQ scenarioStart = storyStartItems.get(1); assertThat(scenarioStart.getName(), equalTo(SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); - StartTestItemRQ beforeScenario = startItems.get(3); + List scenarioStartItems = scenarioCaptor.getAllValues(); + StartTestItemRQ beforeScenario = scenarioStartItems.get(0); String beforeScenarioCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[1]); assertThat(beforeScenario.getName(), equalTo(LIFECYCLE_STEP_NAMES[1])); assertThat(beforeScenario.getCodeRef(), equalTo(beforeScenarioCodeRef)); assertThat(beforeScenario.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ beforeStep = startItems.get(4); + StartTestItemRQ beforeStep = scenarioStartItems.get(1); String beforeStepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[2]); assertThat(beforeStep.getName(), equalTo(LIFECYCLE_STEP_NAMES[2])); assertThat(beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); assertThat(beforeStep.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ step = startItems.get(5); + StartTestItemRQ step = scenarioStartItems.get(2); String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ afterStep = startItems.get(6); + StartTestItemRQ afterStep = scenarioStartItems.get(3); String afterStepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[3]); assertThat(afterStep.getName(), equalTo(LIFECYCLE_STEP_NAMES[3])); assertThat(afterStep.getCodeRef(), equalTo(afterStepCodeRef)); assertThat(afterStep.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ afterScenario = startItems.get(7); + StartTestItemRQ afterScenario = scenarioStartItems.get(4); String afterScenarioCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[4]); assertThat(afterScenario.getName(), equalTo(LIFECYCLE_STEP_NAMES[4])); assertThat(afterScenario.getCodeRef(), equalTo(afterScenarioCodeRef)); assertThat(afterScenario.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ afterStory = startItems.get(2); - String afterStoryCodeRef = STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1]); - assertThat(afterStory.getName(), equalTo(LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1])); - assertThat(afterStory.getCodeRef(), equalTo(afterStoryCodeRef)); - assertThat(afterStory.getType(), equalTo(ItemType.STEP.name())); + StartTestItemRQ afterStoryStart = storyStartItems.get(2); + String afterStoryCodeRef = STORY_PATH + String.format(LIFECYCLE_PATTERN, LIFECYCLE_SUITES_NAMES[1]); + assertThat(afterStoryStart.getName(), equalTo(LIFECYCLE_SUITES_NAMES[1])); + assertThat(afterStoryStart.getCodeRef(), equalTo(afterStoryCodeRef)); + assertThat(afterStoryStart.getType(), equalTo(ItemType.TEST.name())); + + StartTestItemRQ afterStoryStepStart = afterCaptor.getValue(); + String afterStoryStepCodeRef = + afterStoryCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1]); + assertThat(afterStoryStepStart.getName(), equalTo(LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1])); + assertThat(afterStoryStepStart.getCodeRef(), equalTo(afterStoryStepCodeRef)); + assertThat(afterStoryStepStart.getType(), equalTo(ItemType.STEP.name())); // Finish items verification ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryTest.java index 35c21ea..cc8eb9c 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryTest.java @@ -88,7 +88,7 @@ public void verify_before_story_lifecycle_step_reporting() { List startItems = startCaptor.getAllValues(); StartTestItemRQ beforeStorySuiteStart = startItems.get(0); assertThat(beforeStorySuiteStart.getName(), equalTo(LIFECYCLE_SUITE_NAME)); - String beforeSuiteCodeRef = STORY_PATH + String.format("/[LIFECYCLE:%s]", LIFECYCLE_SUITE_NAME); + String beforeSuiteCodeRef = STORY_PATH + String.format(LIFECYCLE_PATTERN, LIFECYCLE_SUITE_NAME); assertThat(beforeStorySuiteStart.getCodeRef(), equalTo(beforeSuiteCodeRef) ); @@ -96,18 +96,18 @@ public void verify_before_story_lifecycle_step_reporting() { StartTestItemRQ beforeStoryStart = beforeCaptor.getValue(); assertThat(beforeStoryStart.getName(), equalTo(LIFECYCLE_STEP_NAME)); assertThat(beforeStoryStart.getCodeRef(), - equalTo(beforeSuiteCodeRef + String.format("/[STEP:%s]", LIFECYCLE_STEP_NAME)) + equalTo(beforeSuiteCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAME)) ); assertThat(beforeStoryStart.getType(), equalTo(ItemType.STEP.name())); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAME); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAME); StartTestItemRQ scenarioStart = startItems.get(1); assertThat(scenarioStart.getName(), equalTo(SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); StartTestItemRQ step = scenarioCaptor.getValue(); - String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); + String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterScenario.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterScenario.java index 42bbd6e..3512771 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterScenario.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterScenario.java @@ -92,7 +92,7 @@ public void verify_after_scenario_lifecycle_step_reporting() { List scenarioStarts = startItems.subList(0, 2); IntStream.range(0, scenarioStarts.size()).forEach(i -> { StartTestItemRQ scenarioStart = startItems.get(i); - String firstScenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAMES[i]); + String firstScenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAMES[i]); assertThat(scenarioStart.getName(), equalTo(SCENARIO_NAMES[i])); assertThat(scenarioStart.getCodeRef(), equalTo(firstScenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); @@ -102,7 +102,7 @@ public void verify_after_scenario_lifecycle_step_reporting() { IntStream.range(0, steps.size()).forEach(i -> { StartTestItemRQ step = steps.get(i); String stepCodeRef = - STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAMES[i]) + String.format("/[STEP:%s]", STEP_NAMES[i]); + STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAMES[i]) + String.format(STEP_PATTERN, STEP_NAMES[i]); assertThat(step.getName(), equalTo(STEP_NAMES[i])); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); @@ -112,7 +112,7 @@ public void verify_after_scenario_lifecycle_step_reporting() { IntStream.range(0, afterStarts.size()).forEach(i -> { StartTestItemRQ beforeStart = afterStarts.get(i); String lifecycleCodeRef = - STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAMES[i]) + String.format("/[STEP:%s]", LIFECYCLE_STEP_NAME); + STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAMES[i]) + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAME); assertThat(beforeStart.getName(), equalTo(LIFECYCLE_STEP_NAME)); assertThat(beforeStart.getCodeRef(), equalTo(lifecycleCodeRef)); assertThat(beforeStart.getType(), equalTo(ItemType.STEP.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterScenarioAnnotationFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterScenarioAnnotationFailed.java index 6e3fb36..740691e 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterScenarioAnnotationFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterScenarioAnnotationFailed.java @@ -80,14 +80,14 @@ public void verify_after_scenario_annotation_failed_method_reporting() { // Start items verification List startItems = startCaptor.getAllValues(); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, DEFAULT_SCENARIO_NAME); StartTestItemRQ scenarioStart = startItems.get(0); assertThat(scenarioStart.getName(), equalTo(DEFAULT_SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); StartTestItemRQ step = startItems.get(1); - String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); + String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStep.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStep.java index e1f4391..c3cf6ed 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStep.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStep.java @@ -91,7 +91,7 @@ public void verify_after_step_lifecycle_step_reporting() { // Start items verification List startItems = startCaptor.getAllValues(); StartTestItemRQ scenarioStart = startItems.get(0); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAME); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAME); assertThat(scenarioStart.getName(), equalTo(SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); @@ -99,7 +99,7 @@ public void verify_after_step_lifecycle_step_reporting() { List steps = Arrays.asList(startItems.get(1), startItems.get(3)); IntStream.range(0, steps.size()).forEach(i -> { StartTestItemRQ step = steps.get(i); - String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAMES[i]); + String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAMES[i]); assertThat(step.getName(), equalTo(STEP_NAMES[i])); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); @@ -108,7 +108,7 @@ public void verify_after_step_lifecycle_step_reporting() { List afterStarts = Arrays.asList(startItems.get(2), startItems.get(4)); IntStream.range(0, afterStarts.size()).forEach(i -> { StartTestItemRQ beforeStart = afterStarts.get(i); - String lifecycleCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", LIFECYCLE_STEP_NAME); + String lifecycleCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAME); assertThat(beforeStart.getName(), equalTo(LIFECYCLE_STEP_NAME)); assertThat(beforeStart.getCodeRef(), equalTo(lifecycleCodeRef)); assertThat(beforeStart.getType(), equalTo(ItemType.STEP.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStory.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStory.java index 57cc667..d9078d6 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStory.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStory.java @@ -80,7 +80,7 @@ public void verify_after_story_lifecycle_step_reporting() { // Start items verification List startItems = startCaptor.getAllValues(); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAME); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAME); StartTestItemRQ scenarioStart = startItems.get(0); assertThat(scenarioStart.getName(), equalTo(SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); @@ -88,11 +88,11 @@ public void verify_after_story_lifecycle_step_reporting() { StartTestItemRQ afterStoryStart = startItems.get(1); assertThat(afterStoryStart.getName(), equalTo(LIFECYCLE_STEP_NAME)); - assertThat(afterStoryStart.getCodeRef(), equalTo(STORY_PATH + String.format("/[STEP:%s]", LIFECYCLE_STEP_NAME))); + assertThat(afterStoryStart.getCodeRef(), equalTo(STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAME))); assertThat(afterStoryStart.getType(), equalTo(ItemType.STEP.name())); StartTestItemRQ step = startItems.get(2); - String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); + String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStoryFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStoryFailed.java index 3f93475..27dafbb 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStoryFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStoryFailed.java @@ -47,7 +47,6 @@ public class VerifyAfterStoryFailed extends BaseTest { - public static final String STEP_PATTERN = "/[STEP:%s]"; private final String storyId = namedId("story_"); private final List lifecycleStepIds = Arrays.asList(namedId("before_story_"), namedId("before_scenario_"), @@ -102,7 +101,7 @@ public void verify_after_story_lifecycle_step_failure_reporting() { assertThat(beforeStoryStart.getCodeRef(), equalTo(STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[0]))); assertThat(beforeStoryStart.getType(), equalTo(ItemType.STEP.name())); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAME); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAME); StartTestItemRQ scenarioStart = startItems.get(1); assertThat(scenarioStart.getName(), equalTo(SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenario.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenario.java index 01f9cc8..01225d4 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenario.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenario.java @@ -92,7 +92,7 @@ public void verify_before_scenario_lifecycle_step_reporting() { List scenarioStarts = startItems.subList(0, 2); IntStream.range(0, scenarioStarts.size()).forEach(i -> { StartTestItemRQ scenarioStart = startItems.get(i); - String firstScenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAMES[i]); + String firstScenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAMES[i]); assertThat(scenarioStart.getName(), equalTo(SCENARIO_NAMES[i])); assertThat(scenarioStart.getCodeRef(), equalTo(firstScenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); @@ -102,7 +102,7 @@ public void verify_before_scenario_lifecycle_step_reporting() { IntStream.range(0, beforeStarts.size()).forEach(i -> { StartTestItemRQ beforeStart = beforeStarts.get(i); String lifecycleCodeRef = - STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAMES[i]) + String.format("/[STEP:%s]", LIFECYCLE_STEP_NAME); + STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAMES[i]) + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAME); assertThat(beforeStart.getName(), equalTo(LIFECYCLE_STEP_NAME)); assertThat(beforeStart.getCodeRef(), equalTo(lifecycleCodeRef)); assertThat(beforeStart.getType(), equalTo(ItemType.STEP.name())); @@ -112,7 +112,7 @@ public void verify_before_scenario_lifecycle_step_reporting() { IntStream.range(0, steps.size()).forEach(i -> { StartTestItemRQ step = steps.get(i); String stepCodeRef = - STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAMES[i]) + String.format("/[STEP:%s]", STEP_NAMES[i]); + STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAMES[i]) + String.format(STEP_PATTERN, STEP_NAMES[i]); assertThat(step.getName(), equalTo(STEP_NAMES[i])); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenarioFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenarioFailed.java index 1c5f64d..53c6a51 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenarioFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenarioFailed.java @@ -46,8 +46,6 @@ import static org.mockito.Mockito.*; public class VerifyBeforeScenarioFailed extends BaseTest { - - public static final String STEP_PATTERN = "/[STEP:%s]"; private final String storyId = namedId("story_"); private final List lifecycleStepIds = Arrays.asList(namedId("before_story_"), namedId("before_scenario_"), @@ -102,7 +100,7 @@ public void verify_before_scenario_lifecycle_step_failure_reporting() { assertThat(beforeStoryStart.getCodeRef(), equalTo(STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[0]))); assertThat(beforeStoryStart.getType(), equalTo(ItemType.STEP.name())); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAME); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAME); StartTestItemRQ scenarioStart = startItems.get(1); assertThat(scenarioStart.getName(), equalTo(SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStep.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStep.java index eed5e40..3c3bfb4 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStep.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStep.java @@ -91,7 +91,7 @@ public void verify_before_step_lifecycle_step_reporting() { // Start items verification List startItems = startCaptor.getAllValues(); StartTestItemRQ scenarioStart = startItems.get(0); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAME); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAME); assertThat(scenarioStart.getName(), equalTo(SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); @@ -99,7 +99,7 @@ public void verify_before_step_lifecycle_step_reporting() { List beforeStarts = Arrays.asList(startItems.get(1), startItems.get(3)); IntStream.range(0, beforeStarts.size()).forEach(i -> { StartTestItemRQ beforeStart = beforeStarts.get(i); - String lifecycleCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", LIFECYCLE_STEP_NAME); + String lifecycleCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAME); assertThat(beforeStart.getName(), equalTo(LIFECYCLE_STEP_NAME)); assertThat(beforeStart.getCodeRef(), equalTo(lifecycleCodeRef)); assertThat(beforeStart.getType(), equalTo(ItemType.STEP.name())); @@ -108,7 +108,7 @@ public void verify_before_step_lifecycle_step_reporting() { List steps = Arrays.asList(startItems.get(2), startItems.get(4)); IntStream.range(0, steps.size()).forEach(i -> { StartTestItemRQ step = steps.get(i); - String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAMES[i]); + String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAMES[i]); assertThat(step.getName(), equalTo(STEP_NAMES[i])); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStepFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStepFailed.java index beaff02..0093d59 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStepFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStepFailed.java @@ -47,7 +47,6 @@ public class VerifyBeforeStepFailed extends BaseTest { - public static final String STEP_PATTERN = "/[STEP:%s]"; private final String storyId = namedId("story_"); private final List lifecycleStepIds = Arrays.asList(namedId("before_story_"), namedId("before_scenario_"), @@ -102,7 +101,7 @@ public void verify_before_step_lifecycle_step_failure_reporting() { assertThat(beforeStoryStart.getCodeRef(), equalTo(STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[0]))); assertThat(beforeStoryStart.getType(), equalTo(ItemType.STEP.name())); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", SCENARIO_NAME); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAME); StartTestItemRQ scenarioStart = startItems.get(1); assertThat(scenarioStart.getName(), equalTo(SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryAnnotationFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryAnnotationFailed.java index e1cfb55..4a56e05 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryAnnotationFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryAnnotationFailed.java @@ -87,7 +87,7 @@ public void verify_before_story_annotation_failed_method_reporting() { assertThat(beforeStoryStart.getCodeRef(), nullValue()); assertThat(beforeStoryStart.getType(), equalTo(ItemType.TEST.name())); - String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME); + String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, DEFAULT_SCENARIO_NAME); StartTestItemRQ scenarioStart = startItems.get(1); assertThat(scenarioStart.getName(), equalTo(DEFAULT_SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); @@ -100,7 +100,7 @@ public void verify_before_story_annotation_failed_method_reporting() { assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_SUITE.name())); StartTestItemRQ step = startItems.get(3); - String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME); + String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/scenario/SimpleScenarioFormatTest.java b/src/test/java/com/epam/reportportal/jbehave/scenario/SimpleScenarioFormatTest.java index fdd4f17..58b9367 100644 --- a/src/test/java/com/epam/reportportal/jbehave/scenario/SimpleScenarioFormatTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/scenario/SimpleScenarioFormatTest.java @@ -89,7 +89,7 @@ public void verify_simple_story_with_scenario_reporter() { List stepRqs = items.subList(2, items.size()); IntStream.range(0, stepRqs.size()).forEach(i -> { StartTestItemRQ step = stepRqs.get(i); - String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", DUMMY_SCENARIO_STEPS.get(i)); + String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, DUMMY_SCENARIO_STEPS.get(i)); assertThat(step.getCodeRef(), allOf(notNullValue(), equalTo(stepCodeRef))); assertThat(step.getType(), allOf(notNullValue(), equalTo(ItemType.STEP.name()))); assertThat(step.isHasStats(), equalTo(Boolean.FALSE)); From 20e2e1e60bee91eef25ae958eac349efa4f3e04b Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 14 Nov 2022 19:42:42 +0300 Subject: [PATCH 23/32] BeforeStepFailedTest fix --- ...pFailed.java => BeforeStepFailedTest.java} | 77 ++++++++++++------- ...ifyBeforeStep.java => BeforeStepTest.java} | 5 +- 2 files changed, 52 insertions(+), 30 deletions(-) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyBeforeStepFailed.java => BeforeStepFailedTest.java} (65%) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyBeforeStep.java => BeforeStepTest.java} (98%) diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStepFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStepFailedTest.java similarity index 65% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStepFailed.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStepFailedTest.java index 0093d59..33fba4c 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStepFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStepFailedTest.java @@ -45,7 +45,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyBeforeStepFailed extends BaseTest { +public class BeforeStepFailedTest extends BaseTest { private final String storyId = namedId("story_"); private final List lifecycleStepIds = Arrays.asList(namedId("before_story_"), @@ -55,14 +55,19 @@ public class VerifyBeforeStepFailed extends BaseTest { namedId("after_scenario_"), namedId("after_story_") ); + private final String beforeStoryId = namedId("before_story_"); + private final String afterStoryId = namedId("after_story_"); private final String scenarioId = namedId("scenario_"); private final String stepId = namedId("step_"); - private final List>> steps = Arrays.asList(Pair.of(lifecycleStepIds.get(0), Collections.emptyList()), + private final List>> steps = Arrays.asList(Pair.of( + beforeStoryId, + Collections.singletonList(lifecycleStepIds.get(0)) + ), Pair.of(scenarioId, Stream.concat(Stream.concat(lifecycleStepIds.subList(1, 3).stream(), Stream.of(stepId)), lifecycleStepIds.subList(3, lifecycleStepIds.size() - 1).stream() ).collect(Collectors.toList())), - Pair.of(lifecycleStepIds.get(lifecycleStepIds.size() - 1), Collections.emptyList()) + Pair.of(afterStoryId, Collections.singletonList(lifecycleStepIds.get(lifecycleStepIds.size() - 1))) ); private final ReportPortalClient client = mock(ReportPortalClient.class); @@ -80,68 +85,84 @@ public void setupMock() { private static final String STORY_PATH = "stories/lifecycle/BeforeStepFailed.story"; private static final String SCENARIO_NAME = "The scenario"; private static final String STEP_NAME = "Given I have empty step"; - private static final String[] LIFECYCLE_STEP_NAMES = new String[] { "When I have one more empty step", "Then I have another empty step", - "Given I have a failed step", "When I have parameter test", "Given It is test with parameters", - "Given It is a step with an integer parameter 42" }; + private static final String[] LIFECYCLE_SUITES_NAMES = new String[] { "BeforeStory", "AfterStory" }; + private static final String[] LIFECYCLE_STEP_NAMES = new String[] { "When I have one more empty step", + "Then I have another empty step", "Given I have a failed step", "When I have parameter test", + "Given It is test with parameters", "Given It is a step with an integer parameter 42" }; @Test public void verify_before_step_lifecycle_step_failure_reporting() { run(format, STORY_PATH, new EmptySteps(), new ParameterizedSteps(), new FailedSteps()); verify(client).startTestItem(any()); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(storyId), startCaptor.capture()); - verify(client, times(5)).startTestItem(same(scenarioId), startCaptor.capture()); + ArgumentCaptor storyCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(storyId), storyCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(5)).startTestItem(same(scenarioId), scenarioCaptor.capture()); + ArgumentCaptor beforeCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(beforeStoryId), beforeCaptor.capture()); + ArgumentCaptor afterCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(afterStoryId), afterCaptor.capture()); // Start items verification - List startItems = startCaptor.getAllValues(); + List storyStartItems = storyCaptor.getAllValues(); - StartTestItemRQ beforeStoryStart = startItems.get(0); + StartTestItemRQ beforeStorySuiteStart = storyStartItems.get(0); + assertThat(beforeStorySuiteStart.getName(), equalTo(LIFECYCLE_SUITES_NAMES[0])); + String beforeSuiteCodeRef = STORY_PATH + String.format(LIFECYCLE_PATTERN, LIFECYCLE_SUITES_NAMES[0]); + assertThat(beforeStorySuiteStart.getCodeRef(), equalTo(beforeSuiteCodeRef)); + assertThat(beforeStorySuiteStart.getType(), equalTo(ItemType.TEST.name())); + + StartTestItemRQ beforeStoryStart = beforeCaptor.getValue(); assertThat(beforeStoryStart.getName(), equalTo(LIFECYCLE_STEP_NAMES[0])); - assertThat(beforeStoryStart.getCodeRef(), equalTo(STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[0]))); + assertThat(beforeStoryStart.getCodeRef(), + equalTo(beforeSuiteCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[0])) + ); assertThat(beforeStoryStart.getType(), equalTo(ItemType.STEP.name())); String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAME); - StartTestItemRQ scenarioStart = startItems.get(1); + StartTestItemRQ scenarioStart = storyStartItems.get(1); assertThat(scenarioStart.getName(), equalTo(SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); - StartTestItemRQ beforeScenario = startItems.get(3); + List scenarioStartItems = scenarioCaptor.getAllValues(); + StartTestItemRQ beforeScenario = scenarioStartItems.get(0); String beforeScenarioCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[1]); assertThat(beforeScenario.getName(), equalTo(LIFECYCLE_STEP_NAMES[1])); assertThat(beforeScenario.getCodeRef(), equalTo(beforeScenarioCodeRef)); assertThat(beforeScenario.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ beforeStep = startItems.get(4); + StartTestItemRQ beforeStep = scenarioStartItems.get(1); String beforeStepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[2]); assertThat(beforeStep.getName(), equalTo(LIFECYCLE_STEP_NAMES[2])); assertThat(beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); assertThat(beforeStep.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ step = startItems.get(5); + StartTestItemRQ step = scenarioStartItems.get(2); String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ afterStep = startItems.get(6); + StartTestItemRQ afterStep = scenarioStartItems.get(3); String afterStepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[3]); assertThat(afterStep.getName(), equalTo(LIFECYCLE_STEP_NAMES[3])); assertThat(afterStep.getCodeRef(), equalTo(afterStepCodeRef)); assertThat(afterStep.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ afterScenario = startItems.get(7); - String afterScenarioCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[4]); - assertThat(afterScenario.getName(), equalTo(LIFECYCLE_STEP_NAMES[4])); - assertThat(afterScenario.getCodeRef(), equalTo(afterScenarioCodeRef)); - assertThat(afterScenario.getType(), equalTo(ItemType.STEP.name())); - - StartTestItemRQ afterStory = startItems.get(2); - String afterStoryCodeRef = STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1]); - assertThat(afterStory.getName(), equalTo(LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1])); - assertThat(afterStory.getCodeRef(), equalTo(afterStoryCodeRef)); - assertThat(afterStory.getType(), equalTo(ItemType.STEP.name())); + StartTestItemRQ afterStoryStart = storyStartItems.get(2); + String afterStoryCodeRef = STORY_PATH + String.format(LIFECYCLE_PATTERN, LIFECYCLE_SUITES_NAMES[1]); + assertThat(afterStoryStart.getName(), equalTo(LIFECYCLE_SUITES_NAMES[1])); + assertThat(afterStoryStart.getCodeRef(), equalTo(afterStoryCodeRef)); + assertThat(afterStoryStart.getType(), equalTo(ItemType.TEST.name())); + + StartTestItemRQ afterStoryStepStart = afterCaptor.getValue(); + String afterStoryStepCodeRef = + afterStoryCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1]); + assertThat(afterStoryStepStart.getName(), equalTo(LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1])); + assertThat(afterStoryStepStart.getCodeRef(), equalTo(afterStoryStepCodeRef)); + assertThat(afterStoryStepStart.getType(), equalTo(ItemType.STEP.name())); // Finish items verification ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStep.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStepTest.java similarity index 98% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStep.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStepTest.java index 3c3bfb4..f817ed6 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStep.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStepTest.java @@ -43,7 +43,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyBeforeStep extends BaseTest { +public class BeforeStepTest extends BaseTest { private static final int STEP_NUMBER = 2; private final String storyId = CommonUtils.namedId("story_"); @@ -76,7 +76,8 @@ public void setupMock() { private static final String STORY_PATH = "stories/lifecycle/BeforeStep.story"; private static final String SCENARIO_NAME = "The scenario"; - private static final String[] STEP_NAMES = new String[] { "Given I have empty step", "When I have one more empty step" }; + private static final String[] STEP_NAMES = new String[] { "Given I have empty step", + "When I have one more empty step" }; private static final String LIFECYCLE_STEP_NAME = "Then I have another empty step"; @Test From d10bd401a74e273b8bda86fcbeff98ac54bfd5cc Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 14 Nov 2022 19:54:51 +0300 Subject: [PATCH 24/32] AfterScenarioAnnotationFailedTest fix --- ...ed.java => AfterScenarioAnnotationFailedTest.java} | 11 ++++++----- .../{VerifyAfterStep.java => AfterStepTest.java} | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyAfterScenarioAnnotationFailed.java => AfterScenarioAnnotationFailedTest.java} (92%) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyAfterStep.java => AfterStepTest.java} (99%) diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterScenarioAnnotationFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterScenarioAnnotationFailedTest.java similarity index 92% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterScenarioAnnotationFailed.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterScenarioAnnotationFailedTest.java index 740691e..b38af34 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterScenarioAnnotationFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterScenarioAnnotationFailedTest.java @@ -42,7 +42,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyAfterScenarioAnnotationFailed extends BaseTest { +public class AfterScenarioAnnotationFailedTest extends BaseTest { private final String storyId = CommonUtils.namedId("story_"); private final String scenarioId = CommonUtils.namedId("scenario_"); @@ -68,6 +68,7 @@ public void setupMock() { private static final String STORY_PATH = "stories/NoScenario.story"; private static final String DEFAULT_SCENARIO_NAME = "No name"; private static final String STEP_NAME = "Given I have empty step"; + private static final String AFTER_SCENARIO_NAME = "afterScenarioFailed"; @Test public void verify_after_scenario_annotation_failed_method_reporting() { @@ -93,10 +94,10 @@ public void verify_after_scenario_annotation_failed_method_reporting() { assertThat(step.getType(), equalTo(ItemType.STEP.name())); StartTestItemRQ afterStep = startItems.get(2); - String afterStepCodeRef = AfterScenarioFailedSteps.class.getCanonicalName() + ".afterScenarioFailed()"; - assertThat(afterStep.getName(), equalTo(afterStepCodeRef)); - assertThat(afterStep.getCodeRef(), equalTo(afterStepCodeRef)); - assertThat(afterStep.getType(), equalTo(ItemType.AFTER_TEST.name())); + assertThat(afterStep.getName(), equalTo(AFTER_SCENARIO_NAME)); + String afterCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, AFTER_SCENARIO_NAME); + assertThat(afterStep.getCodeRef(), equalTo(afterCodeRef)); + assertThat(afterStep.getType(), equalTo(ItemType.STEP.name())); // Finish items verification ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStep.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStepTest.java similarity index 99% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStep.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStepTest.java index c3cf6ed..fc0d74d 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStep.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStepTest.java @@ -43,7 +43,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyAfterStep extends BaseTest { +public class AfterStepTest extends BaseTest { private static final int STEP_NUMBER = 2; private final String storyId = CommonUtils.namedId("story_"); From a1d10b04730fe8d5e016eed21a74c8b436e5188e Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 14 Nov 2022 20:29:33 +0300 Subject: [PATCH 25/32] AfterStoryTest fix --- ...ifyAfterStory.java => AfterStoryTest.java} | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyAfterStory.java => AfterStoryTest.java} (80%) diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStory.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryTest.java similarity index 80% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStory.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryTest.java index d9078d6..337ef82 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStory.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryTest.java @@ -35,20 +35,22 @@ import java.util.Collections; import java.util.List; +import static com.epam.reportportal.util.test.CommonUtils.namedId; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyAfterStory extends BaseTest { +public class AfterStoryTest extends BaseTest { private final String storyId = CommonUtils.namedId("story_"); private final String scenarioId = CommonUtils.namedId("scenario_"); + private final String afterStoryId = namedId("after_story_"); private final String afterStepId = CommonUtils.namedId("after_story_step_"); private final String stepId = CommonUtils.namedId("step_"); private final List>> steps = Arrays.asList(Pair.of(scenarioId, Collections.singletonList(stepId)), - Pair.of(afterStepId, Collections.emptyList()) + Pair.of(afterStoryId, Collections.singletonList(afterStepId)) ); private final ReportPortalClient client = mock(ReportPortalClient.class); @@ -67,6 +69,7 @@ public void setupMock() { private static final String SCENARIO_NAME = "The scenario"; private static final String STEP_NAME = "Given I have empty step"; private static final String LIFECYCLE_STEP_NAME = "Then I have another empty step"; + private static final String AFTER_SUITE_NAME = "AfterStory"; @Test public void verify_after_story_lifecycle_step_reporting() { @@ -76,6 +79,7 @@ public void verify_after_story_lifecycle_step_reporting() { ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); verify(client, times(2)).startTestItem(same(storyId), startCaptor.capture()); verify(client).startTestItem(same(scenarioId), startCaptor.capture()); + verify(client).startTestItem(same(afterStoryId), startCaptor.capture()); // Start items verification List startItems = startCaptor.getAllValues(); @@ -86,10 +90,11 @@ public void verify_after_story_lifecycle_step_reporting() { assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); - StartTestItemRQ afterStoryStart = startItems.get(1); - assertThat(afterStoryStart.getName(), equalTo(LIFECYCLE_STEP_NAME)); - assertThat(afterStoryStart.getCodeRef(), equalTo(STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAME))); - assertThat(afterStoryStart.getType(), equalTo(ItemType.STEP.name())); + StartTestItemRQ beforeStoryStart = startItems.get(1); + assertThat(beforeStoryStart.getName(), equalTo(AFTER_SUITE_NAME)); + String afterStoryCodeRef = STORY_PATH + String.format(LIFECYCLE_PATTERN, AFTER_SUITE_NAME); + assertThat(beforeStoryStart.getCodeRef(), equalTo(afterStoryCodeRef)); + assertThat(beforeStoryStart.getType(), equalTo(ItemType.TEST.name())); StartTestItemRQ step = startItems.get(2); String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); @@ -97,6 +102,11 @@ public void verify_after_story_lifecycle_step_reporting() { assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); + StartTestItemRQ afterStep = startItems.get(3); + assertThat(afterStep.getName(), equalTo(LIFECYCLE_STEP_NAME)); + assertThat(afterStep.getCodeRef(), equalTo(afterStoryCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAME))); + assertThat(afterStep.getType(), equalTo(ItemType.STEP.name())); + // Finish items verification ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); verify(client).finishTestItem(same(stepId), finishStepCaptor.capture()); From a8e4812a33001f317c6ea9b5dd1e252f8403d6c3 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Mon, 14 Nov 2022 20:40:12 +0300 Subject: [PATCH 26/32] AfterStoryFailedTest fix --- ...yFailed.java => AfterStoryFailedTest.java} | 74 +++++++++++++------ 1 file changed, 51 insertions(+), 23 deletions(-) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyAfterStoryFailed.java => AfterStoryFailedTest.java} (66%) diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStoryFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryFailedTest.java similarity index 66% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStoryFailed.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryFailedTest.java index 27dafbb..498e01e 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStoryFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryFailedTest.java @@ -45,7 +45,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyAfterStoryFailed extends BaseTest { +public class AfterStoryFailedTest extends BaseTest { private final String storyId = namedId("story_"); private final List lifecycleStepIds = Arrays.asList(namedId("before_story_"), @@ -55,14 +55,19 @@ public class VerifyAfterStoryFailed extends BaseTest { namedId("after_scenario_"), namedId("after_story_") ); + private final String beforeStoryId = namedId("before_story_"); + private final String afterStoryId = namedId("after_story_"); private final String scenarioId = namedId("scenario_"); private final String stepId = namedId("step_"); - private final List>> steps = Arrays.asList(Pair.of(lifecycleStepIds.get(0), Collections.emptyList()), + private final List>> steps = Arrays.asList(Pair.of( + beforeStoryId, + Collections.singletonList(lifecycleStepIds.get(0)) + ), Pair.of(scenarioId, Stream.concat(Stream.concat(lifecycleStepIds.subList(1, 3).stream(), Stream.of(stepId)), lifecycleStepIds.subList(3, lifecycleStepIds.size() - 1).stream() ).collect(Collectors.toList())), - Pair.of(lifecycleStepIds.get(lifecycleStepIds.size() - 1), Collections.emptyList()) + Pair.of(afterStoryId, Collections.singletonList(lifecycleStepIds.get(lifecycleStepIds.size() - 1))) ); private final ReportPortalClient client = mock(ReportPortalClient.class); @@ -80,68 +85,91 @@ public void setupMock() { private static final String STORY_PATH = "stories/lifecycle/AfterStoryFailed.story"; private static final String SCENARIO_NAME = "The scenario"; private static final String STEP_NAME = "Given I have empty step"; - private static final String[] LIFECYCLE_STEP_NAMES = new String[] { "Given It is a step with an integer parameter 42", - "Then I have another empty step", "Given It is test with parameters", "When I have parameter test", - "Then I have another empty step", "Given I have a failed step" }; + private static final String[] LIFECYCLE_SUITES_NAMES = new String[] { "BeforeStory", "AfterStory" }; + private static final String[] LIFECYCLE_STEP_NAMES = new String[] { + "Given It is a step with an integer parameter 42", "Then I have another empty step", + "Given It is test with parameters", "When I have parameter test", "Then I have another empty step", + "Given I have a failed step" }; @Test public void verify_after_story_lifecycle_step_failure_reporting() { run(format, STORY_PATH, new EmptySteps(), new ParameterizedSteps(), new FailedSteps()); verify(client).startTestItem(any()); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(storyId), startCaptor.capture()); - verify(client, times(5)).startTestItem(same(scenarioId), startCaptor.capture()); + ArgumentCaptor storyCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(storyId), storyCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(5)).startTestItem(same(scenarioId), scenarioCaptor.capture()); + ArgumentCaptor beforeCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(beforeStoryId), beforeCaptor.capture()); + ArgumentCaptor afterCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(afterStoryId), afterCaptor.capture()); // Start items verification - List startItems = startCaptor.getAllValues(); + List storyStartItems = storyCaptor.getAllValues(); - StartTestItemRQ beforeStoryStart = startItems.get(0); + StartTestItemRQ beforeStorySuiteStart = storyStartItems.get(0); + assertThat(beforeStorySuiteStart.getName(), equalTo(LIFECYCLE_SUITES_NAMES[0])); + String beforeSuiteCodeRef = STORY_PATH + String.format(LIFECYCLE_PATTERN, LIFECYCLE_SUITES_NAMES[0]); + assertThat(beforeStorySuiteStart.getCodeRef(), equalTo(beforeSuiteCodeRef)); + assertThat(beforeStorySuiteStart.getType(), equalTo(ItemType.TEST.name())); + + StartTestItemRQ beforeStoryStart = beforeCaptor.getValue(); assertThat(beforeStoryStart.getName(), equalTo(LIFECYCLE_STEP_NAMES[0])); - assertThat(beforeStoryStart.getCodeRef(), equalTo(STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[0]))); + assertThat(beforeStoryStart.getCodeRef(), + equalTo(beforeSuiteCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[0])) + ); assertThat(beforeStoryStart.getType(), equalTo(ItemType.STEP.name())); String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAME); - StartTestItemRQ scenarioStart = startItems.get(1); + StartTestItemRQ scenarioStart = storyStartItems.get(1); assertThat(scenarioStart.getName(), equalTo(SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); - StartTestItemRQ beforeScenario = startItems.get(3); + List scenarioStartItems = scenarioCaptor.getAllValues(); + StartTestItemRQ beforeScenario = scenarioStartItems.get(0); String beforeScenarioCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[1]); assertThat(beforeScenario.getName(), equalTo(LIFECYCLE_STEP_NAMES[1])); assertThat(beforeScenario.getCodeRef(), equalTo(beforeScenarioCodeRef)); assertThat(beforeScenario.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ beforeStep = startItems.get(4); + StartTestItemRQ beforeStep = scenarioStartItems.get(1); String beforeStepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[2]); assertThat(beforeStep.getName(), equalTo(LIFECYCLE_STEP_NAMES[2])); assertThat(beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); assertThat(beforeStep.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ step = startItems.get(5); + StartTestItemRQ step = scenarioStartItems.get(2); String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ afterStep = startItems.get(6); + StartTestItemRQ afterStep = scenarioStartItems.get(3); String afterStepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[3]); assertThat(afterStep.getName(), equalTo(LIFECYCLE_STEP_NAMES[3])); assertThat(afterStep.getCodeRef(), equalTo(afterStepCodeRef)); assertThat(afterStep.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ afterScenario = startItems.get(7); + StartTestItemRQ afterScenario = scenarioStartItems.get(4); String afterScenarioCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[4]); assertThat(afterScenario.getName(), equalTo(LIFECYCLE_STEP_NAMES[4])); assertThat(afterScenario.getCodeRef(), equalTo(afterScenarioCodeRef)); assertThat(afterScenario.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ afterStory = startItems.get(2); - String afterStoryCodeRef = STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1]); - assertThat(afterStory.getName(), equalTo(LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1])); - assertThat(afterStory.getCodeRef(), equalTo(afterStoryCodeRef)); - assertThat(afterStory.getType(), equalTo(ItemType.STEP.name())); + StartTestItemRQ afterStoryStart = storyStartItems.get(2); + String afterStoryCodeRef = STORY_PATH + String.format(LIFECYCLE_PATTERN, LIFECYCLE_SUITES_NAMES[1]); + assertThat(afterStoryStart.getName(), equalTo(LIFECYCLE_SUITES_NAMES[1])); + assertThat(afterStoryStart.getCodeRef(), equalTo(afterStoryCodeRef)); + assertThat(afterStoryStart.getType(), equalTo(ItemType.TEST.name())); + + StartTestItemRQ afterStoryStepStart = afterCaptor.getValue(); + String afterStoryStepCodeRef = + afterStoryCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1]); + assertThat(afterStoryStepStart.getName(), equalTo(LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1])); + assertThat(afterStoryStepStart.getCodeRef(), equalTo(afterStoryStepCodeRef)); + assertThat(afterStoryStepStart.getType(), equalTo(ItemType.STEP.name())); // Finish items verification ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); From 7b2b69c0a7897d7ed0b3436ff6a3179f32135876 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 15 Nov 2022 12:15:15 +0300 Subject: [PATCH 27/32] BeforeStoryAnnotationFailedTest fix, format fix --- ...erScenario.java => AfterScenarioTest.java} | 17 +++++++++------ .../jbehave/lifecycle/AfterStepTest.java | 3 ++- .../AfterStoriesAnnotationFailedTest.java | 5 ++++- .../AfterStoryAnnotationFailedTest.java | 5 ++++- .../lifecycle/AfterStoryFailedTest.java | 3 +-- .../jbehave/lifecycle/AfterStoryTest.java | 10 +++++++-- ...led.java => BeforeScenarioFailedTest.java} | 21 ++++++++++++------- ...eScenario.java => BeforeScenarioTest.java} | 17 +++++++++------ .../lifecycle/BeforeStepFailedTest.java | 3 +-- .../BeforeStoriesAnnotationFailedTest.java | 13 ++++++------ ...a => BeforeStoryAnnotationFailedTest.java} | 20 +++++++++++------- .../jbehave/lifecycle/BeforeStoryTest.java | 4 +--- 12 files changed, 76 insertions(+), 45 deletions(-) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyAfterScenario.java => AfterScenarioTest.java} (93%) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyBeforeScenarioFailed.java => BeforeScenarioFailedTest.java} (92%) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyBeforeScenario.java => BeforeScenarioTest.java} (93%) rename src/test/java/com/epam/reportportal/jbehave/lifecycle/{VerifyBeforeStoryAnnotationFailed.java => BeforeStoryAnnotationFailedTest.java} (87%) diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterScenario.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterScenarioTest.java similarity index 93% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterScenario.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterScenarioTest.java index 3512771..3c00bea 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterScenario.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterScenarioTest.java @@ -42,7 +42,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyAfterScenario extends BaseTest { +public class AfterScenarioTest extends BaseTest { private static final int SCENARIO_NUMBER = 2; private final String storyId = CommonUtils.namedId("story_"); @@ -74,7 +74,8 @@ public void setupMock() { private static final String STORY_PATH = "stories/lifecycle/AfterScenario.story"; private static final String[] SCENARIO_NAMES = new String[] { "The scenario", "Another scenario" }; - private static final String[] STEP_NAMES = new String[] { "Given I have empty step", "When I have one more empty step" }; + private static final String[] STEP_NAMES = new String[] { "Given I have empty step", + "When I have one more empty step" }; private static final String LIFECYCLE_STEP_NAME = "Then I have another empty step"; @Test @@ -101,8 +102,10 @@ public void verify_after_scenario_lifecycle_step_reporting() { List steps = Arrays.asList(startItems.get(2), startItems.get(4)); IntStream.range(0, steps.size()).forEach(i -> { StartTestItemRQ step = steps.get(i); - String stepCodeRef = - STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAMES[i]) + String.format(STEP_PATTERN, STEP_NAMES[i]); + String stepCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAMES[i]) + String.format( + STEP_PATTERN, + STEP_NAMES[i] + ); assertThat(step.getName(), equalTo(STEP_NAMES[i])); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); @@ -111,8 +114,10 @@ public void verify_after_scenario_lifecycle_step_reporting() { List afterStarts = Arrays.asList(startItems.get(3), startItems.get(5)); IntStream.range(0, afterStarts.size()).forEach(i -> { StartTestItemRQ beforeStart = afterStarts.get(i); - String lifecycleCodeRef = - STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAMES[i]) + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAME); + String lifecycleCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAMES[i]) + String.format( + STEP_PATTERN, + LIFECYCLE_STEP_NAME + ); assertThat(beforeStart.getName(), equalTo(LIFECYCLE_STEP_NAME)); assertThat(beforeStart.getCodeRef(), equalTo(lifecycleCodeRef)); assertThat(beforeStart.getType(), equalTo(ItemType.STEP.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStepTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStepTest.java index fc0d74d..a816665 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStepTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStepTest.java @@ -76,7 +76,8 @@ public void setupMock() { private static final String STORY_PATH = "stories/lifecycle/AfterStep.story"; private static final String SCENARIO_NAME = "The scenario"; - private static final String[] STEP_NAMES = new String[] { "Given I have empty step", "When I have one more empty step" }; + private static final String[] STEP_NAMES = new String[] { "Given I have empty step", + "When I have one more empty step" }; private static final String LIFECYCLE_STEP_NAME = "Then I have another empty step"; @Test diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java index 4d0d290..63e5bc1 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java @@ -113,7 +113,10 @@ public void verify_before_story_annotation_failed_method_reporting() { StartTestItemRQ afterStep = startItems.get(4); assertThat(afterStep.getName(), equalTo(AFTER_STORY_NAME)); - assertThat(afterStep.getCodeRef(), equalTo(afterStoriesCodeRef + String.format("/[AFTER_GROUPS:%s]", AFTER_STORY_NAME))); + assertThat( + afterStep.getCodeRef(), + equalTo(afterStoriesCodeRef + String.format("/[AFTER_GROUPS:%s]", AFTER_STORY_NAME)) + ); assertThat(afterStep.getType(), equalTo(ItemType.AFTER_GROUPS.name())); // Finish items verification diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java index 6e8f27f..98587b2 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryAnnotationFailedTest.java @@ -50,7 +50,10 @@ public class AfterStoryAnnotationFailedTest extends BaseTest { private final String scenarioId = CommonUtils.namedId("scenario_"); private final String stepId = CommonUtils.namedId("step_"); - private final List>> steps = Arrays.asList(Pair.of(scenarioId, Collections.singletonList(stepId)), + private final List>> steps = Arrays.asList(Pair.of( + scenarioId, + Collections.singletonList(stepId) + ), Pair.of(afterStoryId, Collections.singletonList(afterStepId)) ); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryFailedTest.java index 498e01e..4ebe104 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryFailedTest.java @@ -60,8 +60,7 @@ public class AfterStoryFailedTest extends BaseTest { private final String scenarioId = namedId("scenario_"); private final String stepId = namedId("step_"); - private final List>> steps = Arrays.asList(Pair.of( - beforeStoryId, + private final List>> steps = Arrays.asList(Pair.of(beforeStoryId, Collections.singletonList(lifecycleStepIds.get(0)) ), Pair.of(scenarioId, Stream.concat(Stream.concat(lifecycleStepIds.subList(1, 3).stream(), Stream.of(stepId)), diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryTest.java index 337ef82..0be57cc 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryTest.java @@ -49,7 +49,10 @@ public class AfterStoryTest extends BaseTest { private final String afterStepId = CommonUtils.namedId("after_story_step_"); private final String stepId = CommonUtils.namedId("step_"); - private final List>> steps = Arrays.asList(Pair.of(scenarioId, Collections.singletonList(stepId)), + private final List>> steps = Arrays.asList(Pair.of( + scenarioId, + Collections.singletonList(stepId) + ), Pair.of(afterStoryId, Collections.singletonList(afterStepId)) ); @@ -104,7 +107,10 @@ public void verify_after_story_lifecycle_step_reporting() { StartTestItemRQ afterStep = startItems.get(3); assertThat(afterStep.getName(), equalTo(LIFECYCLE_STEP_NAME)); - assertThat(afterStep.getCodeRef(), equalTo(afterStoryCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAME))); + assertThat( + afterStep.getCodeRef(), + equalTo(afterStoryCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAME)) + ); assertThat(afterStep.getType(), equalTo(ItemType.STEP.name())); // Finish items verification diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenarioFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioFailedTest.java similarity index 92% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenarioFailed.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioFailedTest.java index 53c6a51..63bd95b 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenarioFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioFailedTest.java @@ -45,7 +45,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyBeforeScenarioFailed extends BaseTest { +public class BeforeScenarioFailedTest extends BaseTest { private final String storyId = namedId("story_"); private final List lifecycleStepIds = Arrays.asList(namedId("before_story_"), namedId("before_scenario_"), @@ -57,7 +57,10 @@ public class VerifyBeforeScenarioFailed extends BaseTest { private final String scenarioId = namedId("scenario_"); private final String stepId = namedId("step_"); - private final List>> steps = Arrays.asList(Pair.of(lifecycleStepIds.get(0), Collections.emptyList()), + private final List>> steps = Arrays.asList(Pair.of( + lifecycleStepIds.get(0), + Collections.emptyList() + ), Pair.of(scenarioId, Stream.concat(Stream.concat(lifecycleStepIds.subList(1, 3).stream(), Stream.of(stepId)), lifecycleStepIds.subList(3, lifecycleStepIds.size() - 1).stream() ).collect(Collectors.toList())), @@ -79,9 +82,9 @@ public void setupMock() { private static final String STORY_PATH = "stories/lifecycle/BeforeScenarioFailed.story"; private static final String SCENARIO_NAME = "The scenario"; private static final String STEP_NAME = "Given I have empty step"; - private static final String[] LIFECYCLE_STEP_NAMES = new String[] { "When I have one more empty step", "Given I have a failed step", - "Given It is test with parameters", "When I have parameter test", "Then I have another empty step", - "Given It is a step with an integer parameter 42" }; + private static final String[] LIFECYCLE_STEP_NAMES = new String[] { "When I have one more empty step", + "Given I have a failed step", "Given It is test with parameters", "When I have parameter test", + "Then I have another empty step", "Given It is a step with an integer parameter 42" }; @Test public void verify_before_scenario_lifecycle_step_failure_reporting() { @@ -97,7 +100,10 @@ public void verify_before_scenario_lifecycle_step_failure_reporting() { StartTestItemRQ beforeStoryStart = startItems.get(0); assertThat(beforeStoryStart.getName(), equalTo(LIFECYCLE_STEP_NAMES[0])); - assertThat(beforeStoryStart.getCodeRef(), equalTo(STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[0]))); + assertThat( + beforeStoryStart.getCodeRef(), + equalTo(STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[0])) + ); assertThat(beforeStoryStart.getType(), equalTo(ItemType.STEP.name())); String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAME); @@ -137,7 +143,8 @@ public void verify_before_scenario_lifecycle_step_failure_reporting() { assertThat(afterScenario.getType(), equalTo(ItemType.STEP.name())); StartTestItemRQ afterStory = startItems.get(2); - String afterStoryCodeRef = STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1]); + String afterStoryCodeRef = + STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1]); assertThat(afterStory.getName(), equalTo(LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1])); assertThat(afterStory.getCodeRef(), equalTo(afterStoryCodeRef)); assertThat(afterStory.getType(), equalTo(ItemType.STEP.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenario.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioTest.java similarity index 93% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenario.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioTest.java index 01225d4..90e56f9 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenario.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioTest.java @@ -42,7 +42,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyBeforeScenario extends BaseTest { +public class BeforeScenarioTest extends BaseTest { private static final int SCENARIO_NUMBER = 2; private final String storyId = CommonUtils.namedId("story_"); @@ -74,7 +74,8 @@ public void setupMock() { private static final String STORY_PATH = "stories/lifecycle/BeforeScenario.story"; private static final String[] SCENARIO_NAMES = new String[] { "The scenario", "Another scenario" }; - private static final String[] STEP_NAMES = new String[] { "Given I have empty step", "When I have one more empty step" }; + private static final String[] STEP_NAMES = new String[] { "Given I have empty step", + "When I have one more empty step" }; private static final String LIFECYCLE_STEP_NAME = "Then I have another empty step"; @Test @@ -101,8 +102,10 @@ public void verify_before_scenario_lifecycle_step_reporting() { List beforeStarts = Arrays.asList(startItems.get(2), startItems.get(4)); IntStream.range(0, beforeStarts.size()).forEach(i -> { StartTestItemRQ beforeStart = beforeStarts.get(i); - String lifecycleCodeRef = - STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAMES[i]) + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAME); + String lifecycleCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAMES[i]) + String.format( + STEP_PATTERN, + LIFECYCLE_STEP_NAME + ); assertThat(beforeStart.getName(), equalTo(LIFECYCLE_STEP_NAME)); assertThat(beforeStart.getCodeRef(), equalTo(lifecycleCodeRef)); assertThat(beforeStart.getType(), equalTo(ItemType.STEP.name())); @@ -111,8 +114,10 @@ public void verify_before_scenario_lifecycle_step_reporting() { List steps = Arrays.asList(startItems.get(3), startItems.get(5)); IntStream.range(0, steps.size()).forEach(i -> { StartTestItemRQ step = steps.get(i); - String stepCodeRef = - STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAMES[i]) + String.format(STEP_PATTERN, STEP_NAMES[i]); + String stepCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAMES[i]) + String.format( + STEP_PATTERN, + STEP_NAMES[i] + ); assertThat(step.getName(), equalTo(STEP_NAMES[i])); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStepFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStepFailedTest.java index 33fba4c..31b4ee3 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStepFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStepFailedTest.java @@ -60,8 +60,7 @@ public class BeforeStepFailedTest extends BaseTest { private final String scenarioId = namedId("scenario_"); private final String stepId = namedId("step_"); - private final List>> steps = Arrays.asList(Pair.of( - beforeStoryId, + private final List>> steps = Arrays.asList(Pair.of(beforeStoryId, Collections.singletonList(lifecycleStepIds.get(0)) ), Pair.of(scenarioId, Stream.concat(Stream.concat(lifecycleStepIds.subList(1, 3).stream(), Stream.of(stepId)), diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java index 969ef7e..8ea3f84 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java @@ -73,8 +73,8 @@ public void setupMock() { private static final String STORY_PATH = "stories/NoScenario.story"; private static final String DEFAULT_SCENARIO_NAME = "No name"; private static final String STEP_NAME = "Given I have empty step"; - - private static final String AFTER_STORY_NAME = "beforeStoriesFailed"; + private static final String BEFORE_STORY_SUITE_NAME = "BeforeStories"; + private static final String BEFORE_STORY_NAME = "beforeStoriesFailed"; @Test public void verify_before_story_annotation_failed_method_reporting() { @@ -89,7 +89,7 @@ public void verify_before_story_annotation_failed_method_reporting() { // Start items verification List startItems = startCaptor.getAllValues(); StartTestItemRQ beforeStoriesStart = startItems.get(0); - String beforeStoriesCodeRef = "BeforeStories"; + String beforeStoriesCodeRef = BEFORE_STORY_SUITE_NAME; assertThat(beforeStoriesStart.getName(), equalTo(beforeStoriesCodeRef)); assertThat(beforeStoriesStart.getCodeRef(), equalTo(beforeStoriesCodeRef)); assertThat(beforeStoriesStart.getType(), equalTo(ItemType.TEST.name())); @@ -99,10 +99,9 @@ public void verify_before_story_annotation_failed_method_reporting() { assertThat(storyStart.getType(), allOf(notNullValue(), equalTo(ItemType.STORY.name()))); StartTestItemRQ beforeStep = startItems.get(2); - assertThat(beforeStep.getName(), equalTo(AFTER_STORY_NAME)); - assertThat( - beforeStep.getCodeRef(), - equalTo(beforeStoriesCodeRef + String.format("/[BEFORE_GROUPS:%s]", AFTER_STORY_NAME)) + assertThat(beforeStep.getName(), equalTo(BEFORE_STORY_NAME)); + assertThat(beforeStep.getCodeRef(), + equalTo(beforeStoriesCodeRef + String.format("/[BEFORE_GROUPS:%s]", BEFORE_STORY_NAME)) ); assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_GROUPS.name())); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryAnnotationFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryAnnotationFailedTest.java similarity index 87% rename from src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryAnnotationFailed.java rename to src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryAnnotationFailedTest.java index 4a56e05..d86dc14 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStoryAnnotationFailed.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryAnnotationFailedTest.java @@ -42,7 +42,7 @@ import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.*; -public class VerifyBeforeStoryAnnotationFailed extends BaseTest { +public class BeforeStoryAnnotationFailedTest extends BaseTest { private final String storyId = CommonUtils.namedId("story_"); private final String beforeStoryId = CommonUtils.namedId("before_story_"); @@ -50,7 +50,10 @@ public class VerifyBeforeStoryAnnotationFailed extends BaseTest { private final String scenarioId = CommonUtils.namedId("scenario_"); private final String stepId = CommonUtils.namedId("step_"); - private final List>> steps = Arrays.asList(Pair.of(beforeStoryId, Collections.singletonList(beforeStepId)), + private final List>> steps = Arrays.asList(Pair.of( + beforeStoryId, + Collections.singletonList(beforeStepId) + ), Pair.of(scenarioId, Collections.singletonList(stepId)) ); @@ -69,6 +72,8 @@ public void setupMock() { private static final String STORY_PATH = "stories/NoScenario.story"; private static final String DEFAULT_SCENARIO_NAME = "No name"; private static final String STEP_NAME = "Given I have empty step"; + private static final String BEFORE_STORY_SUITE_NAME = "BeforeStory"; + private static final String BEFORE_STORY_NAME = "beforeStoryFailed"; @Test public void verify_before_story_annotation_failed_method_reporting() { @@ -83,8 +88,9 @@ public void verify_before_story_annotation_failed_method_reporting() { // Start items verification List startItems = startCaptor.getAllValues(); StartTestItemRQ beforeStoryStart = startItems.get(0); - assertThat(beforeStoryStart.getName(), equalTo("BeforeStory")); - assertThat(beforeStoryStart.getCodeRef(), nullValue()); + assertThat(beforeStoryStart.getName(), equalTo(BEFORE_STORY_SUITE_NAME)); + String beforeStorySuiteCodeRef = STORY_PATH + String.format(LIFECYCLE_PATTERN, BEFORE_STORY_SUITE_NAME); + assertThat(beforeStoryStart.getCodeRef(), equalTo(beforeStorySuiteCodeRef)); assertThat(beforeStoryStart.getType(), equalTo(ItemType.TEST.name())); String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, DEFAULT_SCENARIO_NAME); @@ -94,10 +100,10 @@ public void verify_before_story_annotation_failed_method_reporting() { assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); StartTestItemRQ beforeStep = startItems.get(2); - String beforeStepCodeRef = BeforeStoryFailedSteps.class.getCanonicalName() + ".beforeStoryFailed()"; - assertThat(beforeStep.getName(), equalTo(beforeStepCodeRef)); + String beforeStepCodeRef = beforeStorySuiteCodeRef + String.format(STEP_PATTERN, BEFORE_STORY_NAME); + assertThat(beforeStep.getName(), equalTo(BEFORE_STORY_NAME)); assertThat(beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); - assertThat(beforeStep.getType(), equalTo(ItemType.BEFORE_SUITE.name())); + assertThat(beforeStep.getType(), equalTo(ItemType.STEP.name())); StartTestItemRQ step = startItems.get(3); String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryTest.java index cc8eb9c..7babf58 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryTest.java @@ -89,9 +89,7 @@ public void verify_before_story_lifecycle_step_reporting() { StartTestItemRQ beforeStorySuiteStart = startItems.get(0); assertThat(beforeStorySuiteStart.getName(), equalTo(LIFECYCLE_SUITE_NAME)); String beforeSuiteCodeRef = STORY_PATH + String.format(LIFECYCLE_PATTERN, LIFECYCLE_SUITE_NAME); - assertThat(beforeStorySuiteStart.getCodeRef(), - equalTo(beforeSuiteCodeRef) - ); + assertThat(beforeStorySuiteStart.getCodeRef(), equalTo(beforeSuiteCodeRef)); StartTestItemRQ beforeStoryStart = beforeCaptor.getValue(); assertThat(beforeStoryStart.getName(), equalTo(LIFECYCLE_STEP_NAME)); From a07ac14fdf38fe6dfb45bb92375651e1b8cc3670 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 15 Nov 2022 12:56:04 +0300 Subject: [PATCH 28/32] BeforeScenarioFailedTest fix --- .../lifecycle/BeforeScenarioFailedTest.java | 67 ++++++++++++------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioFailedTest.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioFailedTest.java index 63bd95b..055f2ab 100644 --- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioFailedTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioFailedTest.java @@ -54,17 +54,18 @@ public class BeforeScenarioFailedTest extends BaseTest { namedId("after_scenario_"), namedId("after_story_") ); + private final String beforeStoryId = namedId("before_story_"); + private final String afterStoryId = namedId("after_story_"); private final String scenarioId = namedId("scenario_"); private final String stepId = namedId("step_"); - private final List>> steps = Arrays.asList(Pair.of( - lifecycleStepIds.get(0), - Collections.emptyList() + private final List>> steps = Arrays.asList(Pair.of(beforeStoryId, + Collections.singletonList(lifecycleStepIds.get(0)) ), Pair.of(scenarioId, Stream.concat(Stream.concat(lifecycleStepIds.subList(1, 3).stream(), Stream.of(stepId)), lifecycleStepIds.subList(3, lifecycleStepIds.size() - 1).stream() ).collect(Collectors.toList())), - Pair.of(lifecycleStepIds.get(lifecycleStepIds.size() - 1), Collections.emptyList()) + Pair.of(afterStoryId, Collections.singletonList(lifecycleStepIds.get(lifecycleStepIds.size() - 1))) ); private final ReportPortalClient client = mock(ReportPortalClient.class); @@ -82,6 +83,7 @@ public void setupMock() { private static final String STORY_PATH = "stories/lifecycle/BeforeScenarioFailed.story"; private static final String SCENARIO_NAME = "The scenario"; private static final String STEP_NAME = "Given I have empty step"; + private static final String[] LIFECYCLE_SUITES_NAMES = new String[] { "BeforeStory", "AfterStory" }; private static final String[] LIFECYCLE_STEP_NAMES = new String[] { "When I have one more empty step", "Given I have a failed step", "Given It is test with parameters", "When I have parameter test", "Then I have another empty step", "Given It is a step with an integer parameter 42" }; @@ -91,63 +93,80 @@ public void verify_before_scenario_lifecycle_step_failure_reporting() { run(format, STORY_PATH, new EmptySteps(), new ParameterizedSteps(), new FailedSteps()); verify(client).startTestItem(any()); - ArgumentCaptor startCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); - verify(client, times(3)).startTestItem(same(storyId), startCaptor.capture()); - verify(client, times(5)).startTestItem(same(scenarioId), startCaptor.capture()); + ArgumentCaptor storyCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(3)).startTestItem(same(storyId), storyCaptor.capture()); + ArgumentCaptor scenarioCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client, times(5)).startTestItem(same(scenarioId), scenarioCaptor.capture()); + ArgumentCaptor beforeCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(beforeStoryId), beforeCaptor.capture()); + ArgumentCaptor afterCaptor = ArgumentCaptor.forClass(StartTestItemRQ.class); + verify(client).startTestItem(same(afterStoryId), afterCaptor.capture()); // Start items verification - List startItems = startCaptor.getAllValues(); + List storyStartItems = storyCaptor.getAllValues(); - StartTestItemRQ beforeStoryStart = startItems.get(0); + StartTestItemRQ beforeStorySuiteStart = storyStartItems.get(0); + assertThat(beforeStorySuiteStart.getName(), equalTo(LIFECYCLE_SUITES_NAMES[0])); + String beforeSuiteCodeRef = STORY_PATH + String.format(LIFECYCLE_PATTERN, LIFECYCLE_SUITES_NAMES[0]); + assertThat(beforeStorySuiteStart.getCodeRef(), equalTo(beforeSuiteCodeRef)); + assertThat(beforeStorySuiteStart.getType(), equalTo(ItemType.TEST.name())); + + StartTestItemRQ beforeStoryStart = beforeCaptor.getValue(); assertThat(beforeStoryStart.getName(), equalTo(LIFECYCLE_STEP_NAMES[0])); - assertThat( - beforeStoryStart.getCodeRef(), - equalTo(STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[0])) + assertThat(beforeStoryStart.getCodeRef(), + equalTo(beforeSuiteCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[0])) ); assertThat(beforeStoryStart.getType(), equalTo(ItemType.STEP.name())); String scenarioCodeRef = STORY_PATH + String.format(SCENARIO_PATTERN, SCENARIO_NAME); - StartTestItemRQ scenarioStart = startItems.get(1); + StartTestItemRQ scenarioStart = storyStartItems.get(1); assertThat(scenarioStart.getName(), equalTo(SCENARIO_NAME)); assertThat(scenarioStart.getCodeRef(), equalTo(scenarioCodeRef)); assertThat(scenarioStart.getType(), equalTo(ItemType.SCENARIO.name())); - StartTestItemRQ beforeScenario = startItems.get(3); + List scenarioStartItems = scenarioCaptor.getAllValues(); + StartTestItemRQ beforeScenario = scenarioStartItems.get(0); String beforeScenarioCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[1]); assertThat(beforeScenario.getName(), equalTo(LIFECYCLE_STEP_NAMES[1])); assertThat(beforeScenario.getCodeRef(), equalTo(beforeScenarioCodeRef)); assertThat(beforeScenario.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ beforeStep = startItems.get(4); + StartTestItemRQ beforeStep = scenarioStartItems.get(1); String beforeStepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[2]); assertThat(beforeStep.getName(), equalTo(LIFECYCLE_STEP_NAMES[2])); assertThat(beforeStep.getCodeRef(), equalTo(beforeStepCodeRef)); assertThat(beforeStep.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ step = startItems.get(5); + StartTestItemRQ step = scenarioStartItems.get(2); String stepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, STEP_NAME); assertThat(step.getName(), equalTo(STEP_NAME)); assertThat(step.getCodeRef(), equalTo(stepCodeRef)); assertThat(step.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ afterStep = startItems.get(6); + StartTestItemRQ afterStep = scenarioStartItems.get(3); String afterStepCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[3]); assertThat(afterStep.getName(), equalTo(LIFECYCLE_STEP_NAMES[3])); assertThat(afterStep.getCodeRef(), equalTo(afterStepCodeRef)); assertThat(afterStep.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ afterScenario = startItems.get(7); + StartTestItemRQ afterScenario = scenarioStartItems.get(4); String afterScenarioCodeRef = scenarioCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[4]); assertThat(afterScenario.getName(), equalTo(LIFECYCLE_STEP_NAMES[4])); assertThat(afterScenario.getCodeRef(), equalTo(afterScenarioCodeRef)); assertThat(afterScenario.getType(), equalTo(ItemType.STEP.name())); - StartTestItemRQ afterStory = startItems.get(2); - String afterStoryCodeRef = - STORY_PATH + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1]); - assertThat(afterStory.getName(), equalTo(LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1])); - assertThat(afterStory.getCodeRef(), equalTo(afterStoryCodeRef)); - assertThat(afterStory.getType(), equalTo(ItemType.STEP.name())); + StartTestItemRQ afterStoryStart = storyStartItems.get(2); + String afterStoryCodeRef = STORY_PATH + String.format(LIFECYCLE_PATTERN, LIFECYCLE_SUITES_NAMES[1]); + assertThat(afterStoryStart.getName(), equalTo(LIFECYCLE_SUITES_NAMES[1])); + assertThat(afterStoryStart.getCodeRef(), equalTo(afterStoryCodeRef)); + assertThat(afterStoryStart.getType(), equalTo(ItemType.TEST.name())); + + StartTestItemRQ afterStoryStepStart = afterCaptor.getValue(); + String afterStoryStepCodeRef = + afterStoryCodeRef + String.format(STEP_PATTERN, LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1]); + assertThat(afterStoryStepStart.getName(), equalTo(LIFECYCLE_STEP_NAMES[LIFECYCLE_STEP_NAMES.length - 1])); + assertThat(afterStoryStepStart.getCodeRef(), equalTo(afterStoryStepCodeRef)); + assertThat(afterStoryStepStart.getType(), equalTo(ItemType.STEP.name())); // Finish items verification ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); From d699563e26baffe7ced781f7017754c5c5290441 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 15 Nov 2022 15:05:58 +0300 Subject: [PATCH 29/32] CallbackReportingTest fix --- .../jbehave/CallbackReportingTest.java | 7 ++-- .../basic/CallbackReportingSteps.java | 32 ++++++++++++++----- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/epam/reportportal/jbehave/CallbackReportingTest.java b/src/test/java/com/epam/reportportal/jbehave/CallbackReportingTest.java index 8c30cef..7144775 100644 --- a/src/test/java/com/epam/reportportal/jbehave/CallbackReportingTest.java +++ b/src/test/java/com/epam/reportportal/jbehave/CallbackReportingTest.java @@ -74,7 +74,7 @@ public void callback_reporting_test() { ArgumentCaptor idCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor rqCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class); - verify(client, times(7)).finishTestItem(idCaptor.capture(), rqCaptor.capture()); // Start test class and test method + verify(client, times(9)).finishTestItem(idCaptor.capture(), rqCaptor.capture()); ArgumentCaptor saveLogRQArgumentCaptor = ArgumentCaptor.forClass(SaveLogRQ.class); verify(client, times(1)).log(saveLogRQArgumentCaptor.capture()); @@ -93,9 +93,8 @@ public void callback_reporting_test() { List> secondScenarioIds = idRqs.stream() .filter(e -> stepIds.get(1).equals(e.getKey())) .collect(Collectors.toList()); - - assertThat(firstScenarioIds, hasSize(2)); - assertThat(secondScenarioIds, hasSize(2)); + assertThat(firstScenarioIds, hasSize(3)); + assertThat(secondScenarioIds, hasSize(3)); List> failureUpdates = firstScenarioIds.stream() .filter(r -> "FAILED".equals(r.getValue().getStatus())) diff --git a/src/test/java/com/epam/reportportal/jbehave/integration/basic/CallbackReportingSteps.java b/src/test/java/com/epam/reportportal/jbehave/integration/basic/CallbackReportingSteps.java index f06bbd1..ffc9163 100644 --- a/src/test/java/com/epam/reportportal/jbehave/integration/basic/CallbackReportingSteps.java +++ b/src/test/java/com/epam/reportportal/jbehave/integration/basic/CallbackReportingSteps.java @@ -20,6 +20,7 @@ import com.epam.reportportal.jbehave.ReportPortalStepFormat; import com.epam.reportportal.jbehave.ReportPortalStepStoryReporter; import com.epam.reportportal.jbehave.ReportPortalStoryReporter; +import com.epam.reportportal.jbehave.util.ItemTreeUtils; import com.epam.reportportal.listeners.ItemStatus; import com.epam.reportportal.service.ReportPortal; import com.epam.reportportal.service.tree.ItemTreeReporter; @@ -30,6 +31,7 @@ import org.jbehave.core.annotations.AfterScenario; import org.jbehave.core.annotations.Given; +import javax.annotation.Nonnull; import java.util.Calendar; import java.util.Optional; @@ -39,6 +41,7 @@ public class CallbackReportingSteps { public static final String STEP_TEXT = "I have a step for callback reporting"; + @SuppressWarnings("unused") @Given(STEP_TEXT) public void a_step_for_callback_reporting() throws InterruptedException { Thread.sleep(CommonUtils.MINIMAL_TEST_PAUSE); @@ -53,14 +56,22 @@ public void after() { reporter.flatMap(ReportPortalStoryReporter::getLastStep).ifPresent(itemLeaf -> { TestItemTree.TestItemLeaf scenario = itemLeaf.getAttribute(ReportPortalStepStoryReporter.PARENT); + // For JBehave 5 the item will be `after` method, so we need to find actual step + TestItemTree.TestItemLeaf stepLeaf = ofNullable(scenario).map(TestItemTree.TestItemLeaf::getChildItems) + .map(c -> c.get(ItemTreeUtils.createKey("Given " + STEP_TEXT))) + .orElse(null); if (ofNullable(scenario).isPresent()) { String scenarioName = ofNullable((StartTestItemRQ) scenario.getAttribute(ReportPortalStepStoryReporter.START_REQUEST)).map( - StartTestItemRQ::getName).orElseThrow(() -> new IllegalStateException("Unable to get start item request")); + StartTestItemRQ::getName) + .orElseThrow(() -> new IllegalStateException("Unable to get start item request")); + if (scenarioName.contains("failure")) { - finishWithStatus(rp, tree, "FAILED", itemLeaf); - attachLog(rp, tree, itemLeaf); + ofNullable(stepLeaf).ifPresent(l -> { + finishWithStatus(rp, tree, "FAILED", l); + attachLog(rp, tree, l); + }); } else { - finishWithStatus(rp, tree, "PASSED", itemLeaf); + ofNullable(stepLeaf).ifPresent(l -> finishWithStatus(rp, tree, "PASSED", stepLeaf)); } } else { throw new IllegalStateException("Unable to find parent item"); @@ -68,17 +79,22 @@ public void after() { }); } - private void finishWithStatus(ReportPortal rp, TestItemTree tree, String status, TestItemTree.TestItemLeaf testItemLeaf) { + private void finishWithStatus(@Nonnull ReportPortal rp, @Nonnull TestItemTree tree, @Nonnull String status, + @Nonnull TestItemTree.TestItemLeaf testItemLeaf) { FinishTestItemRQ finishTestItemRQ = new FinishTestItemRQ(); finishTestItemRQ.setStatus(status); finishTestItemRQ.setEndTime(Calendar.getInstance().getTime()); //noinspection ResultOfMethodCallIgnored - ItemTreeReporter.finishItem(rp.getClient(), finishTestItemRQ, tree.getLaunchId(), testItemLeaf).cache().blockingGet(); + ItemTreeReporter.finishItem(rp.getClient(), finishTestItemRQ, tree.getLaunchId(), testItemLeaf) + .cache() + .blockingGet(); testItemLeaf.setStatus(ItemStatus.valueOf(status)); } - private void attachLog(ReportPortal rp, TestItemTree tree, TestItemTree.TestItemLeaf testItemLeaf) { - ItemTreeReporter.sendLog(rp.getClient(), + private void attachLog(@Nonnull ReportPortal rp, @Nonnull TestItemTree tree, + @Nonnull TestItemTree.TestItemLeaf testItemLeaf) { + ItemTreeReporter.sendLog( + rp.getClient(), "ERROR", "Error message", Calendar.getInstance().getTime(), From 651ea3b64ab8833fcda24208dc52dcf351091d4a Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 15 Nov 2022 15:21:47 +0300 Subject: [PATCH 30/32] Javadoc fix --- .../com/epam/reportportal/jbehave/ReportPortalStoryReporter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java index 5b4249a..d6e4667 100644 --- a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java +++ b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java @@ -384,6 +384,7 @@ protected StartTestItemRQ buildStartStepRq(@Nonnull final String step, @Nonnull * Extension point to customize lifecycle suite (before/after) creation event/request * * @param name a lifecycle suite name + * @param codeRef the suite code reference * @param startTime item start time * @return Request to ReportPortal */ From 83cde08a938885d9d20a82ee37d8a1351ac179b3 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 15 Nov 2022 15:49:58 +0300 Subject: [PATCH 31/32] README_TEMPLATE.md update --- README_TEMPLATE.md | 115 +++++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 57 deletions(-) diff --git a/README_TEMPLATE.md b/README_TEMPLATE.md index 147854d..a40818b 100644 --- a/README_TEMPLATE.md +++ b/README_TEMPLATE.md @@ -1,8 +1,8 @@ # Report Portal Java reporter for JBehave tests -> **DISCLAIMER**: We use Google Analytics for sending anonymous usage information such as agent's and client's names, 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. +> **DISCLAIMER**: We use Google Analytics for sending anonymous usage information such as agent's and client's names, +> 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) [![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) @@ -11,7 +11,8 @@ [![stackoverflow](https://img.shields.io/badge/reportportal-stackoverflow-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/reportportal) [![Build with Love](https://img.shields.io/badge/build%20with-❤%EF%B8%8F%E2%80%8D-lightgrey.svg)](http://reportportal.io?style=flat) -The latest version: $LATEST_VERSION. Please use `Download` link above to get the agent. Minimal supported JBehave version: 4.8 +The latest version: $LATEST_VERSION. Please use `Download` link above to get the agent. **For JBehave version 5.0 and +higher** ## Overview: How to Add ReportPortal Logging to Your JBehave Java Project @@ -27,17 +28,17 @@ To start using Report Portal with JBehave framework please do the following step 3. [Running tests](#test-run) * Add test runner class * Build system commands - -Additionally, you may want to configure [Step reporter or Scenario reporter](#steps-vs-scenarios). They are regulate how Report Portal count -your tests. Step reporter posts statistics per a test step (each test step is counted in 'total' column). Scenario reporter posts statistics -per a scenario. + +Additionally, you may want to configure [Step reporter or Scenario reporter](#steps-vs-scenarios). They are regulate how +Report Portal count your tests. Step reporter posts statistics per a test step (each test step is counted in 'total' +column). Scenario reporter posts statistics per a scenario. ## Configuration ### 'reportportal.properties' configuration file -To start using Report Portal you need to create a file named `reportportal.properties` in your Java project in a source folder -`src/main/resources` or `src/test/resources` (depending on where your tests are located): +To start using Report Portal you need to create a file named `reportportal.properties` in your Java project in a source +folder `src/main/resources` or `src/test/resources` (depending on where your tests are located): **reportportal.properties** @@ -51,9 +52,10 @@ rp.project = default_personal **Property description** * `rp.endpoint` - the URL for the report portal server (actual link). -* `rp.api.key` - an access token for Report Portal which is used for user identification. It can be found on your report portal user profile - page. -* `rp.project` - a project ID on which the agent will report test launches. Must be set to one of your assigned projects. +* `rp.api.key` - an access token for Report Portal which is used for user identification. It can be found on your report + portal user profile page. +* `rp.project` - a project ID on which the agent will report test launches. Must be set to one of your assigned + projects. * `rp.launch` - a user-selected identifier of test launches. ### Build system configuration @@ -255,28 +257,24 @@ It should be already here if you used gradle configuration listed above. ### Test runner class -JBehave requires runtime configuration, to do this place the following class into your `src/main/java` (for Maven) or `src/test/java` +JBehave requires runtime configuration, to do this place the following class into your `src/main/java` (for Maven) +or `src/test/java` (for Gradle) folders. Notice that you need replace step initialization in `stepsFactory` method with your own: `MyStories.java` ```java - import com.epam.reportportal.example.jbehave.steps.*; import com.epam.reportportal.jbehave.ReportPortalStepFormat; -import com.epam.reportportal.utils.properties.PropertiesLoader; -import org.apache.commons.lang3.StringUtils; import org.jbehave.core.Embeddable; import org.jbehave.core.configuration.Configuration; import org.jbehave.core.configuration.MostUsefulConfiguration; -import org.jbehave.core.embedder.Embedder; import org.jbehave.core.i18n.LocalizedKeywords; import org.jbehave.core.io.CodeLocations; import org.jbehave.core.io.LoadFromClasspath; import org.jbehave.core.io.StoryFinder; import org.jbehave.core.junit.JUnitStories; import org.jbehave.core.model.ExamplesTableFactory; -import org.jbehave.core.model.TableParsers; import org.jbehave.core.model.TableTransformers; import org.jbehave.core.parsers.RegexStoryParser; import org.jbehave.core.reporters.StoryReporterBuilder; @@ -286,16 +284,15 @@ import org.jbehave.core.steps.ParameterConverters; import org.jbehave.core.steps.ParameterConverters.DateConverter; import org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter; -import java.net.URL; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import static java.util.Optional.ofNullable; import static org.jbehave.core.io.CodeLocations.codeLocationFromClass; -import static org.jbehave.core.reporters.Format.*; +import static org.jbehave.core.io.CodeLocations.getPathFromURL; +import static org.jbehave.core.reporters.Format.CONSOLE; +import static org.jbehave.core.reporters.Format.HTML; /** *

@@ -307,18 +304,13 @@ import static org.jbehave.core.reporters.Format.*; */ public class MyStories extends JUnitStories { - private static final String META_FILTERS_PROPERTY = "metaFilters"; - private static final String STORY_FILTER_PROPERTY = "story"; - public MyStories() { - Embedder embedder = configuredEmbedder(); - embedder.embedderControls() + configuredEmbedder().embedderControls() .doGenerateViewAfterStories(true) .doIgnoreFailureInStories(true) .doIgnoreFailureInView(true) .useThreads(1) .useStoryTimeouts("60"); - ofNullable(System.getProperty(META_FILTERS_PROPERTY)).ifPresent(p -> embedder.useMetaFilters(Arrays.asList(p.split(",")))); } @Override @@ -328,11 +320,9 @@ public class MyStories extends JUnitStories { ParameterConverters parameterConverters = new ParameterConverters(); TableTransformers tableTransformers = new TableTransformers(); - TableParsers tableParsers = new TableParsers(); // factory to allow parameter conversion and loading from external resources (used by StoryParser too) ExamplesTableFactory examplesTableFactory = new ExamplesTableFactory(new LocalizedKeywords(), new LoadFromClasspath(embeddableClass), - tableParsers, tableTransformers ); // add custom converters @@ -341,9 +331,8 @@ public class MyStories extends JUnitStories { ); return new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(embeddableClass)) .useStoryParser(new RegexStoryParser(examplesTableFactory)) - .useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass)) - .withDefaultFormats() - .withFormats(CONSOLE, TXT, HTML, XML, ReportPortalStepFormat.INSTANCE)) + .useStoryReporterBuilder(new StoryReporterBuilder().withCodeLocation(CodeLocations.codeLocationFromClass( + embeddableClass)).withFormats(CONSOLE, HTML, ReportPortalStepFormat.INSTANCE)) .useParameterConverters(parameterConverters); } @@ -360,34 +349,37 @@ public class MyStories extends JUnitStories { } @Override - protected List storyPaths() { - String storyPatternToRun = ofNullable(System.getProperty(STORY_FILTER_PROPERTY)).filter(s -> !s.isEmpty()) + public List storyPaths() { + String storyPatternToRun = ofNullable(System.getProperty("story")).filter(s -> !s.isEmpty()) .map(s -> "**/" + s) .orElse("**/*.story"); - List resourceFolders = new ArrayList<>(); - ofNullable(getClass().getClassLoader().getResource(PropertiesLoader.INNER_PATH)).map(p -> { - String filePath = CodeLocations.getPathFromURL(p); - String rootPath = StringUtils.removeEnd(filePath, "/" + PropertiesLoader.INNER_PATH); - return CodeLocations.codeLocationFromPath(rootPath); - }).ifPresent(resourceFolders::add); - resourceFolders.add(codeLocationFromClass(this.getClass())); - - return resourceFolders.stream() - .flatMap(u -> new StoryFinder().findPaths(u, storyPatternToRun, "**/excluded*.story").stream()) + return new StoryFinder().findPaths(getPathFromURL(codeLocationFromClass(this.getClass())), + storyPatternToRun, + "**/excluded*.story" + ) + .stream() .distinct() .collect(Collectors.toList()); } } ``` + ### Build system commands + We are set. To run set we just need to execute corresponding command in our build system. + #### Maven + `mvn test` or `mvnw test` if you are using Maven wrapper + #### Gradle + `gradle test` or `gradlew test` if you are using Gradle wrapper ## Steps vs scenarios + Let's take a look on a simple example: + ``` Scenario: Stock trade alert @@ -400,15 +392,20 @@ Examples: |STK1|10.0|5.0|OFF| |STK1|10.0|11.0|ON| ``` + ### Step reporter -Step reporter posts statistics per test step. On example above Report Portal display 6 test units. Each example row will be a suite, + +Step reporter posts statistics per test step. On example above Report Portal display 6 test units. Each example row will +be a suite, as on screenshots below and each test step will be marked as a test. ![Story](https://raw.githubusercontent.com/reportportal/agent-java-jbehave/develop/doc/screen-01.png) ![Examples](https://raw.githubusercontent.com/reportportal/agent-java-jbehave/develop/doc/screen-02.png) ![Steps](https://raw.githubusercontent.com/reportportal/agent-java-jbehave/develop/doc/screen-03.png) -To use Step reporter you need to set `ReportPortalStepFormat.INSTANCE` constant as your story reporter format in configuration: +To use Step reporter you need to set `ReportPortalStepFormat.INSTANCE` constant as your story reporter format in +configuration: + ```java new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(embeddableClass)) .useStoryParser(new RegexStoryParser(examplesTableFactory)) @@ -420,20 +417,24 @@ new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(embeddableCla ``` ### Scenario reporter -Scenario reporter posts statistics per a scenario. On example above Report Portal display 2 test units. Each example row will be a test, -as on screenshots below and each test step will be a nested step. + +Scenario reporter posts statistics per a scenario. On example above Report Portal display 2 test units. Each example row +will be a test, +as on screenshots below and each test step will be a nested step. ![Story](https://raw.githubusercontent.com/reportportal/agent-java-jbehave/develop/doc/screen-04.png) ![Examples](https://raw.githubusercontent.com/reportportal/agent-java-jbehave/develop/doc/screen-05.png) ![Steps](https://raw.githubusercontent.com/reportportal/agent-java-jbehave/develop/doc/screen-06.png) -To use Scenario reporter you need to set `ReportPortalScenarioFormat.INSTANCE` constant as your story reporter format in configuration: +To use Scenario reporter you need to set `ReportPortalScenarioFormat.INSTANCE` constant as your story reporter format in +configuration: + ```java new MostUsefulConfiguration().useStoryLoader(new LoadFromClasspath(embeddableClass)) - .useStoryParser(new RegexStoryParser(examplesTableFactory)) - .useStoryReporterBuilder(new StoryReporterBuilder() - .withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass)) - .withDefaultFormats() - .withFormats(ReportPortalScenarioFormat.INSTANCE)) - .useParameterConverters(parameterConverters); + .useStoryParser(new RegexStoryParser(examplesTableFactory)) + .useStoryReporterBuilder(new StoryReporterBuilder() + .withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass)) + .withDefaultFormats() + .withFormats(ReportPortalScenarioFormat.INSTANCE)) + .useParameterConverters(parameterConverters); ``` From 8f7ab5620075e404a67e491e8affca19f1722117 Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Tue, 15 Nov 2022 15:54:47 +0300 Subject: [PATCH 32/32] CHANGELOG.md update --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ec101b..cee55a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ # Changelog ## [Unreleased] -### Changed -- Test new actions +### Added +- JBehave version 5 support, by @HardNorth +### Removed +- JBehave version 4.8 support, by @HardNorth ## [5.1.3] ### Changed