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

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


  @JiraBuildNumberDependent(BN_JIRA_5)
  @Test
  public void testCreateIssueWithoutBrowseProjectPermission() {
    setUser1();
    final IssueRestClient issueClient = client.getIssueClient();

    thrown.expect(RestClientException.class);
    thrown.expectMessage("You do not have permission to create issues in this project.");

    // TODO: add summary when JIRA bug is fixed (JRADEV-13412)
    final IssueInput issueInput = new IssueInputBuilder("RST", 1L/*, "Issue created by testCreateIssueWithoutBrowseProjectPermission"*/)
        .build();
    issueClient.createIssue(issueInput).claim();
  }
 
View Full Code Here


  }

  @JiraBuildNumberDependent(BN_JIRA_5)
  @Test
  public void interactiveUseCase() throws CannotTransformValueException {
    final IssueRestClient issueClient = client.getIssueClient();

    // get project list with fields expanded
    final Iterable<CimProject> metadataProjects = issueClient.getCreateIssueMetadata(
        new GetCreateIssueMetadataOptionsBuilder().withExpandedIssueTypesFields().build()).claim();
    log.log("Available projects: ");
    for (CimProject p : metadataProjects) {
      log.log(MessageFormat.format("\t* [{0}] {1}", p.getKey(), p.getName()));
    }
    log.log("");
    assertTrue("There is no project to select!", metadataProjects.iterator().hasNext());

    // select project
    final CimProject project = metadataProjects.iterator().next();
    log.log(MessageFormat.format("Selected project: [{0}] {1}\n", project.getKey(), project.getName()));

    // select issue type
    log.log("Available issue types for selected project:");
    for (CimIssueType t : project.getIssueTypes()) {
      log.log(MessageFormat.format("\t* [{0}] {1}", t.getId(), t.getName()));
    }
    log.log("");

    final CimIssueType issueType = project.getIssueTypes().iterator().next();
    log.log(MessageFormat.format("Selected issue type: [{0}] {1}\n", issueType.getId(), issueType.getName()));

    final IssueInputBuilder builder = new IssueInputBuilder(project.getKey(), issueType.getId());

    // fill fields
    log.log("Filling fields:");
    for (Map.Entry<String, CimFieldInfo> entry : issueType.getFields().entrySet()) {
      final CimFieldInfo fieldInfo = entry.getValue();
      final String fieldCustomType = fieldInfo.getSchema().getCustom();
      final String fieldType = fieldInfo.getSchema().getType();
      final String fieldId = fieldInfo.getId();

      if ("project".equals(fieldId) || "issuetype".equals(fieldId)) {
        // this field was already set by IssueInputBuilder constructor - skip it
        continue;
      }

      log.log(MessageFormat.format("\t* [{0}] {1}\n\t\t| schema: {2}\n\t\t| required: {3}", fieldId, fieldInfo
          .getName(), fieldInfo.getSchema(), fieldInfo.isRequired()));

      // choose value for this field
      Object value = null;
      final Iterable<Object> allowedValues = fieldInfo.getAllowedValues();
      if (allowedValues != null) {
        log.log("\t\t| field only accepts those values:");
        for (Object val : allowedValues) {
          log.log("\t\t\t* " + val);
        }
        if (allowedValues.iterator().hasNext()) {
          final boolean expectedArray = "array".equals(fieldType);
          Object singleValue = allowedValues.iterator().next();

          if ("com.atlassian.jira.plugin.system.customfieldtypes:cascadingselect".equals(fieldCustomType)) {
            // select option with children - if any
            final Iterable<Object> optionsWithChildren = Iterables.filter(allowedValues, new Predicate<Object>() {
              @Override
              public boolean apply(Object input) {
                return ((CustomFieldOption) input).getChildren().iterator().hasNext();
              }
            });

            if (optionsWithChildren.iterator().hasNext()) {
              // there is option with children - set it
              final CustomFieldOption option = (CustomFieldOption) optionsWithChildren.iterator().next();
              value = new CustomFieldOption(option.getId(), option.getSelf(), option.getValue(),
                  Collections.<CustomFieldOption>emptyList(), option.getChildren().iterator().next());
            }
            else {
              // no sub-values available, set only top level value
              value = allowedValues.iterator().next();
            }
          }
          else {
            value = expectedArray ? Collections.singletonList(singleValue) : singleValue;
          }
          log.log("\t\t| selecting value: " + value);
        } else {
          log.log("\t\t| there is no allowed value - leaving field blank");
        }
      } else {
        if ("com.atlassian.jirafisheyeplugin:jobcheckbox".equals(fieldCustomType)) {
          value = "false";
        }
        else if ("com.atlassian.jira.plugin.system.customfieldtypes:url".equals(fieldCustomType)) {
          value = "http://www.atlassian.com/";
        }
        else if ("string".equals(fieldType)) {
          value = "This is simple string value for field " + fieldId + " named " + fieldInfo.getName() + ".";
        } else if ("number".equals(fieldType)) {
          value = 124;
        } else if ("user".equals(fieldType)) {
          value = IntegrationTestUtil.USER_ADMIN;
        } else if ("array".equals(fieldType) && "user".equals(fieldInfo.getSchema().getItems())) {
          value = ImmutableList.of(IntegrationTestUtil.USER_ADMIN);
        } else if ("group".equals(fieldType)) {
          // TODO change to group object when implemented
          value = ComplexIssueInputFieldValue.with("name", IntegrationTestUtil.GROUP_JIRA_ADMINISTRATORS);
        } else if ("array".equals(fieldType) && "group".equals(fieldInfo.getSchema().getItems())) {
          // TODO change to group object when implemented
          value = ImmutableList.of(ComplexIssueInputFieldValue.with("name", IntegrationTestUtil.GROUP_JIRA_ADMINISTRATORS));
        } else if ("date".equals(fieldType)) {
          value = JsonParseUtil.formatDate(new DateTime());
        } else if ("datetime".equals(fieldType)) {
          value = JsonParseUtil.formatDateTime(new DateTime());
        } else if ("array".equals(fieldType) && "string".equals(fieldInfo.getSchema().getItems())) {
          value = ImmutableList.of("one", "two", "three");
        } else if ("timetracking".equals(fieldType)) {
          value = new TimeTracking(60, 40, null); // time spent is not allowed
        } else {
          if (fieldInfo.isRequired()) {
            fail("I don't know how to fill that required field, sorry.");
          } else {
            log.log("\t\t| field value is not required, leaving blank");
          }
        }
      }
      if (value == null) {
        log.log("\t\t| value is null, skipping filed");
      } else {
        log.log(MessageFormat.format("\t\t| setting value => {0}", value));
        builder.setFieldValue(fieldId, value);
      }
    }
    log.log("");

    // all required data is provided, let's create issue
    final IssueInput issueInput = builder.build();

    final BasicIssue basicCreatedIssue = issueClient.createIssue(issueInput).claim();
    assertNotNull(basicCreatedIssue);

    final Issue createdIssue = issueClient.getIssue(basicCreatedIssue.getKey()).claim();
    assertNotNull(createdIssue);

    log.log("Created new issue successfully, key: " + basicCreatedIssue.getKey());

    // assert few fields
View Full Code Here

    assertTrue(changedIssue.getField(NUMERIC_CUSTOMFIELD_ID).getValue().equals(expectedValue));
  }

  @Test
  public void testDeleteIssue() {
    final IssueRestClient issueClient = client.getIssueClient();

    // verify that issue exist
    final String issueKey = "TST-1";
    final Issue issue = issueClient.getIssue(issueKey).claim();
    assertEquals(issueKey, issue.getKey());

    // delete issue
    issueClient.deleteIssue(issueKey, false).claim();

    // verify
    assertThatIssueNotExists(issueKey);
  }
View Full Code Here

    assertThatIssueNotExists(issueKey);
  }

  @Test
  public void testDeleteIssueWithSubtasks() {
    final IssueRestClient issueClient = client.getIssueClient();

    // verify that issue exist and create subtask
    final String issueKey = "TST-1";
    final Issue issue = issueClient.getIssue(issueKey).claim();
    assertEquals(issueKey, issue.getKey());
    final BasicIssue subtask = addSubtaskToIssue(issue);
    System.out.println(subtask);

    // delete issue
    issueClient.deleteIssue(issueKey, true).claim();

    // verify
    assertThatIssueNotExists(issueKey);
    assertThatIssueNotExists(subtask.getKey());
  }
View Full Code Here

    assertThatIssueNotExists(subtask.getKey());
  }

  @Test
  public void testDeleteIssueWithSubtasksWhenDeleteSubtasksIsFalse() {
    final IssueRestClient issueClient = client.getIssueClient();

    // verify that issue exist and create subtask
    final String issueKey = "TST-1";
    final Issue issue = issueClient.getIssue(issueKey).claim();
    assertEquals(issueKey, issue.getKey());
    BasicIssue subtask = addSubtaskToIssue(issue);
    System.out.println(subtask);

    // delete issue
    expectedException.expect(rceWithSingleError(400, String.format("The issue '%s' has subtasks.  "
        + "You must specify the 'deleteSubtasks' parameter to delete this issue and all its subtasks.", issueKey)));
    issueClient.deleteIssue(issueKey, false).claim();
  }
View Full Code Here

    issueClient.deleteIssue(issueKey, false).claim();
  }

  @Test
  public void testDeleteIssueWhenNoSuchIssue() {
    final IssueRestClient issueClient = client.getIssueClient();

    // verify that issue exist
    final String issueKey = "TST-999";
    assertThatIssueNotExists(issueKey);

    // delete issue should thrown 404
    expectedException.expect(rceWithSingleError(404, "Issue Does Not Exist"));
    issueClient.deleteIssue(issueKey, false).claim();
  }
View Full Code Here

  }

  @Test
  public void testDeleteIssueWithoutDeletePermission() {
    setAnonymousMode();
    final IssueRestClient issueClient = client.getIssueClient();

    // verify that issue doesn't exist
    final String issueKey = "ANONEDIT-2";
    final Issue issue = issueClient.getIssue(issueKey).claim();
    assertEquals(issueKey, issue.getKey());

    // delete issue should thrown 401
    expectedException.expect(rceWithSingleError(401, "You do not have permission to delete issues in this project."));
    issueClient.deleteIssue(issueKey, false).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

        .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


  @Test
  public void testWatchAlreadyWatched() {
    setUser1();
    final IssueRestClient issueClient = client.getIssueClient();
    final Issue issue = issueClient.getIssue("TST-1").claim();
    Assert.assertThat(client.getIssueClient().getWatchers(issue.getWatchers().getSelf()).claim()
        .getUsers(), hasItem(IntegrationTestUtil.USER1));
    // JIRA allows to watch already watched issue by you - such action effectively has no effect
    issueClient.watch(issue.getWatchers().getSelf()).claim();
    Assert.assertThat(client.getIssueClient().getWatchers(issue.getWatchers().getSelf()).claim()
        .getUsers(), hasItem(IntegrationTestUtil.USER1));
  }
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.