use of com.atlassian.jira.rest.client.api.domain.Attachment in project camel-spring-boot by apache.
the class AttachFileProducerTest method contextConfiguration.
@Bean
CamelContextConfiguration contextConfiguration() {
return new CamelContextConfiguration() {
@Override
public void beforeApplicationStart(CamelContext context) {
// get chance to mock camelContext/Registry
jiraRestClientFactory = mock(JiraRestClientFactory.class);
jiraClient = mock(JiraRestClient.class);
issueRestClient = mock(IssueRestClient.class);
lenient().when(jiraRestClientFactory.createWithBasicHttpAuthentication(any(), any(), any())).thenReturn(jiraClient);
lenient().when(jiraClient.getIssueClient()).thenReturn(issueRestClient);
when(issueRestClient.getIssue(any())).then(inv -> {
if (issue == null) {
issue = createIssue(1);
}
return Promises.promise(issue);
});
when(issueRestClient.addAttachments(any(URI.class), any(File.class))).then(inv -> {
File attachedFileTmp = inv.getArgument(1);
// create a temp destiny file as the attached file is marked for removal on AttachFileProducer
attachedFile = File.createTempFile("camel-jira-test-", null);
Files.copy(attachedFileTmp.toPath(), attachedFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
attachedFile.deleteOnExit();
Collection<Attachment> attachments = new ArrayList<>();
attachments.add(new Attachment(issue.getAttachmentsUri(), attachedFile.getName(), null, null, Long.valueOf(attachedFile.length()).intValue(), null, null, null));
// re-create the issue with the attachment sent by the route
issue = createIssueWithAttachment(issue.getId(), issue.getSummary(), issue.getKey(), issue.getIssueType(), issue.getDescription(), issue.getPriority(), issue.getAssignee(), attachments);
return null;
});
camelContext.getRegistry().bind(JIRA_REST_CLIENT_FACTORY, jiraRestClientFactory);
}
@Override
public void afterApplicationStart(CamelContext camelContext) {
// do nothing here
}
};
}
Aggregations