use of com.atlassian.jira.rest.client.api.domain.IssueType in project jira-plugin by jenkinsci.
the class JiraCreateIssueNotifierTest method doFillTypeItems.
@Test
public void doFillTypeItems() 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.getIssueTypes()).thenReturn(Collections.singletonList(new IssueType(null, 1L, "type-1", true, 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.doFillTypeIdItems(p);
assertNotNull(options);
assertThat(options.size(), Matchers.equalTo(2));
assertThat(options.get(1).value, Matchers.equalTo("1"));
assertThat(options.get(1).name, Matchers.containsString("type-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.getIssueTypes()).thenReturn(Collections.singletonList(new IssueType(null, 2L, "type-2", false, null, null)));
when(jiraSite.getSession(any())).thenReturn(jiraSession);
foo.setSites(Collections.singletonList(jiraSite));
folder.getProperties().add(foo);
ListBoxModel options = JiraCreateIssueNotifier.DESCRIPTOR.doFillTypeIdItems(folder);
assertNotNull(options);
assertEquals(2, options.size());
assertEquals("2", options.get(1).value);
assertTrue(options.get(1).name.contains("type-2"));
assertTrue(options.get(1).name.contains("https://pale-ale.com.au"));
}
}
use of com.atlassian.jira.rest.client.api.domain.IssueType in project jira-plugin by jenkinsci.
the class JiraTester method main.
public static void main(String[] args) throws Exception {
final URI uri = new URL(JiraConfig.getUrl()).toURI();
final ExtendedJiraRestClient jiraRestClient = new ExtendedAsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(uri, JiraConfig.getUsername(), JiraConfig.getPassword());
final JiraRestService restService = new JiraRestService(uri, jiraRestClient, JiraConfig.getUsername(), JiraConfig.getPassword(), JiraSite.DEFAULT_TIMEOUT);
final String projectKey = "TESTPROJECT";
final String issueId = "TESTPROJECT-425";
final Integer actionId = 21;
final Issue issue = restService.getIssue(issueId);
System.out.println("issue:" + issue);
final List<Transition> availableActions = restService.getAvailableActions(issueId);
for (Transition action : availableActions) {
System.out.println("Action:" + action);
}
for (IssueType issueType : restService.getIssueTypes()) {
System.out.println(" issue type: " + issueType);
}
// restService.addVersion("TESTPROJECT", "0.0.2");
final List<Component> components = restService.getComponents(projectKey);
for (Component component : components) {
System.out.println("component: " + component);
}
// BasicComponent backendComponent = null;
// final Iterable<BasicComponent> components1 = Lists.newArrayList(backendComponent);
// restService.createIssue("TESTPROJECT", "This is a test issue created using Jira jenkins plugin. Please ignore it.", "TESTUSER", components1, "test issue from Jira jenkins plugin");
final List<Issue> searchResults = restService.getIssuesFromJqlSearch("project = \"TESTPROJECT\"", 3);
for (Issue searchResult : searchResults) {
System.out.println("JQL search result: " + searchResult);
}
final List<String> projectsKeys = restService.getProjectsKeys();
for (String projectsKey : projectsKeys) {
System.out.println("project key: " + projectsKey);
}
final List<Status> statuses = restService.getStatuses();
for (Status status : statuses) {
System.out.println("status:" + status);
}
final User user = restService.getUser("TESTUSER");
System.out.println("user: " + user);
final List<ExtendedVersion> versions = restService.getVersions(projectKey);
for (ExtendedVersion version : versions) {
System.out.println("version: " + version);
}
for (int i = 0; i < 10; i++) {
callUniq(restService);
}
for (int i = 0; i < 10; i++) {
callDuplicate(restService);
}
}
use of com.atlassian.jira.rest.client.api.domain.IssueType 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
}
};
}
Aggregations