Skip to content

Commit

Permalink
[vividus-to-zephyr-exporter] Add ability import automated tests to ze…
Browse files Browse the repository at this point in the history
…phyr
  • Loading branch information
TatianaTochko committed Feb 1, 2022
1 parent b8a0370 commit 1a62f99
Show file tree
Hide file tree
Showing 50 changed files with 1,980 additions and 302 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 39 additions & 1 deletion 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,18 +20,34 @@ include::partial$jira-configuration.adoc[]
|Required
|Description

|`zephyr.exporter.export-results`
|true
|Property to export tests

|`zephyr.exporter.level`
|false
|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

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

|`zephyr.exporter.update-execution-statuses-only`
|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 +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`
|Key of a field containing story type

|===

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
@@ -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
@@ -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 @@ -21,6 +21,7 @@
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.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verifyNoInteractions;
Expand Down Expand Up @@ -67,6 +68,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 +222,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 +309,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 1a62f99

Please sign in to comment.