diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2018-07-02 15:32:13 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2018-07-09 10:39:32 +0200 |
commit | abc4af5ab9751bb9babdc50bb3549d8ab53d8ce2 (patch) | |
tree | 89320bb089e5ca713da5fb1bfea59fb11aeb6bed /server/sonar-server-common/src/test/java/org | |
parent | 8c7686ec1e25d01f9b5a07077b01a27ecfe67f12 (diff) | |
download | sonarqube-abc4af5ab9751bb9babdc50bb3549d8ab53d8ce2.tar.gz sonarqube-abc4af5ab9751bb9babdc50bb3549d8ab53d8ce2.zip |
move metric shared classes to server-common
Diffstat (limited to 'server/sonar-server-common/src/test/java/org')
2 files changed, 121 insertions, 0 deletions
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/metric/CoreCustomMetricsTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/metric/CoreCustomMetricsTest.java new file mode 100644 index 00000000000..3e01a7876a6 --- /dev/null +++ b/server/sonar-server-common/src/test/java/org/sonar/server/metric/CoreCustomMetricsTest.java @@ -0,0 +1,41 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.metric; + +import org.junit.Test; +import org.sonar.api.measures.Metric; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CoreCustomMetricsTest { + + @Test + public void checkDefinitions() { + CoreCustomMetrics coreCustomMetrics = new CoreCustomMetrics(); + List<Metric> metrics = coreCustomMetrics.getMetrics(); + assertThat(metrics.size()).isGreaterThan(2); + for (Metric metric : metrics) { + assertThat(metric.getUserManaged()).isTrue(); + assertThat(metric.getDomain()).isEqualTo("Management"); + } + } +} diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/metric/DefaultMetricFinderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/metric/DefaultMetricFinderTest.java new file mode 100644 index 00000000000..a44564f01b3 --- /dev/null +++ b/server/sonar-server-common/src/test/java/org/sonar/server/metric/DefaultMetricFinderTest.java @@ -0,0 +1,80 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.metric; + +import java.util.Arrays; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.api.measures.Metric; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; +import org.sonar.db.metric.MetricDto; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.db.metric.MetricTesting.newMetricDto; + + +public class DefaultMetricFinderTest { + + @Rule + public DbTester db = DbTester.create(System2.INSTANCE); + + private DefaultMetricFinder underTest = new DefaultMetricFinder(db.getDbClient()); + + @Test + public void findAll_enabled() { + db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); + db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); + db.getDbClient().metricDao().insert(db.getSession(), newMetricDto().setEnabled(false)); + db.commit(); + + assertThat(underTest.findAll()).hasSize(2); + } + + @Test + public void findAll_by_keys() { + db.getDbClient().metricDao().insert(db.getSession(), newMetricDto().setKey("ncloc")); + db.getDbClient().metricDao().insert(db.getSession(), newMetricDto().setKey("foo")); + db.getDbClient().metricDao().insert(db.getSession(), newMetricDto().setKey("coverage")); + db.commit(); + + assertThat(underTest.findAll(Arrays.asList("ncloc", "foo"))).extracting(Metric::getKey).containsExactlyInAnyOrder("ncloc", "foo") + .doesNotContain("coverage"); + + } + + @Test + public void findById() { + MetricDto firstMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); + MetricDto secondMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); + db.commit(); + + assertThat(underTest.findById(firstMetric.getId())).extracting(Metric::getKey).containsExactly(firstMetric.getKey()); + } + + @Test + public void findByKey() { + MetricDto firstMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); + MetricDto secondMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); + db.commit(); + + assertThat(underTest.findByKey(secondMetric.getKey())).extracting(Metric::getKey).containsExactly(secondMetric.getKey()); + } +} |