Search in sources :

Example 1 with SearchRestClient

use of com.atlassian.jira.rest.client.api.SearchRestClient in project camel-spring-boot by apache.

the class NewCommentsConsumerTest 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);
            searchRestClient = mock(SearchRestClient.class);
            SearchResult result = new SearchResult(0, 50, 100, issues);
            Promise<SearchResult> promiseSearchResult = Promises.promise(result);
            Issue issue = createIssueWithComments(4L, 1);
            Promise<Issue> promiseIssue = Promises.promise(issue);
            when(jiraClient.getSearchClient()).thenReturn(searchRestClient);
            when(jiraClient.getIssueClient()).thenReturn(issueRestClient);
            when(jiraRestClientFactory.createWithBasicHttpAuthentication(any(), any(), any())).thenReturn(jiraClient);
            when(searchRestClient.searchJql(any(), any(), any(), any())).thenReturn(promiseSearchResult);
            when(issueRestClient.getIssue(anyString())).thenReturn(promiseIssue);
            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) Issue(com.atlassian.jira.rest.client.api.domain.Issue) Utils.createIssue(org.apache.camel.component.jira.springboot.test.Utils.createIssue) JiraRestClientFactory(com.atlassian.jira.rest.client.api.JiraRestClientFactory) SearchRestClient(com.atlassian.jira.rest.client.api.SearchRestClient) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) SearchResult(com.atlassian.jira.rest.client.api.domain.SearchResult) Bean(org.springframework.context.annotation.Bean)

Example 2 with SearchRestClient

use of com.atlassian.jira.rest.client.api.SearchRestClient in project camel-spring-boot by apache.

the class NewIssuesConsumerTest 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);
            searchRestClient = mock(SearchRestClient.class);
            SearchResult result = new SearchResult(0, 50, 100, issues);
            Promise<SearchResult> promiseSearchResult = Promises.promise(result);
            when(jiraClient.getSearchClient()).thenReturn(searchRestClient);
            when(jiraRestClientFactory.createWithBasicHttpAuthentication(any(), any(), any())).thenReturn(jiraClient);
            when(searchRestClient.searchJql(any(), any(), any(), any())).thenReturn(promiseSearchResult);
            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) JiraRestClientFactory(com.atlassian.jira.rest.client.api.JiraRestClientFactory) SearchRestClient(com.atlassian.jira.rest.client.api.SearchRestClient) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) SearchResult(com.atlassian.jira.rest.client.api.domain.SearchResult) Bean(org.springframework.context.annotation.Bean)

Example 3 with SearchRestClient

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

the class JiraConnector method issueAlreadyExists.

/**
 * Check if issue already exists, and if so, returns an updated IssueBean
 * @param issueBean		a JiraBean instance
 *
 * @return
 */
@Override
public IssueBean issueAlreadyExists(IssueBean issueBean) {
    if (!(issueBean instanceof JiraBean)) {
        throw new ClassCastException("JiraConnector needs JiraBean instances");
    }
    JiraBean jiraBean = (JiraBean) issueBean;
    String jql = String.format("project=%s and summary ~ \"%s\" and status in (\"%s\")", projectKey, jiraBean.getSummary().replace("[", "\\\\[").replace("]", "\\\\]"), StringUtils.join(openStates, "\",\""));
    SearchRestClient searchClient = restClient.getSearchClient();
    List<Issue> issues = ImmutableList.copyOf(searchClient.searchJql(jql).claim().getIssues());
    if (!issues.isEmpty()) {
        Issue issue = issues.get(0);
        JiraBean updatedJiraBean = new JiraBean(issue.getKey(), jiraBean.getSummary(), issue.getDescription(), jiraBean.getPriority(), jiraBean.getIssueType(), jiraBean.getTestName(), jiraBean.getTestStep(), jiraBean.getAssignee(), jiraBean.getReporter(), jiraBean.getScreenShots(), jiraBean.getDetailedResult(), jiraBean.getCustomFields(), jiraBean.getComponents());
        updatedJiraBean.setDate(issue.getCreationDate().toString("yyyy-MM-dd'T'HH:mmZZ"));
        updatedJiraBean.setAccessUrl(browseUrl + issue.getKey());
        return updatedJiraBean;
    } else {
        return null;
    }
}
Also used : Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) SearchRestClient(com.atlassian.jira.rest.client.api.SearchRestClient)

Example 4 with SearchRestClient

use of com.atlassian.jira.rest.client.api.SearchRestClient in project domui by fjalvingh.

the class JiraReporter method updateIssueByHash.

private boolean updateIssueByHash(JiraRestClient client, BugItem item, String hash) {
    String hashField = getHashCodeFieldname();
    if (null == hashField)
        return false;
    // see https://community.atlassian.com/t5/Jira-questions/Jira-Text-Search-in-Custom-Fields/qaq-p/26757
    SearchRestClient searchClient = client.getSearchClient();
    StringBuilder sb = new StringBuilder();
    sb.append("project=\"").append(getProjectKey(item)).append("\"");
    sb.append(" and ").append("cf[").append(hashField).append("]").append("~\"").append(hash).append("\"");
    SearchResult result = searchClient.searchJql(sb.toString()).claim();
    int total = result.getTotal();
    if (0 == total) {
        System.err.println("jira: no result for hash=" + hash);
        return false;
    }
    for (Issue issue : result.getIssues()) {
        String key = issue.getKey();
        System.err.println("jira: key=" + key);
        Comment comment = Comment.valueOf(calculateDescription(item));
        client.getIssueClient().addComment(issue.getCommentsUri(), comment).claim();
        System.err.println("jira: issue " + key + " updated");
        return true;
    }
    return false;
}
Also used : Comment(com.atlassian.jira.rest.client.api.domain.Comment) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) Issue(com.atlassian.jira.rest.client.api.domain.Issue) SearchRestClient(com.atlassian.jira.rest.client.api.SearchRestClient) SearchResult(com.atlassian.jira.rest.client.api.domain.SearchResult)

Example 5 with SearchRestClient

use of com.atlassian.jira.rest.client.api.SearchRestClient in project camel-spring-boot by apache.

the class WatchUpdatesConsumerTest 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);
            searchRestClient = mock(SearchRestClient.class);
            SearchResult result = new SearchResult(0, 50, 100, issues);
            Promise<SearchResult> promiseSearchResult = Promises.promise(result);
            when(jiraClient.getSearchClient()).thenReturn(searchRestClient);
            when(jiraRestClientFactory.createWithBasicHttpAuthentication(any(), any(), any())).thenReturn(jiraClient);
            when(searchRestClient.searchJql(any(), any(), any(), any())).thenReturn(promiseSearchResult);
            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) JiraRestClientFactory(com.atlassian.jira.rest.client.api.JiraRestClientFactory) SearchRestClient(com.atlassian.jira.rest.client.api.SearchRestClient) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) SearchResult(com.atlassian.jira.rest.client.api.domain.SearchResult) Bean(org.springframework.context.annotation.Bean)

Aggregations

SearchRestClient (com.atlassian.jira.rest.client.api.SearchRestClient)5 SearchResult (com.atlassian.jira.rest.client.api.domain.SearchResult)4 IssueRestClient (com.atlassian.jira.rest.client.api.IssueRestClient)3 JiraRestClient (com.atlassian.jira.rest.client.api.JiraRestClient)3 JiraRestClientFactory (com.atlassian.jira.rest.client.api.JiraRestClientFactory)3 Issue (com.atlassian.jira.rest.client.api.domain.Issue)3 CamelContext (org.apache.camel.CamelContext)3 CamelContextConfiguration (org.apache.camel.spring.boot.CamelContextConfiguration)3 Bean (org.springframework.context.annotation.Bean)3 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)2 Comment (com.atlassian.jira.rest.client.api.domain.Comment)1 Utils.createIssue (org.apache.camel.component.jira.springboot.test.Utils.createIssue)1