Search in sources :

Example 1 with Priority

use of com.atlassian.jira.rest.client.api.domain.Priority in project jira-plugin by jenkinsci.

the class JiraCreateIssueNotifierTest method doFillPriorityIdItems.

@Test
public void doFillPriorityIdItems() throws Exception {
    String credId_1 = "cred-1-id";
    String credId_2 = "cred-2-id";
    String pwd1 = "pwd1";
    String pwd2 = "pwd2";
    UsernamePasswordCredentialsImpl cred1 = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, credId_1, null, "user1", pwd1);
    UsernamePasswordCredentialsImpl cred2 = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, credId_2, null, "user2", pwd2);
    SystemCredentialsProvider systemProvider = SystemCredentialsProvider.getInstance();
    systemProvider.getCredentials().add(cred1);
    systemProvider.save();
    {
        // test at project level
        URL url = new URL("https://pacific-ale.com.au");
        JiraSite jiraSite = mock(JiraSite.class);
        when(jiraSite.getUrl()).thenReturn(url);
        when(jiraSite.getCredentialsId()).thenReturn(credId_1);
        when(jiraSite.getName()).thenReturn(url.toExternalForm());
        JiraSession jiraSession = mock(JiraSession.class);
        when(jiraSession.getPriorities()).thenReturn(Collections.singletonList(new Priority(null, 2L, "priority-1", null, null, null)));
        when(jiraSite.getSession(any())).thenReturn(jiraSession);
        JiraGlobalConfiguration.get().setSites(Collections.singletonList(jiraSite));
        FreeStyleProject p = j.jenkins.createProject(FreeStyleProject.class, "p" + j.jenkins.getItems().size());
        ListBoxModel options = JiraCreateIssueNotifier.DESCRIPTOR.doFillPriorityIdItems(p);
        assertNotNull(options);
        assertThat(options.size(), Matchers.equalTo(2));
        assertThat(options.get(1).value, Matchers.equalTo("2"));
        assertThat(options.get(1).name, Matchers.containsString("priority-1"));
        assertThat(options.get(1).name, Matchers.containsString("https://pacific-ale.com.au"));
    }
    {
        // test at folder level
        Folder folder = j.jenkins.createProject(Folder.class, "folder" + j.jenkins.getItems().size());
        CredentialsStore folderStore = JiraFolderPropertyTest.getFolderStore(folder);
        folderStore.addCredentials(Domain.global(), cred2);
        JiraFolderProperty foo = new JiraFolderProperty();
        JiraSite jiraSite = mock(JiraSite.class);
        URL url = new URL("https://pale-ale.com.au");
        when(jiraSite.getUrl()).thenReturn(url);
        when(jiraSite.getCredentialsId()).thenReturn(credId_2);
        when(jiraSite.getName()).thenReturn(url.toExternalForm());
        JiraSession jiraSession = mock(JiraSession.class);
        when(jiraSession.getPriorities()).thenReturn(Collections.singletonList(new Priority(null, 3L, "priority-2", null, null, null)));
        when(jiraSite.getSession(any())).thenReturn(jiraSession);
        foo.setSites(Collections.singletonList(jiraSite));
        folder.getProperties().add(foo);
        ListBoxModel options = JiraCreateIssueNotifier.DESCRIPTOR.doFillPriorityIdItems(folder);
        assertNotNull(options);
        assertEquals(2, options.size());
        assertEquals("3", options.get(1).value);
        assertTrue(options.get(1).name.contains("priority-2"));
        assertTrue(options.get(1).name.contains("https://pale-ale.com.au"));
    }
}
Also used : SystemCredentialsProvider(com.cloudbees.plugins.credentials.SystemCredentialsProvider) Priority(com.atlassian.jira.rest.client.api.domain.Priority) CredentialsStore(com.cloudbees.plugins.credentials.CredentialsStore) UsernamePasswordCredentialsImpl(com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl) FreeStyleProject(hudson.model.FreeStyleProject) Folder(com.cloudbees.hudson.plugins.folder.Folder) TemporaryFolder(org.junit.rules.TemporaryFolder) URL(java.net.URL) ListBoxModel(hudson.util.ListBoxModel) Test(org.junit.Test)

Example 2 with Priority

use of com.atlassian.jira.rest.client.api.domain.Priority in project seleniumRobot by bhecquet.

the class JiraConnector method createIssue.

/**
 * Create issue
 */
public void createIssue(IssueBean issueBean) {
    if (!(issueBean instanceof JiraBean)) {
        throw new ClassCastException("JiraConnector needs JiraBean instances");
    }
    JiraBean jiraBean = (JiraBean) issueBean;
    IssueType issueType = issueTypes.get(jiraBean.getIssueType());
    if (issueType == null) {
        throw new ConfigurationException(String.format("Issue type %s cannot be found among valid issue types %s", jiraBean.getIssueType(), issueTypes.keySet()));
    }
    Map<String, CimFieldInfo> fieldInfos = getCustomFieldInfos(project, issueType);
    IssueRestClient issueClient = restClient.getIssueClient();
    IssueInputBuilder issueBuilder = new IssueInputBuilder(project, issueType, jiraBean.getSummary()).setDescription(jiraBean.getDescription());
    if (isDueDateRequired(fieldInfos)) {
        issueBuilder.setDueDate(jiraBean.getJodaDateTime());
    }
    if (jiraBean.getAssignee() != null && !jiraBean.getAssignee().isEmpty()) {
        User user = getUser(jiraBean.getAssignee());
        if (user == null) {
            throw new ConfigurationException(String.format("Assignee %s cannot be found among jira users", jiraBean.getAssignee()));
        }
        issueBuilder.setAssignee(user);
    }
    if (jiraBean.getPriority() != null && !jiraBean.getPriority().isEmpty()) {
        Priority priority = priorities.get(jiraBean.getPriority());
        if (priority == null) {
            throw new ConfigurationException(String.format("Priority %s cannot be found on this jira project, valid priorities are %s", jiraBean.getPriority(), priorities.keySet()));
        }
        issueBuilder.setPriority(priority);
    }
    if (jiraBean.getReporter() != null && !jiraBean.getReporter().isEmpty()) {
        issueBuilder.setReporterName(jiraBean.getReporter());
    }
    // set fields
    setCustomFields(jiraBean, fieldInfos, issueBuilder);
    // set components
    issueBuilder.setComponents(jiraBean.getComponents().stream().filter(component -> components.get(component) != null).map(component -> components.get(component)).collect(Collectors.toList()).toArray(new BasicComponent[] {}));
    // add issue
    IssueInput newIssue = issueBuilder.build();
    BasicIssue basicIssue = issueClient.createIssue(newIssue).claim();
    Issue issue = issueClient.getIssue(basicIssue.getKey()).claim();
    addAttachments(jiraBean, issueClient, issue);
    jiraBean.setId(issue.getKey());
    jiraBean.setAccessUrl(browseUrl + issue.getKey());
}
Also used : Arrays(java.util.Arrays) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) Priority(com.atlassian.jira.rest.client.api.domain.Priority) Issue(com.atlassian.jira.rest.client.api.domain.Issue) URISyntaxException(java.net.URISyntaxException) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) HashMap(java.util.HashMap) Snapshot(com.seleniumtests.reporter.logger.Snapshot) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) SeleniumTestsContextManager(com.seleniumtests.core.SeleniumTestsContextManager) Logger(org.apache.log4j.Logger) BugTracker(com.seleniumtests.connectors.bugtracker.BugTracker) WaitHelper(com.seleniumtests.util.helper.WaitHelper) ImmutableList(com.google.common.collect.ImmutableList) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Map(java.util.Map) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) Project(com.atlassian.jira.rest.client.api.domain.Project) URI(java.net.URI) ScenarioException(com.seleniumtests.customexception.ScenarioException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) Transition(com.atlassian.jira.rest.client.api.domain.Transition) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) CustomFieldOption(com.atlassian.jira.rest.client.api.domain.CustomFieldOption) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder) TransitionInput(com.atlassian.jira.rest.client.api.domain.input.TransitionInput) Field(com.atlassian.jira.rest.client.api.domain.Field) Collectors(java.util.stream.Collectors) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File) SearchRestClient(com.atlassian.jira.rest.client.api.SearchRestClient) List(java.util.List) User(com.atlassian.jira.rest.client.api.domain.User) Version(com.atlassian.jira.rest.client.api.domain.Version) BasicProject(com.atlassian.jira.rest.client.api.domain.BasicProject) TestStep(com.seleniumtests.reporter.logger.TestStep) Entry(java.util.Map.Entry) Comment(com.atlassian.jira.rest.client.api.domain.Comment) BasicComponent(com.atlassian.jira.rest.client.api.domain.BasicComponent) AsynchronousJiraRestClientFactory(com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory) IssueBean(com.seleniumtests.connectors.bugtracker.IssueBean) BasicPriority(com.atlassian.jira.rest.client.api.domain.BasicPriority) User(com.atlassian.jira.rest.client.api.domain.User) Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) 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) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) BasicComponent(com.atlassian.jira.rest.client.api.domain.BasicComponent) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder)

Example 3 with Priority

use of com.atlassian.jira.rest.client.api.domain.Priority 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 4 with Priority

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

the class WatchUpdatesConsumerTest method multipleChangesWithAddedNewIssueTest.

@Test
public void multipleChangesWithAddedNewIssueTest() throws Exception {
    final Issue issue = transitionIssueDone(issues.get(1));
    final Issue issue2 = setPriority(issues.get(2), new Priority(null, 4L, "High", null, null, null));
    reset(searchRestClient);
    AtomicBoolean searched = new AtomicBoolean();
    when(searchRestClient.searchJql(any(), any(), any(), any())).then(invocation -> {
        if (!searched.get()) {
            issues.add(createIssue(4L));
            issues.remove(1);
            issues.add(1, issue);
            issues.remove(2);
            issues.add(2, issue2);
            searched.set(true);
        }
        SearchResult result = new SearchResult(0, 50, 3, issues);
        return Promises.promise(result);
    });
    mockResult.expectedMessageCount(3);
    mockResult.expectedBodiesReceivedInAnyOrder(issue.getStatus(), issue.getResolution(), issue2.getPriority());
    mockResult.assertIsSatisfied(1000);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Issue(com.atlassian.jira.rest.client.api.domain.Issue) Utils.createIssue(org.apache.camel.component.jira.springboot.test.Utils.createIssue) Priority(com.atlassian.jira.rest.client.api.domain.Priority) Utils.setPriority(org.apache.camel.component.jira.springboot.test.Utils.setPriority) SearchResult(com.atlassian.jira.rest.client.api.domain.SearchResult) CamelSpringBootTest(org.apache.camel.test.spring.junit5.CamelSpringBootTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Priority

use of com.atlassian.jira.rest.client.api.domain.Priority in project opennms by OpenNMS.

the class ListPrioritiesCommand method doExecute.

@Override
protected void doExecute(JiraRestClient jiraRestClient) throws Exception {
    Iterable<Priority> priorities = jiraRestClient.getMetadataClient().getPriorities().get();
    if (!priorities.iterator().hasNext()) {
        System.out.println("No priorities found");
        return;
    }
    System.out.println(String.format(DEFAULT_ROW_FORMAT, "Id", "Name", "Description"));
    for (Priority eachPriority : priorities) {
        System.out.println(String.format(DEFAULT_ROW_FORMAT, eachPriority.getId(), eachPriority.getName(), removeNewLines(eachPriority.getDescription())));
    }
}
Also used : Priority(com.atlassian.jira.rest.client.api.domain.Priority)

Aggregations

Priority (com.atlassian.jira.rest.client.api.domain.Priority)8 Issue (com.atlassian.jira.rest.client.api.domain.Issue)4 IssueType (com.atlassian.jira.rest.client.api.domain.IssueType)4 IssueRestClient (com.atlassian.jira.rest.client.api.IssueRestClient)3 JiraRestClient (com.atlassian.jira.rest.client.api.JiraRestClient)3 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)3 BasicPriority (com.atlassian.jira.rest.client.api.domain.BasicPriority)3 IssueInput (com.atlassian.jira.rest.client.api.domain.input.IssueInput)3 JiraRestClientFactory (com.atlassian.jira.rest.client.api.JiraRestClientFactory)2 MetadataRestClient (com.atlassian.jira.rest.client.api.MetadataRestClient)2 SearchResult (com.atlassian.jira.rest.client.api.domain.SearchResult)2 Folder (com.cloudbees.hudson.plugins.folder.Folder)2 HashMap (java.util.HashMap)2 RestClientException (com.atlassian.jira.rest.client.api.RestClientException)1 SearchRestClient (com.atlassian.jira.rest.client.api.SearchRestClient)1 StatusCategory (com.atlassian.jira.rest.client.api.StatusCategory)1 BasicComponent (com.atlassian.jira.rest.client.api.domain.BasicComponent)1 BasicProject (com.atlassian.jira.rest.client.api.domain.BasicProject)1 CimFieldInfo (com.atlassian.jira.rest.client.api.domain.CimFieldInfo)1 Comment (com.atlassian.jira.rest.client.api.domain.Comment)1