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