Skip to content

Commit

Permalink
[vividus-to-zephyr-exporter] Add ability import tests to zephyr
Browse files Browse the repository at this point in the history
  • Loading branch information
TatianaTochko committed Jan 17, 2022
1 parent 476c13b commit 1eb61f8
Show file tree
Hide file tree
Showing 49 changed files with 1,702 additions and 281 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions docs/modules/integrations/pages/zephyr-exporter.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Zephyr Exporter is a tool used for exporting test execution results into Jira Ze

Features:

* Create test cases
* Update test cases
* Create test executions
* Set test execution statuses
Expand All @@ -18,6 +20,10 @@ include::partial$jira-configuration.adoc[]
|Required
|Description

|`zephyr.exporter.level`
|true
|Property to export stories on STORY or SCENARIO level

|`zephyr.exporter.jira-instance-key`
|false
|The key of the configured JIRA instance, in case of missing value it will be evaluated automatically based on issue keys being exported
Expand All @@ -30,6 +36,14 @@ include::partial$jira-configuration.adoc[]
|false
|Property for update existing executions statuses only.

|`zephyr.exporter.update-cases-on-export`
|false
|Property to update existing test cases. User with update status permissions required in order to work.

|`zephyr.exporter.status-for-updated-test-cases`
|false
|Property defines status which will be set for all updated tests ("Backlog" by default).

|`zephyr.exporter.statuses-of-test-cases-to-add-to-execution`
|false
|List of test case statuses for adding to execution.
Expand All @@ -52,6 +66,30 @@ include::partial$jira-configuration.adoc[]

|===

== Jira Fields Mapping

The Zephyr is a Jira plugin that uses custom Jira fields for it's data, one of the ways to find out custom field names for particular field used by Zephyr on Jira UI (if access to Jira configuration is prohibited) is to request description of some issue.

=== Test Case Properties

image::zephyr.png[Zephyr test case view]

[cols="1,2", options="header"]
|===

|Property
|Description

|`jira.fields-mapping.story-type`
|Key of a field containing story type

|`jira.fields-mapping.test-step`
|Key of a field containing step of cucumber story/scenario

|===

include::partial$authentication.adoc[]

== Zephyr Execution Status Mapping

The Zephyr plugin for Jira has own configurable execution statuses. testExecutionStatus endpoint is used to get the detailed information about the statuses, like: https://jira.example.com/rest/zapi/latest/util/testExecutionStatus. The following properties are used to setup a mapping between Vividus and Zephyr execution statuses.
Expand Down
22 changes: 22 additions & 0 deletions vividus-common-exporter/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
project.description = 'Vividus common exporter'

configurations.testImplementation {
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j18-impl'
exclude group: 'ch.qos.logback', module: 'logback-classic'
}

dependencies {
implementation project(':vividus-facade-jira')

implementation(group: 'org.slf4j', name: 'slf4j-api', version: versions.slf4j)
implementation platform(group: 'org.apache.logging.log4j', name: 'log4j-bom', version: '2.17.0')
implementation(group: 'org.apache.logging.log4j', name: 'log4j-api')
implementation(group: 'org.apache.logging.log4j', name: 'log4j-core')
implementation(group: 'org.apache.logging.log4j', name: 'log4j-slf4j18-impl')
implementation(group: 'org.hamcrest', name: 'hamcrest', version: versions.hamcrest)

testImplementation platform(group: 'org.junit', name: 'junit-bom', version: versions.junit)
testImplementation(group: 'org.junit.jupiter', name: 'junit-jupiter')
testImplementation(group: 'org.mockito', name: 'mockito-junit-jupiter', version: versions.mockito)
testImplementation(group: 'com.github.valfirst', name: 'slf4j-test', version: versions.slf4jTest)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.vividus.model.jbehave;

import static org.vividus.model.MetaWrapper.META_VALUES_SEPARATOR;

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;

public interface IContainingMeta
{
List<Meta> getMeta();

/**
* Get unique <b>meta</b> value
*
* <p>If the <b>meta</b> does not exist or has no value, an empty {@link Optional} will be returned
*
* <p><i>Notes</i>
* <ul>
* <li><b>meta</b> value is trimmed upon returning</li>
* <li><i>;</i> char is used as a separator for <b>meta</b> with multiple values</li>
* </ul>
*
* @param metaName the meta name
* @return the meta value
* @throws NotUniqueMetaValueException if the <b>meta</b> has more than one value
*/
default Optional<String> getUniqueMetaValue(String metaName) throws NotUniqueMetaValueException
{
Set<String> values = getMetaValues(metaName);
if (values.size() > 1)
{
throw new NotUniqueMetaValueException(metaName, values);
}
return values.isEmpty() ? Optional.empty() : Optional.of(values.iterator().next());
}

/**
* Get all <b>meta</b> values
*
* <p><i>Notes</i>
* <ul>
* <li><b>meta</b>s without value are ignored</li>
* <li><b>meta</b> values are trimmed upon returning</li>
* <li><i>;</i> char is used as a separator for <b>meta</b> with multiple values</li>
* </ul>
*
* @param metaName the meta name
* @return the meta values
*/
default Set<String> getMetaValues(String metaName)
{
return getMetaStream().filter(m -> metaName.equals(m.getName()))
.map(Meta::getValue)
.filter(StringUtils::isNotEmpty)
.map(String::trim)
.map(value -> StringUtils.splitPreserveAllTokens(value, META_VALUES_SEPARATOR))
.flatMap(Stream::of)
.map(String::trim)
.collect(Collectors.toCollection(LinkedHashSet::new));
}

/**
* Determine if scenario has <b>meta</b> with the name
*
* @param metaName the meta name
* @return {@code true} if scenario has meta with the name
*/
default boolean hasMetaWithName(String metaName)
{
return getMetaStream().anyMatch(m -> metaName.equals(m.getName()));
}

private Stream<Meta> getMetaStream()
{
return Optional.ofNullable(getMeta()).stream().flatMap(Collection::stream);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,19 +16,11 @@

package org.vividus.model.jbehave;

import static org.vividus.model.MetaWrapper.META_VALUES_SEPARATOR;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;

public class Scenario extends AbstractStepsContainer
public class Scenario extends AbstractStepsContainer implements IContainingMeta
{
private String title;
private List<Meta> meta;
Expand All @@ -46,6 +38,7 @@ public void setTitle(String title)
this.title = title;
}

@Override
public List<Meta> getMeta()
{
return meta;
Expand Down Expand Up @@ -101,76 +94,8 @@ public List<Step> collectSteps()
.orElse(List.of());
}

/**
* Get unique <b>meta</b> value
*
* <p>If the <b>meta</b> does not exist or has no value, an empty {@link Optional} will be returned
*
* <p><i>Notes</i>
* <ul>
* <li><b>meta</b> value is trimmed upon returning</li>
* <li><i>;</i> char is used as a separator for <b>meta</b> with multiple values</li>
* </ul>
*
* @param metaName the meta name
* @return the meta value
* @throws NotUniqueMetaValueException if the <b>meta</b> has more than one value
*/
public Optional<String> getUniqueMetaValue(String metaName) throws NotUniqueMetaValueException
{
Set<String> values = getMetaValues(metaName);
if (values.size() > 1)
{
throw new NotUniqueMetaValueException(metaName, values);
}
return values.isEmpty() ? Optional.empty() : Optional.of(values.iterator().next());
}

/**
* Get all <b>meta</b> values
*
* <p><i>Notes</i>
* <ul>
* <li><b>meta</b>s without value are ignored</li>
* <li><b>meta</b> values are trimmed upon returning</li>
* <li><i>;</i> char is used as a separator for <b>meta</b> with multiple values</li>
* </ul>
*
* @param metaName the meta name
* @return the meta values
*/
public Set<String> getMetaValues(String metaName)
{
return getMetaStream().filter(m -> metaName.equals(m.getName()))
.map(Meta::getValue)
.filter(StringUtils::isNotEmpty)
.map(String::trim)
.map(value -> StringUtils.splitPreserveAllTokens(value, META_VALUES_SEPARATOR))
.flatMap(Stream::of)
.map(String::trim)
.collect(Collectors.toCollection(LinkedHashSet::new));
}

/**
* Determine if scenario has <b>meta</b> with the name
*
* @param metaName the meta name
* @return {@code true} if scenario has meta with the name
*/
public boolean hasMetaWithName(String metaName)
{
return getMetaStream().anyMatch(m -> metaName.equals(m.getName()));
}

public boolean isManual()
{
return collectSteps().stream().allMatch(Step::isManual);
}

private Stream<Meta> getMetaStream()
{
return Optional.ofNullable(getMeta())
.map(List::stream)
.orElseGet(Stream::empty);
}
}
16 changes: 14 additions & 2 deletions vividus-engine/src/main/java/org/vividus/model/jbehave/Story.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,11 +24,12 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;

public class Story
public class Story implements IContainingMeta
{
private String path;
private Lifecycle lifecycle;
private List<Scenario> scenarios;
private List<Meta> meta;

public String getPath()
{
Expand Down Expand Up @@ -60,6 +61,17 @@ public void setScenarios(List<Scenario> scenarios)
this.scenarios = scenarios;
}

@Override
public List<Meta> getMeta()
{
return meta;
}

public void setMeta(List<Meta> meta)
{
this.meta = meta;
}

/**
* Get unique scenarios.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verifyNoInteractions;
Expand Down Expand Up @@ -67,6 +65,8 @@ class StoryTests
private static final String SCENARIO_KEY = "scenario-key-";
private static final String SCENARIO_VALUE = "scenario-val-";
private static final String STORY = "story.json";
private static final String META = "meta";
private static final String VALUE = "value";

private static final org.jbehave.core.model.Story TEST_STORY = new org.jbehave.core.model.Story(STORY_PATH);
private static final org.jbehave.core.model.Scenario TEST_SCENARIO = new org.jbehave.core.model.Scenario(
Expand Down Expand Up @@ -219,6 +219,22 @@ void shouldHandleStoryWithOneScenario()
), params.getValues());
}

@Test
void shouldCheckIfStoryHasMetaWithEmptyValues()
{
Story story = new Story();
story.setMeta(List.of(createMeta("")));
assertThat(story.getMetaValues(META), hasSize(0));
}

@Test
void shouldCheckIfStoryHasMetaWithName()
{
Story story = new Story();
story.setMeta(List.of(createMeta(VALUE)));
assertTrue(story.hasMetaWithName(META));
}

private static void reportStep(StoryReporter reporter, Stage stage, ExecutionType type)
{
reporter.beforeScenarioSteps(stage, type);
Expand Down Expand Up @@ -290,4 +306,12 @@ private static Story readStory(String resource)
throw new UncheckedIOException(e);
}
}

private static Meta createMeta(String value)
{
Meta meta = new Meta();
meta.setName(META);
meta.setValue(value);
return meta;
}
}
Loading

0 comments on commit 1eb61f8

Please sign in to comment.