Package com.atlassian.jira.rest.client.domain

Examples of com.atlassian.jira.rest.client.domain.Issue


      }
    });
  }

  private void testTransitionImpl(Comment comment) {
    final Issue issue = client.getIssueClient().getIssue("TST-1", pm);
    final Iterable<Transition> transitions = client.getIssueClient().getTransitions(issue, pm);
    Transition transitionFound = TestUtil.getTransitionByName(transitions, "Estimate");
    DateTime now = new DateTime();
    client.getIssueClient().transition(issue, new TransitionInput(transitionFound.getId(), comment), pm);

    final Issue changedIssue = client.getIssueClient().getIssue("TST-1", pm);
    final Comment lastComment = Iterables.getLast(changedIssue.getComments());
    assertEquals(comment.getBody(), lastComment.getBody());
    assertEquals(USER_ADMIN, lastComment.getAuthor());
    assertEquals(USER_ADMIN, lastComment.getUpdateAuthor());
    assertEquals(lastComment.getCreationDate(), lastComment.getUpdateDate());
    assertTrue(lastComment.getCreationDate().isAfter(now) || lastComment.getCreationDate().isEqual(now));
View Full Code Here


    assertEquals(comment.getVisibility(), lastComment.getVisibility());
  }

  @Test
  public void testVoteUnvote() {
    final Issue issue1 = client.getIssueClient().getIssue("TST-1", pm);
    assertFalse(issue1.getVotes().hasVoted());
    assertEquals(1, issue1.getVotes().getVotes()); // the other user has voted
    final String expectedMessage = isJira5xOrNewer() // JIRA 5.0 comes without Polish translation OOB
        ? "You cannot vote for an issue you have reported."
        : "Nie mo\u017cesz g\u0142osowa\u0107 na zadanie kt\u00f3re utworzy\u0142e\u015b.";

    // I hope that such Polish special characters (for better testing local specific behaviour of REST
    assertErrorCode(Response.Status.NOT_FOUND, expectedMessage, new Runnable() {
      @Override
      public void run() {
        client.getIssueClient().vote(issue1.getVotesUri(), pm);
      }
    });


    final String issueKey = "TST-7";
    Issue issue = client.getIssueClient().getIssue(issueKey, pm);
    assertFalse(issue.getVotes().hasVoted());
    assertEquals(0, issue.getVotes().getVotes());

    client.getIssueClient().vote(issue.getVotesUri(), pm);
    issue = client.getIssueClient().getIssue(issueKey, pm);
    assertTrue(issue.getVotes().hasVoted());
    assertEquals(1, issue.getVotes().getVotes());

    client.getIssueClient().unvote(issue.getVotesUri(), pm);
    issue = client.getIssueClient().getIssue(issueKey, pm);
    assertFalse(issue.getVotes().hasVoted());
    assertEquals(0, issue.getVotes().getVotes());

    setUser2();
    issue = client.getIssueClient().getIssue(issueKey, pm);
    assertFalse(issue.getVotes().hasVoted());
    assertEquals(0, issue.getVotes().getVotes());
    final Issue finalIssue = issue;
    assertErrorCode(Response.Status.NOT_FOUND, "Cannot remove a vote for an issue that the user has not already voted for.",
        new Runnable() {
      @Override
      public void run() {
        client.getIssueClient().unvote(finalIssue.getVotesUri(), pm);
      }
    });


    issue = client.getIssueClient().getIssue(issueKey, pm);
View Full Code Here

  }

  @Test
  public void testWatchUnwatch() {
    final IssueRestClient issueClient = client.getIssueClient();
    final Issue issue1 = issueClient.getIssue("TST-1", pm);

    Assert.assertThat(issueClient.getWatchers(issue1.getWatchers().getSelf(), pm).getUsers(), not(hasItem(USER_ADMIN)));

    issueClient.watch(issue1.getWatchers().getSelf(), pm);
    Assert.assertThat(issueClient.getWatchers(issue1.getWatchers().getSelf(), pm).getUsers(), hasItem(USER_ADMIN));

    issueClient.unwatch(issue1.getWatchers().getSelf(), pm);
    Assert.assertThat(issueClient.getWatchers(issue1.getWatchers().getSelf(), pm).getUsers(), not(hasItem(USER_ADMIN)));

    Assert.assertThat(issueClient.getWatchers(issue1.getWatchers().getSelf(), pm).getUsers(), hasItem(USER1));
    issueClient.removeWatcher(issue1.getWatchers().getSelf(), USER1.getName(), pm);
    Assert.assertThat(issueClient.getWatchers(issue1.getWatchers().getSelf(), pm).getUsers(), not(hasItem(USER1)));
    issueClient.addWatcher(issue1.getWatchers().getSelf(), USER1.getName(), pm);
    Assert.assertThat(issueClient.getWatchers(issue1.getWatchers().getSelf(), pm).getUsers(), hasItem(USER1));
  }
View Full Code Here

  }

  @Test
  public void testRemoveWatcherUnauthorized() {
    final IssueRestClient issueClient = client.getIssueClient();
    final Issue issue1 = issueClient.getIssue("TST-1", pm);
    issueClient.watch(issue1.getWatchers().getSelf(), pm);

    setUser1();
    final IssueRestClient issueClient2 = client.getIssueClient();
    assertErrorCode(Response.Status.UNAUTHORIZED,
        "User 'wseliga' is not allowed to remove watchers from issue 'TST-1'", new Runnable() {
      @Override
      public void run() {
        issueClient2.removeWatcher(issue1.getWatchers().getSelf(), ADMIN_USERNAME, pm);
      }
    });
  }
View Full Code Here

  @Test
  public void testWatchAlreadyWatched() {
    setUser1();
    final IssueRestClient issueClient = client.getIssueClient();
    final Issue issue = issueClient.getIssue("TST-1", pm);
    Assert.assertThat(client.getIssueClient().getWatchers(issue.getWatchers().getSelf(), pm).getUsers(), hasItem(USER1));
    // JIRA allows to watch already watched issue by you - such action effectively has no effect
    issueClient.watch(issue.getWatchers().getSelf(), pm);
    Assert.assertThat(client.getIssueClient().getWatchers(issue.getWatchers().getSelf(), pm).getUsers(), hasItem(USER1));
  }
View Full Code Here

  }

  @Test
  public void testAddWatcherUnauthorized() {
    final IssueRestClient issueClient = client.getIssueClient();
    final Issue issue1 = issueClient.getIssue("TST-1", pm);
    issueClient.addWatcher(issue1.getWatchers().getSelf(), USER1_USERNAME, pm);
    assertThat(client.getIssueClient().getWatchers(issue1.getWatchers().getSelf(), pm).getUsers(), hasItem(USER1));

    setUser1();
    assertTrue(client.getIssueClient().getIssue("TST-1", pm).getWatchers().isWatching());
    String expectedErrorMsg = isJraDev3516Fixed() ? ("User '" + USER1_USERNAME
        + "' is not allowed to add watchers to issue 'TST-1'") : null;
    assertErrorCode(Response.Status.UNAUTHORIZED, expectedErrorMsg, new Runnable() {
      @Override
      public void run() {
        client.getIssueClient().addWatcher(issue1.getWatchers().getSelf(), ADMIN_USERNAME, pm);
      }
    });
  }
View Full Code Here

  @Test
  public void testAddWatcherWhoDoesNotHaveViewIssuePermissions() {
    final IssueRestClient issueClient = client.getIssueClient();
    final String issueKey = "RST-1";
    final Issue issue1 = issueClient.getIssue(issueKey, pm);
    final String expectedErrorMessage;

    if (isJira5xOrNewer()) {
      expectedErrorMessage = "The user \"" + USER2_USERNAME +"\" does not have permission to view this issue."
          + " This user will not be added to the watch list.";
    }
    else if (isJira4x3OrNewer()) {
        expectedErrorMessage = "User '" + ADMIN_USERNAME + "' is not allowed to add watchers to issue '" + issueKey + "'";
    }
    else {
        expectedErrorMessage = "com.sun.jersey.api.client.UniformInterfaceException: Client response status: 401";
    }

    assertErrorCode(Response.Status.UNAUTHORIZED, expectedErrorMessage,
        new Runnable() {
          @Override
          public void run() {
            issueClient.addWatcher(issue1.getWatchers().getSelf(), USER2_USERNAME, pm);
          }
        });
  }
View Full Code Here

  }


  private void testLinkIssuesImpl(@Nullable Comment commentInput) {
    final IssueRestClient issueClient = client.getIssueClient();
    final Issue originalIssue = issueClient.getIssue("TST-7", pm);
    int origNumComments = Iterables.size(originalIssue.getComments());
    assertFalse(originalIssue.getIssueLinks().iterator().hasNext());

    issueClient.linkIssue(new LinkIssuesInput("TST-7", "TST-6", "Duplicate", commentInput), pm);

    final Issue linkedIssue = issueClient.getIssue("TST-7", pm);
    assertEquals(1, Iterables.size(linkedIssue.getIssueLinks()));
    final IssueLink addedLink = linkedIssue.getIssueLinks().iterator().next();
    assertEquals("Duplicate", addedLink.getIssueLinkType().getName());
    assertEquals("TST-6", addedLink.getTargetIssueKey());
    assertEquals(IssueLinkType.Direction.OUTBOUND, addedLink.getIssueLinkType().getDirection());

    final int expectedNumComments = commentInput != null ? origNumComments + 1 : origNumComments;
    assertEquals(expectedNumComments, Iterables.size(linkedIssue.getComments()));
    if (commentInput != null) {
      final Comment comment = linkedIssue.getComments().iterator().next();
      assertEquals(commentInput.getBody(), comment.getBody());
      assertEquals(USER_ADMIN, comment.getAuthor());
      assertEquals(commentInput.getVisibility(), comment.getVisibility());
    } else {
      assertFalse(linkedIssue.getComments().iterator().hasNext());
    }


    final Issue targetIssue = issueClient.getIssue("TST-6", pm);
    final IssueLink targetLink = targetIssue.getIssueLinks().iterator().next();
    assertEquals(IssueLinkType.Direction.INBOUND, targetLink.getIssueLinkType().getDirection());
    assertEquals("Duplicate", targetLink.getIssueLinkType().getName());
  }
View Full Code Here

  public void testAddAttachment() throws IOException {
    if (!doesJiraSupportAddingAttachment()) {
      return;
    }
    final IssueRestClient issueClient = client.getIssueClient();
    final Issue issue = issueClient.getIssue("TST-3", pm);
    assertFalse(issue.getAttachments().iterator().hasNext());

    String str = "Wojtek";
    final String filename1 = "my-test-file";
    issueClient.addAttachment(pm, issue.getAttachmentsUri(), new ByteArrayInputStream(str.getBytes("UTF-8")), filename1);
    final String filename2 = "my-picture.png";
    issueClient.addAttachment(pm, issue.getAttachmentsUri(), JerseyIssueRestClientTest.class.getResourceAsStream("/attachment-test/transparent-png.png"), filename2);

    final Issue issueWithAttachments = issueClient.getIssue("TST-3", pm);
    final Iterable<Attachment> attachments = issueWithAttachments.getAttachments();
    assertEquals(2, Iterables.size(attachments));
    final Iterable<String> attachmentsNames = Iterables.transform(attachments, new Function<Attachment, String>() {
      @Override
      public String apply(@Nullable Attachment from) {
        return from.getFilename();
View Full Code Here

  public void testAddAttachments() throws IOException {
    if (!doesJiraSupportAddingAttachment()) {
      return;
    }
    final IssueRestClient issueClient = client.getIssueClient();
    final Issue issue = issueClient.getIssue("TST-4", pm);
    assertFalse(issue.getAttachments().iterator().hasNext());

    final AttachmentInput[] attachmentInputs = new AttachmentInput[3];
    for (int i = 1; i <= 3; i++) {
      attachmentInputs[i - 1] = new AttachmentInput("my-test-file-" + i + ".txt", new ByteArrayInputStream(("content-of-the-file-" + i).getBytes("UTF-8")));
    }
    issueClient.addAttachments(pm, issue.getAttachmentsUri(), attachmentInputs);

    final Issue issueWithAttachments = issueClient.getIssue("TST-4", pm);
    final Iterable<Attachment> attachments = issueWithAttachments.getAttachments();
    assertEquals(3, Iterables.size(attachments));
    Pattern pattern = Pattern.compile("my-test-file-(\\d)\\.txt");
    for (Attachment attachment : attachments) {
      assertTrue(pattern.matcher(attachment.getFilename()).matches());
      final Matcher matcher = pattern.matcher(attachment.getFilename());
View Full Code Here

TOP

Related Classes of com.atlassian.jira.rest.client.domain.Issue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.