Search in sources :

Example 1 with FixVersion

use of de.simpleworks.staf.plugin.maven.testflo.commons.pojo.FixVersion in project staf by simpleworks-gmbh.

the class TestFlo method addFixVersions.

public void addFixVersions(final List<String> fixVersions, TestPlan testPlan) {
    if (Convert.isEmpty(fixVersions)) {
        throw new IllegalArgumentException("fixVersions can't be null or empty.");
    }
    if (testPlan == null) {
        throw new IllegalArgumentException("testPlan can't be null.");
    }
    final String testplanId = testPlan.getId();
    if (Convert.isEmpty(testplanId)) {
        throw new IllegalArgumentException("testplanId can't be nur or empty string.");
    }
    List<FixVersion> versions = new ArrayList<FixVersion>();
    for (final String fixVersion : fixVersions) {
        if (TestFlo.logger.isDebugEnabled()) {
            TestFlo.logger.debug(String.format("fetch fix Version '%s'.", fixVersion));
        }
        try {
            final FixVersion version = testFloFixVersion.fetchFixVersion(fixVersion, testplanId);
            if (!versions.add(version)) {
                TestFlo.logger.error(String.format("can't  add fix Version '%s'.", fixVersion));
            }
        } catch (Exception ex) {
            final String msg = String.format("can't fetch Fix Version '%s'.", fixVersion);
            TestFlo.logger.error(msg, ex);
        }
    }
    for (TestCase testcase : testPlan.getTestCases()) {
        if (TestFlo.logger.isDebugEnabled()) {
            TestFlo.logger.debug(String.format("add fix versions '%s' to issue '%s'.", String.join(", ", versions.stream().map(version -> version.toString()).collect(Collectors.toList())), testcase.getId()));
        }
        try {
            testFloFixVersion.addFixVersions(versions, testcase.getId());
        } catch (Exception ex) {
            final String msg = String.format("can't add Fix Version, for testcase '%s'.", testcase.getId());
            TestFlo.logger.error(msg, ex);
        }
    }
}
Also used : FixVersion(de.simpleworks.staf.plugin.maven.testflo.commons.pojo.FixVersion) TestCase(de.simpleworks.staf.commons.elements.TestCase) ArrayList(java.util.ArrayList) SystemException(de.simpleworks.staf.commons.exceptions.SystemException)

Example 2 with FixVersion

use of de.simpleworks.staf.plugin.maven.testflo.commons.pojo.FixVersion in project staf by simpleworks-gmbh.

the class TestFloFixVersion method addFixVersions.

public void addFixVersions(final List<FixVersion> fetchedFixedVersion, final String id) {
    if (Convert.isEmpty(fetchedFixedVersion)) {
        throw new IllegalArgumentException("fetchedFixedVersion can't be null or empty string.");
    }
    if (Convert.isEmpty(id)) {
        throw new IllegalArgumentException("id can't be null or empty string.");
    }
    try {
        final Promise<Issue> promise = jira.getIssue(id);
        final Issue issue = promise.claim();
        if (issue == null) {
            throw new RuntimeException("issue can't be null.");
        }
        final IssueInputBuilder issueBuilder = new IssueInputBuilder();
        List<Version> versions = new ArrayList<Version>();
        for (final FixVersion fixVersion : fetchedFixedVersion) {
            if (!versions.add(new Version(new URI(fixVersion.getSelf()), null, fixVersion.getName(), fixVersion.getDescription(), false, false, null))) {
                TestFloFixVersion.logger.error(String.format("can't add version '%s'.", fixVersion.getId()));
            }
        }
        issueBuilder.setFixVersions(versions);
        final IssueInput newIssue = issueBuilder.build();
        if (newIssue == null) {
            throw new IllegalArgumentException("newIssue can't be null or empty string.");
        }
        final Promise<Void> update = jira.updateIssue(id, newIssue);
        update.claim();
    } catch (Exception ex) {
        if (TestFloFixVersion.logger.isDebugEnabled()) {
            TestFloFixVersion.logger.debug(String.format("can't add fix version '%s' for testcase '%s'.", String.join(", ", fetchedFixedVersion.stream().map(v -> v.toString()).collect(Collectors.toList())), id), ex);
        }
    }
}
Also used : IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) SystemException(de.simpleworks.staf.commons.exceptions.SystemException) Issue(com.atlassian.jira.rest.client.api.domain.Issue) URL(java.net.URL) UtilsIO(de.simpleworks.staf.commons.utils.UtilsIO) ArrayList(java.util.ArrayList) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) Response(okhttp3.Response) Call(okhttp3.Call) URI(java.net.URI) FixVersion(de.simpleworks.staf.plugin.maven.testflo.commons.pojo.FixVersion) Convert(de.simpleworks.staf.commons.utils.Convert) ResponseBody(okhttp3.ResponseBody) Request(okhttp3.Request) JiraProperties(de.simpleworks.staf.module.jira.util.JiraProperties) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder) JsonPath(com.jayway.jsonpath.JsonPath) Collectors(java.util.stream.Collectors) List(java.util.List) Promise(com.atlassian.util.concurrent.Promise) Logger(org.apache.logging.log4j.Logger) OkHttpClient(okhttp3.OkHttpClient) Version(com.atlassian.jira.rest.client.api.domain.Version) JSONArray(net.minidev.json.JSONArray) Assert(org.junit.Assert) LogManager(org.apache.logging.log4j.LogManager) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) FixVersion(de.simpleworks.staf.plugin.maven.testflo.commons.pojo.FixVersion) Issue(com.atlassian.jira.rest.client.api.domain.Issue) ArrayList(java.util.ArrayList) URI(java.net.URI) SystemException(de.simpleworks.staf.commons.exceptions.SystemException) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) FixVersion(de.simpleworks.staf.plugin.maven.testflo.commons.pojo.FixVersion) Version(com.atlassian.jira.rest.client.api.domain.Version) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder)

Example 3 with FixVersion

use of de.simpleworks.staf.plugin.maven.testflo.commons.pojo.FixVersion in project staf by simpleworks-gmbh.

the class TestFloFixVersion method fetchFixVersion.

private FixVersion fetchFixVersion(final URL jiraURL, final String username, final String password, final String fixVersion, final String id) throws SystemException {
    if (jiraURL == null) {
        throw new IllegalArgumentException("jiraURL can't be null.");
    }
    if (Convert.isEmpty(username)) {
        throw new IllegalArgumentException("username can't be null or empty string.");
    }
    if (Convert.isEmpty(password)) {
        throw new IllegalArgumentException("password can't be null or empty string.");
    }
    if (Convert.isEmpty(fixVersion)) {
        throw new IllegalArgumentException("fixVersion can't be null or empty string.");
    }
    if (Convert.isEmpty(id)) {
        throw new IllegalArgumentException("id can't be null or empty string.");
    }
    // fetch fixVersion
    FixVersion result;
    try {
        final Promise<Issue> promise = jira.getIssue(id);
        final Issue issue = promise.claim();
        if (issue == null) {
            throw new RuntimeException("issue can't be null.");
        }
        final URL url = new URL(String.format("%s/rest/api/latest/project/%s/version?maxResults=1000000&startAt=0", jiraURL, issue.getProject().getKey()));
        if (TestFloFixVersion.logger.isDebugEnabled()) {
            TestFloFixVersion.logger.debug(String.format("use url '%s' to fetch available fix versions .", url));
        }
        final Request request = new Request.Builder().url(url).build();
        final Call call = this.httpClient.newCall(request);
        final Response response = call.execute();
        Assert.assertTrue(String.format("Status Code 200 was expected, but was '%s'.", Integer.toString(response.code())), (200 == response.code()));
        final ResponseBody responseBody = response.body();
        final String json = UtilsIO.getAllContentFromBytesArray(responseBody.bytes());
        if (Convert.isEmpty(json)) {
            throw new RuntimeException("json can't be null or empty.");
        }
        final JSONArray jsonArray = (JSONArray) JsonPath.read(json, String.format("$.values[?(@.name == '%s')]", fixVersion));
        final FixVersion[] fixVersions = (new ObjectMapper()).readValue(jsonArray.toJSONString(), FixVersion[].class);
        Assert.assertTrue(String.format("there is more than one fix version '%s'.", fixVersion), (fixVersions.length == 1));
        result = fixVersions[0];
    } catch (Exception ex) {
        final String msg = "can't fetch Fix Version.";
        logger.error(msg, ex);
        throw new SystemException(msg);
    }
    return result;
}
Also used : Call(okhttp3.Call) FixVersion(de.simpleworks.staf.plugin.maven.testflo.commons.pojo.FixVersion) Issue(com.atlassian.jira.rest.client.api.domain.Issue) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder) Request(okhttp3.Request) JSONArray(net.minidev.json.JSONArray) URL(java.net.URL) SystemException(de.simpleworks.staf.commons.exceptions.SystemException) ResponseBody(okhttp3.ResponseBody) Response(okhttp3.Response) SystemException(de.simpleworks.staf.commons.exceptions.SystemException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

SystemException (de.simpleworks.staf.commons.exceptions.SystemException)3 FixVersion (de.simpleworks.staf.plugin.maven.testflo.commons.pojo.FixVersion)3 Issue (com.atlassian.jira.rest.client.api.domain.Issue)2 IssueInputBuilder (com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 JSONArray (net.minidev.json.JSONArray)2 Call (okhttp3.Call)2 Request (okhttp3.Request)2 Response (okhttp3.Response)2 ResponseBody (okhttp3.ResponseBody)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 IssueRestClient (com.atlassian.jira.rest.client.api.IssueRestClient)1 Version (com.atlassian.jira.rest.client.api.domain.Version)1 IssueInput (com.atlassian.jira.rest.client.api.domain.input.IssueInput)1 Promise (com.atlassian.util.concurrent.Promise)1 JsonPath (com.jayway.jsonpath.JsonPath)1 TestCase (de.simpleworks.staf.commons.elements.TestCase)1 Convert (de.simpleworks.staf.commons.utils.Convert)1 UtilsIO (de.simpleworks.staf.commons.utils.UtilsIO)1