Package com.atlassian.jira.rest.client.api

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


        .getUsers(), hasItem(IntegrationTestUtil.USER1));
  }

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

    setUser1();
    assertTrue(client.getIssueClient().getIssue("TST-1").claim().getWatchers().isWatching());
View Full Code Here


    return client.getMetadataClient().getServerInfo().claim().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).claim();
    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).claim();
          }
        });
  }
View Full Code Here

  }


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

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

    final Issue linkedIssue = issueClient.getIssue("TST-7").claim();
    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(IntegrationTestUtil.USER_ADMIN, comment.getAuthor());
      assertEquals(commentInput.getVisibility(), comment.getVisibility());
    } else {
      assertFalse(linkedIssue.getComments().iterator().hasNext());
    }


    final Issue targetIssue = issueClient.getIssue("TST-6").claim();
    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").claim();
    assertFalse(issue.getAttachments().iterator().hasNext());

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

    final Issue issueWithAttachments = issueClient.getIssue("TST-3").claim();
    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(AsynchronousIssueRestClientTest.class
            .getResourceAsStream("/attachment-test/transparent-png.png"),
            issueClient.getAttachment(pictureAttachment.getContentUri()).claim()));
  }
View Full Code Here

  // TODO: implement
  public void testAddAttachments() throws IOException {
    if (!doesJiraSupportAddingAttachment()) {
      return;
    }
    final IssueRestClient issueClient = client.getIssueClient();
    final Issue issue = issueClient.getIssue("TST-4").claim();
    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(issue.getAttachmentsUri(), attachmentInputs).claim();

    final Issue issueWithAttachments = issueClient.getIssue("TST-4").claim();
    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(attachment.getContentUri()).claim()));

    }
  }
View Full Code Here

  // TODO: implement
  public void testAddFileAttachments() throws IOException {
    if (!doesJiraSupportAddingAttachment()) {
      return;
    }
    final IssueRestClient issueClient = client.getIssueClient();
    final Issue issue = issueClient.getIssue("TST-5").claim();
    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(issue.getAttachmentsUri(), tempFile).claim();

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

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

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

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

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

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

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

    final AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
    final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "admin", "admin");

    try {
      final List<Promise<BasicIssue>> promises = Lists.newArrayList();
      final IssueRestClient issueClient = restClient.getIssueClient();

      System.out.println("Sending issue creation requests...");
      for (int i = 0; i < 100; i++) {
        final String summary = "NewIssue#" + i;
        final IssueInput newIssue = new IssueInputBuilder("TST", 1L, summary).build();
        System.out.println("\tCreating: " + summary);
        promises.add(issueClient.createIssue(newIssue));
      }

      System.out.println("Collecting responses...");
      final Iterable<BasicIssue> createdIssues = transform(promises, new Function<Promise<BasicIssue>, BasicIssue>() {
        @Override
View Full Code Here

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

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

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

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

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

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

        .getUsers(), hasItem(IntegrationTestUtil.USER1));
  }

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

    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).claim();
      }
    });
  }
View Full Code Here

TOP

Related Classes of com.atlassian.jira.rest.client.api.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.