Search in sources :

Example 1 with IssueType

use of com.atlassian.jira.rest.client.api.domain.IssueType 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())));
        }
    }
}
Also used : Status(com.atlassian.jira.rest.client.api.domain.Status) Subtask(com.atlassian.jira.rest.client.api.domain.Subtask) Issue(com.atlassian.jira.rest.client.api.domain.Issue) IssueField(com.atlassian.jira.rest.client.api.domain.IssueField) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) Transition(com.atlassian.jira.rest.client.api.domain.Transition) Attachment(com.atlassian.jira.rest.client.api.domain.Attachment)

Example 2 with IssueType

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

the class JiraCreateReleaseNotesTest method releaseNotesContent.

@Test
public void releaseNotesContent() throws InterruptedException, Exception {
    JiraCreateReleaseNotes jcrn = spy(new JiraCreateReleaseNotes(JIRA_PRJ, JIRA_RELEASE, JIRA_VARIABLE));
    doReturn(site).when(jcrn).getSiteForProject(Mockito.any());
    when(site.getReleaseNotesForFixVersion(JIRA_PRJ, JIRA_RELEASE, JiraCreateReleaseNotes.DEFAULT_FILTER)).thenCallRealMethod();
    Issue issue1 = Mockito.mock(Issue.class);
    IssueType issueType1 = Mockito.mock(IssueType.class);
    Status issueStatus = Mockito.mock(Status.class);
    when(issue1.getIssueType()).thenReturn(issueType1);
    when(issue1.getStatus()).thenReturn(issueStatus);
    when(issueType1.getName()).thenReturn("Bug");
    Issue issue2 = Mockito.mock(Issue.class);
    IssueType issueType2 = Mockito.mock(IssueType.class);
    when(issue2.getIssueType()).thenReturn(issueType2);
    when(issue2.getStatus()).thenReturn(issueStatus);
    when(issueType2.getName()).thenReturn("Feature");
    when(session.getIssuesWithFixVersion(JIRA_PRJ, JIRA_RELEASE, JiraCreateReleaseNotes.DEFAULT_FILTER)).thenReturn(Arrays.asList(issue1, issue2));
    BuildWrapper.Environment environment = jcrn.setUp(build, launcher, buildListener);
    Map<String, String> envVars = new HashMap<>();
    environment.buildEnvVars(envVars);
    String releaseNotes = envVars.get(jcrn.getJiraEnvironmentVariable());
    assertNotNull(releaseNotes);
    assertThat(releaseNotes, Matchers.containsString(issueType1.getName()));
    assertThat(releaseNotes, Matchers.containsString(issueType2.getName()));
    assertThat(releaseNotes, Matchers.not(Matchers.containsString("UNKNOWN")));
}
Also used : Status(com.atlassian.jira.rest.client.api.domain.Status) Issue(com.atlassian.jira.rest.client.api.domain.Issue) HashMap(java.util.HashMap) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) BuildWrapper(hudson.tasks.BuildWrapper) Test(org.junit.Test)

Example 3 with IssueType

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

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

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

the class JiraConnector method main.

/**
 * Method for getting required fields and allowed values for creating an issue on a project
 *
 * @param args
 * 		server => url of jira server
 * 		user => user to connect to jira
 * 		password => password to connect to jira
 * 		project => projectkey
 * 		issueType => type of the issue that will be created
 * 		issueKey (optional) => give the transitions for a specific issue
 */
public static void main(String[] args) {
    if (args.length < 5) {
        System.out.println("Usage: JiraConnector <server> <projectKey> <user> <password> <issueType>");
        System.exit(1);
    }
    JiraConnector jiraConnector = new JiraConnector(args[0], args[1], args[2], args[3]);
    IssueType issueType = jiraConnector.issueTypes.get(args[4]);
    if (issueType == null) {
        throw new ConfigurationException(String.format("Issue type %s cannot be found among valid issue types %s", args[4], jiraConnector.issueTypes.keySet()));
    }
    System.out.println("Proprities:");
    for (String priority : jiraConnector.priorities.keySet()) {
        System.out.println(String.format(ITEM, priority));
    }
    System.out.println("\nComponents:");
    for (String component : jiraConnector.components.keySet()) {
        System.out.println(String.format(ITEM, component));
    }
    System.out.println(String.format("\nListing required fields and allowed values (if any) for issue '%s'", args[4]));
    Map<String, CimFieldInfo> fieldInfos = jiraConnector.getCustomFieldInfos(jiraConnector.project, issueType);
    for (Entry<String, List<String>> entry : jiraConnector.getRequiredFieldsAndValues(fieldInfos).entrySet()) {
        System.out.println(String.format("Field '%s':", entry.getKey()));
        for (String value : entry.getValue()) {
            System.out.println(String.format(ITEM, value));
        }
    }
    if (args.length >= 6) {
        IssueRestClient issueClient = jiraConnector.restClient.getIssueClient();
        Issue issue;
        try {
            issue = issueClient.getIssue(args[5]).claim();
        } catch (RestClientException e) {
            throw new ScenarioException(String.format("Jira issue %s does not exist, cannot close it", args[5]));
        }
        Map<String, Transition> transitions = new HashMap<>();
        issueClient.getTransitions(issue).claim().forEach(transition -> transitions.put(transition.getName(), transition));
        System.out.println(transitions);
    }
}
Also used : Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) HashMap(java.util.HashMap) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) Transition(com.atlassian.jira.rest.client.api.domain.Transition) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Aggregations

IssueType (com.atlassian.jira.rest.client.api.domain.IssueType)8 Issue (com.atlassian.jira.rest.client.api.domain.Issue)5 HashMap (java.util.HashMap)5 IssueRestClient (com.atlassian.jira.rest.client.api.IssueRestClient)4 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)4 Transition (com.atlassian.jira.rest.client.api.domain.Transition)4 JiraRestClient (com.atlassian.jira.rest.client.api.JiraRestClient)3 BasicPriority (com.atlassian.jira.rest.client.api.domain.BasicPriority)3 Priority (com.atlassian.jira.rest.client.api.domain.Priority)3 Status (com.atlassian.jira.rest.client.api.domain.Status)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 RestClientException (com.atlassian.jira.rest.client.api.RestClientException)2 CimFieldInfo (com.atlassian.jira.rest.client.api.domain.CimFieldInfo)2 User (com.atlassian.jira.rest.client.api.domain.User)2 ImmutableList (com.google.common.collect.ImmutableList)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 ScenarioException (com.seleniumtests.customexception.ScenarioException)2 URL (java.net.URL)2