]> source.dussan.org Git - sonarqube.git/commitdiff
Fix tests when timezone is not GMT+2
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 16 Aug 2013 21:11:08 +0000 (23:11 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 16 Aug 2013 21:11:08 +0000 (23:11 +0200)
sonar-batch/src/test/java/org/sonar/batch/scan/JsonReportTest.java
sonar-batch/src/test/resources/org/sonar/batch/scan/JsonReportTest/report.json
sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java
sonar-core/src/test/java/org/sonar/core/permission/PermissionDaoTest.java
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createNonAsciiPermissionTemplate-result.xml
sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createPermissionTemplate-result.xml
sonar-ws-client/src/test/java/org/sonar/wsclient/internal/HttpRequestFactoryTest.java

index 51ad93918b4830fffae08b9496993535cf084c92..71cf7d91048c738fe6c462100aabb4551ec334ed 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.batch.scan;
 
 import com.google.common.collect.Lists;
 import org.json.JSONException;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -45,6 +46,7 @@ import java.io.IOException;
 import java.io.StringWriter;
 import java.util.Collections;
 import java.util.Locale;
+import java.util.TimeZone;
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -62,9 +64,12 @@ public class JsonReportTest {
   RuleI18nManager ruleI18nManager = mock(RuleI18nManager.class);
   Settings settings;
   IssueCache issueCache = mock(IssueCache.class);
+  TimeZone initialTimeZone;
 
   @Before
   public void setUp() {
+    initialTimeZone = TimeZone.getDefault();
+    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
     when(resource.getEffectiveKey()).thenReturn("Action.java");
     when(server.getVersion()).thenReturn("3.6");
 
@@ -73,6 +78,11 @@ public class JsonReportTest {
     jsonReport = new JsonReport(settings, fileSystem, server, ruleI18nManager, issueCache, mock(EventBus.class));
   }
 
+  @After
+  public void tearDown() throws Exception {
+    TimeZone.setDefault(initialTimeZone);
+  }
+
   @Test
   public void should_write_json() throws JSONException {
     DefaultIssue issue = new DefaultIssue()
index 6b6ead4619ec5ee2a1d7b85dc0487e390f07249e..a6a5165f1b181bee64a5f0522747f4d58d02d798 100644 (file)
@@ -11,8 +11,8 @@
     "reporter": "julien",
     "assignee": "simon",
     "effortToFix": 3.14,
-    "creationDate": "2013-04-24T00:00:00+0200",
-    "updateDate": "2013-04-25T00:00:00+0200"
+    "creationDate": "2013-04-24T00:00:00+0000",
+    "updateDate": "2013-04-25T00:00:00+0000"
   }
 ], "components": [
   {
index f0b464fb987495b11a05bec5855f63f4da476e71..825890ac7d2a8dc922f0bf69b795a09d16d0ddc7 100644 (file)
@@ -58,12 +58,12 @@ public class IssueNotificationsTest {
 
   @Test
   public void should_send_new_issues() throws Exception {
-    Date date = DateUtils.parseDateTime("2013-05-18T00:00:03+0200");
+    Date date = DateUtils.parseDateTime("2013-05-18T13:00:03+0200");
     Project project = new Project("struts").setAnalysisDate(date);
     Notification notification = issueNotifications.sendNewIssues(project, 42);
 
     assertThat(notification.getFieldValue("count")).isEqualTo("42");
-    assertThat(notification.getFieldValue("projectDate")).isEqualTo("2013-05-18T00:00:03+0200");
+    assertThat(DateUtils.parseDateTime(notification.getFieldValue("projectDate"))).isEqualTo(date);
     Mockito.verify(manager).scheduleForSending(notification);
   }
 
index 424943b66adc2e924b1e0ab371dac1380338235e..45b8bd1ca77d198fd3565d22e1e86517bb45ad8f 100644 (file)
@@ -28,6 +28,8 @@ import org.sonar.core.date.DateProvider;
 import org.sonar.core.persistence.AbstractDaoTestCase;
 import org.sonar.core.persistence.MyBatis;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
 
@@ -36,13 +38,13 @@ import static org.mockito.Mockito.*;
 
 public class PermissionDaoTest extends AbstractDaoTestCase {
 
-  private final Date now = DateUtils.parseDateTime("2013-01-02T03:04:05+0100");
-
-  private PermissionDao permissionDao;
-  private DateProvider dateProvider;
+  Date now;
+  PermissionDao permissionDao;
+  DateProvider dateProvider;
 
   @Before
-  public void setUpDao() {
+  public void setUpDao() throws ParseException {
+    now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2013-01-02 01:04:05");
     dateProvider = mock(DateProvider.class);
     stub(dateProvider.now()).toReturn(now);
     permissionDao = new PermissionDao(getMyBatis(), dateProvider);
index 962c1d62f61932c70fdc3456e09e6e5358fdf78f..d80de102071d162d65ec594817e675a38bc926de 100644 (file)
@@ -1,3 +1,3 @@
 <dataset>
-  <permission_templates id="1" name="Môü Gnô Gnèçàß" kee="mou_gno_gneca_20130102_030405" description="my description"/>
+  <permission_templates id="1" name="Môü Gnô Gnèçàß" kee="mou_gno_gneca_20130102_010405" description="my description"/>
 </dataset>
\ No newline at end of file
index 0fbf6524539d193c71062584ef0bbb32ae05595f..0c2bd559342e0fb731185c05db208f024e870041 100644 (file)
@@ -1,3 +1,3 @@
 <dataset>
-  <permission_templates id="1" name="my template" kee="my_template_20130102_030405" description="my description"/>
+  <permission_templates id="1" name="my template" kee="my_template_20130102_010405" description="my description"/>
 </dataset>
\ No newline at end of file
index 79f399cb7ea6baa94e0f47dae559ded2dd7b18f6..ff870ec59388e3a4f44904a2be494f3a7d5432bd 100644 (file)
@@ -31,6 +31,7 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Collections;
 import java.util.Date;
+import java.util.TimeZone;
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.fest.assertions.Fail.fail;
@@ -44,7 +45,7 @@ public class HttpRequestFactoryTest {
     httpServer.stubStatusCode(200).stubResponseBody("{'issues': []}");
 
     HttpRequestFactory factory = new HttpRequestFactory(httpServer.url());
-    String json = factory.get("/api/issues", Collections.<String, Object> emptyMap());
+    String json = factory.get("/api/issues", Collections.<String, Object>emptyMap());
 
     assertThat(json).isEqualTo("{'issues': []}");
     assertThat(httpServer.requestedPath()).isEqualTo("/api/issues");
@@ -54,7 +55,7 @@ public class HttpRequestFactoryTest {
   public void should_throw_illegal_state_exc_if_connect_exception() {
     HttpRequestFactory factory = new HttpRequestFactory("http://localhost:1");
     try {
-      factory.get("/api/issues", Collections.<String, Object> emptyMap());
+      factory.get("/api/issues", Collections.<String, Object>emptyMap());
       fail();
     } catch (Exception e) {
       assertThat(e).isInstanceOf(IllegalStateException.class);
@@ -68,7 +69,7 @@ public class HttpRequestFactoryTest {
     httpServer.stubStatusCode(200).stubResponseBody("{}");
 
     HttpRequestFactory factory = new HttpRequestFactory(httpServer.url());
-    String json = factory.post("/api/issues/change", Collections.<String, Object> emptyMap());
+    String json = factory.post("/api/issues/change", Collections.<String, Object>emptyMap());
 
     assertThat(json).isEqualTo("{}");
     assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/change");
@@ -79,7 +80,7 @@ public class HttpRequestFactoryTest {
     httpServer.stubStatusCode(200).stubResponseBody("{}");
 
     HttpRequestFactory factory = new HttpRequestFactory(httpServer.url()).setLogin("karadoc").setPassword("legrascestlavie");
-    String json = factory.get("/api/issues", Collections.<String, Object> emptyMap());
+    String json = factory.get("/api/issues", Collections.<String, Object>emptyMap());
 
     assertThat(json).isEqualTo("{}");
     assertThat(httpServer.requestedPath()).isEqualTo("/api/issues");
@@ -89,10 +90,10 @@ public class HttpRequestFactoryTest {
   @Test
   public void test_proxy() throws Exception {
     HttpRequestFactory factory = new HttpRequestFactory(httpServer.url())
-        .setProxyHost("localhost").setProxyPort(1)
-        .setProxyLogin("john").setProxyPassword("smith");
+      .setProxyHost("localhost").setProxyPort(1)
+      .setProxyLogin("john").setProxyPassword("smith");
     try {
-      factory.get("/api/issues", Collections.<String, Object> emptyMap());
+      factory.get("/api/issues", Collections.<String, Object>emptyMap());
       fail();
     } catch (IllegalStateException e) {
       // it's not possible to check that the proxy is correctly configured
@@ -102,18 +103,24 @@ public class HttpRequestFactoryTest {
 
   @Test
   public void should_encode_characters() {
-    HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
-    httpServer.stubResponseBody("{\"issues\": [{\"key\": \"ABCDE\"}]}");
+    TimeZone initialTimeZone = TimeZone.getDefault();
+    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+    try {
+      HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
+      httpServer.stubResponseBody("{\"issues\": [{\"key\": \"ABCDE\"}]}");
 
-    IssueClient client = new DefaultIssueClient(requestFactory);
-    client.find(IssueQuery.create().issues("ABC DE"));
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?issues=ABC%20DE");
+      IssueClient client = new DefaultIssueClient(requestFactory);
+      client.find(IssueQuery.create().issues("ABC DE"));
+      assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?issues=ABC%20DE");
 
-    client.find(IssueQuery.create().issues("ABC+BDE"));
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?issues=ABC%2BBDE");
+      client.find(IssueQuery.create().issues("ABC+BDE"));
+      assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?issues=ABC%2BBDE");
 
-    client.find(IssueQuery.create().createdAfter(toDate("2013-01-01")));
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?createdAfter=2013-01-01T00:00:00%2B0100");
+      client.find(IssueQuery.create().createdAfter(toDate("2013-01-01")));
+      assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?createdAfter=2013-01-01T00:00:00%2B0000");
+    } finally {
+      TimeZone.setDefault(initialTimeZone);
+    }
   }
 
   protected static Date toDate(String sDate) {