public boolean setPastEffort(DefaultIssue issue, @Nullable Duration previousEffort, IssueChangeContext context) { Duration currentEffort = issue.effort(); issue.setEffort(previousEffort); return setEffort(issue, currentEffort, context); }
public boolean setEffort(DefaultIssue issue, @Nullable Duration value, IssueChangeContext context) { Duration oldValue = issue.effort(); if (!Objects.equals(value, oldValue)) { issue.setEffort(value); issue.setFieldChange(context, TECHNICAL_DEBT, oldValue != null ? oldValue.toMinutes() : null, value != null ? value.toMinutes() : null); issue.setUpdateDate(context.date()); issue.setChanged(true); return true; } return false; }
private static DefaultIssue newIssue(long effort, String severity, RuleType type) { return newIssue(severity, type) .setEffort(Duration.create(effort)); }
private static DefaultIssue newIssue(long effort, String severity, RuleType type) { return newIssue(severity, type) .setEffort(Duration.create(effort)); }
private DefaultIssue oldBugIssue(long effort) { return newCodeSmellIssueWithoutEffort() .setEffort(Duration.create(effort)) .setType(RuleType.BUG) .setCreationDate(new Date(OLD_ISSUES_DATES[random.nextInt(OLD_ISSUES_DATES.length)])); }
private DefaultIssue oldCodeSmellIssue(long effort) { return newCodeSmellIssueWithoutEffort() .setEffort(Duration.create(effort)) .setType(RuleType.CODE_SMELL) .setCreationDate(new Date(OLD_ISSUES_DATES[random.nextInt(OLD_ISSUES_DATES.length)])); }
private DefaultIssue oldVulnerabilityIssue(long effort) { return newCodeSmellIssueWithoutEffort() .setEffort(Duration.create(effort)) .setType(RuleType.VULNERABILITY) .setCreationDate(new Date(OLD_ISSUES_DATES[random.nextInt(OLD_ISSUES_DATES.length)])); }
@Test public void set_past_technical_debt_without_previous_value() { Duration newDebt = Duration.create(15 * 8 * 60); issue.setEffort(newDebt); boolean updated = underTest.setPastEffort(issue, null, context); assertThat(updated).isTrue(); assertThat(issue.effort()).isEqualTo(newDebt); assertThat(issue.mustSendNotifications()).isFalse(); FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT); assertThat(diff.oldValue()).isNull(); assertThat(diff.newValue()).isEqualTo(15L * 8 * 60); }
@Test public void set_past_technical_debt() { Duration newDebt = Duration.create(15 * 8 * 60); Duration previousDebt = Duration.create(10 * 8 * 60); issue.setEffort(newDebt); boolean updated = underTest.setPastEffort(issue, previousDebt, context); assertThat(updated).isTrue(); assertThat(issue.effort()).isEqualTo(newDebt); assertThat(issue.mustSendNotifications()).isFalse(); FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT); assertThat(diff.oldValue()).isEqualTo(10L * 8 * 60); assertThat(diff.newValue()).isEqualTo(15L * 8 * 60); }
@Test public void set_past_technical_debt_with_null_new_value() { issue.setEffort(null); Duration previousDebt = Duration.create(10 * 8 * 60); boolean updated = underTest.setPastEffort(issue, previousDebt, context); assertThat(updated).isTrue(); assertThat(issue.effort()).isNull(); assertThat(issue.mustSendNotifications()).isFalse(); FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT); assertThat(diff.oldValue()).isEqualTo(10L * 8 * 60); assertThat(diff.newValue()).isNull(); }
@Test public void add_does_not_sum_effort_if_null_neither_globally_nor_per_assignee() { String assignee = randomAlphanumeric(10); underTest.add(new DefaultIssue().setType(randomRuleTypeExceptHotspot).setEffort(null).setAssigneeUuid(assignee).setNew(new Random().nextBoolean())); MetricStatsLong globalDistribution = underTest.globalStatistics().effort(); MetricStatsLong assigneeDistribution = underTest.getAssigneesStatistics().get(assignee).effort(); Stream.of(globalDistribution, assigneeDistribution) .forEach(distribution -> assertThat(distribution.getTotal()).isEqualTo(0)); }
private static DefaultIssue newCodeSmellIssue(long effort) { return newCodeSmellIssueWithoutEffort().setEffort(Duration.create(effort)).setType(CODE_SMELL); }
private static DefaultIssue newBugIssue(long effort) { return newCodeSmellIssueWithoutEffort().setEffort(Duration.create(effort)).setType(BUG); }
private static DefaultIssue newVulnerabilityIssue(long effort) { return newCodeSmellIssueWithoutEffort().setEffort(Duration.create(effort)).setType(VULNERABILITY); }
public void initNewOpenIssue(DefaultIssue issue) { Preconditions.checkArgument(issue.isFromExternalRuleEngine() != (issue.type() == null), "At this stage issue type should be set for and only for external issues"); issue.setKey(Uuids.create()); issue.setCreationDate(changeContext.date()); issue.setUpdateDate(changeContext.date()); issue.setStatus(Issue.STATUS_OPEN); issue.setEffort(debtCalculator.calculate(issue)); setType(issue); }
@Test public void copy_effort_for_external_issues() { issue.setGap(null); issue.setIsFromExternalRuleEngine(true); issue.setEffort(Duration.create(20l)); rule.setFunction(null); assertThat(underTest.calculate(issue).toMinutes()).isEqualTo(20l); }
@Test public void do_not_send_global_new_issues_notification_if_issue_has_been_backdated() { issueCache.newAppender().append( new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION) .setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS))) .close(); when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), NOTIF_TYPES)).thenReturn(true); TestComputationStepContext context = new TestComputationStepContext(); underTest.execute(context); verify(notificationService, never()).deliver(any()); verifyStatistics(context, 0, 0, 0); }
@Test public void send_global_new_issues_notification() { issueCache.newAppender().append( new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION) .setCreationDate(new Date(ANALYSE_DATE))) .close(); when(notificationService.hasProjectSubscribersForTypes(eq(PROJECT.getUuid()), any())).thenReturn(true); TestComputationStepContext context = new TestComputationStepContext(); underTest.execute(context); verify(notificationService).deliver(newIssuesNotificationMock); verify(newIssuesNotificationMock).setProject(PROJECT.getKey(), PROJECT.getName(), null, null); verify(newIssuesNotificationMock).setAnalysisDate(new Date(ANALYSE_DATE)); verify(newIssuesNotificationMock).setStatistics(eq(PROJECT.getName()), any()); verify(newIssuesNotificationMock).setDebt(ISSUE_DURATION); verifyStatistics(context, 1, 0, 0); }
@Test public void do_not_send_global_new_issues_notification_on_branch_if_issue_has_been_backdated() { ComponentDto branch = setUpProjectWithBranch(); issueCache.newAppender().append( new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS))).close(); when(notificationService.hasProjectSubscribersForTypes(branch.uuid(), NOTIF_TYPES)).thenReturn(true); analysisMetadataHolder.setBranch(newBranch()); TestComputationStepContext context = new TestComputationStepContext(); underTest.execute(context); verify(notificationService, never()).deliver(any()); verifyStatistics(context, 0, 0, 0); }
@Test public void do_not_send_new_issues_notification_to_user_if_issue_is_backdated() { UserDto user = db.users().insertUser(); issueCache.newAppender().append( new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setAssigneeUuid(user.getUuid()) .setCreationDate(new Date(ANALYSE_DATE - FIVE_MINUTES_IN_MS))) .close(); when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), NOTIF_TYPES)).thenReturn(true); TestComputationStepContext context = new TestComputationStepContext(); underTest.execute(context); verify(notificationService, never()).deliver(any()); verifyStatistics(context, 0, 0, 0); }