Search in sources :

Example 6 with IssueType

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"));
    }
}
Also used : SystemCredentialsProvider(com.cloudbees.plugins.credentials.SystemCredentialsProvider) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) 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 7 with IssueType

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);
    }
}
Also used : Status(com.atlassian.jira.rest.client.api.domain.Status) Issue(com.atlassian.jira.rest.client.api.domain.Issue) User(com.atlassian.jira.rest.client.api.domain.User) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) ExtendedJiraRestClient(hudson.plugins.jira.extension.ExtendedJiraRestClient) URI(java.net.URI) URL(java.net.URL) ExtendedAsynchronousJiraRestClientFactory(hudson.plugins.jira.JiraSite.ExtendedAsynchronousJiraRestClientFactory) Transition(com.atlassian.jira.rest.client.api.domain.Transition) ExtendedVersion(hudson.plugins.jira.extension.ExtendedVersion) JiraRestService(hudson.plugins.jira.JiraRestService) Component(com.atlassian.jira.rest.client.api.domain.Component)

Example 8 with IssueType

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
        }
    };
}
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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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)

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