use of com.atlassian.jira.rest.client.api.domain.Attachment in project staf by simpleworks-gmbh.
the class DebugTestFLOClientMojo method dumpIssue.
public void dumpIssue() {
final Issue issue = client.getIssue(testPlanId).claim();
DebugTestFLOClientMojo.logger.debug(String.format("key: '%s', issue: id: %d.", issue.getKey(), issue.getId()));
final IssueType type = issue.getIssueType();
DebugTestFLOClientMojo.logger.debug(String.format("issue type: id: %d, name: '%s'.", type.getId(), type.getName()));
final Status status = issue.getStatus();
DebugTestFLOClientMojo.logger.debug(String.format("status: id: %d, name: '%s'.", status.getId(), status.getName()));
DebugTestFLOClientMojo.dumpFields("fields for issue.", issue.getFields());
DebugTestFLOClientMojo.logger.debug("attachments:");
for (final Attachment attachment : issue.getAttachments()) {
DebugTestFLOClientMojo.logger.debug(String.format("attachment: '%s'.", attachment));
}
final IssueField field = issue.getField("Test Plan Iteration");
Assert.assertNotNull("field \"Test Plan Iteration\" can't be null.", field);
final Object obj = field.getValue();
DebugTestFLOClientMojo.logger.debug(String.format("class for field: \"Iteration\" is: '%s'.", obj.getClass().getName()));
{
DebugTestFLOClientMojo.logger.debug("transition:");
final Iterable<Transition> transitions = client.getTransitions(issue).claim();
for (final Transition transition : transitions) {
DebugTestFLOClientMojo.logger.debug(String.format("transition: name: '%s', id: %d.", transition.getName(), Integer.valueOf(transition.getId())));
}
}
for (final Subtask subtask : issue.getSubtasks()) {
final Issue i = client.getIssue(subtask.getIssueKey()).claim();
final IssueField steps = i.getFieldByName("Steps");
DebugTestFLOClientMojo.logger.debug(String.format("steps: '%s'.", steps.getValue()));
final IssueField template = i.getFieldByName("TC Template");
DebugTestFLOClientMojo.logger.debug(String.format("template: '%s'.", template.getValue()));
final Iterable<Transition> transitions = client.getTransitions(i).claim();
for (final Transition transition : transitions) {
DebugTestFLOClientMojo.logger.debug(String.format("subtask: '%s', transition: name: '%s', id: %d.", subtask.getIssueKey(), transition.getName(), Integer.valueOf(transition.getId())));
}
}
}
use of com.atlassian.jira.rest.client.api.domain.Attachment in project camel-quarkus by apache.
the class JiraTest method attachments.
@Test
public void attachments() {
// Create issue
String issueKey = createIssue();
try {
// Create attachment
RestAssured.given().contentType(ContentType.TEXT).pathParam("key", issueKey).body(ISSUE_ATTACHMENT).when().post("/jira/issue/{key}/attach").then().statusCode(201);
// Verify attachment
await().atMost(10, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
Issue issue = getClient().getIssueClient().getIssue(issueKey).claim();
assertNotNull(issue);
Iterable<Attachment> iterable = issue.getAttachments();
return iterable != null && iterable.iterator().hasNext();
});
Issue issue = getClient().getIssueClient().getIssue(issueKey).claim();
Attachment attachment = issue.getAttachments().iterator().next();
assertTrue(attachment.getFilename().startsWith("cq-jira"));
} finally {
deleteIssue(issueKey);
}
}
use of com.atlassian.jira.rest.client.api.domain.Attachment in project staf by simpleworks-gmbh.
the class Jira method fetchAttachements.
public List<Attachment> fetchAttachements(final Task task) throws SystemException {
if (task == null) {
throw new IllegalArgumentException("task can't be null.");
}
final List<Attachment> attachements = new ArrayList<>();
try {
final IssueRestClient issueClient = getIssueRestClient();
final Promise<Issue> promise = issueClient.getIssue(task.getKey());
final Issue issue = promise.claim();
issue.getAttachments().forEach(attachement -> attachements.add(attachement));
} catch (final Exception ex) {
final String message = "can't fetch attachements.";
Jira.logger.error(message, ex);
throw new SystemException(message);
}
if (Jira.logger.isDebugEnabled()) {
if (Convert.isEmpty(attachements)) {
Jira.logger.debug(String.format("No attachements were fetched from Task, identified by '%s'.", task.getKey()));
}
}
return attachements;
}
use of com.atlassian.jira.rest.client.api.domain.Attachment in project staf by simpleworks-gmbh.
the class Jira method uploadAttachements.
public boolean uploadAttachements(final String subTaskKey, final List<Attachment> attachements) throws SystemException {
if (Convert.isEmpty(subTaskKey)) {
throw new IllegalArgumentException("subTaskKey can't be null.");
}
if (Convert.isEmpty(attachements)) {
throw new IllegalArgumentException("attachements can't be null.");
}
try {
final IssueRestClient issueClient = getIssueRestClient();
for (final Attachment attachement : attachements) {
final Promise<Issue> promise = issueClient.getIssue(subTaskKey);
final Issue newIssue = promise.claim();
final AsynchronousIssueRestClient asynchronousIssueRestClient = (AsynchronousIssueRestClient) issueClient;
final Promise<InputStream> attachment = asynchronousIssueRestClient.getAttachment(attachement.getContentUri());
try (final InputStream inputStream = attachment.get()) {
final Promise<Void> upload = issueClient.addAttachments(newIssue.getAttachmentsUri(), new AttachmentInput(attachement.getFilename(), inputStream));
upload.claim();
}
}
} catch (final Exception ex) {
final String message = "can't upload attachements.";
Jira.logger.error(message, ex);
throw new SystemException(message);
}
return true;
}
use of com.atlassian.jira.rest.client.api.domain.Attachment in project camel-spring-boot by apache.
the class AttachFileProducerTest method verifyAttachment.
@Test
public void verifyAttachment() throws InterruptedException, IOException {
template.sendBody(generateSampleFile());
Issue retrievedIssue = issueRestClient.getIssue(issue.getKey()).claim();
assertEquals(issue, retrievedIssue);
// there is only one attachment
Attachment attachFile = retrievedIssue.getAttachments().iterator().next();
assertEquals(attachFile.getFilename(), attachedFile.getName());
assertEquals(attachFile.getSize(), attachedFile.length());
mockResult.expectedMessageCount(1);
mockResult.assertIsSatisfied();
}
Aggregations