Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability import automated tests to zephyr #2319

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 43 additions & 5 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,19 +20,35 @@ include::partial$jira-configuration.adoc[]
|Required
|Description

|`zephyr.exporter.jira-instance-key`
|`zephyr-exporter.export-results`
|true
|Property regulates if test entity export is needed

|`zephyr-exporter.test-entity`
|false
|Test entity export level. 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

|`zephyr.exporter.source-directory`
|`zephyr-exporter.source-directory`
|true
|Path to directory with test execution JSON results.
|Path to directory with test execution JSON results and test entity.

|`zephyr.exporter.update-execution-statuses-only`
|`zephyr-exporter.update-execution-statuses-only`
|false
|Property for update existing executions statuses only.

|`zephyr.exporter.statuses-of-test-cases-to-add-to-execution`
|`zephyr-exporter.update-test-cases`
|false
|Property to update existing test cases. User with update status permissions required in order to work.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please provide more details what will be updated


|`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 +70,26 @@ 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[]
[cols="1,2", options="header"]
|===

|Property
|Description

|`jira.<jira-instance-key>.fields-mapping.story-type`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not clear

|Key of a custom field which contains story type (Task)

|===

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
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 @@ -17,7 +17,7 @@
package org.vividus.report.allure;

import static java.util.Map.entry;
import static org.vividus.model.MetaWrapper.META_VALUES_SEPARATOR;
import static org.vividus.model.jbehave.HasMeta.META_VALUES_SEPARATOR;

import java.util.Collection;
import java.util.LinkedHashSet;
Expand Down
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,6 +16,8 @@

package org.vividus.model;

import static org.vividus.model.jbehave.HasMeta.META_VALUES_SEPARATOR;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
Expand All @@ -31,8 +33,6 @@

public class MetaWrapper
{
public static final char META_VALUES_SEPARATOR = ';';

private final Meta meta;

public MetaWrapper(Meta meta)
Expand Down
100 changes: 100 additions & 0 deletions vividus-engine/src/main/java/org/vividus/model/jbehave/HasMeta.java
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 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 HasMeta
{
char META_VALUES_SEPARATOR = ';';

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 HasMeta
{
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
@@ -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 HasMeta
{
private String path;
private Lifecycle lifecycle;
private List<Scenario> scenarios;
private List<Meta> meta;
Comment on lines 29 to +32
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private String path;
private Lifecycle lifecycle;
private List<Scenario> scenarios;
private List<Meta> meta;
private String path;
private List<Meta> meta;
private Lifecycle lifecycle;
private List<Scenario> scenarios;


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
Loading