Skip to content

Commit

Permalink
[vividus-to-zephyr-exporter] Add 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 aad030d commit b863c68
Show file tree
Hide file tree
Showing 47 changed files with 1,647 additions and 274 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
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions vividus-exporter-commons/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
project.description = 'Common module for all VIVIDUS exporters'

apply from: "logging.gradle"

dependencies {
implementation project(':vividus-facade-jira')
implementation project(':vividus-util')
implementation(group: 'org.springframework.boot', name: 'spring-boot-starter', version: versions.springBoot)

Expand Down
11 changes: 0 additions & 11 deletions vividus-exporter-commons/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,10 @@ dependencies {
implementation(group: 'org.springframework.boot', name: 'spring-boot-starter')
implementation(group: 'org.springframework.boot', name: 'spring-boot-starter-validation')

implementation(group: 'org.slf4j', name: 'slf4j-api', version: versions.slf4j)
implementation platform(group: 'org.apache.logging.log4j', name: 'log4j-bom', version: '2.17.1')
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')

testImplementation(group: 'org.springframework.boot', name: 'spring-boot-starter-test')
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)
}

configurations.all {
exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
}

configurations.testImplementation {
Expand Down
13 changes: 13 additions & 0 deletions vividus-exporter-commons/logging.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
configurations.all {
exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
}

dependencies {
implementation(group: 'org.slf4j', name: 'slf4j-api', version: versions.slf4j)
implementation platform(group: 'org.apache.logging.log4j', name: 'log4j-bom', version: '2.17.1')
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')

testImplementation(group: 'com.github.valfirst', name: 'slf4j-test', version: versions.slf4jTest)
}
Loading

0 comments on commit b863c68

Please sign in to comment.