Search in sources :

Example 1 with MetadataRestClient

use of com.atlassian.jira.rest.client.api.MetadataRestClient in project camel-spring-boot by apache.

the class AddIssueProducerTest 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);
            metadataRestClient = mock(MetadataRestClient.class);
            lenient().when(jiraRestClientFactory.createWithBasicHttpAuthentication(any(), any(), any())).thenReturn(jiraClient);
            lenient().when(jiraClient.getIssueClient()).thenReturn(issueRestClient);
            lenient().when(jiraClient.getMetadataClient()).thenReturn(metadataRestClient);
            Map<Integer, IssueType> issueTypes = new HashMap<>();
            issueTypes.put(1, new IssueType(null, 1L, "Bug", false, null, null));
            issueTypes.put(2, new IssueType(null, 2L, "Task", false, null, null));
            Promise<Iterable<IssueType>> promiseIssueTypes = Promises.promise(issueTypes.values());
            lenient().when(metadataRestClient.getIssueTypes()).thenReturn(promiseIssueTypes);
            Map<Integer, Priority> issuePriorities = new HashMap<>();
            issuePriorities.put(1, new Priority(null, 1L, "High", null, null, null));
            issuePriorities.put(2, new Priority(null, 2L, "Low", null, null, null));
            Promise<Iterable<Priority>> promisePriorities = Promises.promise(issuePriorities.values());
            lenient().when(metadataRestClient.getPriorities()).thenReturn(promisePriorities);
            lenient().when(issueRestClient.createIssue(any(IssueInput.class))).then(inv -> {
                IssueInput issueInput = inv.getArgument(0);
                String summary = (String) issueInput.getField("summary").getValue();
                Integer issueTypeId = Integer.parseInt(getValue(issueInput, "issuetype", "id"));
                IssueType issueType = issueTypes.get(issueTypeId);
                String project = getValue(issueInput, "project", "key");
                String description = (String) issueInput.getField("description").getValue();
                Integer priorityId = Integer.parseInt(getValue(issueInput, "priority", "id"));
                BasicPriority priority = issuePriorities.get(priorityId);
                backendIssue = createIssue(11L, summary, project, issueType, description, priority, userAssignee, null, null);
                BasicIssue basicIssue = new BasicIssue(backendIssue.getSelf(), backendIssue.getKey(), backendIssue.getId());
                return Promises.promise(basicIssue);
            });
            lenient().when(issueRestClient.getIssue(any())).then(inv -> Promises.promise(backendIssue));
            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) HashMap(java.util.HashMap) JiraRestClientFactory(com.atlassian.jira.rest.client.api.JiraRestClientFactory) MetadataRestClient(com.atlassian.jira.rest.client.api.MetadataRestClient) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) Priority(com.atlassian.jira.rest.client.api.domain.Priority) BasicPriority(com.atlassian.jira.rest.client.api.domain.BasicPriority) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) BasicPriority(com.atlassian.jira.rest.client.api.domain.BasicPriority) Bean(org.springframework.context.annotation.Bean)

Example 2 with MetadataRestClient

use of com.atlassian.jira.rest.client.api.MetadataRestClient in project camel-spring-boot by apache.

the class UpdateIssueProducerTest 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);
            metadataRestClient = mock(MetadataRestClient.class);
            when(jiraRestClientFactory.createWithBasicHttpAuthentication(any(), any(), any())).thenReturn(jiraClient);
            when(jiraClient.getIssueClient()).thenReturn(issueRestClient);
            when(jiraClient.getMetadataClient()).thenReturn(metadataRestClient);
            Map<Integer, IssueType> issueTypes = new HashMap<>();
            issueTypes.put(1, new IssueType(null, 1L, "Bug", false, null, null));
            issueTypes.put(2, new IssueType(null, 2L, "Task", false, null, null));
            Promise<Iterable<IssueType>> promiseIssueTypes = Promises.promise(issueTypes.values());
            when(metadataRestClient.getIssueTypes()).thenReturn(promiseIssueTypes);
            Map<Integer, Priority> issuePriorities = new HashMap<>();
            issuePriorities.put(1, new Priority(null, 1L, "High", null, null, null));
            issuePriorities.put(2, new Priority(null, 2L, "Low", null, null, null));
            Promise<Iterable<Priority>> promisePriorities = Promises.promise(issuePriorities.values());
            when(metadataRestClient.getPriorities()).thenReturn(promisePriorities);
            backendIssue = createIssue(11L);
            when(issueRestClient.updateIssue(anyString(), any(IssueInput.class))).then(inv -> {
                String issueKey = inv.getArgument(0);
                IssueInput issueInput = inv.getArgument(1);
                String summary = (String) issueInput.getField("summary").getValue();
                Integer issueTypeId = Integer.parseInt(getValue(issueInput, "issuetype", "id"));
                IssueType issueType = issueTypes.get(issueTypeId);
                String description = (String) issueInput.getField("description").getValue();
                Integer priorityId = Integer.parseInt(getValue(issueInput, "priority", "id"));
                BasicPriority priority = issuePriorities.get(priorityId);
                backendIssue = createIssue(11L, summary, issueKey, issueType, description, priority, userAssignee, null, null);
                BasicIssue basicIssue = new BasicIssue(backendIssue.getSelf(), backendIssue.getKey(), backendIssue.getId());
                return Promises.promise(basicIssue);
            });
            when(issueRestClient.getIssue(any())).then(inv -> Promises.promise(backendIssue));
            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) HashMap(java.util.HashMap) JiraRestClientFactory(com.atlassian.jira.rest.client.api.JiraRestClientFactory) MetadataRestClient(com.atlassian.jira.rest.client.api.MetadataRestClient) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) Priority(com.atlassian.jira.rest.client.api.domain.Priority) BasicPriority(com.atlassian.jira.rest.client.api.domain.BasicPriority) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) BasicPriority(com.atlassian.jira.rest.client.api.domain.BasicPriority) Bean(org.springframework.context.annotation.Bean)

Aggregations

IssueRestClient (com.atlassian.jira.rest.client.api.IssueRestClient)2 JiraRestClient (com.atlassian.jira.rest.client.api.JiraRestClient)2 JiraRestClientFactory (com.atlassian.jira.rest.client.api.JiraRestClientFactory)2 MetadataRestClient (com.atlassian.jira.rest.client.api.MetadataRestClient)2 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)2 BasicPriority (com.atlassian.jira.rest.client.api.domain.BasicPriority)2 IssueType (com.atlassian.jira.rest.client.api.domain.IssueType)2 Priority (com.atlassian.jira.rest.client.api.domain.Priority)2 IssueInput (com.atlassian.jira.rest.client.api.domain.input.IssueInput)2 HashMap (java.util.HashMap)2 CamelContext (org.apache.camel.CamelContext)2 CamelContextConfiguration (org.apache.camel.spring.boot.CamelContextConfiguration)2 Bean (org.springframework.context.annotation.Bean)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1