@@ -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'
}
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);
```
diff --git a/build.gradle b/build.gradle
index a8aa4cc..959c552 100644
--- a/build.gradle
+++ b/build.gradle
@@ -44,9 +44,12 @@ dependencies {
api ("org.jbehave:jbehave-core:${project.jbehave_version}") {
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'
@@ -56,7 +59,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 +67,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'
}
}
diff --git a/gradle.properties b/gradle.properties
index 1ede057..5205e1e 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -13,11 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-version=5.1.5-SNAPSHOT
+version=5.2.0-SNAPSHOT
description=JBehave reporters for Report Portal
-jbehave_version=4.8.3
-junit5_version=5.6.3
-junit5_launcher_version=1.6.3
+jbehave_version=5.0
+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
diff --git a/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java b/src/main/java/com/epam/reportportal/jbehave/ReportPortalStoryReporter.java
index e17e3e4..d6e4667 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;
@@ -73,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";
@@ -85,8 +87,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 ItemType currentLifecycleTopItemType;
+ private volatile ItemType currentLifecycleItemType;
public ReportPortalStoryReporter(final Supplier launchSupplier, TestItemTree testItemTree) {
launch = launchSupplier;
@@ -111,15 +115,27 @@ 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,
+ @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);
@@ -173,7 +189,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 +232,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 +254,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 +332,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 +374,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;
}
@@ -360,13 +384,16 @@ 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
*/
@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;
@@ -377,15 +404,16 @@ 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
*/
@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;
@@ -464,23 +492,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,13 +531,19 @@ 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,
+ getCodeRef(parentCodeRef, k, ItemType.TEST),
+ itemDate
+ ),
+ parentLeaf
+ ))
+ ));
break;
}
}
- return leafChain.get(leafChain.size() - 1).getValue();
+ return leafChain.isEmpty() ? null : leafChain.get(leafChain.size() - 1).getValue();
}
/**
@@ -559,7 +596,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 +617,14 @@ 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;
}
@@ -597,8 +639,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 +685,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 +717,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 +737,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 +749,15 @@ 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);
+ //noinspection ReactiveStreamsUnusedPublisher
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);
}
@@ -770,7 +819,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 = ItemType.AFTER_GROUPS;
+ currentLifecycleItemType = ItemType.BEFORE_SUITE;
structure.add(new Entity<>(ItemType.STORY, story));
}
@@ -810,7 +860,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();
@@ -825,13 +875,38 @@ public void afterScenario() {
* @param step Step to be reported
*/
@Override
- public void beforeStep(@Nonnull String step) {
+ 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,
+ 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,
+ currentLifecycleItemType == ItemType.BEFORE_SUITE ? BEFORE_STORY : AFTER_STORY
+ ));
+ }
+ if (parentItem == null) {
+ ofNullable(retrieveLeaf()).map(i -> startLifecycleMethod(
+ step.getStepAsString(),
+ currentLifecycleTopItemType,
+ i
+ )).ifPresent(stepStack::add);
+ return;
+ }
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;
@@ -846,7 +921,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
@@ -864,13 +940,24 @@ public void afterExamples() {
evaluateAndFinishLastItem();
}
+ 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);
+ }
+ }
+
/**
* Finishes step in ReportPortal
*/
@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);
+ finishBeforeAfterSuites(s);
+ });
}
/**
@@ -881,21 +968,10 @@ public void successful(String step) {
*/
@Override
public void failed(String step, Throwable cause) {
- TestItemTree.TestItemLeaf item = retrieveLeaf();
- 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(retrieveLeaf()).map(i -> startLifecycleMethod(step, currentLifecycleItemType, i)).orElse(null));
- }
ofNullable(stepStack.pollLast()).ifPresent(i -> {
sendStackTraceToRP(i.getItemId(), cause);
finishStep(i, ItemStatus.FAILED);
+ finishBeforeAfterSuites(i);
});
}
@@ -906,10 +982,10 @@ 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);
+ finishBeforeAfterSuites(i);
});
}
@@ -920,26 +996,24 @@ public void ignorable(String step) {
*/
@Override
public void notPerformed(String step) {
- TestItemTree.TestItemLeaf item = retrieveLeaf();
- ofNullable(item).ifPresent(i -> {
- TestItemTree.TestItemLeaf leaf = startStep(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);
+ finishBeforeAfterSuites(i);
});
}
@Override
public void pending(String step) {
- TestItemTree.TestItemLeaf item = retrieveLeaf();
- ofNullable(item).ifPresent(i -> {
- TestItemTree.TestItemLeaf leaf = startStep(step, i);
- createPendingSteps(step, leaf);
- finishStep(leaf, ItemStatus.SKIPPED);
+ ofNullable(stepStack.pollLast()).ifPresent(i -> {
+ createPendingSteps(step, i);
+ finishStep(i, ItemStatus.SKIPPED);
+ finishBeforeAfterSuites(i);
});
}
@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++) {
diff --git a/src/test/java/com/epam/reportportal/jbehave/BaseTest.java b/src/test/java/com/epam/reportportal/jbehave/BaseTest.java
index 82e4a00..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);
@@ -108,7 +112,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);
}
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/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/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/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(),
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 89%
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 6e3fb36..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() {
@@ -80,23 +81,23 @@ 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()));
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/VerifyAfterScenario.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterScenarioTest.java
similarity index 91%
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 42bbd6e..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
@@ -92,7 +93,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()));
@@ -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:%s]", SCENARIO_NAMES[i]) + String.format("/[STEP:%s]", 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:%s]", SCENARIO_NAMES[i]) + String.format("/[STEP:%s]", 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/VerifyAfterStep.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStepTest.java
similarity index 93%
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 e1f4391..a816665 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_");
@@ -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
@@ -91,7 +92,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 +100,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 +109,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/VerifyAfterStoriesAnnotationFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoriesAnnotationFailedTest.java
similarity index 78%
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..63e5bc1 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();
@@ -94,32 +94,30 @@ 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"));
- assertThat(afterStoriesStart.getCodeRef(), equalTo("AfterStories"));
- assertThat(afterStoriesStart.getType(), equalTo(ItemType.STORY.name()));
+ 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);
+ 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()));
- 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(afterStoriesCodeRef + String.format("/[AFTER_GROUPS:%s]", AFTER_STORY_NAME))
+ );
+ assertThat(afterStep.getType(), equalTo(ItemType.AFTER_GROUPS.name()));
// Finish items verification
ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class);
@@ -127,7 +125,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 +144,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());
}
}
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 87%
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..98587b2 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_");
@@ -50,7 +50,10 @@ public class VerifyAfterStoryAnnotationFailed 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))
);
@@ -69,6 +72,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() {
@@ -82,7 +86,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));
@@ -90,20 +94,20 @@ 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_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);
- String beforeStepCodeRef = AfterStoryFailedSteps.class.getCanonicalName() + ".afterStoryFailed()";
- assertThat(afterStep.getName(), equalTo(beforeStepCodeRef));
- assertThat(afterStep.getCodeRef(), equalTo(beforeStepCodeRef));
- assertThat(afterStep.getType(), equalTo(ItemType.AFTER_SUITE.name()));
+ assertThat(afterStep.getName(), equalTo(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
ArgumentCaptor finishStepCaptor = ArgumentCaptor.forClass(FinishTestItemRQ.class);
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 65%
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 3f93475..4ebe104 100644
--- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyAfterStoryFailed.java
+++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryFailedTest.java
@@ -45,9 +45,8 @@
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.*;
-public class VerifyAfterStoryFailed extends BaseTest {
+public class AfterStoryFailedTest 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_"),
@@ -56,14 +55,18 @@ 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);
@@ -81,68 +84,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:%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/VerifyAfterStory.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/AfterStoryTest.java
similarity index 76%
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 57cc667..0be57cc 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,25 @@
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())
+ private final List>> steps = Arrays.asList(Pair.of(
+ scenarioId,
+ Collections.singletonList(stepId)
+ ),
+ Pair.of(afterStoryId, Collections.singletonList(afterStepId))
);
private final ReportPortalClient client = mock(ReportPortalClient.class);
@@ -67,6 +72,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,27 +82,37 @@ 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();
- 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));
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:%s]", 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:%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(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());
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..5080519 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());
@@ -81,20 +83,20 @@ 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));
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_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/VerifyBeforeScenarioFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioFailedTest.java
similarity index 65%
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 1c5f64d..055f2ab 100644
--- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeScenarioFailed.java
+++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioFailedTest.java
@@ -45,9 +45,7 @@
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.*;
-public class VerifyBeforeScenarioFailed extends BaseTest {
-
- public static final String STEP_PATTERN = "/[STEP:%s]";
+public class BeforeScenarioFailedTest extends BaseTest {
private final String storyId = namedId("story_");
private final List lifecycleStepIds = Arrays.asList(namedId("before_story_"),
namedId("before_scenario_"),
@@ -56,14 +54,18 @@ public class VerifyBeforeScenarioFailed 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);
@@ -81,68 +83,90 @@ 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_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" };
@Test
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 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/VerifyBeforeScenario.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeScenarioTest.java
similarity index 91%
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 01f9cc8..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
@@ -92,7 +93,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()));
@@ -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:%s]", SCENARIO_NAMES[i]) + String.format("/[STEP:%s]", 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:%s]", SCENARIO_NAMES[i]) + String.format("/[STEP:%s]", 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/VerifyBeforeStepFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStepFailedTest.java
similarity index 64%
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 beaff02..31b4ee3 100644
--- a/src/test/java/com/epam/reportportal/jbehave/lifecycle/VerifyBeforeStepFailed.java
+++ b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStepFailedTest.java
@@ -45,9 +45,8 @@
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.*;
-public class VerifyBeforeStepFailed extends BaseTest {
+public class BeforeStepFailedTest 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_"),
@@ -56,14 +55,18 @@ 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);
@@ -81,68 +84,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:%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);
- 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 93%
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 eed5e40..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
@@ -91,7 +92,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 +100,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 +109,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/VerifyBeforeStoriesAnnotationFailed.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoriesAnnotationFailedTest.java
similarity index 75%
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..8ea3f84 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)
));
@@ -74,6 +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 BEFORE_STORY_SUITE_NAME = "BeforeStories";
+ private static final String BEFORE_STORY_NAME = "beforeStoriesFailed";
@Test
public void verify_before_story_annotation_failed_method_reporting() {
@@ -82,40 +83,36 @@ 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());
// Start items verification
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()));
+ String beforeStoriesCodeRef = BEFORE_STORY_SUITE_NAME;
+ assertThat(beforeStoriesStart.getName(), equalTo(beforeStoriesCodeRef));
+ assertThat(beforeStoriesStart.getCodeRef(), equalTo(beforeStoriesCodeRef));
+ 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(2);
+ 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()));
- 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()));
-
- String scenarioCodeRef = STORY_PATH + String.format("/[SCENARIO:%s]", DEFAULT_SCENARIO_NAME);
- StartTestItemRQ scenarioStart = startItems.get(4);
+ 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(5);
- String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME);
+ StartTestItemRQ step = startItems.get(4);
+ 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()));
@@ -123,7 +120,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 +134,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()));
}
}
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 84%
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..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,24 +88,25 @@ 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:%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));
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:%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/VerifyBeforeStory.java b/src/test/java/com/epam/reportportal/jbehave/lifecycle/BeforeStoryTest.java
similarity index 75%
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..7babf58 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,23 +79,33 @@ 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_PATTERN, 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_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 = startItems.get(2);
- String stepCodeRef = scenarioCodeRef + String.format("/[STEP:%s]", STEP_NAME);
+ StartTestItemRQ step = scenarioCaptor.getValue();
+ 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));