aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-03-17 09:32:20 +0100
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-03-17 09:32:20 +0100
commit7f32a128f3997c0fe8fa32b3462129faace2c154 (patch)
tree6ef061de065b3503139b0b399923b007d0dae04b
parent4a97e3539c69b00802f88a30e10a4cbc0d8336d7 (diff)
parent6b51007577170c81989e0084a82ad8c88d0b4d6b (diff)
downloadsonarqube-7f32a128f3997c0fe8fa32b3462129faace2c154.tar.gz
sonarqube-7f32a128f3997c0fe8fa32b3462129faace2c154.zip
Manual merge from branch-5.1
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java89
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/System2.java9
3 files changed, 57 insertions, 47 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
index a3e02ea1211..87a8e607fae 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
@@ -61,7 +61,6 @@ import org.sonar.server.view.index.ViewIndexDefinition;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;
@@ -410,9 +409,8 @@ public class IssueIndex extends BaseIndex {
private AggregationBuilder getCreatedAtFacet(IssueQuery query, Map<String, FilterBuilder> filters, QueryBuilder esQuery) {
Date now = system.newDate();
- SimpleDateFormat tzFormat = new SimpleDateFormat("XX");
- tzFormat.setTimeZone(TimeZone.getDefault());
- String timeZoneString = tzFormat.format(now);
+
+ String timeZoneString = system.getDefaultTimeZone().getID();
DateHistogram.Interval bucketSize = DateHistogram.Interval.YEAR;
Date createdAfter = query.createdAfter();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
index a833498bdef..66c0b4fa71a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
@@ -50,15 +50,14 @@ import org.sonar.server.view.index.ViewIndexer;
import javax.annotation.Nullable;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class IssueIndexTest {
@@ -77,7 +76,12 @@ public class IssueIndexTest {
issueIndexer = new IssueIndexer(null, tester.client());
issueAuthorizationIndexer = new IssueAuthorizationIndexer(null, tester.client());
viewIndexer = new ViewIndexer(null, tester.client());
- index = new IssueIndex(tester.client(), System2.INSTANCE);
+ System2 system = mock(System2.class);
+ when(system.getDefaultTimeZone()).thenReturn(TimeZone.getTimeZone("+01:00"));
+ when(system.newDate()).thenReturn(new Date());
+
+ index = new IssueIndex(tester.client(), system);
+
}
@Test
@@ -751,14 +755,14 @@ public class IssueIndexTest {
SearchResult<IssueDoc> result = index.search(query, options);
Map<String, Long> buckets = result.getFacets().get("createdAt");
assertThat(buckets).containsOnly(
- entry("2014-08-31T01:00:00+0000", 0L),
- entry("2014-09-01T01:00:00+0000", 2L),
- entry("2014-09-02T01:00:00+0000", 1L),
- entry("2014-09-03T01:00:00+0000", 0L),
- entry("2014-09-04T01:00:00+0000", 0L),
- entry("2014-09-05T01:00:00+0000", 1L),
- entry("2014-09-06T01:00:00+0000", 0L),
- entry("2014-09-07T01:00:00+0000", 0L));
+ entry("2014-08-31T00:00:00+0000", 0L),
+ entry("2014-09-01T00:00:00+0000", 2L),
+ entry("2014-09-02T00:00:00+0000", 1L),
+ entry("2014-09-03T00:00:00+0000", 0L),
+ entry("2014-09-04T00:00:00+0000", 0L),
+ entry("2014-09-05T00:00:00+0000", 1L),
+ entry("2014-09-06T00:00:00+0000", 0L),
+ entry("2014-09-07T00:00:00+0000", 0L));
}
@Test
@@ -769,10 +773,10 @@ public class IssueIndexTest {
Map<String, Long> createdAt = index.search(IssueQuery.builder().createdAfter(DateUtils.parseDate("2014-09-01")).createdBefore(DateUtils.parseDate("2014-09-21")).build(),
SearchOptions).getFacets().get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2014-08-25T01:00:00+0000", 0L),
- entry("2014-09-01T01:00:00+0000", 4L),
- entry("2014-09-08T01:00:00+0000", 0L),
- entry("2014-09-15T01:00:00+0000", 1L));
+ entry("2014-08-25T00:00:00+0000", 0L),
+ entry("2014-09-01T00:00:00+0000", 4L),
+ entry("2014-09-08T00:00:00+0000", 0L),
+ entry("2014-09-15T00:00:00+0000", 1L));
}
@Test
@@ -783,12 +787,12 @@ public class IssueIndexTest {
Map<String, Long> createdAt = index.search(IssueQuery.builder().createdAfter(DateUtils.parseDate("2014-09-01")).createdBefore(DateUtils.parseDate("2015-01-19")).build(),
SearchOptions).getFacets().get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2014-08-01T01:00:00+0000", 0L),
- entry("2014-09-01T01:00:00+0000", 5L),
- entry("2014-10-01T01:00:00+0000", 0L),
- entry("2014-11-01T01:00:00+0000", 0L),
- entry("2014-12-01T01:00:00+0000", 0L),
- entry("2015-01-01T01:00:00+0000", 1L));
+ entry("2014-08-01T00:00:00+0000", 0L),
+ entry("2014-09-01T00:00:00+0000", 5L),
+ entry("2014-10-01T00:00:00+0000", 0L),
+ entry("2014-11-01T00:00:00+0000", 0L),
+ entry("2014-12-01T00:00:00+0000", 0L),
+ entry("2015-01-01T00:00:00+0000", 1L));
}
@Test
@@ -798,12 +802,12 @@ public class IssueIndexTest {
Map<String, Long> createdAt = index.search(IssueQuery.builder().createdAfter(DateUtils.parseDate("2011-01-01")).createdBefore(DateUtils.parseDate("2016-01-01")).build(),
SearchOptions).getFacets().get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2011-01-01T01:00:00+0000", 1L),
- entry("2012-01-01T01:00:00+0000", 0L),
- entry("2013-01-01T01:00:00+0000", 0L),
- entry("2014-01-01T01:00:00+0000", 5L),
- entry("2015-01-01T01:00:00+0000", 1L),
- entry("2016-01-01T01:00:00+0000", 0L));
+ entry("2010-01-01T00:00:00+0000", 0L),
+ entry("2011-01-01T00:00:00+0000", 1L),
+ entry("2012-01-01T00:00:00+0000", 0L),
+ entry("2013-01-01T00:00:00+0000", 0L),
+ entry("2014-01-01T00:00:00+0000", 5L),
+ entry("2015-01-01T00:00:00+0000", 1L));
}
@@ -816,14 +820,14 @@ public class IssueIndexTest {
.createdBefore(DateUtils.parseDate("2016-01-01"))
.build(), options).getFacets().get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2009-01-01T01:00:00+0000", 0L),
- entry("2010-01-01T01:00:00+0000", 0L),
- entry("2011-01-01T01:00:00+0000", 1L),
- entry("2012-01-01T01:00:00+0000", 0L),
- entry("2013-01-01T01:00:00+0000", 0L),
- entry("2014-01-01T01:00:00+0000", 5L),
- entry("2015-01-01T01:00:00+0000", 1L),
- entry("2016-01-01T01:00:00+0000", 0L));
+ entry("2008-01-01T00:00:00+0000", 0L),
+ entry("2009-01-01T00:00:00+0000", 0L),
+ entry("2010-01-01T00:00:00+0000", 0L),
+ entry("2011-01-01T00:00:00+0000", 1L),
+ entry("2012-01-01T00:00:00+0000", 0L),
+ entry("2013-01-01T00:00:00+0000", 0L),
+ entry("2014-01-01T00:00:00+0000", 5L),
+ entry("2015-01-01T00:00:00+0000", 1L));
}
@Test
@@ -833,12 +837,11 @@ public class IssueIndexTest {
Map<String, Long> createdAt = index.search(IssueQuery.builder().createdBefore(DateUtils.parseDate("2016-01-01")).build(),
SearchOptions).getFacets().get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2011-01-01T01:00:00+0000", 1L),
- entry("2012-01-01T01:00:00+0000", 0L),
- entry("2013-01-01T01:00:00+0000", 0L),
- entry("2014-01-01T01:00:00+0000", 5L),
- entry("2015-01-01T01:00:00+0000", 1L),
- entry("2016-01-01T01:00:00+0000", 0L));
+ entry("2011-01-01T00:00:00+0000", 1L),
+ entry("2012-01-01T00:00:00+0000", 0L),
+ entry("2013-01-01T00:00:00+0000", 0L),
+ entry("2014-01-01T00:00:00+0000", 5L),
+ entry("2015-01-01T00:00:00+0000", 1L));
}
@Test
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/System2.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/System2.java
index 964df41ed0d..27c5cc3e206 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/System2.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/System2.java
@@ -28,6 +28,7 @@ import javax.annotation.CheckForNull;
import java.util.Date;
import java.util.Map;
import java.util.Properties;
+import java.util.TimeZone;
/**
* Proxy over {@link java.lang.System}. It aims to improve testability of classes
@@ -127,6 +128,14 @@ public class System2 implements BatchComponent, ServerComponent {
}
/**
+ * @since 5.1
+ * @return the JVM's default time zone
+ */
+ public TimeZone getDefaultTimeZone() {
+ return TimeZone.getDefault();
+ }
+
+ /**
* Closes the object and throws an {@link java.lang.IllegalStateException} on error.
* @since 5.1
*/