Package com.atlassian.jira.rest.client

Examples of com.atlassian.jira.rest.client.IssueRestClient


    assertEquals(2, issue.getVotes().getVotes());
  }

  @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


    Assert.assertThat(issueClient.getWatchers(issue1.getWatchers().getSelf(), pm).getUsers(), hasItem(USER1));
  }

  @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

    Assert.assertThat(client.getIssueClient().getWatchers(issue.getWatchers().getSelf(), pm).getUsers(), hasItem(USER1));
  }

  @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
View Full Code Here

    return client.getMetadataClient().getServerInfo(pm).getBuildNumber() >= BN_JIRA_4_3;
  }

  @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

  @Test
  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();
      }
    });
    assertThat(attachmentsNames, containsInAnyOrder(filename1, filename2));
    final Attachment pictureAttachment = Iterables.find(attachments, new Predicate<Attachment>() {
      @Override
      public boolean apply(@Nullable Attachment input) {
        return filename2.equals(input.getFilename());
      }
    });

    // let's download it now and compare it's binary content

    assertTrue(
        IOUtils.contentEquals(JerseyIssueRestClientTest.class.getResourceAsStream("/attachment-test/transparent-png.png"),
            issueClient.getAttachment(pm, pictureAttachment.getContentUri())));
  }
View Full Code Here

  @Test
  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());
      matcher.find();
      final String interfix = matcher.group(1);
      assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(("content-of-the-file-" + interfix).getBytes("UTF-8")),
          issueClient.getAttachment(pm, attachment.getContentUri())));

    }
  }
View Full Code Here

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

    final File tempFile = File.createTempFile("jim-integration-test", ".txt");
    tempFile.deleteOnExit();
    FileWriter writer = new FileWriter(tempFile);
    writer.write("This is the content of my file which I am going to upload to JIRA for testing.");
    writer.close();
    issueClient.addAttachments(pm, issue.getAttachmentsUri(), tempFile);

    final Issue issueWithAttachments = issueClient.getIssue("TST-5", pm);
    final Iterable<Attachment> attachments = issueWithAttachments.getAttachments();
    assertEquals(1, Iterables.size(attachments));
    assertTrue(IOUtils.contentEquals(new FileInputStream(tempFile),
        issueClient.getAttachment(pm, attachments.iterator().next().getContentUri())));
  }
View Full Code Here

   
    // set estimate in issue
    navigation.issue().setEstimates(ISSUE_KEY, "20", "20");
   
    final WorklogInputBuilder worklogInputBuilder = createDefaulWorklogInputBuilder();
    final IssueRestClient issueClient = client.getIssueClient();

    // get issue
    final Issue initialIssue = issueClient.getIssue(issueKey, pm);

    // # First change - test auto
    final WorklogInput worklogInput = worklogInputBuilder
        .setIssueUri(initialIssue.getSelf())
        .setMinutesSpent(2)
        .build();
    issueClient.addWorklog(initialIssue.getWorklogUri(), worklogInput, pm);

    // check if estimate has changed
    final Issue issueAfterFirstChange = issueClient.getIssue(issueKey, pm);
    final Integer actualTimeSpentAfterChange = getTimeSpentMinutesNotNull(issueAfterFirstChange.getTimeTracking());
    final Integer expectedTimeSpentAfterChange = getTimeSpentMinutesNotNull(initialIssue.getTimeTracking()) + worklogInput.getMinutesSpent();
    assertEquals(expectedTimeSpentAfterChange, actualTimeSpentAfterChange);

    final int actualRemainingEstimate = getRemainingEstimateMinutesNotNull(issueAfterFirstChange.getTimeTracking());
    final int expectedRemaningEstimate = getRemainingEstimateMinutesNotNull(initialIssue.getTimeTracking()) - worklogInput.getMinutesSpent();
    assertEquals(expectedRemaningEstimate, actualRemainingEstimate);

    // # Second change - test new; also we want to be sure that logged time are added, and not set to given value
    final Integer newEstimateValue = 15;
    final WorklogInput worklogInput2 = worklogInputBuilder
        .setIssueUri(initialIssue.getSelf())
        .setMinutesSpent(2)
        .setAdjustEstimateNew(newEstimateValue)
        .build();
    issueClient.addWorklog(initialIssue.getWorklogUri(), worklogInput2, pm);

    // check if logged time has changed
    final Issue issueAfterSecondChange = issueClient.getIssue(issueKey, pm);
    final Integer actualTimeSpentAfterChange2 = getTimeSpentMinutesNotNull(issueAfterSecondChange.getTimeTracking());
    final Integer expectedTimeSpentAfterChange2 = getTimeSpentMinutesNotNull(issueAfterFirstChange.getTimeTracking()) + worklogInput2.getMinutesSpent();
    assertEquals(expectedTimeSpentAfterChange2, actualTimeSpentAfterChange2);

    // check if estimate has changed
    final Integer actualRemainingEstimate2 = getRemainingEstimateMinutesNotNull(issueAfterSecondChange.getTimeTracking());
    assertEquals(newEstimateValue, actualRemainingEstimate2);

    // # Third change - test leave
    final WorklogInput worklogInput3 = worklogInputBuilder
        .setIssueUri(initialIssue.getSelf())
        .setMinutesSpent(2)
        .setAdjustEstimateLeave()
        .build();
    issueClient.addWorklog(initialIssue.getWorklogUri(), worklogInput3, pm);

    // check if logged time has changed
    final Issue issueAfterThirdChange = issueClient.getIssue(issueKey, pm);
    final Integer actualTimeSpentAfterChange3 = getTimeSpentMinutesNotNull(issueAfterThirdChange.getTimeTracking());
    final Integer expectedTimeSpentAfterChange3 = getTimeSpentMinutesNotNull(issueAfterSecondChange.getTimeTracking()) + worklogInput3.getMinutesSpent();
    assertEquals(expectedTimeSpentAfterChange3, actualTimeSpentAfterChange3);

    // check if estimate has NOT changed
    final Integer actualRemainingEstimate3 = getRemainingEstimateMinutesNotNull(issueAfterThirdChange.getTimeTracking());
    final Integer expectedRemainingEstimate3 = getRemainingEstimateMinutesNotNull(issueAfterSecondChange.getTimeTracking());
    assertEquals(expectedRemainingEstimate3, actualRemainingEstimate3);

    // # Fourth change - test manual
    final int reduceByValueManual = 7;
    final WorklogInput worklogInput4 = worklogInputBuilder
        .setIssueUri(initialIssue.getSelf())
        .setMinutesSpent(2)
        .setAdjustEstimateManual(reduceByValueManual)
        .build();

    issueClient.addWorklog(initialIssue.getWorklogUri(), worklogInput4, pm);

    // check if logged time has changed
    final Issue issueAfterFourthChange = issueClient.getIssue(issueKey, pm);
    final Integer actualTimeSpentAfterChange4 = getTimeSpentMinutesNotNull(issueAfterFourthChange.getTimeTracking());
    final Integer expectedTimeSpentAfterChange4 = getTimeSpentMinutesNotNull(issueAfterThirdChange.getTimeTracking()) + worklogInput4.getMinutesSpent();
    assertEquals(expectedTimeSpentAfterChange4, actualTimeSpentAfterChange4);

    // check if estimate has NOT changed
View Full Code Here

TOP

Related Classes of com.atlassian.jira.rest.client.IssueRestClient

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.