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())));
}
}
}
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")));
}
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());
}
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
}
};
}
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);
}
}
Aggregations