diff options
author | Godin <mandrikov@gmail.com> | 2010-12-14 00:01:41 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-12-14 00:01:41 +0000 |
commit | 454242aa5438d5ca6c69351e885de290dc4bb776 (patch) | |
tree | 62e1f8493bfb96ea1e394e44ec30ab3efdbf0bfd /tests | |
parent | 7b06a8b620df7137fa8629f86d35628b1f4c76af (diff) | |
download | sonarqube-454242aa5438d5ca6c69351e885de290dc4bb776.tar.gz sonarqube-454242aa5438d5ca6c69351e885de290dc4bb776.zip |
Add IT for violations timemachine
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/tests/src/it/java/org/sonar/tests/integration/ViolationsTimemachineTest.java | 69 |
1 files changed, 69 insertions, 0 deletions
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 index 00000000000..13ab6f68aa6 --- /dev/null +++ b/tests/integration/tests/src/it/java/org/sonar/tests/integration/ViolationsTimemachineTest.java @@ -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 + } + +} |