Search in sources :

Example 1 with User

use of com.atlassian.jira.rest.client.api.domain.User 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());
}
Also used : Arrays(java.util.Arrays) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) Priority(com.atlassian.jira.rest.client.api.domain.Priority) Issue(com.atlassian.jira.rest.client.api.domain.Issue) URISyntaxException(java.net.URISyntaxException) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) HashMap(java.util.HashMap) Snapshot(com.seleniumtests.reporter.logger.Snapshot) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) SeleniumTestsContextManager(com.seleniumtests.core.SeleniumTestsContextManager) Logger(org.apache.log4j.Logger) BugTracker(com.seleniumtests.connectors.bugtracker.BugTracker) WaitHelper(com.seleniumtests.util.helper.WaitHelper) ImmutableList(com.google.common.collect.ImmutableList) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Map(java.util.Map) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) Project(com.atlassian.jira.rest.client.api.domain.Project) URI(java.net.URI) ScenarioException(com.seleniumtests.customexception.ScenarioException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) Transition(com.atlassian.jira.rest.client.api.domain.Transition) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) CustomFieldOption(com.atlassian.jira.rest.client.api.domain.CustomFieldOption) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder) TransitionInput(com.atlassian.jira.rest.client.api.domain.input.TransitionInput) Field(com.atlassian.jira.rest.client.api.domain.Field) Collectors(java.util.stream.Collectors) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File) SearchRestClient(com.atlassian.jira.rest.client.api.SearchRestClient) List(java.util.List) User(com.atlassian.jira.rest.client.api.domain.User) Version(com.atlassian.jira.rest.client.api.domain.Version) BasicProject(com.atlassian.jira.rest.client.api.domain.BasicProject) TestStep(com.seleniumtests.reporter.logger.TestStep) Entry(java.util.Map.Entry) Comment(com.atlassian.jira.rest.client.api.domain.Comment) BasicComponent(com.atlassian.jira.rest.client.api.domain.BasicComponent) AsynchronousJiraRestClientFactory(com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory) IssueBean(com.seleniumtests.connectors.bugtracker.IssueBean) BasicPriority(com.atlassian.jira.rest.client.api.domain.BasicPriority) User(com.atlassian.jira.rest.client.api.domain.User) Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) 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) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) BasicComponent(com.atlassian.jira.rest.client.api.domain.BasicComponent) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder)

Example 2 with User

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

the class TestJiraConnector method initJira.

@BeforeMethod(groups = { "ut" })
public void initJira() throws Exception {
    Map<String, URI> avatars = new HashMap<>();
    avatars.put("48x48", new URI("http://foo/bar/a"));
    user = new User(new URI("http://foo/bar/u"), "user1", "user 1", "1", "user1@company.com", true, null, avatars, "UTC");
    // create test steps
    File tmpImg = File.createTempFile("img", "123456.png");
    tmpImg.deleteOnExit();
    File tmpHtml = File.createTempFile("html", "123456.html");
    tmpHtml.deleteOnExit();
    screenshot = new ScreenShot();
    screenshot.setImagePath("screenshot/" + tmpImg.getName());
    screenshot.setHtmlSourcePath("htmls/" + tmpHtml.getName());
    FileUtils.copyFile(tmpImg, new File(screenshot.getFullImagePath()));
    FileUtils.copyFile(tmpHtml, new File(screenshot.getFullHtmlPath()));
    step1 = new TestStep("step 1", null, new ArrayList<>(), false);
    step1.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
    step1.setPosition(0);
    step2 = new TestStep("step 2", null, new ArrayList<>(), false);
    step2.setFailed(true);
    step2.setActionException(new NullPointerException("Error clicking"));
    step2.addAction(new TestAction("action1", false, new ArrayList<>()));
    step2.addAction(new TestAction("action2", false, new ArrayList<>()));
    step2.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
    step2.setPosition(1);
    stepWithErrorCauseAndDetails = new TestStep("step 3", null, new ArrayList<>(), false, RootCause.REGRESSION, "Check  your script", false);
    stepWithErrorCauseAndDetails.setFailed(true);
    stepWithErrorCauseAndDetails.setActionException(new NullPointerException("Error clicking"));
    stepWithErrorCauseAndDetails.addAction(new TestAction("action1", false, new ArrayList<>()));
    stepWithErrorCauseAndDetails.addAction(new TestAction("action2", false, new ArrayList<>()));
    stepWithErrorCauseAndDetails.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
    stepWithErrorCauseAndDetails.setPosition(1);
    stepWithErrorCause = new TestStep("step 4", null, new ArrayList<>(), false, RootCause.REGRESSION, "", false);
    stepWithErrorCause.setFailed(true);
    stepWithErrorCause.setActionException(new NullPointerException("Error clicking"));
    stepWithErrorCause.addAction(new TestAction("action1", false, new ArrayList<>()));
    stepWithErrorCause.addAction(new TestAction("action2", false, new ArrayList<>()));
    stepWithErrorCause.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
    stepWithErrorCause.setPosition(1);
    stepEnd = new TestStep("Test end", null, new ArrayList<>(), false);
    stepEnd.addSnapshot(new Snapshot(screenshot, "end", SnapshotCheckType.FULL), 1, null);
    stepEnd.addSnapshot(new Snapshot(screenshot, "end2", SnapshotCheckType.FULL), 1, null);
    stepEnd.setPosition(2);
    // mock all clients
    PowerMockito.whenNew(AsynchronousJiraRestClientFactory.class).withNoArguments().thenReturn(restClientFactory);
    when(restClientFactory.createWithBasicHttpAuthentication(any(URI.class), eq("user"), eq("password"))).thenReturn(restClient);
    when(restClient.getProjectClient()).thenReturn(projectRestClient);
    when(projectRestClient.getProject(anyString())).thenReturn(promiseProject);
    when(promiseProject.claim()).thenReturn(project);
    when(project.getComponents()).thenReturn(Arrays.asList(component1, component2));
    when(project.getIssueTypes()).thenReturn(new OptionalIterable(Arrays.asList(issueType1, issueType2)));
    when(project.getVersions()).thenReturn(Arrays.asList(version1, version2));
    when(project.getKey()).thenReturn(PROJECT_KEY);
    when(projectRestClient.getAllProjects()).thenReturn(promiseAllProjects);
    when(promiseAllProjects.claim()).thenReturn(Arrays.asList(project1, project2));
    when(restClient.getMetadataClient()).thenReturn(metadataRestClient);
    when(metadataRestClient.getPriorities()).thenReturn(promisePriorities);
    when(promisePriorities.claim()).thenReturn(Arrays.asList(priority1, priority2));
    when(metadataRestClient.getFields()).thenReturn(promiseFields);
    when(promiseFields.claim()).thenReturn(Arrays.asList(fieldApplication, fieldEnvironment, fieldStep));
    when(restClient.getSearchClient()).thenReturn(searchRestClient);
    when(searchRestClient.searchJql(anyString())).thenReturn(promiseSearch);
    when(restClient.getUserClient()).thenReturn(userRestClient);
    doThrow(RestClientException.class).when(userRestClient).findUsers(anyString());
    doReturn(promiseUsers).when(userRestClient).findUsers("me");
    when(promiseUsers.claim()).thenReturn(Arrays.asList(user));
    when(restClient.getIssueClient()).thenReturn(issueRestClient);
    when(issueRestClient.createIssue(any(IssueInput.class))).thenReturn(promiseBasicIssue);
    when(promiseBasicIssue.claim()).thenReturn(new BasicIssue(new URI("http://foo/bar/i"), "ISSUE-1", 1L));
    when(issueRestClient.getIssue(anyString())).thenReturn(promiseIssueEmpty);
    when(issueRestClient.getIssue("ISSUE-1")).thenReturn(promiseIssue);
    when(promiseIssue.claim()).thenReturn(issue1);
    when(promiseIssueEmpty.claim()).thenThrow(RestClientException.class);
    when(issueRestClient.getCreateIssueMetaFields(anyString(), anyString(), any(), any())).thenReturn(promiseFieldInfo);
    when(promiseFieldInfo.claim()).thenReturn(fieldInfos);
    when(fieldInfos.getValues()).thenReturn(Arrays.asList(fieldInfo1, fieldInfo2, fieldInfo3));
    when(issueRestClient.getTransitions(issue1)).thenReturn(promiseTransitions);
    when(promiseTransitions.claim()).thenReturn(Arrays.asList(transition1, transition2));
    when(issueRestClient.addAttachments(any(), any(File.class))).thenReturn(promiseVoid);
    when(issue1.getKey()).thenReturn("ISSUE-1");
    when(issue1.getDescription()).thenReturn("jira issue 1");
    when(issue1.getAttachmentsUri()).thenReturn(new URI("http://foo/bar/i/1/attachments"));
    when(issue1.getCommentsUri()).thenReturn(new URI("http://foo/bar/i/1/comments"));
    when(issue2.getKey()).thenReturn("ISSUE-2");
    when(issue2.getDescription()).thenReturn("jira issue 2");
    when(issue2.getAttachmentsUri()).thenReturn(new URI("http://foo/bar/i/2/attachments"));
    when(issue2.getCommentsUri()).thenReturn(new URI("http://foo/bar/i/2/comments"));
    detailedResult = File.createTempFile("detailed", ".zip");
    detailedResult.deleteOnExit();
    jiraOptions.put("jira.openStates", "Open,To Do");
    jiraOptions.put("jira.closeTransition", "close");
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) OptionalIterable(com.atlassian.jira.rest.client.api.OptionalIterable) User(com.atlassian.jira.rest.client.api.domain.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) URI(java.net.URI) TestAction(com.seleniumtests.reporter.logger.TestAction) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) File(java.io.File) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with User

use of com.atlassian.jira.rest.client.api.domain.User 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)

Aggregations

User (com.atlassian.jira.rest.client.api.domain.User)3 URI (java.net.URI)3 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)2 Issue (com.atlassian.jira.rest.client.api.domain.Issue)2 IssueType (com.atlassian.jira.rest.client.api.domain.IssueType)2 Transition (com.atlassian.jira.rest.client.api.domain.Transition)2 IssueInput (com.atlassian.jira.rest.client.api.domain.input.IssueInput)2 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)2 Snapshot (com.seleniumtests.reporter.logger.Snapshot)2 TestStep (com.seleniumtests.reporter.logger.TestStep)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IssueRestClient (com.atlassian.jira.rest.client.api.IssueRestClient)1 JiraRestClient (com.atlassian.jira.rest.client.api.JiraRestClient)1 OptionalIterable (com.atlassian.jira.rest.client.api.OptionalIterable)1 RestClientException (com.atlassian.jira.rest.client.api.RestClientException)1 SearchRestClient (com.atlassian.jira.rest.client.api.SearchRestClient)1 BasicComponent (com.atlassian.jira.rest.client.api.domain.BasicComponent)1 BasicPriority (com.atlassian.jira.rest.client.api.domain.BasicPriority)1