Examples of IssueRestClient


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

    // 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);

    // add worklog
    final int estimateWeeks = 2;
    final int estimateDays = 3;
    final int estimateHours = 4;
    final int estimateMinutes = 7;
    final WorklogInput worklogInput = worklogInputBuilder
        .setIssueUri(initialIssue.getSelf())
        .setAdjustEstimateNew(String.format("%sw %sd %sh %sm", estimateWeeks, estimateDays, estimateHours, estimateMinutes))
        .build();
    issueClient.addWorklog(initialIssue.getWorklogUri(), worklogInput, pm);

    // check if estimate has changed
    final Issue modifiedIssue = issueClient.getIssue(issueKey, pm);
    final int actualRemainingEstimate = getRemainingEstimateMinutesNotNull(modifiedIssue.getTimeTracking());
    // in current configuration 1w = 5d, 1d = 8h
    final int expectedRemaningEstimate = ((estimateWeeks * 5 + estimateDays) * 8 + estimateHours) * 60 + estimateMinutes;
    assertEquals(expectedRemaningEstimate, actualRemainingEstimate);
  }
View Full Code Here

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

    assertEquals(1, worklogs.size());
    return worklogs.iterator().next();
  }

  private void testAddWorklogImpl(String issueKey, WorklogInputBuilder worklogInputBuilder) {
    final IssueRestClient issueClient = client.getIssueClient();

    // get initial worklogs
    final Issue issue = issueClient.getIssue(issueKey, pm);
    final Set<Worklog> initialWorklogs = ImmutableSet.copyOf(issue.getWorklogs());

    // create and add new
    final WorklogInput worklogInput = worklogInputBuilder.setIssueUri(issue.getSelf()).build();
    issueClient.addWorklog(issue.getWorklogUri(), worklogInput, pm);

    // check if added correctly
    final Issue issueWithWorklog = issueClient.getIssue(issueKey, pm);
    final Worklog addedWorklog = getAddedWorklog(initialWorklogs, issueWithWorklog);
    assertEquals(worklogInput.getStartDate(), addedWorklog.getStartDate());
    assertEquals(worklogInput.getMinutesSpent(), addedWorklog.getMinutesSpent());
    assertEquals(worklogInput.getIssueUri(), addedWorklog.getIssueUri());
    assertEquals(worklogInput.getComment(), addedWorklog.getComment());
View Full Code Here

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

    final Comment addedComment = testAddCommentToIssueImpl(issueKey, comment);

    // try to get as anonymous user
    setAnonymousMode();

    final IssueRestClient issueClient = client.getIssueClient();
    final Issue issue = issueClient.getIssue(issueKey, pm);

    // test if we can see added comment
    assertFalse(hasComment(issue.getComments(), addedComment.getId()));
  }
View Full Code Here

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

    final Comment addedComment = testAddCommentToIssueImpl(issueKey, comment);

    // try to get as anonymous user
    setAnonymousMode();

    final IssueRestClient issueClient = client.getIssueClient();
    final Issue issue = issueClient.getIssue(issueKey, pm);

    // test if we can see added comment
    assertFalse(hasComment(issue.getComments(), addedComment.getId()));
  }
View Full Code Here

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

      }
    }).iterator().hasNext();
  }

  private Comment testAddCommentToIssueImpl(final String issueKey, final Comment comment) {
    final IssueRestClient issueClient = client.getIssueClient();
    final Issue issue = issueClient.getIssue(issueKey, pm);
    final List<Comment> initialComments = Lists.newArrayList(issue.getComments());

    issueClient.addComment(pm, issue.getCommentsUri(), comment);

    final Issue issueWithComments = issueClient.getIssue(issueKey, pm);
    final List<Comment> newComments = Lists.newArrayList(issueWithComments.getComments());
    newComments.removeAll(initialComments);
    assertEquals(1, Iterables.size(newComments));
    Comment addedComment = newComments.get(0);
    assertEquals(comment.getBody(), addedComment.getBody());
View Full Code Here

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

  @JiraBuildNumberDependent(BN_JIRA_5)
  @Test
  public void testCreateIssueWithoutCreateIssuePermission() {
    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("NCIFU", 1L/*, "Issue created by testCreateIssueWithoutCreateIssuePermission"*/)
        .build();
    issueClient.createIssue(issueInput, pm);
  }
View Full Code Here

Examples of com.atlassian.jira.rest.client.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, pm);
  }
View Full Code Here

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

  }

  @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(),
        pm
    );
    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, pm);
    assertNotNull(basicCreatedIssue);

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

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

    // assert few fields
View Full Code Here

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

  @JiraBuildNumberDependent(BN_JIRA_5)
  @Test
  public void testCreateIssue() {
    // collect CreateIssueMetadata for project with key TST
    final IssueRestClient issueClient = client.getIssueClient();
    final Iterable<CimProject> metadataProjects = issueClient.getCreateIssueMetadata(
        new GetCreateIssueMetadataOptionsBuilder().withProjectKeys("TST").withExpandedIssueTypesFields().build(), pm);

    // select project and issue
    assertEquals(1, Iterables.size(metadataProjects));
    final CimProject project = metadataProjects.iterator().next();
    final CimIssueType issueType = EntityHelper.findEntityByName(project.getIssueTypes(), "Bug");

    // grab the first component
    final Iterable<Object> allowedValuesForComponents = issueType.getField(IssueFieldId.COMPONENTS_FIELD).getAllowedValues();
    assertNotNull(allowedValuesForComponents);
    assertTrue(allowedValuesForComponents.iterator().hasNext());
    final BasicComponent component = (BasicComponent) allowedValuesForComponents.iterator().next();

    // grab the first priority
    final Iterable<Object> allowedValuesForPriority = issueType.getField(IssueFieldId.PRIORITY_FIELD).getAllowedValues();
    assertNotNull(allowedValuesForPriority);
    assertTrue(allowedValuesForPriority.iterator().hasNext());
    final BasicPriority priority = (BasicPriority) allowedValuesForPriority.iterator().next();

    // build issue input
    final String summary = "My new issue!";
    final String description = "Some description";
    final BasicUser assignee = IntegrationTestUtil.USER1;
    final List<String> affectedVersionsNames = Collections.emptyList();
    final DateTime dueDate = new DateTime(new Date().getTime());
    final ArrayList<String> fixVersionsNames = Lists.newArrayList("1.1");

    // prepare IssueInput
    final IssueInputBuilder issueInputBuilder = new IssueInputBuilder(project, issueType, summary)
        .setDescription(description)
        .setAssignee(assignee)
        .setAffectedVersionsNames(affectedVersionsNames)
        .setFixVersionsNames(fixVersionsNames)
        .setComponents(component)
        .setDueDate(dueDate)
        .setPriority(priority);

    // create
    final BasicIssue basicCreatedIssue = issueClient.createIssue(issueInputBuilder.build(), pm);
    assertNotNull(basicCreatedIssue.getKey());

    // get issue and check if everything was set as we expected
    final Issue createdIssue = issueClient.getIssue(basicCreatedIssue.getKey(), pm);
    assertNotNull(createdIssue);

    assertEquals(basicCreatedIssue.getKey(), createdIssue.getKey());
    assertEquals(project.getKey(), createdIssue.getProject().getKey());
    assertEquals(issueType.getId(), createdIssue.getIssueType().getId());
View Full Code Here

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

  @JiraBuildNumberDependent(BN_JIRA_5)
  @Test
  public void testCreateIssueWithOnlyRequiredFields() {
    // collect CreateIssueMetadata for project with key TST
    final IssueRestClient issueClient = client.getIssueClient();
    final Iterable<CimProject> metadataProjects = issueClient.getCreateIssueMetadata(
        new GetCreateIssueMetadataOptionsBuilder().withProjectKeys("TST").withExpandedIssueTypesFields().build(),
        pm
    );

    // select project and issue
    assertEquals(1, Iterables.size(metadataProjects));
    final CimProject project = metadataProjects.iterator().next();
    final CimIssueType issueType = EntityHelper.findEntityByName(project.getIssueTypes(), "Bug");

    // build issue input
    final String summary = "My new issue!";

    // create
    final IssueInput issueInput = new IssueInputBuilder(project, issueType, summary).build();
    final BasicIssue basicCreatedIssue = issueClient.createIssue(issueInput, pm);
    assertNotNull(basicCreatedIssue.getKey());

    // get issue and check if everything was set as we expected
    final Issue createdIssue = issueClient.getIssue(basicCreatedIssue.getKey(), pm);
    assertNotNull(createdIssue);

    assertEquals(basicCreatedIssue.getKey(), createdIssue.getKey());
    assertEquals(project.getKey(), createdIssue.getProject().getKey());
    assertEquals(issueType.getId(), createdIssue.getIssueType().getId());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.