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;
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;
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");
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()
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;
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);
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;
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");
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);
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");
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");
@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
@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) {