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

Refactored report annotations to AnnotationConverter and show related… #7

Merged
merged 1 commit into from
Sep 14, 2021
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package eu.tsystems.mms.tic.testerra.plugins.xray.annotation;

import eu.tsystems.mms.tic.testerra.plugins.xray.config.XrayConfig;
import eu.tsystems.mms.tic.testframework.logging.Loggable;
import eu.tsystems.mms.tic.testframework.report.AnnotationConverter;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;

public class XrayTestAnnotationConverter implements AnnotationConverter<XrayTest>, Loggable {
@Override
public Map<String, Object> toMap(XrayTest annotation) {
XrayConfig config = XrayConfig.getInstance();
URI restServiceUri = config.getRestServiceUri();
URI baseUrl;
try {
baseUrl = new URI(restServiceUri.getScheme(), restServiceUri.getUserInfo(), restServiceUri.getHost(), restServiceUri.getPort(), null, null, null);
} catch (URISyntaxException e) {
baseUrl = URI.create("example.com");
log().error(e.getMessage());
}
final URI finalBaseUrl = baseUrl;
Map<String, Object> map = new HashMap<>();
List<String> ticketUrls = Arrays.stream(annotation.key())
.filter(StringUtils::isNotBlank)
.map(ticketKey -> {
return String.format("%s/browse/%s", finalBaseUrl, ticketKey);
})
.collect(Collectors.toList());

map.put("ticketUrls", ticketUrls);
return map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public class XrayConfig {
private final boolean webResourceFilterGetRequestsOnlyEnabled;
private final boolean isSyncSkippedTests;

private boolean isSyncEnabled;
private String fakeTestExecutionKey;

private XrayConfig() {
Expand All @@ -68,7 +67,6 @@ private XrayConfig() {
username = PropertyManager.getProperty("xray.user");
password = PropertyManager.getProperty("xray.password");

isSyncEnabled = PropertyManager.getBooleanProperty("xray.sync.enabled", false);
isSyncSkippedTests = PropertyManager.getBooleanProperty("xray.sync.skipped", false);

URI uri = null;
Expand All @@ -94,7 +92,7 @@ private XrayConfig() {
fakeTestExecutionKey = PropertyManager.getProperty("xray.webresource.filter.getrequestsonly.fake.response.key", "FAKE-666666");

previousResultsFilename = PropertyManager.getProperty("xray.previous.result.filename", "");

/**
* @todo Replace by field validation {@link Field#getValidationRegex()}
*/
Expand Down Expand Up @@ -170,7 +168,7 @@ public String getRevisionJQLTerm() {
}

public boolean isSyncEnabled() {
return isSyncEnabled;
return PropertyManager.getBooleanProperty("xray.sync.enabled", false);
}

private List<String> createTransitionList(String prop) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@

package eu.tsystems.mms.tic.testerra.plugins.xray.hook;

import eu.tsystems.mms.tic.testerra.plugins.xray.annotation.XrayTest;
import eu.tsystems.mms.tic.testerra.plugins.xray.annotation.XrayTestAnnotationConverter;
import eu.tsystems.mms.tic.testerra.plugins.xray.synchronize.AbstractXrayResultsSynchronizer;
import eu.tsystems.mms.tic.testframework.hooks.ModuleHook;
import eu.tsystems.mms.tic.testframework.logging.Loggable;
import eu.tsystems.mms.tic.testframework.report.DefaultReport;
import eu.tsystems.mms.tic.testframework.report.Report;
import eu.tsystems.mms.tic.testframework.report.TesterraListener;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -49,11 +53,15 @@ public class XrayConnectorHook implements ModuleHook, Loggable {
public void init() {

this.initListener();
DefaultReport report = (DefaultReport) TesterraListener.getReport();
report.registerAnnotationConverter(XrayTest.class, new XrayTestAnnotationConverter());

}

@Override
public void terminate() {
DefaultReport report = (DefaultReport) TesterraListener.getReport();
report.unregisterAnnotationConverter(XrayTest.class);

for (final AbstractXrayResultsSynchronizer xraySynchronizer : XRAY_LISTENER) {
xraySynchronizer.shutdown();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package eu.tsystems.mms.tic.testerra.plugins.xray;

import eu.tsystems.mms.tic.testerra.plugins.xray.annotation.XrayTest;
import eu.tsystems.mms.tic.testframework.annotations.Fails;
import eu.tsystems.mms.tic.testframework.common.PropertyManager;
import org.testng.annotations.Test;

public class ExportTest extends AbstractTest {

@Test(description = "This is a simple test for exported annotations, see more here: https://docs.testerra.io")
@XrayTest(key = {"SWFTE-802", "SWFTE-989"})
@Fails(description = "This should fail", ticketString = "https://testerra.io")
public void test_exportAnnotation() {
PropertyManager.getThreadLocalProperties().setProperty("xray.sync.enabled", "false");
}
}