aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-05-03 00:02:45 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-05-03 00:02:45 +0200
commita1a1cd56cf3464200911a8c0dbef3ed25563aa6a (patch)
tree4e62793cab6a0d89de8457d68570977ea27f674d /sonar-batch
parent1dbff7660b5957d1dc346f7e1da60be8d6ee6da6 (diff)
downloadsonarqube-a1a1cd56cf3464200911a8c0dbef3ed25563aa6a.tar.gz
sonarqube-a1a1cd56cf3464200911a8c0dbef3ed25563aa6a.zip
SONAR-3755 refactor issue dates
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/IssuePersister.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssues.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/report/SonarReport.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/IssueCacheTest.java19
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/IssuePersisterTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssuesTest.java7
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/SonarReportTest.java12
8 files changed, 36 insertions, 29 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java
index 21b8746a99d..b136805f815 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java
@@ -41,18 +41,14 @@ public class IssueCache implements BatchComponent {
cache = caches.createCache("issues");
}
- public Collection<DefaultIssue> componentIssues(String componentKey) {
+ public Collection<DefaultIssue> byComponent(String componentKey) {
return cache.values(componentKey);
}
- public Collection<DefaultIssue> componentIssues() {
+ public Collection<DefaultIssue> all() {
return newArrayList(cache.allValues());
}
- public Issue componentIssue(String componentKey, String issueKey) {
- return cache.get(componentKey, issueKey);
- }
-
public IssueCache put(DefaultIssue issue) {
cache.put(issue.componentKey(), issue.key(), issue);
return this;
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssuePersister.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssuePersister.java
index 29f6ec69450..9a613ab4882 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssuePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/IssuePersister.java
@@ -37,7 +37,7 @@ public class IssuePersister implements ScanPersister {
@Override
public void persist() {
- Iterable<DefaultIssue> issues = issueCache.componentIssues();
+ Iterable<DefaultIssue> issues = issueCache.all();
storage.save(issues);
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssues.java
index e617398fd61..bb9b10e62a9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssues.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssues.java
@@ -46,11 +46,11 @@ public class ScanIssues implements BatchComponent {
}
public Collection<DefaultIssue> issues(String componentKey) {
- return cache.componentIssues(componentKey);
+ return cache.byComponent(componentKey);
}
public Collection<DefaultIssue> issues() {
- return cache.componentIssues();
+ return cache.all();
}
public ScanIssues addOrUpdate(DefaultIssue issue) {
@@ -65,8 +65,9 @@ public class ScanIssues implements BatchComponent {
// rule does not exist or is not enabled -> ignore the issue
return false;
}
- issue.setCreatedAt(project.getAnalysisDate());
- issue.setUpdatedAt(project.getAnalysisDate());
+ issue.setCreationDate(project.getAnalysisDate());
+ issue.setUpdateDate(project.getAnalysisDate());
+ issue.setCloseDate(project.getAnalysisDate());
if (issue.severity() == null) {
issue.setSeverity(activeRule.getSeverity().name());
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/SonarReport.java b/sonar-batch/src/main/java/org/sonar/batch/report/SonarReport.java
index e7548b476f4..dc758adf734 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/report/SonarReport.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/report/SonarReport.java
@@ -118,9 +118,9 @@ public class SonarReport implements BatchComponent {
put(jsonIssue, "status", issue.status());
put(jsonIssue, "resolution", issue.resolution());
put(jsonIssue, "isNew", issue.isNew());
- put(jsonIssue, "createdAt", issue.createdAt());
- put(jsonIssue, "updatedAt", issue.updatedAt());
- put(jsonIssue, "closedAt", issue.closedAt());
+ put(jsonIssue, "creationDate", issue.creationDate());
+ put(jsonIssue, "updateDate", issue.updateDate());
+ put(jsonIssue, "closeDate", issue.closeDate());
json.add(jsonIssue);
componentKeyList.add(issue.componentKey());
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/IssueCacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/IssueCacheTest.java
index 85fdc6d5909..7d0102afef6 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/IssueCacheTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/IssueCacheTest.java
@@ -56,8 +56,8 @@ public class IssueCacheTest {
DefaultIssue issue3 = new DefaultIssue().setKey("333").setComponentKey("org.struts.Filter");
cache.put(issue1).put(issue2).put(issue3);
- assertThat(issueKeys(cache.componentIssues("org.struts.Action"))).containsOnly("111", "222");
- assertThat(issueKeys(cache.componentIssues("org.struts.Filter"))).containsOnly("333");
+ assertThat(issueKeys(cache.byComponent("org.struts.Action"))).containsOnly("111", "222");
+ assertThat(issueKeys(cache.byComponent("org.struts.Filter"))).containsOnly("333");
}
@Test
@@ -69,14 +69,25 @@ public class IssueCacheTest {
issue.setSeverity(Severity.MINOR);
cache.put(issue);
- Collection<DefaultIssue> issues = cache.componentIssues("org.struts.Action");
+ Collection<DefaultIssue> issues = cache.byComponent("org.struts.Action");
assertThat(issues).hasSize(1);
Issue reloaded = issues.iterator().next();
assertThat(reloaded.key()).isEqualTo("111");
assertThat(reloaded.severity()).isEqualTo(Severity.MINOR);
}
- Collection<String> issueKeys(Collection<DefaultIssue> issues) {
+ @Test
+ public void should_get_all_issues() throws Exception {
+ IssueCache cache = new IssueCache(caches);
+ DefaultIssue issue1 = new DefaultIssue().setKey("111").setComponentKey("org.struts.Action").setSeverity(Severity.BLOCKER);
+ DefaultIssue issue2 = new DefaultIssue().setKey("222").setComponentKey("org.struts.Filter").setSeverity(Severity.INFO);
+ cache.put(issue1).put(issue2);
+
+ Collection<DefaultIssue> issues = cache.all();
+ assertThat(issues).hasSize(2).containsOnly(issue1, issue2);
+ }
+
+ private Collection<String> issueKeys(Collection<DefaultIssue> issues) {
return Collections2.transform(issues, new Function<DefaultIssue, String>() {
@Override
public String apply(@Nullable DefaultIssue issue) {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuePersisterTest.java
index 9d87b52e3e3..dfcd68a58ee 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuePersisterTest.java
@@ -36,7 +36,7 @@ public class IssuePersisterTest extends AbstractDaoTestCase {
public void should_persist_all_issues() throws Exception {
List<DefaultIssue> issues = Arrays.asList(new DefaultIssue());
IssueCache issueCache = mock(IssueCache.class);
- when(issueCache.componentIssues()).thenReturn(issues);
+ when(issueCache.all()).thenReturn(issues);
ScanIssueStorage storage = mock(ScanIssueStorage.class);
persister = new IssuePersister(issueCache, storage);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssuesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssuesTest.java
index 695d2292f97..c19ae73fc02 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssuesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssuesTest.java
@@ -21,7 +21,6 @@ package org.sonar.batch.issue;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-import org.sonar.api.issue.Issue;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
import org.sonar.api.rule.RuleKey;
@@ -46,7 +45,7 @@ public class ScanIssuesTest {
@Test
public void should_get_issues() throws Exception {
scanIssues.issues("key");
- verify(cache).componentIssues("key");
+ verify(cache).byComponent("key");
}
@Test
@@ -94,7 +93,7 @@ public class ScanIssuesTest {
ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class);
verify(cache).put(argument.capture());
assertThat(argument.getValue().severity()).isEqualTo(Severity.CRITICAL);
- assertThat(argument.getValue().createdAt()).isEqualTo(analysisDate);
+ assertThat(argument.getValue().creationDate()).isEqualTo(analysisDate);
}
@Test
@@ -114,6 +113,6 @@ public class ScanIssuesTest {
ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class);
verify(cache).put(argument.capture());
assertThat(argument.getValue().severity()).isEqualTo(Severity.INFO);
- assertThat(argument.getValue().createdAt()).isEqualTo(analysisDate);
+ assertThat(argument.getValue().creationDate()).isEqualTo(analysisDate);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/SonarReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/SonarReportTest.java
index fe305366147..d328b1457e6 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/SonarReportTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/SonarReportTest.java
@@ -132,9 +132,9 @@ public class SonarReportTest {
.setResolution(Issue.RESOLUTION_FALSE_POSITIVE)
.setLine(1)
.setRuleKey(RuleKey.of("squid", "AvoidCycle"))
- .setCreatedAt(DateUtils.parseDate("2013-04-24"))
- .setUpdatedAt(DateUtils.parseDate("2013-04-25"))
- .setClosedAt(DateUtils.parseDate("2013-04-26"))
+ .setCreationDate(DateUtils.parseDate("2013-04-24"))
+ .setUpdateDate(DateUtils.parseDate("2013-04-25"))
+ .setCloseDate(DateUtils.parseDate("2013-04-26"))
.setNew(false);
when(sonarReport.getIssues()).thenReturn(Lists.<DefaultIssue>newArrayList(issue));
@@ -155,9 +155,9 @@ public class SonarReportTest {
assertThat(jsonIssue.get("status")).isEqualTo("CLOSED");
assertThat(jsonIssue.get("resolution")).isEqualTo("FALSE-POSITIVE");
assertThat(jsonIssue.get("isNew")).isEqualTo(false);
- assertThat((String) jsonIssue.get("createdAt")).contains("2013-04-24T00:00");
- assertThat((String) jsonIssue.get("updatedAt")).contains("2013-04-25T00:00");
- assertThat((String) jsonIssue.get("closedAt")).contains("2013-04-26T00:00");
+ assertThat((String) jsonIssue.get("creationDate")).contains("2013-04-24T00:00");
+ assertThat((String) jsonIssue.get("updateDate")).contains("2013-04-25T00:00");
+ assertThat((String) jsonIssue.get("closeDate")).contains("2013-04-26T00:00");
}
@Test