]> source.dussan.org Git - sonarqube.git/commitdiff
Add IT for violations timemachine
authorGodin <mandrikov@gmail.com>
Tue, 14 Dec 2010 00:01:41 +0000 (00:01 +0000)
committerGodin <mandrikov@gmail.com>
Tue, 14 Dec 2010 00:01:41 +0000 (00:01 +0000)
tests/integration/tests/src/it/java/org/sonar/tests/integration/ViolationsTimemachineTest.java [new file with mode: 0644]

diff --git a/tests/integration/tests/src/it/java/org/sonar/tests/integration/ViolationsTimemachineTest.java b/tests/integration/tests/src/it/java/org/sonar/tests/integration/ViolationsTimemachineTest.java
new file mode 100644 (file)
index 0000000..13ab6f6
--- /dev/null
@@ -0,0 +1,69 @@
+package org.sonar.tests.integration;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.wsclient.Sonar;
+import org.sonar.wsclient.services.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class ViolationsTimemachineTest {
+
+  private static Sonar sonar;
+  private static final String PROJECT = "org.sonar.tests:violations-timemachine";
+  private static final String FILE = "org.sonar.tests:violations-timemachine:org.sonar.tests.violationstimemachine.Hello";
+
+  @BeforeClass
+  public static void buildServer() {
+    sonar = ITUtils.createSonarWsClient();
+  }
+
+  @Test
+  public void projectIsAnalyzed() {
+    assertThat(sonar.find(new ResourceQuery(PROJECT)).getName(), is("Violations timemachine"));
+    assertThat(sonar.find(new ResourceQuery(PROJECT)).getVersion(), is("1.0-SNAPSHOT"));
+    assertThat(sonar.find(new ResourceQuery(PROJECT)).getDate().getMonth(), is(10)); // November
+  }
+
+  @Test
+  public void timemachine() {
+    TimeMachineQuery query = TimeMachineQuery.create(PROJECT).setMetrics(
+        CoreMetrics.BLOCKER_VIOLATIONS_KEY,
+        CoreMetrics.CRITICAL_VIOLATIONS_KEY,
+        CoreMetrics.MAJOR_VIOLATIONS_KEY,
+        CoreMetrics.MINOR_VIOLATIONS_KEY,
+        CoreMetrics.INFO_VIOLATIONS_KEY);
+    List<TimeMachineData> snapshots = sonar.findAll(query);
+    assertThat(snapshots.size(), is(2));
+
+    TimeMachineData snapshot1 = snapshots.get(0);
+    TimeMachineData snapshot2 = snapshots.get(1);
+
+    assertThat(snapshot1.getDate().getMonth(), is(9));
+    assertThat(snapshot1.getValues(), is(Arrays.asList("0.0", "0.0", "3.0", "4.0", "0.0")));
+
+    assertThat(snapshot2.getDate().getMonth(), is(10));
+    assertThat(snapshot2.getValues(), is(Arrays.asList("0.0", "0.0", "4.0", "3.0", "0.0")));
+  }
+
+  @Test
+  public void correctLinesAndDates() {
+    ViolationQuery query = ViolationQuery.createForResource(FILE).setSeverities("MAJOR");
+    List<Violation> violations = sonar.findAll(query);
+
+    assertThat(violations.get(0).getLine(), is(8));
+    assertThat(violations.get(0).getCreatedAt().getMonth(), is(9)); // old violation
+
+    assertThat(violations.get(1).getLine(), is(13));
+    assertThat(violations.get(1).getCreatedAt().getMonth(), is(9)); // old violation
+
+    assertThat(violations.get(2).getLine(), is(18));
+    assertThat(violations.get(2).getCreatedAt().getMonth(), is(10)); // new violation
+  }
+
+}