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);
}
}
}
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);
}
}
}
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;
}
Aggregations