aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-01-06 17:46:38 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-01-13 14:13:35 +0100
commit0242e1da3fea5a96a9f0632156b1cacdd89b9ace (patch)
tree68166c8f6ed52713ba24b5d94e9fe00616491e05 /sonar-db
parent49b3b0bc394ce675356d832e1d12459b9be543bd (diff)
downloadsonarqube-0242e1da3fea5a96a9f0632156b1cacdd89b9ace.tar.gz
sonarqube-0242e1da3fea5a96a9f0632156b1cacdd89b9ace.zip
SONAR-7135 WS api/measures/component_tree navigate through components and display measures
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/MyBatis.java2
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java4
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentDtoFunctions.java1
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentDtoWithSnapshotId.java33
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java4
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java6
-rw-r--r--sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java14
-rw-r--r--sonar-db/src/main/java/org/sonar/db/measure/MeasureMapper.java2
-rw-r--r--sonar-db/src/main/java/org/sonar/db/metric/MetricDtoFunctions.java58
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml8
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml20
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java16
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java9
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentTesting.java8
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java4
-rw-r--r--sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java66
-rw-r--r--sonar-db/src/test/java/org/sonar/db/measure/MeasureTesting.java1
-rw-r--r--sonar-db/src/test/java/org/sonar/db/metric/MetricTesting.java3
18 files changed, 197 insertions, 62 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/MyBatis.java b/sonar-db/src/main/java/org/sonar/db/MyBatis.java
index 21b20373ad9..6555942244e 100644
--- a/sonar-db/src/main/java/org/sonar/db/MyBatis.java
+++ b/sonar-db/src/main/java/org/sonar/db/MyBatis.java
@@ -34,6 +34,7 @@ import org.sonar.db.activity.ActivityMapper;
import org.sonar.db.ce.CeActivityMapper;
import org.sonar.db.ce.CeQueueMapper;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentDtoWithSnapshotId;
import org.sonar.db.component.ComponentLinkDto;
import org.sonar.db.component.ComponentLinkMapper;
import org.sonar.db.component.ComponentMapper;
@@ -164,6 +165,7 @@ public class MyBatis {
confBuilder.loadAlias("ActiveDashboard", ActiveDashboardDto.class);
confBuilder.loadAlias("Author", AuthorDto.class);
confBuilder.loadAlias("Component", ComponentDto.class);
+ confBuilder.loadAlias("ComponentWithSnapshot", ComponentDtoWithSnapshotId.class);
confBuilder.loadAlias("ComponentLink", ComponentLinkDto.class);
confBuilder.loadAlias("Dashboard", DashboardDto.class);
confBuilder.loadAlias("DuplicationUnit", DuplicationUnitDto.class);
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java
index bd66c881d5a..c98d585e368 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java
@@ -150,12 +150,12 @@ public class ComponentDao implements Dao {
return mapper(session).selectComponentsHavingSameKeyOrderedById(key);
}
- public List<ComponentDto> selectDirectChildren(DbSession dbSession, ComponentTreeQuery componentQuery) {
+ public List<ComponentDtoWithSnapshotId> selectDirectChildren(DbSession dbSession, ComponentTreeQuery componentQuery) {
RowBounds rowBounds = new RowBounds(offset(componentQuery.getPage(), componentQuery.getPageSize()), componentQuery.getPageSize());
return mapper(dbSession).selectDirectChildren(componentQuery, rowBounds);
}
- public List<ComponentDto> selectAllChildren(DbSession dbSession, ComponentTreeQuery componentQuery) {
+ public List<ComponentDtoWithSnapshotId> selectAllChildren(DbSession dbSession, ComponentTreeQuery componentQuery) {
RowBounds rowBounds = new RowBounds(offset(componentQuery.getPage(), componentQuery.getPageSize()), componentQuery.getPageSize());
return mapper(dbSession).selectAllChildren(componentQuery, rowBounds);
}
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentDtoFunctions.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentDtoFunctions.java
index d24e066f70e..db15e751d29 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentDtoFunctions.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentDtoFunctions.java
@@ -59,7 +59,6 @@ public final class ComponentDtoFunctions {
}
}
-
private enum ToKey implements Function<ComponentDto, String> {
INSTANCE;
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentDtoWithSnapshotId.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentDtoWithSnapshotId.java
new file mode 100644
index 00000000000..45ca736d67c
--- /dev/null
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentDtoWithSnapshotId.java
@@ -0,0 +1,33 @@
+/*
+ * SonarQube :: Database
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.db.component;
+
+public class ComponentDtoWithSnapshotId extends ComponentDto {
+ private Long snapshotId;
+
+ public Long getSnapshotId() {
+ return snapshotId;
+ }
+
+ public ComponentDtoWithSnapshotId setSnapshotId(Long snapshotId) {
+ this.snapshotId = snapshotId;
+ return this;
+ }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java
index 41a873a524b..5a492a554f7 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java
@@ -65,14 +65,14 @@ public interface ComponentMapper {
/**
* Return direct children components
*/
- List<ComponentDto> selectDirectChildren(@Param("query") ComponentTreeQuery componentTreeQuery, RowBounds rowBounds);
+ List<ComponentDtoWithSnapshotId> selectDirectChildren(@Param("query") ComponentTreeQuery componentTreeQuery, RowBounds rowBounds);
int countDirectChildren(@Param("query") ComponentTreeQuery componentTreeQuery);
/**
* Return all children components.
*/
- List<ComponentDto> selectAllChildren(@Param("query") ComponentTreeQuery componentTreeQuery,
+ List<ComponentDtoWithSnapshotId> selectAllChildren(@Param("query") ComponentTreeQuery componentTreeQuery,
RowBounds rowBounds);
int countAllChildren(@Param("query") ComponentTreeQuery componentTreeQuery);
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java
index ebe74a6b62a..96ac077613a 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java
@@ -28,6 +28,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.sonar.db.WildcardPosition;
+import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.FluentIterable.from;
import static java.util.Objects.requireNonNull;
import static org.sonar.db.DatabaseUtils.buildLikeValue;
@@ -163,8 +164,9 @@ public class ComponentTreeQuery {
return this;
}
- public Builder setSortFields(List<String> sorts) {
- this.sortFields = requireNonNull(sorts);
+ public Builder setSortFields(@Nullable List<String> sorts) {
+ checkArgument(sorts != null && !sorts.isEmpty());
+ this.sortFields = sorts;
return this;
}
diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java
index 49ec6e465f6..dc4c01deffe 100644
--- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureDao.java
@@ -55,7 +55,7 @@ public class MeasureDao implements Dao {
/**
* Selects all measures of a specific snapshot for the specified metric keys.
- *
+ * <p/>
* Uses by Views.
*/
public List<MeasureDto> selectBySnapshotIdAndMetricKeys(final long snapshotId, Set<String> metricKeys, final DbSession dbSession) {
@@ -69,7 +69,7 @@ public class MeasureDao implements Dao {
}
public List<PastMeasureDto> selectByComponentUuidAndProjectSnapshotIdAndMetricIds(final DbSession session, final String componentUuid, final long projectSnapshotId,
- Set<Integer> metricIds) {
+ Set<Integer> metricIds) {
return DatabaseUtils.executeLargeInputs(metricIds, new Function<List<Integer>, List<PastMeasureDto>>() {
@Override
public List<PastMeasureDto> apply(List<Integer> ids) {
@@ -105,6 +105,16 @@ public class MeasureDao implements Dao {
});
}
+ public List<MeasureDto> selectBySnapshotIdsAndMetricIds(final DbSession dbSession, List<Long> snapshotIds, final List<Integer> metricIds) {
+ return DatabaseUtils.executeLargeInputs(snapshotIds, new Function<List<Long>, List<MeasureDto>>() {
+ @Override
+ @Nonnull
+ public List<MeasureDto> apply(@Nonnull List<Long> input) {
+ return mapper(dbSession).selectBySnapshotIdsAndMetricIds(input, metricIds);
+ }
+ });
+ }
+
public void insert(DbSession session, MeasureDto measureDto) {
mapper(session).insert(measureDto);
}
diff --git a/sonar-db/src/main/java/org/sonar/db/measure/MeasureMapper.java b/sonar-db/src/main/java/org/sonar/db/measure/MeasureMapper.java
index f9b70f46e17..e9ce46a9e74 100644
--- a/sonar-db/src/main/java/org/sonar/db/measure/MeasureMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/measure/MeasureMapper.java
@@ -36,6 +36,8 @@ public interface MeasureMapper {
List<MeasureDto> selectBySnapshotAndMetrics(@Param("snapshotId") long snapshotId, @Param("metricIds") List<Integer> input);
+ List<MeasureDto> selectBySnapshotIdsAndMetricIds(@Param("snapshotIds") List<Long> snapshotIds, @Param("metricIds") List<Integer> metricIds);
+
@CheckForNull
MeasureDto selectByComponentAndMetric(@Param("componentKey") String componentKey, @Param("metricKey") String metricKey);
diff --git a/sonar-db/src/main/java/org/sonar/db/metric/MetricDtoFunctions.java b/sonar-db/src/main/java/org/sonar/db/metric/MetricDtoFunctions.java
new file mode 100644
index 00000000000..a1b0fa484e4
--- /dev/null
+++ b/sonar-db/src/main/java/org/sonar/db/metric/MetricDtoFunctions.java
@@ -0,0 +1,58 @@
+/*
+ * SonarQube :: Database
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.db.metric;
+
+import com.google.common.base.Function;
+import javax.annotation.Nonnull;
+
+/**
+ * Common functions on MetricDto
+ */
+public class MetricDtoFunctions {
+ private MetricDtoFunctions() {
+ // prevents instantiation
+ }
+
+ public static Function<MetricDto, Integer> toId() {
+ return ToId.INSTANCE;
+ }
+
+ public static Function<MetricDto, String> toKey() {
+ return ToKey.INSTANCE;
+ }
+
+ private enum ToId implements Function<MetricDto, Integer> {
+ INSTANCE;
+
+ @Override
+ public Integer apply(@Nonnull MetricDto input) {
+ return input.getId();
+ }
+ }
+
+ private enum ToKey implements Function<MetricDto, String> {
+ INSTANCE;
+
+ @Override
+ public String apply(@Nonnull MetricDto input) {
+ return input.getKey();
+ }
+ }
+}
diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index 0618022f2f8..28c94bb38f5 100644
--- a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -302,9 +302,9 @@
</where>
</sql>
- <select id="selectDirectChildren" resultType="Component">
+ <select id="selectDirectChildren" resultType="ComponentWithSnapshot">
select
- <include refid="componentColumns"/>
+ <include refid="componentColumns"/>, s.id as snapshotId
<include refid="sqlSelectByTreeQuery"/>
and s.parent_snapshot_id = #{query.baseSnapshot.id}
order by ${query.sqlSort}
@@ -316,9 +316,9 @@
and s.parent_snapshot_id = #{query.baseSnapshot.id}
</select>
- <select id="selectAllChildren" resultType="Component">
+ <select id="selectAllChildren" resultType="ComponentWithSnapshot">
select
- <include refid="componentColumns"/>
+ <include refid="componentColumns"/>, s.id as snapshotId
<include refid="sqlSelectAllChildren" />
order by ${query.sqlSort}
</select>
diff --git a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
index f2d22396374..ed8a80b3f70 100644
--- a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
@@ -92,6 +92,26 @@
</where>
</select>
+ <select id="selectBySnapshotIdsAndMetricIds" parameterType="map" resultType="Measure">
+ SELECT
+ <include refid="measureColumns"/>
+ FROM project_measures pm
+ <where>
+ pm.snapshot_id in
+ <foreach item="snapshotId" collection="snapshotIds" open="(" separator="," close=")">
+ #{snapshotId}
+ </foreach>
+ AND
+ pm.metric_id in
+ <foreach item="metricId" collection="metricIds" open="(" separator="," close=")">
+ #{metricId}
+ </foreach>
+ AND pm.rule_id is NULL
+ AND pm.characteristic_id is NULL
+ AND pm.person_id is NULL
+ </where>
+ </select>
+
<select id="selectBySnapshotAndMetrics" parameterType="map" resultType="Measure">
SELECT
<include refid="measureColumns"/>
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index 5a46d9fed37..0eaf33e3482 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -742,7 +742,7 @@ public class ComponentDaoTest {
ComponentTreeQuery query = newTreeQuery(projectSnapshot).build();
- List<ComponentDto> result = underTest.selectDirectChildren(dbSession, query);
+ List<ComponentDtoWithSnapshotId> result = underTest.selectDirectChildren(dbSession, query);
int count = underTest.countDirectChildren(dbSession, query);
assertThat(count).isEqualTo(2);
@@ -762,7 +762,7 @@ public class ComponentDaoTest {
ComponentTreeQuery query = newTreeQuery(projectSnapshot)
.setNameOrKeyQuery("file-name").build();
- List<ComponentDto> result = underTest.selectDirectChildren(dbSession, query);
+ List<ComponentDtoWithSnapshotId> result = underTest.selectDirectChildren(dbSession, query);
int count = underTest.countDirectChildren(dbSession, query);
assertThat(count).isEqualTo(1);
@@ -782,7 +782,7 @@ public class ComponentDaoTest {
ComponentTreeQuery query = newTreeQuery(projectSnapshot)
.setNameOrKeyQuery("file-key").build();
- List<ComponentDto> result = underTest.selectDirectChildren(dbSession, query);
+ List<ComponentDtoWithSnapshotId> result = underTest.selectDirectChildren(dbSession, query);
int count = underTest.countDirectChildren(dbSession, query);
assertThat(count).isEqualTo(1);
@@ -805,7 +805,7 @@ public class ComponentDaoTest {
.setAsc(false)
.build();
- List<ComponentDto> result = underTest.selectDirectChildren(dbSession, query);
+ List<ComponentDtoWithSnapshotId> result = underTest.selectDirectChildren(dbSession, query);
int count = underTest.countDirectChildren(dbSession, query);
assertThat(count).isEqualTo(9);
@@ -827,7 +827,7 @@ public class ComponentDaoTest {
.setAsc(true)
.build();
- List<ComponentDto> result = underTest.selectDirectChildren(dbSession, query);
+ List<ComponentDtoWithSnapshotId> result = underTest.selectDirectChildren(dbSession, query);
assertThat(result).extracting("uuid").containsExactly("file-uuid-3", "file-uuid-2", "file-uuid-1");
}
@@ -844,7 +844,7 @@ public class ComponentDaoTest {
ComponentTreeQuery query = newTreeQuery(moduleSnapshot).build();
- List<ComponentDto> result = underTest.selectDirectChildren(dbSession, query);
+ List<ComponentDtoWithSnapshotId> result = underTest.selectDirectChildren(dbSession, query);
assertThat(result).extracting("uuid").containsOnly("file-2-uuid");
}
@@ -861,7 +861,7 @@ public class ComponentDaoTest {
ComponentTreeQuery query = newTreeQuery(projectSnapshot).build();
- List<ComponentDto> result = underTest.selectAllChildren(dbSession, query);
+ List<ComponentDtoWithSnapshotId> result = underTest.selectAllChildren(dbSession, query);
int count = underTest.countAllChildren(dbSession, query);
assertThat(count).isEqualTo(3);
@@ -890,7 +890,7 @@ public class ComponentDaoTest {
.setAsc(false)
.build();
- List<ComponentDto> result = underTest.selectAllChildren(dbSession, query);
+ List<ComponentDtoWithSnapshotId> result = underTest.selectAllChildren(dbSession, query);
int count = underTest.countAllChildren(dbSession, query);
assertThat(count).isEqualTo(9);
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java
index 3c1f85bfba6..0727e1163d2 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java
@@ -24,6 +24,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import static org.sonar.db.component.SnapshotTesting.createForComponent;
+import static org.sonar.db.component.SnapshotTesting.newSnapshotForDeveloper;
import static org.sonar.db.component.SnapshotTesting.newSnapshotForProject;
import static org.sonar.db.component.SnapshotTesting.newSnapshotForView;
@@ -54,6 +55,14 @@ public class ComponentDbTester {
return snapshot;
}
+ public SnapshotDto insertDeveloperAndSnapshot(ComponentDto component) {
+ dbClient.componentDao().insert(dbSession, component);
+ SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newSnapshotForDeveloper(component));
+ db.commit();
+
+ return snapshot;
+ }
+
public SnapshotDto insertComponentAndSnapshot(ComponentDto component, SnapshotDto parentSnapshot) {
dbClient.componentDao().insert(dbSession, component);
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, createForComponent(component, parentSnapshot));
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentTesting.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentTesting.java
index 6e59f8a6bf9..37d04cb66ad 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentTesting.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentTesting.java
@@ -46,6 +46,10 @@ public class ComponentTesting {
.setLanguage("xoo");
}
+ public static ComponentDto newDirectory(ComponentDto module, String path) {
+ return newDirectory(module, Uuids.create(), path);
+ }
+
public static ComponentDto newDirectory(ComponentDto module, String uuid, String path) {
return newChildComponent(uuid, module)
.setKey(!path.equals("/") ? module.getKey() + ":" + path : module.getKey() + ":/")
@@ -65,10 +69,6 @@ public class ComponentTesting {
.setQualifier(Qualifiers.SUBVIEW);
}
- public static ComponentDto newDirectory(ComponentDto module, String path) {
- return newDirectory(module, Uuids.create(), path);
- }
-
public static ComponentDto newModuleDto(String uuid, ComponentDto subProjectOrProject) {
return newChildComponent(uuid, subProjectOrProject)
.setModuleUuidPath(subProjectOrProject.moduleUuidPath() + uuid + MODULE_UUID_PATH_SEP)
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java
index 9fa87e631f8..2b464c2e442 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java
@@ -19,12 +19,12 @@
*/
package org.sonar.db.component;
-import java.util.Collections;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
public class ComponentTreeQueryTest {
@@ -47,7 +47,7 @@ public class ComponentTreeQueryTest {
expectedException.expect(NullPointerException.class);
ComponentTreeQuery.builder()
- .setSortFields(Collections.<String>emptyList())
+ .setSortFields(singletonList("name"))
.build();
}
diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java
index 49fa5a33065..82018b73e1c 100644
--- a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java
@@ -96,7 +96,7 @@ public class MeasureDaoTest {
db.prepareDbUnit(getClass(), "shared.xml");
List<MeasureDto> results = underTest.selectByComponentKeyAndMetricKeys(db.getSession(), "org.struts:struts-core:src/org/struts/RequestContext.java",
- newArrayList("ncloc", "authors_by_line"));
+ newArrayList("ncloc", "authors_by_line"));
assertThat(results).hasSize(2);
results = underTest.selectByComponentKeyAndMetricKeys(db.getSession(), "org.struts:struts-core:src/org/struts/RequestContext.java", newArrayList("ncloc"));
@@ -329,8 +329,8 @@ public class MeasureDaoTest {
db.prepareDbUnit(getClass(), "shared.xml");
List<MeasureDto> measureDtos = underTest.selectByDeveloperForSnapshotAndMetrics(db.getSession(),
- DEVELOPER_ID, SNAPSHOT_ID,
- ImmutableList.of(AUTHORS_BY_LINE_METRIC_ID, COVERAGE_LINE_HITS_DATA_METRIC_ID, NCLOC_METRIC_ID));
+ DEVELOPER_ID, SNAPSHOT_ID,
+ ImmutableList.of(AUTHORS_BY_LINE_METRIC_ID, COVERAGE_LINE_HITS_DATA_METRIC_ID, NCLOC_METRIC_ID));
assertThat(measureDtos).isEmpty();
}
@@ -340,8 +340,8 @@ public class MeasureDaoTest {
db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml");
List<MeasureDto> measureDtos = underTest.selectByDeveloperForSnapshotAndMetrics(db.getSession(),
- DEVELOPER_ID, SNAPSHOT_ID,
- ImmutableList.of(AUTHORS_BY_LINE_METRIC_ID, COVERAGE_LINE_HITS_DATA_METRIC_ID, NCLOC_METRIC_ID));
+ DEVELOPER_ID, SNAPSHOT_ID,
+ ImmutableList.of(AUTHORS_BY_LINE_METRIC_ID, COVERAGE_LINE_HITS_DATA_METRIC_ID, NCLOC_METRIC_ID));
assertThat(measureDtos).extracting("id").containsOnly(30L, 31L, 32L);
}
@@ -351,8 +351,8 @@ public class MeasureDaoTest {
db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml");
List<MeasureDto> measureDtos = underTest.selectByDeveloperForSnapshotAndMetrics(db.getSession(),
- DEVELOPER_ID, SNAPSHOT_ID,
- ImmutableList.of(NCLOC_METRIC_ID));
+ DEVELOPER_ID, SNAPSHOT_ID,
+ ImmutableList.of(NCLOC_METRIC_ID));
assertThat(measureDtos).extracting("id").containsOnly(32L);
}
@@ -362,8 +362,8 @@ public class MeasureDaoTest {
db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml");
List<MeasureDto> measureDtos = underTest.selectBySnapshotAndMetrics(db.getSession(),
- SNAPSHOT_ID,
- ImmutableList.of(666));
+ SNAPSHOT_ID,
+ ImmutableList.of(666));
assertThat(measureDtos).isEmpty();
}
@@ -373,8 +373,8 @@ public class MeasureDaoTest {
db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml");
List<MeasureDto> measureDtos = underTest.selectBySnapshotAndMetrics(db.getSession(),
- SNAPSHOT_ID,
- ImmutableList.of(AUTHORS_BY_LINE_METRIC_ID, COVERAGE_LINE_HITS_DATA_METRIC_ID, NCLOC_METRIC_ID));
+ SNAPSHOT_ID,
+ ImmutableList.of(AUTHORS_BY_LINE_METRIC_ID, COVERAGE_LINE_HITS_DATA_METRIC_ID, NCLOC_METRIC_ID));
assertThat(measureDtos).extracting("id").containsOnly(20L, 21L, 22L);
}
@@ -384,8 +384,8 @@ public class MeasureDaoTest {
db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml");
List<MeasureDto> measureDtos = underTest.selectBySnapshotAndMetrics(db.getSession(),
- SNAPSHOT_ID,
- ImmutableList.of(NCLOC_METRIC_ID));
+ SNAPSHOT_ID,
+ ImmutableList.of(NCLOC_METRIC_ID));
assertThat(measureDtos).extracting("id").containsOnly(22L);
}
@@ -395,8 +395,8 @@ public class MeasureDaoTest {
db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml");
List<MeasureDto> measureDtos = underTest.selectByDeveloperForSnapshotAndMetrics(db.getSession(),
- DEVELOPER_ID, SNAPSHOT_ID,
- ImmutableList.of(666));
+ DEVELOPER_ID, SNAPSHOT_ID,
+ ImmutableList.of(666));
assertThat(measureDtos).isEmpty();
}
@@ -406,33 +406,35 @@ public class MeasureDaoTest {
db.prepareDbUnit(getClass(), "with_some_measures_for_developer.xml");
List<MeasureDto> measureDtos = underTest.selectByDeveloperForSnapshotAndMetrics(db.getSession(),
- DEVELOPER_ID, 10,
- ImmutableList.of(AUTHORS_BY_LINE_METRIC_ID, COVERAGE_LINE_HITS_DATA_METRIC_ID, NCLOC_METRIC_ID));
+ DEVELOPER_ID, 10,
+ ImmutableList.of(AUTHORS_BY_LINE_METRIC_ID, COVERAGE_LINE_HITS_DATA_METRIC_ID, NCLOC_METRIC_ID));
assertThat(measureDtos).isEmpty();
}
+ //TODO add test for selectBySnapshotIdsAndMetricIds
+
@Test
public void insert() {
db.prepareDbUnit(getClass(), "empty.xml");
underTest.insert(db.getSession(), new MeasureDto()
- .setSnapshotId(2L)
- .setMetricId(3)
- .setCharacteristicId(4)
+ .setSnapshotId(2L)
+ .setMetricId(3)
+ .setCharacteristicId(4)
.setDeveloperId(23L)
- .setRuleId(5)
- .setComponentId(6L)
- .setValue(2.0d)
- .setData("measure-value")
- .setVariation(1, 1.0d)
- .setVariation(2, 2.0d)
- .setVariation(3, 3.0d)
- .setVariation(4, 4.0d)
- .setVariation(5, 5.0d)
- .setAlertStatus("alert")
- .setAlertText("alert-text")
- .setDescription("measure-description")
+ .setRuleId(5)
+ .setComponentId(6L)
+ .setValue(2.0d)
+ .setData("measure-value")
+ .setVariation(1, 1.0d)
+ .setVariation(2, 2.0d)
+ .setVariation(3, 3.0d)
+ .setVariation(4, 4.0d)
+ .setVariation(5, 5.0d)
+ .setAlertStatus("alert")
+ .setAlertText("alert-text")
+ .setDescription("measure-description")
);
db.getSession().commit();
diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureTesting.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureTesting.java
index 5e58b6962bb..bbdd410f106 100644
--- a/sonar-db/src/test/java/org/sonar/db/measure/MeasureTesting.java
+++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureTesting.java
@@ -32,7 +32,6 @@ public class MeasureTesting {
return new MeasureDto()
.setMetricId(metricDto.getId())
.setMetricKey(metricDto.getKey())
- .setSnapshotId((long) nextInt())
.setComponentId((long) nextInt())
.setSnapshotId(snapshotId);
}
diff --git a/sonar-db/src/test/java/org/sonar/db/metric/MetricTesting.java b/sonar-db/src/test/java/org/sonar/db/metric/MetricTesting.java
index 05247b30fee..65be1a5f1bf 100644
--- a/sonar-db/src/test/java/org/sonar/db/metric/MetricTesting.java
+++ b/sonar-db/src/test/java/org/sonar/db/metric/MetricTesting.java
@@ -41,11 +41,10 @@ public class MetricTesting {
.setDeleteHistoricalData(RandomUtils.nextBoolean())
.setDirection(RandomUtils.nextInt())
.setHidden(RandomUtils.nextBoolean())
- .setEnabled(RandomUtils.nextBoolean())
+ .setEnabled(true)
.setOptimizedBestValue(RandomUtils.nextBoolean())
.setQualitative(RandomUtils.nextBoolean())
.setUserManaged(RandomUtils.nextBoolean())
.setWorstValue(RandomUtils.nextDouble());
}
-
}