예제 #1
0
 private void updateIssue(DefaultIssue issue, Rule rule, ActiveRule activeRule) {
   if (Strings.isNullOrEmpty(issue.message())) {
     issue.setMessage(rule.name());
   }
   issue.setCreationDate(project.getAnalysisDate());
   issue.setUpdateDate(project.getAnalysisDate());
   if (issue.severity() == null) {
     issue.setSeverity(activeRule.severity());
   }
   DebtRemediationFunction function = rule.debtRemediationFunction();
   if (rule.debtSubCharacteristic() != null && function != null) {
     issue.setDebt(calculateDebt(function, issue.effortToFix(), rule.key()));
   }
 }
  @Test
  public void should_send_notification_if_issue_change() throws Exception {
    when(project.getAnalysisDate()).thenReturn(DateUtils.parseDate("2013-05-18"));
    RuleKey ruleKey = RuleKey.of("squid", "AvoidCycles");
    Rule rule = new Rule("squid", "AvoidCycles");
    DefaultIssue issue =
        new DefaultIssue()
            .setNew(false)
            .setChanged(true)
            .setFieldChange(mock(IssueChangeContext.class), "severity", "MINOR", "BLOCKER")
            .setRuleKey(ruleKey);
    when(issueCache.all()).thenReturn(Arrays.asList(issue));
    when(ruleFinder.findByKey(ruleKey)).thenReturn(rule);

    SendIssueNotificationsPostJob job =
        new SendIssueNotificationsPostJob(issueCache, notifications, ruleFinder);
    job.executeOn(project, sensorContext);

    verify(notifications)
        .sendChanges(
            eq(issue),
            any(IssueChangeContext.class),
            eq(rule),
            any(Component.class),
            (Component) isNull());
  }
  @Test
  public void should_not_send_notif_if_no_new_issues() throws Exception {
    when(project.getAnalysisDate()).thenReturn(DateUtils.parseDate("2013-05-18"));
    when(issueCache.all()).thenReturn(Arrays.asList(new DefaultIssue().setNew(false)));

    SendIssueNotificationsPostJob job =
        new SendIssueNotificationsPostJob(issueCache, notifications, ruleFinder);
    job.executeOn(project, sensorContext);

    verifyZeroInteractions(notifications);
  }
예제 #4
0
  private boolean initAndAddIssue(DefaultIssue issue, @Nullable Violation violation) {
    // TODO fail fast : if rule does not exist

    ActiveRule activeRule =
        qProfile.getActiveRule(issue.ruleKey().repository(), issue.ruleKey().rule());
    if (activeRule == null || activeRule.getRule() == null) {
      // rule does not exist or is not enabled -> ignore the issue
      return false;
    }
    issue.setCreationDate(project.getAnalysisDate());
    issue.setUpdateDate(project.getAnalysisDate());
    if (issue.severity() == null) {
      issue.setSeverity(activeRule.getSeverity().name());
    }
    issue.setRemediationCost(technicalDebtCalculator.cost(issue));

    if (filters.accept(issue, violation)) {
      cache.put(issue);
      return true;
    }
    return false;
  }
 public IssueAutoAssignDecorator(
     Settings settings,
     Project project,
     IssueCache issueCache,
     IssueUpdater issueUpdater,
     ResourcePerspectives perspectives,
     UserDao userDao) {
   this.settings = settings;
   this.issueCache = issueCache;
   this.issueUpdater = issueUpdater;
   this.changeContext = IssueChangeContext.createScan(project.getAnalysisDate());
   this.perspectives = perspectives;
   this.userDao = userDao;
   this.enabled = settings.getBoolean(IssueAutoAssignPlugin.PROPERTY_PLUGIN_ENABLED);
 }
예제 #6
0
  @Test
  public void initQuery() throws ParseException {
    Project project = mock(Project.class);
    when(project.getAnalysisDate()).thenReturn(date("2009-12-25"));

    MetricFinder metricFinder = mock(MetricFinder.class);
    when(metricFinder.findAll())
        .thenReturn(
            Arrays.asList(
                CoreMetrics.LINES,
                CoreMetrics.COVERAGE,
                CoreMetrics.COVERAGE_LINE_HITS_DATA,
                CoreMetrics.PROFILE));

    TendencyDecorator decorator = new TendencyDecorator(null, metricFinder, newConf());

    TimeMachineQuery query = decorator.initQuery(project);
    assertThat(query.getMetrics().size(), is(2));
    assertThat(query.getMetrics(), hasItems(CoreMetrics.LINES, CoreMetrics.COVERAGE));
    assertThat(query.getFrom(), is(date("2009-11-25")));
    assertThat(query.isToCurrentAnalysis(), is(true));
  }
 @Before
 public void setUp() throws ParseException {
   Project project = mock(Project.class);
   when(project.getAnalysisDate()).thenReturn(analysisDate);
   decorator = new ViolationTrackingDecorator(project, null, null);
 }