aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src/test/java
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-12-20 21:46:50 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-12-20 21:46:50 +0000
commitea3eb66a50e49b349174b1c03e9567e79f8c6596 (patch)
tree2a3391e47d5b39140f23e6be60561cdd0d0c854b /sonar-ws-client/src/test/java
parentd3bac1b2a70bd187247e6c44ba35f09e1a5a44c6 (diff)
downloadsonarqube-ea3eb66a50e49b349174b1c03e9567e79f8c6596.tar.gz
sonarqube-ea3eb66a50e49b349174b1c03e9567e79f8c6596.zip
SONAR-833 time machine WS : improve SQL requests + better support of Q model characteristics
Diffstat (limited to 'sonar-ws-client/src/test/java')
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineDataTest.java22
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineQueryTest.java52
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java77
3 files changed, 109 insertions, 42 deletions
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineDataTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineDataTest.java
deleted file mode 100644
index 6672a3acf5e..00000000000
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineDataTest.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package org.sonar.wsclient.services;
-
-import org.junit.Test;
-
-import java.util.Arrays;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
-
-public class TimeMachineDataTest {
-
- @Test
- public void valueAsDouble() {
- TimeMachineData data = new TimeMachineData().setValues(Arrays.asList(null, "20.3", "hello"));
-
- assertThat(data.getValueAsDouble(0), nullValue());
- assertThat(data.getValueAsDouble(1), is(20.3));
- assertThat(data.getValueAsDouble(2), nullValue());
- }
-
-}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineQueryTest.java
new file mode 100644
index 00000000000..86bc13d4542
--- /dev/null
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/TimeMachineQueryTest.java
@@ -0,0 +1,52 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.wsclient.JdkUtils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+public class TimeMachineQueryTest {
+
+ @Before
+ public void before() {
+ WSUtils.setInstance(new JdkUtils());
+ }
+ @Test
+ public void shouldGetUrl() {
+ TimeMachineQuery query = TimeMachineQuery.createForMetrics("12345", "ncloc", "coverage");
+ assertThat(query.getUrl(), is("/api/timemachine?resource=12345&metrics=ncloc,coverage&"));
+ }
+
+ @Test
+ public void shouldSetPeriod() throws ParseException {
+ Date from = new SimpleDateFormat("yyyy-MM-dd").parse("2010-02-18");
+ Date to = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("2010-03-25 14:59");
+ TimeMachineQuery query = TimeMachineQuery.createForMetrics("12345", "ncloc").setFrom(from).setTo(to);
+ assertThat(query.getUrl(), is("/api/timemachine?resource=12345&metrics=ncloc&fromDateTime=2010-02-18T00%3A00%3A00%2B0100&toDateTime=2010-03-25T14%3A59%3A00%2B0100&"));
+ }
+}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java
index 908658f336b..774dd1bfd81 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java
@@ -1,37 +1,74 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
package org.sonar.wsclient.unmarshallers;
import org.junit.Test;
-import org.sonar.wsclient.services.TimeMachineData;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
+import org.sonar.wsclient.services.TimeMachine;
+import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
public class TimeMachineUnmarshallerTest {
@Test
- public void toModel() throws Exception {
- TimeMachineData data = new TimeMachineUnmarshaller().toModel(WSTestUtils.loadFile("/timemachine/timemachine.json"));
-
- Date date = data.getDate();
- final Date expectedDate = new SimpleDateFormat("yyyy-MM-dd'T'kk:mm:ssZZZZ").parse("2010-12-04T15:59:23+0000");
- assertThat(date, is(expectedDate));
- List<String> values = data.getValues();
- assertThat(values.size(), is(3));
- assertThat(values.get(0), is("20.0"));
- assertThat(values.get(1), nullValue());
- assertThat(values.get(2), is("12.8"));
+ public void testToModel() throws Exception {
+ TimeMachine timeMachine = new TimeMachineUnmarshaller().toModel(WSTestUtils.loadFile("/timemachine/timemachine.json"));
+
+ // columns
+ assertThat(timeMachine.getColumns().length, is(2));
+ assertThat(timeMachine.getColumns()[0].getIndex(), is(0));
+ assertThat(timeMachine.getColumns()[0].getMetricKey(), is("ncloc"));
+ assertThat(timeMachine.getColumns()[1].getIndex(), is(1));
+ assertThat(timeMachine.getColumns()[1].getMetricKey(), is("coverage"));
+
+ // values sorted by date
+ assertThat(timeMachine.getCells().length, is(3)); // 3 days
+ assertThat(timeMachine.getCells()[0].getDate().getDate(), is(19));
+ assertThat(timeMachine.getCells()[1].getDate().getDate(), is(21));
+ assertThat(timeMachine.getCells()[2].getDate().getDate(), is(25));
+
+ assertThat(timeMachine.getCells()[0].getValues().length, is(2));
+ assertThat((Double) timeMachine.getCells()[0].getValues()[0], is(21.0));
+ assertThat((Double) timeMachine.getCells()[0].getValues()[1], is(80.0));
}
@Test
- public void many() throws Exception {
- List<TimeMachineData> data = new TimeMachineUnmarshaller().toModels(WSTestUtils.loadFile("/timemachine/many.json"));
+ public void shouldAcceptNullValues() throws Exception {
+ TimeMachine timeMachine = new TimeMachineUnmarshaller().toModel(WSTestUtils.loadFile("/timemachine/null-values.json"));
+
+ assertThat(timeMachine.getCells()[0].getValues().length, is(2));
+ assertThat(timeMachine.getCells()[0].getValues()[0], nullValue());
+ assertThat((Double) timeMachine.getCells()[0].getValues()[1], is(80.0));
- assertThat(data.size(), is(3));
+ assertThat((Double) timeMachine.getCells()[1].getValues()[0], is(29.0));
+ assertThat(timeMachine.getCells()[1].getValues()[1], nullValue());
}
+ @Test
+ public void shouldCastValues() throws Exception {
+ TimeMachine timeMachine = new TimeMachineUnmarshaller().toModel(WSTestUtils.loadFile("/timemachine/typed-values.json"));
+
+ assertThat(timeMachine.getCells()[0].getValues().length, is(2));
+ assertThat((String)timeMachine.getCells()[0].getValues()[0], is("Sonar way"));
+ assertThat((Double) timeMachine.getCells()[0].getValues()[1], is(80.0));
+
+ }
}