Skip to content

Commit

Permalink
Merge pull request #102 from veepee-oss/feature/tags-refactor
Browse files Browse the repository at this point in the history
Feature/tags refactor
  • Loading branch information
josefd8 authored Jul 15, 2021
2 parents 57db00a + 5ded8c4 commit bb2ad93
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 76 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### 2.2.4

* Jira tags can now use brackets instead of parenthesis (i.e @jira[QMS-123]). This is because it can be problematic to run scenarios based on tags if the tags contains parenthesis (it is a reserved character for cucumber tags)

* For Jira tags, the scenarios are now skipped at hook level using SkipException from TestNG. This is to improve the integration of GingerSpec with intellij IDEA (aspects are not picked up when running tests as cucumber java in Intellij IDEA)

## 2.2.3

* Added a new tag, @jira(QMS-123), that will allow users to skip the execution of scenarios based on the status of the referenced entities in Jira. this tag could also change the status of the entity in Jira based on the result of the scenario execution
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.github.privaliatech</groupId>
<artifactId>gingerspec</artifactId>
<version>2.2.3</version>
<version>2.2.4</version>

<name>Privalia GingerSpec framework</name>
<description>Acceptance Test library. General purpose automation framework.</description>
Expand Down
62 changes: 0 additions & 62 deletions src/main/java/com/privalia/qa/aspects/JiraTagAspect.java

This file was deleted.

24 changes: 22 additions & 2 deletions src/main/java/com/privalia/qa/specs/HookGSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.safari.SafariOptions;
import org.slf4j.LoggerFactory;
import org.testng.SkipException;

import java.io.IOException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -97,18 +98,37 @@ public HookGSpec(CommonG spec) {

/**
* Clean the exception list before each scenario.
* @param scenario scenario reference
*/
@Before(order = 0)
public void globalSetup() {
public void globalSetup(Scenario scenario) {
/*Removes unnecessary logging messages that are produced by dependencies that make use of java.util.logging.Logger*/
Logger rootLogger = LogManager.getLogManager().getLogger("");
rootLogger.setLevel(Level.WARNING);

/*Clears the exceptions stacktrace for the new test*/
commonspec.getExceptions().clear();

}
/*Get list of tags present in the Scenario*/
Collection<String> tags = scenario.getSourceTagNames();
String ticket = this.jiraConnector.getFirstTicketReference(new ArrayList(tags));

/*If theres a jira ticket in the scenario*/
if (ticket != null) {
try {
if (!jiraConnector.entityShouldRun(ticket)) {
String message = String.format("Scenario skipped!, it is in a non runnable status in Jira (check %s/browse/%s)", jiraConnector.getProperty("jira.server.url", null), ticket);
scenario.log(message);
throw new SkipException(message);
}
} catch (SkipException se) {
throw se;
} catch (Exception e) {
LOGGER.error("Could not retrieve info of ticket " + ticket + " from jira: " + e.getMessage() + ". Proceeding with execution...");
}

}
}

/**
* If the feature has the @web annotation, creates a new selenium web driver
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/com/privalia/qa/utils/JiraConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import com.ning.http.client.Request;
import com.ning.http.client.RequestBuilder;
import com.ning.http.client.Response;
import com.privalia.qa.lookups.DefaultLookUp;
import org.apache.commons.text.StringSubstitutor;
import net.minidev.json.JSONArray;
import org.apache.commons.text.lookup.StringLookupFactory;
import org.apache.commons.text.StringSubstitutor;

import java.util.List;
import java.util.concurrent.Future;
Expand All @@ -31,10 +29,11 @@ public class JiraConnector {
* Reads the given key from the properties file. The system will try to locate the key first in
* the maven variables (System.getProperty) and if not found will look for it in the properties file.
* If the value is still not found it will return the default value (if provided) or an exception
* @param property key
* @return value
* @param property key
* @param defaultValue defaultValue
* @return value
*/
private String getProperty(String property, String defaultValue) {
public String getProperty(String property, String defaultValue) {

if (System.getProperty(property) != null) {
return System.getProperty(property);
Expand Down Expand Up @@ -213,7 +212,7 @@ public void transitionEntity(String entity) throws Exception {
* @return The first ticket reference (i.e QMS-123)
*/
public String getFirstTicketReference(List<String> tags) {
String pattern = "@jira\\((.*)\\)";
String pattern = "@jira[\\(\\[](.*)[\\)\\]]";
Pattern r = Pattern.compile(pattern);

for (String tag: tags) {
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/com/privalia/qa/ATests/JiraTagTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,17 @@ public void shouldReturnExceptionIkFeyVariablesNotFound() {
public void shouldReturnTheTicketFromTheTag() throws Exception {
List<String> tags = Arrays.asList("@jira(QMS-990)", "@ignore", "@jira(QMS-123)");
assertThat("QMS-990").isEqualToIgnoringCase(this.jc.getFirstTicketReference(tags));

tags = Arrays.asList("@jira[QMS-990]", "@ignore", "@jira(QMS-123)");
assertThat("QMS-990").isEqualToIgnoringCase(this.jc.getFirstTicketReference(tags));

tags = Arrays.asList("@jira[QMS-123]", "@ignore", "@jira(QMS-990)");
assertThat("QMS-123").isEqualToIgnoringCase(this.jc.getFirstTicketReference(tags));

tags = Arrays.asList("@ignore", "@jira(QMS-123)");
assertThat("QMS-123").isEqualToIgnoringCase(this.jc.getFirstTicketReference(tags));

tags = Arrays.asList("@ignore");
assertThat(this.jc.getFirstTicketReference(tags)).isNull();
}
}
1 change: 0 additions & 1 deletion src/test/resources/META-INF/aop.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<aspect name="com.privalia.qa.aspects.LoopIncludeTagAspect"/>
<aspect name="com.privalia.qa.aspects.ReplacementAspect"/>
<aspect name="com.privalia.qa.aspects.IgnoreTagAspect"/>
<aspect name="com.privalia.qa.aspects.JiraTagAspect"/>
</aspects>
<weaver
options="-Xlint:ignore -Xset:weaveJavaPackages=true,weaveJavaxPackages=true">
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/features/jiraTag.feature
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@ignore
Feature: Testing the Jira Integration

Using the @jira() you can control the execution of scenarios based on its status
Using the @jira[] you can control the execution of scenarios based on its status
in Jira as well as update an entity status in Jira based on the result of
the scenario execution. You can fully configure the behavior of this tag using the
configuration file located at src/test/resources/jira.properties

@jira(QMS-990)
@jira[QMS-990] @rest
Scenario: A new element is inserted via a POST call
Given I send requests to '${REST_SERVER_HOST}:3000'
When I send a 'POST' request to '/posts' based on 'schemas/mytestdata.json' as 'json'
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/jira.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The Jira connector allows you to annotate your scenarios with a reference to an entity
# in Jira, for example @jira(QMS-123)
# in Jira, for example @jira[QMS-123]
#
# This will allow you to control the execution of scenarios based on the status
# of the linked entity in Jira as well as to update the status of the entity
Expand Down

0 comments on commit bb2ad93

Please sign in to comment.