assertThat(issue.isOnDisabledRule()).isTrue();
}
+ @Test
+ public void manual_issues_should_be_closed_if_manual_rule_is_not_found() throws Exception {
+ // "Unmatched" issues existed in previous scan but not in current one -> they have to be closed
+ Resource file = new File("Action.java").setEffectiveKey("struts:Action.java").setId(123);
+
+ // INPUT : one issue existing during previous scan
+ IssueDto unmatchedIssue = new IssueDto().setKee("ABCDE").setReporter("freddy").setStatus("OPEN").setRuleKey_unit_test_only("manual", "Performance");
+ when(ruleFinder.findByKey(RuleKey.of("manual", "Performance"))).thenReturn(null);
+
+ IssueTrackingResult trackingResult = new IssueTrackingResult();
+ trackingResult.addUnmatched(unmatchedIssue);
+
+ when(tracking.track(eq(file), anyCollection(), anyCollection())).thenReturn(trackingResult);
+
+ decorator.doDecorate(file);
+
+ verify(workflow, times(1)).doAutomaticTransition(any(DefaultIssue.class), any(IssueChangeContext.class));
+ verify(handlers, times(1)).execute(any(DefaultIssue.class), any(IssueChangeContext.class));
+
+ ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class);
+ verify(issueCache).put(argument.capture());
+
+ DefaultIssue issue = argument.getValue();
+ assertThat(issue.key()).isEqualTo("ABCDE");
+ assertThat(issue.isNew()).isFalse();
+ assertThat(issue.isEndOfLife()).isTrue();
+ assertThat(issue.isOnDisabledRule()).isTrue();
+ }
+
@Test
public void should_register_issues_on_deleted_components() throws Exception {
Project project = new Project("struts");
}
@Test
- public void test_some_setters_and_getters2() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(), new Snapshot());
+ public void test_some_setters_and_getters_with_empty_snapshot() {
+ PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION);
assertThat(pastSnapshot.getQualifier()).isNull();
assertThat(pastSnapshot.getDate()).isNull();
import org.sonar.api.issue.internal.IssueChangeContext;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationManager;
+import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.DateUtils;
+import org.sonar.core.component.ResourceComponent;
import org.sonar.core.i18n.RuleI18nManager;
import java.util.Arrays;
.setAssignee("freddy")
.setFieldChange(context, "resolution", null, "FIXED")
.setFieldChange(context, "status", "OPEN", "RESOLVED")
+ .setFieldChange(context, "assignee", "simon", null)
.setSendNotifications(true)
.setComponentKey("struts:Action")
.setProjectKey("struts");
assertThat(notification.getFieldValue("message")).isEqualTo("the message");
assertThat(notification.getFieldValue("key")).isEqualTo("ABCDE");
+ assertThat(notification.getFieldValue("componentKey")).isEqualTo("struts:Action");
+ assertThat(notification.getFieldValue("componentName")).isNull();
assertThat(notification.getFieldValue("old.resolution")).isNull();
assertThat(notification.getFieldValue("new.resolution")).isEqualTo("FIXED");
assertThat(notification.getFieldValue("old.status")).isEqualTo("OPEN");
assertThat(notification.getFieldValue("new.status")).isEqualTo("RESOLVED");
+ assertThat(notification.getFieldValue("old.assignee")).isEqualTo("simon");
+ assertThat(notification.getFieldValue("new.assignee")).isNull();
Mockito.verify(manager).scheduleForSending(notification);
}
Mockito.verify(manager).scheduleForSending(notification);
}
+ @Test
+ public void should_send_changes_with_component_name() throws Exception {
+ IssueChangeContext context = IssueChangeContext.createScan(new Date());
+ DefaultIssue issue = new DefaultIssue()
+ .setMessage("the message")
+ .setKey("ABCDE")
+ .setAssignee("freddy")
+ .setFieldChange(context, "resolution", null, "FIXED")
+ .setSendNotifications(true)
+ .setComponentKey("struts:Action")
+ .setProjectKey("struts");
+ DefaultIssueQueryResult queryResult = new DefaultIssueQueryResult(Arrays.<Issue>asList(issue));
+ queryResult.addProjects(Arrays.<Component>asList(new Project("struts")));
+ queryResult.addComponents(Arrays.<Component>asList(new ResourceComponent(new File("struts:Action").setEffectiveKey("struts:Action"))));
+
+ Notification notification = issueNotifications.sendChanges(issue, context, queryResult);
+
+ assertThat(notification.getFieldValue("message")).isEqualTo("the message");
+ assertThat(notification.getFieldValue("key")).isEqualTo("ABCDE");
+ assertThat(notification.getFieldValue("componentKey")).isEqualTo("struts:Action");
+ assertThat(notification.getFieldValue("componentName")).isEqualTo("struts:Action");
+ assertThat(notification.getFieldValue("old.resolution")).isNull();
+ assertThat(notification.getFieldValue("new.resolution")).isEqualTo("FIXED");
+ Mockito.verify(manager).scheduleForSending(notification);
+ }
+
@Test
public void should_not_send_changes_if_no_diffs() throws Exception {
IssueChangeContext context = IssueChangeContext.createScan(new Date());
verifyZeroInteractions(issueNotifications);
}
+ @Test
+ public void should_not_execute_bulk_if_action_is_not_verified() {
+ Map<String, Object> properties = newHashMap();
+ properties.put("issues", "ABCD");
+ properties.put("actions", "assign");
+ properties.put("assign.assignee", "fred");
+ actions.add(new MockAction("assign", false, true, true));
+
+ IssueBulkChangeQuery issueBulkChangeQuery = new IssueBulkChangeQuery(properties);
+ IssueBulkChangeResult result = service.execute(issueBulkChangeQuery, userSession);
+ assertThat(result.issuesChanged()).isEmpty();
+ assertThat(result.issuesNotChanged()).isEmpty();
+
+ verifyZeroInteractions(issueStorage);
+ verifyZeroInteractions(issueNotifications);
+ }
+
@Test
public void should_not_execute_bulk_if_action_could_not_be_executed_on_issue() {
Map<String, Object> properties = newHashMap();
verify(issueNotifications).sendChanges(eq(issue), eq(issueChangeContext), eq(issueQueryResult));
}
+
+ @Test
+ public void should_unassign() {
+ when(issueUpdater.assign(eq(issue), eq((User) null), any(IssueChangeContext.class))).thenReturn(true);
+
+ Issue result = issueService.assign("ABCD", null, userSession);
+ assertThat(result).isNotNull();
+
+ ArgumentCaptor<IssueChangeContext> measureCaptor = ArgumentCaptor.forClass(IssueChangeContext.class);
+ verify(issueUpdater).assign(eq(issue), eq((User) null), measureCaptor.capture());
+ verify(issueStorage).save(issue);
+
+ IssueChangeContext issueChangeContext = measureCaptor.getValue();
+ assertThat(issueChangeContext.login()).isEqualTo("arthur");
+ assertThat(issueChangeContext.date()).isNotNull();
+
+ verify(issueNotifications).sendChanges(eq(issue), eq(issueChangeContext), eq(issueQueryResult));
+ verify(userFinder, never()).findByLogin(anyString());
+ }
+
@Test
public void should_not_assign() {
String assignee = "perceval";
verify(issueNotifications).sendChanges(eq(issue), eq(issueChangeContext), eq(issueQueryResult));
}
+ @Test
+ public void should_unplan() {
+ when(issueUpdater.plan(eq(issue), eq((ActionPlan) null), any(IssueChangeContext.class))).thenReturn(true);
+
+ Issue result = issueService.plan("ABCD", null, userSession);
+ assertThat(result).isNotNull();
+
+ ArgumentCaptor<IssueChangeContext> measureCaptor = ArgumentCaptor.forClass(IssueChangeContext.class);
+ verify(issueUpdater).plan(eq(issue), eq((ActionPlan) null), measureCaptor.capture());
+ verify(issueStorage).save(issue);
+
+ IssueChangeContext issueChangeContext = measureCaptor.getValue();
+ assertThat(issueChangeContext.login()).isEqualTo("arthur");
+ assertThat(issueChangeContext.date()).isNotNull();
+
+ verify(issueNotifications).sendChanges(eq(issue), eq(issueChangeContext), eq(issueQueryResult));
+ verify(actionPlanService, never()).findByKey(anyString(), any(UserSession.class));
+ }
+
@Test
public void should_not_plan() {
String actionPlanKey = "EFGH";