Search in sources :

Example 6 with Attachment

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
        }
    };
}
Also used : CamelContext(org.apache.camel.CamelContext) CamelContextConfiguration(org.apache.camel.spring.boot.CamelContextConfiguration) JiraRestClientFactory(com.atlassian.jira.rest.client.api.JiraRestClientFactory) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) ArrayList(java.util.ArrayList) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) Attachment(com.atlassian.jira.rest.client.api.domain.Attachment) Utils.createIssueWithAttachment(org.apache.camel.component.jira.springboot.test.Utils.createIssueWithAttachment) URI(java.net.URI) File(java.io.File) Bean(org.springframework.context.annotation.Bean)

Aggregations

Attachment (com.atlassian.jira.rest.client.api.domain.Attachment)6 Issue (com.atlassian.jira.rest.client.api.domain.Issue)5 IssueRestClient (com.atlassian.jira.rest.client.api.IssueRestClient)3 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)2 AsynchronousIssueRestClient (com.atlassian.jira.rest.client.internal.async.AsynchronousIssueRestClient)2 SystemException (de.simpleworks.staf.commons.exceptions.SystemException)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 Utils.createIssueWithAttachment (org.apache.camel.component.jira.springboot.test.Utils.createIssueWithAttachment)2 Test (org.junit.jupiter.api.Test)2 JiraRestClient (com.atlassian.jira.rest.client.api.JiraRestClient)1 JiraRestClientFactory (com.atlassian.jira.rest.client.api.JiraRestClientFactory)1 IssueField (com.atlassian.jira.rest.client.api.domain.IssueField)1 IssueType (com.atlassian.jira.rest.client.api.domain.IssueType)1 Status (com.atlassian.jira.rest.client.api.domain.Status)1 Subtask (com.atlassian.jira.rest.client.api.domain.Subtask)1 Transition (com.atlassian.jira.rest.client.api.domain.Transition)1 AttachmentInput (com.atlassian.jira.rest.client.api.domain.input.AttachmentInput)1 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 File (java.io.File)1