Exemple #1
0
  @Test
  public void set_issue_fields() {
    Date createdAt = DateUtils.addDays(new Date(), -5);
    Date updatedAt = DateUtils.addDays(new Date(), -3);
    Date closedAt = DateUtils.addDays(new Date(), -1);

    IssueDto dto =
        new IssueDto()
            .setKee("100")
            .setRuleId(1)
            .setRuleKey_unit_test_only("squid", "AvoidCycle")
            .setComponentKey_unit_test_only("org.sonar.sample:Sample")
            .setRootComponentKey_unit_test_only("org.sonar.sample")
            .setComponentId(1l)
            .setRootComponentId(1l)
            .setStatus(Issue.STATUS_CLOSED)
            .setResolution(Issue.RESOLUTION_FALSE_POSITIVE)
            .setEffortToFix(15.0)
            .setTechnicalDebt(101010L)
            .setLine(6)
            .setSeverity("BLOCKER")
            .setMessage("message")
            .setManualSeverity(true)
            .setReporter("arthur")
            .setAssignee("perceval")
            .setIssueAttributes("key=value")
            .setAuthorLogin("pierre")
            .setIssueCreationDate(createdAt)
            .setIssueUpdateDate(updatedAt)
            .setIssueCloseDate(closedAt);

    DefaultIssue issue = dto.toDefaultIssue();
    assertThat(issue.key()).isEqualTo("100");
    assertThat(issue.ruleKey().toString()).isEqualTo("squid:AvoidCycle");
    assertThat(issue.componentKey()).isEqualTo("org.sonar.sample:Sample");
    assertThat(issue.projectKey()).isEqualTo("org.sonar.sample");
    assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED);
    assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FALSE_POSITIVE);
    assertThat(issue.effortToFix()).isEqualTo(15.0);
    assertThat(issue.technicalDebt()).isEqualTo(WorkDayDuration.of(10, 10, 10));
    assertThat(issue.line()).isEqualTo(6);
    assertThat(issue.severity()).isEqualTo("BLOCKER");
    assertThat(issue.message()).isEqualTo("message");
    assertThat(issue.manualSeverity()).isTrue();
    assertThat(issue.reporter()).isEqualTo("arthur");
    assertThat(issue.assignee()).isEqualTo("perceval");
    assertThat(issue.attribute("key")).isEqualTo("value");
    assertThat(issue.authorLogin()).isEqualTo("pierre");
    assertThat(issue.creationDate()).isEqualTo(DateUtils.truncate(createdAt, Calendar.SECOND));
    assertThat(issue.updateDate()).isEqualTo(DateUtils.truncate(updatedAt, Calendar.SECOND));
    assertThat(issue.closeDate()).isEqualTo(DateUtils.truncate(closedAt, Calendar.SECOND));
    assertThat(issue.isNew()).isFalse();
  }
 public IssueChangeNotification setIssue(DefaultIssue issue) {
   setFieldValue("key", issue.key());
   setFieldValue("reporter", issue.reporter());
   setFieldValue("assignee", issue.assignee());
   setFieldValue("message", issue.message());
   setFieldValue("componentKey", issue.componentKey());
   FieldDiffs currentChange = issue.currentChange();
   if (currentChange != null) {
     for (Map.Entry<String, FieldDiffs.Diff> entry : currentChange.diffs().entrySet()) {
       String type = entry.getKey();
       FieldDiffs.Diff diff = entry.getValue();
       setFieldValue("old." + type, neverEmptySerializableToString(diff.oldValue()));
       setFieldValue("new." + type, neverEmptySerializableToString(diff.newValue()));
     }
   }
   return this;
 }
Exemple #3
0
  private void writeIssue(IssueQueryResult result, DefaultIssue issue, JsonWriter json) {
    Component component = result.component(issue);
    Component project = result.project(issue);
    String actionPlanKey = issue.actionPlanKey();
    WorkDayDuration technicalDebt = issue.technicalDebt();
    Date updateDate = issue.updateDate();
    Date closeDate = issue.closeDate();

    json.prop("key", issue.key())
        .prop("component", issue.componentKey())
        .prop("componentLongName", component != null ? component.longName() : null)
        .prop("componentQualifier", component != null ? component.qualifier() : null)
        .prop("project", issue.projectKey())
        .prop("projectLongName", project != null ? project.longName() : null)
        .prop("rule", issue.ruleKey().toString())
        .prop("ruleName", result.rule(issue).getName())
        .prop("line", issue.line())
        .prop("message", issue.message())
        .prop("resolution", issue.resolution())
        .prop("status", issue.status())
        .prop("severity", issue.severity())
        .prop("author", issue.authorLogin())
        .prop("actionPlan", actionPlanKey)
        .prop(
            "debt",
            technicalDebt != null
                ? technicalDebtFormatter.format(UserSession.get().locale(), technicalDebt)
                : null)
        .prop("actionPlanName", actionPlanKey != null ? result.actionPlan(issue).name() : null)
        .prop("creationDate", DateUtils.formatDateTime(issue.creationDate()))
        .prop("fCreationDate", formatDate(issue.creationDate()))
        .prop("updateDate", updateDate != null ? DateUtils.formatDateTime(updateDate) : null)
        .prop("fUpdateDate", formatDate(updateDate))
        .prop("fUpdateAge", formatAgeDate(updateDate))
        .prop("closeDate", closeDate != null ? DateUtils.formatDateTime(closeDate) : null)
        .prop("fCloseDate", formatDate(issue.closeDate()));

    addUserWithLabel(result, issue.assignee(), "assignee", json);
    addUserWithLabel(result, issue.reporter(), "reporter", json);
  }