]> source.dussan.org Git - sonarqube.git/commitdiff
move metric related classes in a specific package - SONAR-6570 325/head
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 22 May 2015 15:54:41 +0000 (17:54 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 26 May 2015 11:49:12 +0000 (13:49 +0200)
50 files changed:
server/sonar-server/src/main/java/org/sonar/server/batch/GlobalAction.java
server/sonar-server/src/main/java/org/sonar/server/computation/measure/MetricCache.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationsStep.java
server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java
server/sonar-server/src/main/java/org/sonar/server/measure/persistence/MetricDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/measure/ws/ListAction.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/measure/ws/MetricsWs.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/measure/ws/MetricsWsAction.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/metric/persistence/MetricDao.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/metric/persistence/package-info.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/metric/ws/ListAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/metric/ws/MetricsWs.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/metric/ws/MetricsWsAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/main/resources/org/sonar/server/measure/ws/example-list.json [deleted file]
server/sonar-server/src/main/resources/org/sonar/server/metric/ws/example-list.json [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/batch/GlobalActionTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/measure/MetricCacheTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/persistence/MetricDaoTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/measure/ws/ListActionTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/measure/ws/MetricTesting.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/measure/ws/MetricsWsTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/metric/persistence/MetricDaoTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/metric/ws/ListActionTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/metric/ws/MetricTesting.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/metric/ws/MetricsWsTest.java [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MetricDaoTest/manual_metric.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MetricDaoTest/shared.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/measure/ws/ListActionTest/list_metrics.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/metric/persistence/MetricDaoTest/manual_metric.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/metric/persistence/MetricDaoTest/shared.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/metric/ws/ListActionTest/list_metrics.json [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/measure/db/MetricDto.java [deleted file]
sonar-core/src/main/java/org/sonar/core/measure/db/MetricMapper.java [deleted file]
sonar-core/src/main/java/org/sonar/core/metric/db/MetricDto.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/metric/db/MetricMapper.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/metric/db/package-info.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shared.xml [new file with mode: 0644]
sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shouldInsert-result.xml [new file with mode: 0644]
sonar-core/src/main/resources/org/sonar/core/measure/db/MetricMapper.xml [deleted file]
sonar-core/src/main/resources/org/sonar/core/metric/db/MetricMapper.xml [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/measure/db/MetricDtoTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/metric/db/MetricDtoTest.java [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shared.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shouldInsert-result.xml [deleted file]

index 84529cae0b717255333eb810b184b42cc29cd3c7..23956d9bbba3c4b8c27dc09fe2f855720db00a6a 100644 (file)
@@ -25,7 +25,7 @@ import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.batch.protocol.input.GlobalRepositories;
-import org.sonar.core.measure.db.MetricDto;
+import org.sonar.core.metric.db.MetricDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.persistence.MyBatis;
index febaaf9e6a3734a009caa1bf3c4f3a9c59dae070..ac130fda5545d468641a49e070e6e06cc8762d3d 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.computation.measure;
 
 import com.google.common.base.Function;
 import com.google.common.collect.Maps;
-import org.sonar.core.measure.db.MetricDto;
+import org.sonar.core.metric.db.MetricDto;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.persistence.MyBatis;
 import org.sonar.server.db.DbClient;
index fd678891c96d449d6b1e6672801a765ff3fb96ed..e6cb38a50faeb233349062aba18720a61da3e26c 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.batch.protocol.output.BatchReport.Range;
 import org.sonar.batch.protocol.output.BatchReportReader;
 import org.sonar.core.measure.db.MeasureDto;
-import org.sonar.core.measure.db.MetricDto;
+import org.sonar.core.metric.db.MetricDto;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.persistence.MyBatis;
 import org.sonar.server.computation.ComputationContext;
index 56334b663af760b1324a38cbb2da33e627a13c36..6e6df811f34fde5fa7526bc25c9c5487cf452249 100644 (file)
@@ -48,7 +48,7 @@ import org.sonar.server.dashboard.db.WidgetPropertyDao;
 import org.sonar.server.event.db.EventDao;
 import org.sonar.server.issue.db.IssueDao;
 import org.sonar.server.measure.persistence.MeasureDao;
-import org.sonar.server.measure.persistence.MetricDao;
+import org.sonar.server.metric.persistence.MetricDao;
 import org.sonar.server.qualityprofile.db.ActiveRuleDao;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.server.source.db.FileSourceDao;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/persistence/MetricDao.java b/server/sonar-server/src/main/java/org/sonar/server/measure/persistence/MetricDao.java
deleted file mode 100644 (file)
index 32bf681..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.measure.persistence;
-
-import com.google.common.collect.Maps;
-import org.apache.ibatis.session.RowBounds;
-import org.sonar.api.server.ServerSide;
-import org.sonar.core.measure.db.MetricDto;
-import org.sonar.core.measure.db.MetricMapper;
-import org.sonar.core.persistence.DaoComponent;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.server.es.SearchOptions;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import java.util.List;
-import java.util.Map;
-
-@ServerSide
-public class MetricDao implements DaoComponent {
-
-  @CheckForNull
-  public MetricDto selectByKey(DbSession session, String key) {
-    return session.getMapper(MetricMapper.class).selectByKey(key);
-  }
-
-  public List<MetricDto> selectEnabled(DbSession session) {
-    return session.getMapper(MetricMapper.class).selectAllEnabled();
-  }
-
-  public List<MetricDto> selectEnabled(DbSession session, @Nullable Boolean isCustom, SearchOptions searchOptions) {
-    Map<String, Object> properties = Maps.newHashMapWithExpectedSize(1);
-    if (isCustom != null) {
-      properties.put("isCustom", isCustom);
-    }
-
-    return session.getMapper(MetricMapper.class).selectAllEnabled(properties, new RowBounds(searchOptions.getOffset(), searchOptions.getLimit()));
-  }
-
-  public void insert(DbSession session, MetricDto dto) {
-    session.getMapper(MetricMapper.class).insert(dto);
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ListAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ListAction.java
deleted file mode 100644 (file)
index 9ba67c1..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.measure.ws;
-
-import org.sonar.api.measures.Metric;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.server.ws.WebService.Param;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.core.measure.db.MetricDto;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.es.SearchOptions;
-
-import javax.annotation.Nullable;
-
-import java.util.List;
-import java.util.Set;
-
-import static com.google.common.collect.Sets.newHashSet;
-
-public class ListAction implements MetricsWsAction {
-
-  public static final String PARAM_IS_CUSTOM = "is_custom";
-
-  public static final String FIELD_ID = "id";
-  public static final String FIELD_KEY = "key";
-  public static final String FIELD_NAME = "name";
-  public static final String FIELD_DESCRIPTION = "description";
-  public static final String FIELD_DOMAIN = "domain";
-  public static final String FIELD_TYPE = "type";
-  private static final Set<String> POSSIBLE_FIELDS = newHashSet(FIELD_ID, FIELD_KEY, FIELD_NAME, FIELD_DESCRIPTION, FIELD_DOMAIN, FIELD_TYPE);
-
-  private final DbClient dbClient;
-
-  public ListAction(DbClient dbClient) {
-    this.dbClient = dbClient;
-  }
-
-  @Override
-  public void define(WebService.NewController context) {
-    WebService.NewAction action = context.createAction("list")
-      .setSince("5.2")
-      .setResponseExample(getClass().getResource("example-list.json"))
-      .addPagingParams(100)
-      .addFieldsParam(POSSIBLE_FIELDS)
-      .setHandler(this);
-
-    action.createParam(PARAM_IS_CUSTOM)
-      .setExampleValue("true")
-      .setDescription("Choose custom metrics following 3 cases:" +
-        "<ul>" +
-        "<li>true: only custom metrics are returned</li>" +
-        "<li>false: only non custom metrics are returned</li>" +
-        "<li>not specified: all metrics are returned</li>" +
-        "</ul>");
-  }
-
-  @Override
-  public void handle(Request request, Response response) throws Exception {
-    SearchOptions searchOptions = new SearchOptions()
-      .setPage(request.mandatoryParamAsInt(Param.PAGE),
-        request.mandatoryParamAsInt(Param.PAGE_SIZE));
-    Boolean isCustom = request.paramAsBoolean(PARAM_IS_CUSTOM);
-    DbSession dbSession = dbClient.openSession(false);
-    try {
-      List<MetricDto> metrics = dbClient.metricDao().selectEnabled(dbSession, isCustom, searchOptions);
-      JsonWriter json = response.newJsonWriter();
-      json.beginObject();
-      Set<String> desiredFields = desiredFields(request.paramAsStrings(Param.FIELDS));
-      writeMetrics(json, metrics, desiredFields);
-      json.endObject();
-      json.close();
-    } finally {
-      MyBatis.closeQuietly(dbSession);
-    }
-  }
-
-  private Set<String> desiredFields(@Nullable List<String> fields) {
-    if (fields == null || fields.isEmpty()) {
-      return POSSIBLE_FIELDS;
-    }
-
-    return newHashSet(fields);
-  }
-
-  private void writeMetrics(JsonWriter json, List<MetricDto> metrics, Set<String> desiredFields) {
-    json.name("metrics");
-    json.beginArray();
-    for (MetricDto metric : metrics) {
-      json.beginObject();
-      json.prop(FIELD_ID, String.valueOf(metric.getId()));
-      json.prop(FIELD_KEY, metric.getKey());
-      writeIfDesired(json, FIELD_NAME, metric.getShortName(), desiredFields);
-      writeIfDesired(json, FIELD_DESCRIPTION, metric.getDescription(), desiredFields);
-      writeIfDesired(json, FIELD_DOMAIN, metric.getDomain(), desiredFields);
-      writeIfDesired(json, FIELD_TYPE, Metric.ValueType.descriptionOf(metric.getValueType()), desiredFields);
-      json.endObject();
-    }
-    json.endArray();
-  }
-
-  private void writeIfDesired(JsonWriter json, String field, String value, Set<String> desiredFields) {
-    if (desiredFields.contains(field)) {
-      json.prop(field, value);
-    }
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/MetricsWs.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/MetricsWs.java
deleted file mode 100644 (file)
index 2f352ef..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.measure.ws;
-
-import org.sonar.api.server.ws.RailsHandler;
-import org.sonar.api.server.ws.WebService;
-
-public class MetricsWs implements WebService {
-
-  private final MetricsWsAction[] actions;
-
-  public MetricsWs(MetricsWsAction... actions) {
-    this.actions = actions;
-  }
-
-  @Override
-  public void define(Context context) {
-    NewController controller = context.createController("api/metrics");
-    controller.setDescription("Metrics management");
-    controller.setSince("2.6");
-
-    for (MetricsWsAction action : actions) {
-      action.define(controller);
-    }
-    defineIndexAction(controller);
-
-    controller.done();
-  }
-
-  private void defineIndexAction(NewController controller) {
-    controller.createAction("index")
-      .setDescription("Documentation of this web service is available <a href=\"http://redirect.sonarsource.com/doc/old-web-service-api.html\">here</a>")
-      .setSince("2.6")
-      .setHandler(RailsHandler.INSTANCE);
-  }
-
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/MetricsWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/ws/MetricsWsAction.java
deleted file mode 100644 (file)
index 61b28ba..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.measure.ws;
-
-import org.sonar.server.ws.WsAction;
-
-public interface MetricsWsAction extends WsAction {
-  // marker interface
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/persistence/MetricDao.java b/server/sonar-server/src/main/java/org/sonar/server/metric/persistence/MetricDao.java
new file mode 100644 (file)
index 0000000..ae46328
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.persistence;
+
+import com.google.common.collect.Maps;
+import org.apache.ibatis.session.RowBounds;
+import org.sonar.api.server.ServerSide;
+import org.sonar.core.metric.db.MetricDto;
+import org.sonar.core.metric.db.MetricMapper;
+import org.sonar.core.persistence.DaoComponent;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.server.es.SearchOptions;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import java.util.List;
+import java.util.Map;
+
+@ServerSide
+public class MetricDao implements DaoComponent {
+
+  @CheckForNull
+  public MetricDto selectByKey(DbSession session, String key) {
+    return session.getMapper(MetricMapper.class).selectByKey(key);
+  }
+
+  public List<MetricDto> selectEnabled(DbSession session) {
+    return session.getMapper(MetricMapper.class).selectAllEnabled();
+  }
+
+  public List<MetricDto> selectEnabled(DbSession session, @Nullable Boolean isCustom, SearchOptions searchOptions) {
+    Map<String, Object> properties = Maps.newHashMapWithExpectedSize(1);
+    if (isCustom != null) {
+      properties.put("isCustom", isCustom);
+    }
+
+    return session.getMapper(MetricMapper.class).selectAllEnabled(properties, new RowBounds(searchOptions.getOffset(), searchOptions.getLimit()));
+  }
+
+  public void insert(DbSession session, MetricDto dto) {
+    session.getMapper(MetricMapper.class).insert(dto);
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/persistence/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/metric/persistence/package-info.java
new file mode 100644 (file)
index 0000000..2b47d5b
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.server.metric.persistence;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/ListAction.java b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/ListAction.java
new file mode 100644 (file)
index 0000000..d77523a
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.ws;
+
+import org.sonar.api.measures.Metric;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.server.ws.WebService.Param;
+import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.core.metric.db.MetricDto;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.MyBatis;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.es.SearchOptions;
+
+import javax.annotation.Nullable;
+
+import java.util.List;
+import java.util.Set;
+
+import static com.google.common.collect.Sets.newHashSet;
+
+public class ListAction implements MetricsWsAction {
+
+  public static final String PARAM_IS_CUSTOM = "is_custom";
+
+  public static final String FIELD_ID = "id";
+  public static final String FIELD_KEY = "key";
+  public static final String FIELD_NAME = "name";
+  public static final String FIELD_DESCRIPTION = "description";
+  public static final String FIELD_DOMAIN = "domain";
+  public static final String FIELD_TYPE = "type";
+  private static final Set<String> POSSIBLE_FIELDS = newHashSet(FIELD_ID, FIELD_KEY, FIELD_NAME, FIELD_DESCRIPTION, FIELD_DOMAIN, FIELD_TYPE);
+
+  private final DbClient dbClient;
+
+  public ListAction(DbClient dbClient) {
+    this.dbClient = dbClient;
+  }
+
+  @Override
+  public void define(WebService.NewController context) {
+    WebService.NewAction action = context.createAction("list")
+      .setSince("5.2")
+      .setResponseExample(getClass().getResource("example-list.json"))
+      .addPagingParams(100)
+      .addFieldsParam(POSSIBLE_FIELDS)
+      .setHandler(this);
+
+    action.createParam(PARAM_IS_CUSTOM)
+      .setExampleValue("true")
+      .setDescription("Choose custom metrics following 3 cases:" +
+        "<ul>" +
+        "<li>true: only custom metrics are returned</li>" +
+        "<li>false: only non custom metrics are returned</li>" +
+        "<li>not specified: all metrics are returned</li>" +
+        "</ul>");
+  }
+
+  @Override
+  public void handle(Request request, Response response) throws Exception {
+    SearchOptions searchOptions = new SearchOptions()
+      .setPage(request.mandatoryParamAsInt(Param.PAGE),
+        request.mandatoryParamAsInt(Param.PAGE_SIZE));
+    Boolean isCustom = request.paramAsBoolean(PARAM_IS_CUSTOM);
+    DbSession dbSession = dbClient.openSession(false);
+    try {
+      List<MetricDto> metrics = dbClient.metricDao().selectEnabled(dbSession, isCustom, searchOptions);
+      JsonWriter json = response.newJsonWriter();
+      json.beginObject();
+      Set<String> desiredFields = desiredFields(request.paramAsStrings(Param.FIELDS));
+      writeMetrics(json, metrics, desiredFields);
+      json.endObject();
+      json.close();
+    } finally {
+      MyBatis.closeQuietly(dbSession);
+    }
+  }
+
+  private Set<String> desiredFields(@Nullable List<String> fields) {
+    if (fields == null || fields.isEmpty()) {
+      return POSSIBLE_FIELDS;
+    }
+
+    return newHashSet(fields);
+  }
+
+  private void writeMetrics(JsonWriter json, List<MetricDto> metrics, Set<String> desiredFields) {
+    json.name("metrics");
+    json.beginArray();
+    for (MetricDto metric : metrics) {
+      json.beginObject();
+      json.prop(FIELD_ID, String.valueOf(metric.getId()));
+      json.prop(FIELD_KEY, metric.getKey());
+      writeIfDesired(json, FIELD_NAME, metric.getShortName(), desiredFields);
+      writeIfDesired(json, FIELD_DESCRIPTION, metric.getDescription(), desiredFields);
+      writeIfDesired(json, FIELD_DOMAIN, metric.getDomain(), desiredFields);
+      writeIfDesired(json, FIELD_TYPE, Metric.ValueType.descriptionOf(metric.getValueType()), desiredFields);
+      json.endObject();
+    }
+    json.endArray();
+  }
+
+  private void writeIfDesired(JsonWriter json, String field, String value, Set<String> desiredFields) {
+    if (desiredFields.contains(field)) {
+      json.prop(field, value);
+    }
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/MetricsWs.java b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/MetricsWs.java
new file mode 100644 (file)
index 0000000..0d6f060
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.ws;
+
+import org.sonar.api.server.ws.RailsHandler;
+import org.sonar.api.server.ws.WebService;
+
+public class MetricsWs implements WebService {
+
+  private final MetricsWsAction[] actions;
+
+  public MetricsWs(MetricsWsAction... actions) {
+    this.actions = actions;
+  }
+
+  @Override
+  public void define(Context context) {
+    NewController controller = context.createController("api/metrics");
+    controller.setDescription("Metrics management");
+    controller.setSince("2.6");
+
+    for (MetricsWsAction action : actions) {
+      action.define(controller);
+    }
+    defineIndexAction(controller);
+
+    controller.done();
+  }
+
+  private void defineIndexAction(NewController controller) {
+    controller.createAction("index")
+      .setDescription("Documentation of this web service is available <a href=\"http://redirect.sonarsource.com/doc/old-web-service-api.html\">here</a>")
+      .setSince("2.6")
+      .setHandler(RailsHandler.INSTANCE);
+  }
+
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/metric/ws/MetricsWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/MetricsWsAction.java
new file mode 100644 (file)
index 0000000..e9a6f0e
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.ws;
+
+import org.sonar.server.ws.WsAction;
+
+public interface MetricsWsAction extends WsAction {
+  // marker interface
+}
index 0be187f699df46c563557d45525602e5f324fe75..4fa1e41d2aa9005a04be3e665f0610bc557cdeec 100644 (file)
@@ -49,7 +49,7 @@ import org.sonar.server.event.db.EventDao;
 import org.sonar.server.issue.db.IssueDao;
 import org.sonar.server.issue.index.IssueIndex;
 import org.sonar.server.measure.persistence.MeasureDao;
-import org.sonar.server.measure.persistence.MetricDao;
+import org.sonar.server.metric.persistence.MetricDao;
 import org.sonar.server.platform.DatabaseServerCompatibility;
 import org.sonar.server.platform.DefaultServerFileSystem;
 import org.sonar.server.platform.Platform;
index a7af1692d9672822af58461906e433b33724b9a0..192c9fecd6538c67119d91ed11ee87726d07344a 100644 (file)
@@ -133,8 +133,8 @@ import org.sonar.server.measure.MeasureFilterEngine;
 import org.sonar.server.measure.MeasureFilterExecutor;
 import org.sonar.server.measure.MeasureFilterFactory;
 import org.sonar.server.measure.ws.ManualMeasuresWs;
-import org.sonar.server.measure.ws.MetricsWs;
 import org.sonar.server.measure.ws.TimeMachineWs;
+import org.sonar.server.metric.ws.MetricsWs;
 import org.sonar.server.notifications.NotificationCenter;
 import org.sonar.server.notifications.NotificationService;
 import org.sonar.server.permission.InternalPermissionService;
@@ -432,7 +432,7 @@ public class PlatformLevel4 extends PlatformLevel {
       TimeMachineWs.class,
       ManualMeasuresWs.class,
       MetricsWs.class,
-      org.sonar.server.measure.ws.ListAction.class,
+      org.sonar.server.metric.ws.ListAction.class,
 
       // quality gates
       QualityGateDao.class,
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/example-list.json b/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/example-list.json
deleted file mode 100644 (file)
index 3a7a4dd..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-{
-  "metrics": [
-    {
-      "id": "23",
-      "key": "team_size",
-      "name": "Team size",
-      "description": "Number of people in the team",
-      "domain": "Management",
-      "type": "INT"
-    },
-    {
-      "id": "2",
-      "key": "uncovered_lines",
-      "name": "Uncovered lines",
-      "description": "Uncovered lines",
-      "domain": "Tests",
-      "type": "INT"
-    }
-  ],
-  "total": 2,
-  "p": 1,
-  "ps": 100
-}
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/metric/ws/example-list.json b/server/sonar-server/src/main/resources/org/sonar/server/metric/ws/example-list.json
new file mode 100644 (file)
index 0000000..3a7a4dd
--- /dev/null
@@ -0,0 +1,23 @@
+{
+  "metrics": [
+    {
+      "id": "23",
+      "key": "team_size",
+      "name": "Team size",
+      "description": "Number of people in the team",
+      "domain": "Management",
+      "type": "INT"
+    },
+    {
+      "id": "2",
+      "key": "uncovered_lines",
+      "name": "Uncovered lines",
+      "description": "Uncovered lines",
+      "domain": "Tests",
+      "type": "INT"
+    }
+  ],
+  "total": 2,
+  "p": 1,
+  "ps": 100
+}
index b9ffed89f199d90dac9093a26d0b6c4ff17cecc3..3f26d051c4fd9c98cb9c7d0d4af59cb6a500f118 100644 (file)
@@ -27,14 +27,14 @@ import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.core.measure.db.MetricDto;
+import org.sonar.core.metric.db.MetricDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.properties.PropertiesDao;
 import org.sonar.core.properties.PropertyDto;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.measure.persistence.MetricDao;
+import org.sonar.server.metric.persistence.MetricDao;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.WsTester;
 
index ef27d3ba663ea4fd748ec66dddd30457907f947c..8670bb1821e508121009389ebf24cd9b455567d6 100644 (file)
@@ -26,7 +26,7 @@ import org.junit.Test;
 import org.sonar.core.persistence.DbTester;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.measure.persistence.MetricDao;
+import org.sonar.server.metric.persistence.MetricDao;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
index 2b96c2b4b6ab32d7b8daae10704fa31d6084ce07..67c9dfc2781574e91f949859f7f62c49ccbe2bba 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.batch.protocol.output.BatchReport.Range;
 import org.sonar.batch.protocol.output.BatchReportReader;
 import org.sonar.batch.protocol.output.BatchReportWriter;
-import org.sonar.core.measure.db.MetricDto;
+import org.sonar.core.metric.db.MetricDto;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.persistence.DbTester;
 import org.sonar.server.computation.ComputationContext;
@@ -45,7 +45,7 @@ import org.sonar.server.computation.component.DbComponentsRefCache;
 import org.sonar.server.computation.component.DbComponentsRefCache.DbComponent;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.measure.persistence.MeasureDao;
-import org.sonar.server.measure.persistence.MetricDao;
+import org.sonar.server.metric.persistence.MetricDao;
 import org.sonar.test.DbTests;
 
 import java.io.File;
index 4a75cd23e327c1e3e82c214f22584fb5a5a90068..cc0acaff668e3306318e52c0c5b8e0fcf4dea254 100644 (file)
 
 package org.sonar.server.computation.step;
 
-import java.io.File;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
@@ -44,7 +39,7 @@ import org.sonar.batch.protocol.output.BatchReportReader;
 import org.sonar.batch.protocol.output.BatchReportWriter;
 import org.sonar.core.component.ComponentDto;
 import org.sonar.core.measure.db.MeasureDto;
-import org.sonar.core.measure.db.MetricDto;
+import org.sonar.core.metric.db.MetricDto;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.persistence.DbTester;
 import org.sonar.core.rule.RuleDto;
@@ -59,11 +54,17 @@ import org.sonar.server.computation.language.LanguageRepository;
 import org.sonar.server.computation.measure.MetricCache;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.measure.persistence.MeasureDao;
-import org.sonar.server.measure.persistence.MetricDao;
+import org.sonar.server.metric.persistence.MetricDao;
 import org.sonar.server.rule.RuleTesting;
 import org.sonar.server.rule.db.RuleDao;
 import org.sonar.test.DbTests;
 
+import java.io.File;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 
index 884c854b79a1593207e4e0e7fcf01787c89bfff1..b764fed99392a6a162a4cec36cb207a0c0b986ae 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.batch.protocol.Constants;
 import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.batch.protocol.output.BatchReportReader;
 import org.sonar.batch.protocol.output.BatchReportWriter;
-import org.sonar.core.measure.db.MetricDto;
+import org.sonar.core.metric.db.MetricDto;
 import org.sonar.core.persistence.DbTester;
 import org.sonar.server.computation.ComputationContext;
 import org.sonar.server.computation.component.DbComponentsRefCache;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/persistence/MetricDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/persistence/MetricDaoTest.java
deleted file mode 100644 (file)
index 06039d9..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.measure.persistence;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.sonar.core.measure.db.MetricDto;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.DbTester;
-import org.sonar.test.DbTests;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Category(DbTests.class)
-public class MetricDaoTest {
-
-  @ClassRule
-  public static DbTester dbTester = new DbTester();
-
-  DbSession session;
-
-  MetricDao dao;
-
-  @Before
-  public void createDao() {
-    dbTester.truncateTables();
-    session = dbTester.myBatis().openSession(false);
-    dao = new MetricDao();
-  }
-
-  @After
-  public void tearDown() {
-    session.close();
-  }
-
-  @Test
-  public void get_by_key() {
-    dbTester.prepareDbUnit(getClass(), "shared.xml");
-
-    MetricDto result = dao.selectByKey(session, "coverage");
-    assertThat(result.getId()).isEqualTo(2);
-    assertThat(result.getKey()).isEqualTo("coverage");
-    assertThat(result.getShortName()).isEqualTo("Coverage");
-    assertThat(result.getDescription()).isEqualTo("Coverage by unit tests");
-    assertThat(result.getDomain()).isEqualTo("Tests");
-    assertThat(result.getValueType()).isEqualTo("PERCENT");
-    assertThat(result.getOrigin()).isEqualTo("JAV");
-    assertThat(result.getDirection()).isEqualTo(1);
-    assertThat(result.isQualitative()).isTrue();
-    assertThat(result.isUserManaged()).isFalse();
-    assertThat(result.getWorstValue()).isEqualTo(0d);
-    assertThat(result.getBestValue()).isEqualTo(100d);
-    assertThat(result.isOptimizedBestValue()).isFalse();
-    assertThat(result.isDeleteHistoricalData()).isFalse();
-    assertThat(result.isHidden()).isFalse();
-    assertThat(result.isEnabled()).isTrue();
-
-    // Disabled metrics are returned
-    result = dao.selectByKey(session, "disabled");
-    assertThat(result.getId()).isEqualTo(3);
-    assertThat(result.isEnabled()).isFalse();
-  }
-
-  @Test
-  public void get_manual_metric() {
-    dbTester.prepareDbUnit(getClass(), "manual_metric.xml");
-
-    MetricDto result = dao.selectByKey(session, "manual");
-    assertThat(result.getId()).isEqualTo(1);
-    assertThat(result.getKey()).isEqualTo("manual");
-    assertThat(result.getShortName()).isEqualTo("Manual metric");
-    assertThat(result.getDescription()).isEqualTo("Manual metric");
-    assertThat(result.getDomain()).isNullOrEmpty();
-    assertThat(result.getValueType()).isEqualTo("INT");
-    assertThat(result.getOrigin()).isEqualTo("GUI");
-    assertThat(result.getDirection()).isEqualTo(0);
-    assertThat(result.isQualitative()).isFalse();
-    assertThat(result.isUserManaged()).isTrue();
-    assertThat(result.getWorstValue()).isNull();
-    assertThat(result.getBestValue()).isNull();
-    assertThat(result.isOptimizedBestValue()).isNull();
-    assertThat(result.isDeleteHistoricalData()).isNull();
-    assertThat(result.isHidden()).isNull();
-    assertThat(result.isEnabled()).isTrue();
-  }
-
-  @Test
-  public void find_all_enabled() {
-    dbTester.prepareDbUnit(getClass(), "shared.xml");
-
-    assertThat(dao.selectEnabled(session)).hasSize(2);
-  }
-
-  @Test
-  public void insert() {
-    dao.insert(session, new MetricDto()
-      .setId(1)
-      .setKey("coverage")
-      .setShortName("Coverage")
-      .setDescription("Coverage by unit tests")
-      .setDomain("Tests")
-      .setValueType("PERCENT")
-      .setQualitative(true)
-      .setUserManaged(true)
-      .setWorstValue(0d)
-      .setBestValue(100d)
-      .setOptimizedBestValue(true)
-      .setDirection(1)
-      .setOrigin("JAV")
-      .setHidden(true)
-      .setDeleteHistoricalData(true)
-      .setEnabled(true));
-
-    MetricDto result = dao.selectByKey(session, "coverage");
-    assertThat(result.getId()).isNotNull();
-    assertThat(result.getKey()).isEqualTo("coverage");
-    assertThat(result.getShortName()).isEqualTo("Coverage");
-    assertThat(result.getDescription()).isEqualTo("Coverage by unit tests");
-    assertThat(result.getDomain()).isEqualTo("Tests");
-    assertThat(result.getValueType()).isEqualTo("PERCENT");
-    assertThat(result.getOrigin()).isEqualTo("JAV");
-    assertThat(result.getDirection()).isEqualTo(1);
-    assertThat(result.isQualitative()).isTrue();
-    assertThat(result.isUserManaged()).isTrue();
-    assertThat(result.getWorstValue()).isEqualTo(0d);
-    assertThat(result.getBestValue()).isEqualTo(100d);
-    assertThat(result.isOptimizedBestValue()).isTrue();
-    assertThat(result.isDeleteHistoricalData()).isTrue();
-    assertThat(result.isHidden()).isTrue();
-    assertThat(result.isEnabled()).isTrue();
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ListActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ListActionTest.java
deleted file mode 100644 (file)
index 4bbcb9b..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.measure.ws;
-
-import org.apache.commons.lang.StringUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.sonar.api.server.ws.WebService.Param;
-import org.sonar.core.measure.db.MetricDto;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.DbTester;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.measure.persistence.MetricDao;
-import org.sonar.server.ws.WsTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.measure.ws.ListAction.PARAM_IS_CUSTOM;
-
-public class ListActionTest {
-
-  @ClassRule
-  public static DbTester db = new DbTester();
-  DbClient dbClient;
-  DbSession dbSession;
-  WsTester ws;
-
-  @Before
-  public void setUp() {
-    dbClient = new DbClient(db.database(), db.myBatis(), new MetricDao());
-    dbSession = dbClient.openSession(false);
-    ws = new WsTester(new MetricsWs(new ListAction(dbClient)));
-    db.truncateTables();
-  }
-
-  @After
-  public void tearDown() {
-    dbSession.close();
-  }
-
-  @Test
-  public void list_metrics_in_database() throws Exception {
-    insertNewCustomMetric("1", "2", "3");
-
-    WsTester.Result result = newRequest().execute();
-
-    result.assertJson(getClass(), "list_metrics.json");
-  }
-
-  @Test
-  public void list_metrics_ordered_by_name_case_insensitive() throws Exception {
-    insertNewCustomMetric("3", "1", "2");
-
-    String firstResult = newRequest().setParam(Param.PAGE, "1").setParam(Param.PAGE_SIZE, "1").execute().outputAsString();
-    String secondResult = newRequest().setParam(Param.PAGE, "2").setParam(Param.PAGE_SIZE, "1").execute().outputAsString();
-    String thirdResult = newRequest().setParam(Param.PAGE, "3").setParam(Param.PAGE_SIZE, "1").execute().outputAsString();
-
-    assertThat(firstResult).contains("custom-key-1").doesNotContain("custom-key-2").doesNotContain("custom-key-3");
-    assertThat(secondResult).contains("custom-key-2").doesNotContain("custom-key-1").doesNotContain("custom-key-3");
-    assertThat(thirdResult).contains("custom-key-3").doesNotContain("custom-key-1").doesNotContain("custom-key-2");
-  }
-
-  @Test
-  public void list_metrics_with_pagination() throws Exception {
-    insertNewCustomMetric("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
-
-    WsTester.Result result = newRequest()
-      .setParam(Param.PAGE, "3")
-      .setParam(Param.PAGE_SIZE, "4")
-      .execute();
-
-    assertThat(StringUtils.countMatches(result.outputAsString(), "custom-key")).isEqualTo(2);
-  }
-
-  @Test
-  public void list_metric_with_is_custom_true() throws Exception {
-    insertNewCustomMetric("1", "2");
-    insertNewNonCustomMetric("3");
-
-    String result = newRequest()
-      .setParam(PARAM_IS_CUSTOM, "true").execute().outputAsString();
-
-    assertThat(result).contains("custom-key-1", "custom-key-2")
-      .doesNotContain("non-custom-key-3");
-  }
-
-  @Test
-  public void list_metric_with_is_custom_false() throws Exception {
-    insertNewCustomMetric("1", "2");
-    insertNewNonCustomMetric("3");
-
-    String result = newRequest()
-      .setParam(PARAM_IS_CUSTOM, "false").execute().outputAsString();
-
-    assertThat(result).doesNotContain("custom-key-1")
-      .doesNotContain("custom-key-2")
-      .contains("non-custom-key-3");
-  }
-
-  @Test
-  public void list_metric_with_chosen_fields() throws Exception {
-    insertNewCustomMetric("1");
-
-    String result = newRequest().setParam(Param.FIELDS, "name").execute().outputAsString();
-
-    assertThat(result).contains("id", "key", "name")
-      .doesNotContain("domain")
-      .doesNotContain("description")
-      .doesNotContain("type");
-  }
-
-  private void insertNewNonCustomMetric(String... ids) {
-    for (String id : ids) {
-      dbClient.metricDao().insert(dbSession, MetricTesting.newDto()
-        .setKey("non-custom-key-" + id)
-        .setEnabled(true)
-        .setUserManaged(false));
-    }
-    dbSession.commit();
-  }
-
-  private void insertNewCustomMetric(String... ids) {
-    for (String id : ids) {
-      dbClient.metricDao().insert(dbSession, newCustomMetric(id));
-    }
-    dbSession.commit();
-  }
-
-  private MetricDto newCustomMetric(String id) {
-    return MetricTesting.newDto()
-      .setKey("custom-key-" + id)
-      .setShortName("custom-name-" + id)
-      .setDomain("custom-domain-" + id)
-      .setDescription("custom-description-" + id)
-      .setValueType("INT")
-      .setUserManaged(true)
-      .setEnabled(true);
-  }
-
-  private WsTester.TestRequest newRequest() {
-    return ws.newGetRequest("api/metrics", "list");
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/MetricTesting.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/MetricTesting.java
deleted file mode 100644 (file)
index 753faf4..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.measure.ws;
-
-import org.apache.commons.lang.RandomStringUtils;
-import org.apache.commons.lang.math.RandomUtils;
-import org.sonar.api.measures.Metric;
-import org.sonar.core.measure.db.MetricDto;
-
-public class MetricTesting {
-  private MetricTesting() {
-    // static stuff only
-  }
-
-  public static MetricDto newDto() {
-    Metric.ValueType[] metricTypes = Metric.ValueType.values();
-    return new MetricDto()
-      .setId(RandomUtils.nextInt())
-      .setKey(RandomStringUtils.randomAlphanumeric(64))
-      .setShortName(RandomStringUtils.randomAlphanumeric(64))
-      .setValueType(metricTypes[RandomUtils.nextInt(metricTypes.length - 1)].name())
-      .setDomain(RandomStringUtils.randomAlphanumeric(64))
-      .setDescription(RandomStringUtils.randomAlphanumeric(250))
-      .setBestValue(RandomUtils.nextDouble())
-      .setDeleteHistoricalData(RandomUtils.nextBoolean())
-      .setDirection(RandomUtils.nextInt())
-      .setHidden(RandomUtils.nextBoolean())
-      .setEnabled(RandomUtils.nextBoolean())
-      .setOptimizedBestValue(RandomUtils.nextBoolean())
-      .setQualitative(RandomUtils.nextBoolean())
-      .setOrigin(RandomStringUtils.randomAlphabetic(3))
-      .setUserManaged(RandomUtils.nextBoolean())
-      .setWorstValue(RandomUtils.nextDouble());
-  }
-
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/MetricsWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/ws/MetricsWsTest.java
deleted file mode 100644 (file)
index 030a28e..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.measure.ws;
-
-import org.junit.Test;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.server.ws.WsTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class MetricsWsTest {
-
-  WsTester tester = new WsTester(new MetricsWs());
-
-  @Test
-  public void define_ws() {
-    WebService.Controller controller = tester.controller("api/metrics");
-    assertThat(controller).isNotNull();
-    assertThat(controller.description()).isNotEmpty();
-    assertThat(controller.actions()).hasSize(1);
-  }
-
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/persistence/MetricDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/persistence/MetricDaoTest.java
new file mode 100644 (file)
index 0000000..ee5913e
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.persistence;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.sonar.core.metric.db.MetricDto;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.DbTester;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@Category(DbTests.class)
+public class MetricDaoTest {
+
+  @ClassRule
+  public static DbTester dbTester = new DbTester();
+
+  DbSession session;
+
+  MetricDao dao;
+
+  @Before
+  public void createDao() {
+    dbTester.truncateTables();
+    session = dbTester.myBatis().openSession(false);
+    dao = new MetricDao();
+  }
+
+  @After
+  public void tearDown() {
+    session.close();
+  }
+
+  @Test
+  public void get_by_key() {
+    dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+    MetricDto result = dao.selectByKey(session, "coverage");
+    assertThat(result.getId()).isEqualTo(2);
+    assertThat(result.getKey()).isEqualTo("coverage");
+    assertThat(result.getShortName()).isEqualTo("Coverage");
+    assertThat(result.getDescription()).isEqualTo("Coverage by unit tests");
+    assertThat(result.getDomain()).isEqualTo("Tests");
+    assertThat(result.getValueType()).isEqualTo("PERCENT");
+    assertThat(result.getOrigin()).isEqualTo("JAV");
+    assertThat(result.getDirection()).isEqualTo(1);
+    assertThat(result.isQualitative()).isTrue();
+    assertThat(result.isUserManaged()).isFalse();
+    assertThat(result.getWorstValue()).isEqualTo(0d);
+    assertThat(result.getBestValue()).isEqualTo(100d);
+    assertThat(result.isOptimizedBestValue()).isFalse();
+    assertThat(result.isDeleteHistoricalData()).isFalse();
+    assertThat(result.isHidden()).isFalse();
+    assertThat(result.isEnabled()).isTrue();
+
+    // Disabled metrics are returned
+    result = dao.selectByKey(session, "disabled");
+    assertThat(result.getId()).isEqualTo(3);
+    assertThat(result.isEnabled()).isFalse();
+  }
+
+  @Test
+  public void get_manual_metric() {
+    dbTester.prepareDbUnit(getClass(), "manual_metric.xml");
+
+    MetricDto result = dao.selectByKey(session, "manual");
+    assertThat(result.getId()).isEqualTo(1);
+    assertThat(result.getKey()).isEqualTo("manual");
+    assertThat(result.getShortName()).isEqualTo("Manual metric");
+    assertThat(result.getDescription()).isEqualTo("Manual metric");
+    assertThat(result.getDomain()).isNullOrEmpty();
+    assertThat(result.getValueType()).isEqualTo("INT");
+    assertThat(result.getOrigin()).isEqualTo("GUI");
+    assertThat(result.getDirection()).isEqualTo(0);
+    assertThat(result.isQualitative()).isFalse();
+    assertThat(result.isUserManaged()).isTrue();
+    assertThat(result.getWorstValue()).isNull();
+    assertThat(result.getBestValue()).isNull();
+    assertThat(result.isOptimizedBestValue()).isNull();
+    assertThat(result.isDeleteHistoricalData()).isNull();
+    assertThat(result.isHidden()).isNull();
+    assertThat(result.isEnabled()).isTrue();
+  }
+
+  @Test
+  public void find_all_enabled() {
+    dbTester.prepareDbUnit(getClass(), "shared.xml");
+
+    assertThat(dao.selectEnabled(session)).hasSize(2);
+  }
+
+  @Test
+  public void insert() {
+    dao.insert(session, new MetricDto()
+      .setId(1)
+      .setKey("coverage")
+      .setShortName("Coverage")
+      .setDescription("Coverage by unit tests")
+      .setDomain("Tests")
+      .setValueType("PERCENT")
+      .setQualitative(true)
+      .setUserManaged(true)
+      .setWorstValue(0d)
+      .setBestValue(100d)
+      .setOptimizedBestValue(true)
+      .setDirection(1)
+      .setOrigin("JAV")
+      .setHidden(true)
+      .setDeleteHistoricalData(true)
+      .setEnabled(true));
+
+    MetricDto result = dao.selectByKey(session, "coverage");
+    assertThat(result.getId()).isNotNull();
+    assertThat(result.getKey()).isEqualTo("coverage");
+    assertThat(result.getShortName()).isEqualTo("Coverage");
+    assertThat(result.getDescription()).isEqualTo("Coverage by unit tests");
+    assertThat(result.getDomain()).isEqualTo("Tests");
+    assertThat(result.getValueType()).isEqualTo("PERCENT");
+    assertThat(result.getOrigin()).isEqualTo("JAV");
+    assertThat(result.getDirection()).isEqualTo(1);
+    assertThat(result.isQualitative()).isTrue();
+    assertThat(result.isUserManaged()).isTrue();
+    assertThat(result.getWorstValue()).isEqualTo(0d);
+    assertThat(result.getBestValue()).isEqualTo(100d);
+    assertThat(result.isOptimizedBestValue()).isTrue();
+    assertThat(result.isDeleteHistoricalData()).isTrue();
+    assertThat(result.isHidden()).isTrue();
+    assertThat(result.isEnabled()).isTrue();
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/ListActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/ListActionTest.java
new file mode 100644 (file)
index 0000000..66ad2d8
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.ws;
+
+import org.apache.commons.lang.StringUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.api.server.ws.WebService.Param;
+import org.sonar.core.metric.db.MetricDto;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.DbTester;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.metric.persistence.MetricDao;
+import org.sonar.server.ws.WsTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.metric.ws.ListAction.PARAM_IS_CUSTOM;
+
+public class ListActionTest {
+
+  @ClassRule
+  public static DbTester db = new DbTester();
+  DbClient dbClient;
+  DbSession dbSession;
+  WsTester ws;
+
+  @Before
+  public void setUp() {
+    dbClient = new DbClient(db.database(), db.myBatis(), new MetricDao());
+    dbSession = dbClient.openSession(false);
+    ws = new WsTester(new MetricsWs(new ListAction(dbClient)));
+    db.truncateTables();
+  }
+
+  @After
+  public void tearDown() {
+    dbSession.close();
+  }
+
+  @Test
+  public void list_metrics_in_database() throws Exception {
+    insertNewCustomMetric("1", "2", "3");
+
+    WsTester.Result result = newRequest().execute();
+
+    result.assertJson(getClass(), "list_metrics.json");
+  }
+
+  @Test
+  public void list_metrics_ordered_by_name_case_insensitive() throws Exception {
+    insertNewCustomMetric("3", "1", "2");
+
+    String firstResult = newRequest().setParam(Param.PAGE, "1").setParam(Param.PAGE_SIZE, "1").execute().outputAsString();
+    String secondResult = newRequest().setParam(Param.PAGE, "2").setParam(Param.PAGE_SIZE, "1").execute().outputAsString();
+    String thirdResult = newRequest().setParam(Param.PAGE, "3").setParam(Param.PAGE_SIZE, "1").execute().outputAsString();
+
+    assertThat(firstResult).contains("custom-key-1").doesNotContain("custom-key-2").doesNotContain("custom-key-3");
+    assertThat(secondResult).contains("custom-key-2").doesNotContain("custom-key-1").doesNotContain("custom-key-3");
+    assertThat(thirdResult).contains("custom-key-3").doesNotContain("custom-key-1").doesNotContain("custom-key-2");
+  }
+
+  @Test
+  public void list_metrics_with_pagination() throws Exception {
+    insertNewCustomMetric("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
+
+    WsTester.Result result = newRequest()
+      .setParam(Param.PAGE, "3")
+      .setParam(Param.PAGE_SIZE, "4")
+      .execute();
+
+    assertThat(StringUtils.countMatches(result.outputAsString(), "custom-key")).isEqualTo(2);
+  }
+
+  @Test
+  public void list_metric_with_is_custom_true() throws Exception {
+    insertNewCustomMetric("1", "2");
+    insertNewNonCustomMetric("3");
+
+    String result = newRequest()
+      .setParam(PARAM_IS_CUSTOM, "true").execute().outputAsString();
+
+    assertThat(result).contains("custom-key-1", "custom-key-2")
+      .doesNotContain("non-custom-key-3");
+  }
+
+  @Test
+  public void list_metric_with_is_custom_false() throws Exception {
+    insertNewCustomMetric("1", "2");
+    insertNewNonCustomMetric("3");
+
+    String result = newRequest()
+      .setParam(PARAM_IS_CUSTOM, "false").execute().outputAsString();
+
+    assertThat(result).doesNotContain("custom-key-1")
+      .doesNotContain("custom-key-2")
+      .contains("non-custom-key-3");
+  }
+
+  @Test
+  public void list_metric_with_chosen_fields() throws Exception {
+    insertNewCustomMetric("1");
+
+    String result = newRequest().setParam(Param.FIELDS, "name").execute().outputAsString();
+
+    assertThat(result).contains("id", "key", "name")
+      .doesNotContain("domain")
+      .doesNotContain("description")
+      .doesNotContain("type");
+  }
+
+  private void insertNewNonCustomMetric(String... ids) {
+    for (String id : ids) {
+      dbClient.metricDao().insert(dbSession, MetricTesting.newDto()
+        .setKey("non-custom-key-" + id)
+        .setEnabled(true)
+        .setUserManaged(false));
+    }
+    dbSession.commit();
+  }
+
+  private void insertNewCustomMetric(String... ids) {
+    for (String id : ids) {
+      dbClient.metricDao().insert(dbSession, newCustomMetric(id));
+    }
+    dbSession.commit();
+  }
+
+  private MetricDto newCustomMetric(String id) {
+    return MetricTesting.newDto()
+      .setKey("custom-key-" + id)
+      .setShortName("custom-name-" + id)
+      .setDomain("custom-domain-" + id)
+      .setDescription("custom-description-" + id)
+      .setValueType("INT")
+      .setUserManaged(true)
+      .setEnabled(true);
+  }
+
+  private WsTester.TestRequest newRequest() {
+    return ws.newGetRequest("api/metrics", "list");
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/MetricTesting.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/MetricTesting.java
new file mode 100644 (file)
index 0000000..c991e27
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.ws;
+
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang.math.RandomUtils;
+import org.sonar.api.measures.Metric;
+import org.sonar.core.metric.db.MetricDto;
+
+public class MetricTesting {
+  private MetricTesting() {
+    // static stuff only
+  }
+
+  public static MetricDto newDto() {
+    Metric.ValueType[] metricTypes = Metric.ValueType.values();
+    return new MetricDto()
+      .setId(RandomUtils.nextInt())
+      .setKey(RandomStringUtils.randomAlphanumeric(64))
+      .setShortName(RandomStringUtils.randomAlphanumeric(64))
+      .setValueType(metricTypes[RandomUtils.nextInt(metricTypes.length - 1)].name())
+      .setDomain(RandomStringUtils.randomAlphanumeric(64))
+      .setDescription(RandomStringUtils.randomAlphanumeric(250))
+      .setBestValue(RandomUtils.nextDouble())
+      .setDeleteHistoricalData(RandomUtils.nextBoolean())
+      .setDirection(RandomUtils.nextInt())
+      .setHidden(RandomUtils.nextBoolean())
+      .setEnabled(RandomUtils.nextBoolean())
+      .setOptimizedBestValue(RandomUtils.nextBoolean())
+      .setQualitative(RandomUtils.nextBoolean())
+      .setOrigin(RandomStringUtils.randomAlphabetic(3))
+      .setUserManaged(RandomUtils.nextBoolean())
+      .setWorstValue(RandomUtils.nextDouble());
+  }
+
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/metric/ws/MetricsWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/MetricsWsTest.java
new file mode 100644 (file)
index 0000000..3dc57d5
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.ws;
+
+import org.junit.Test;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.ws.WsTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MetricsWsTest {
+
+  WsTester tester = new WsTester(new MetricsWs());
+
+  @Test
+  public void define_ws() {
+    WebService.Controller controller = tester.controller("api/metrics");
+    assertThat(controller).isNotNull();
+    assertThat(controller.description()).isNotEmpty();
+    assertThat(controller.actions()).hasSize(1);
+  }
+
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MetricDaoTest/manual_metric.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MetricDaoTest/manual_metric.xml
deleted file mode 100644 (file)
index 630722c..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<dataset>
-
-  <metrics id="1" name="manual" val_type="INT" description="Manual metric" domain="" short_name="Manual metric"
-           qualitative="[false]" enabled="[true]" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="[null]"
-           origin="GUI" delete_historical_data="[null]" user_managed="[true]"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MetricDaoTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MetricDaoTest/shared.xml
deleted file mode 100644 (file)
index 82b23ee..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<dataset>
-
-  <metrics id="1" name="ncloc" val_type="INT" description="Non Commenting Lines of Code" domain="Size" short_name="Lines of code"
-           qualitative="[false]" enabled="[true]" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="-1" hidden="[false]"
-           origin="JAV" delete_historical_data="[false]" user_managed="[false]"/>
-
-  <metrics id="2" name="coverage" val_type="PERCENT" description="Coverage by unit tests" domain="Tests" short_name="Coverage"
-           qualitative="[true]" enabled="[true]" worst_value="0" optimized_best_value="[false]" best_value="100" direction="1" hidden="[false]"
-           origin="JAV" delete_historical_data="[false]" user_managed="[false]"/>
-
-  <metrics id="3" name="disabled" val_type="INT" description="[null]" domain="[null]" short_name="disabled"
-           qualitative="[false]" enabled="[false]" worst_value="0" optimized_best_value="[true]" best_value="100" direction="1" hidden="[false]"
-           origin="JAV" delete_historical_data="[false]" user_managed="[false]"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/ws/ListActionTest/list_metrics.json b/server/sonar-server/src/test/resources/org/sonar/server/measure/ws/ListActionTest/list_metrics.json
deleted file mode 100644 (file)
index 4f5049c..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-{
-  "metrics":[
-    {
-      "key":"custom-key-1",
-      "name":"custom-name-1",
-      "type":"Integer",
-      "domain":"custom-domain-1",
-      "description":"custom-description-1"
-    },
-    {
-      "key":"custom-key-2",
-      "name":"custom-name-2",
-      "type":"Integer",
-      "domain":"custom-domain-2",
-      "description":"custom-description-2"
-    },
-    {
-      "key":"custom-key-3",
-      "name":"custom-name-3",
-      "type":"Integer",
-      "domain":"custom-domain-3",
-      "description":"custom-description-3"
-    }
-  ]
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/metric/persistence/MetricDaoTest/manual_metric.xml b/server/sonar-server/src/test/resources/org/sonar/server/metric/persistence/MetricDaoTest/manual_metric.xml
new file mode 100644 (file)
index 0000000..630722c
--- /dev/null
@@ -0,0 +1,7 @@
+<dataset>
+
+  <metrics id="1" name="manual" val_type="INT" description="Manual metric" domain="" short_name="Manual metric"
+           qualitative="[false]" enabled="[true]" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="[null]"
+           origin="GUI" delete_historical_data="[null]" user_managed="[true]"/>
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/metric/persistence/MetricDaoTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/metric/persistence/MetricDaoTest/shared.xml
new file mode 100644 (file)
index 0000000..82b23ee
--- /dev/null
@@ -0,0 +1,15 @@
+<dataset>
+
+  <metrics id="1" name="ncloc" val_type="INT" description="Non Commenting Lines of Code" domain="Size" short_name="Lines of code"
+           qualitative="[false]" enabled="[true]" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="-1" hidden="[false]"
+           origin="JAV" delete_historical_data="[false]" user_managed="[false]"/>
+
+  <metrics id="2" name="coverage" val_type="PERCENT" description="Coverage by unit tests" domain="Tests" short_name="Coverage"
+           qualitative="[true]" enabled="[true]" worst_value="0" optimized_best_value="[false]" best_value="100" direction="1" hidden="[false]"
+           origin="JAV" delete_historical_data="[false]" user_managed="[false]"/>
+
+  <metrics id="3" name="disabled" val_type="INT" description="[null]" domain="[null]" short_name="disabled"
+           qualitative="[false]" enabled="[false]" worst_value="0" optimized_best_value="[true]" best_value="100" direction="1" hidden="[false]"
+           origin="JAV" delete_historical_data="[false]" user_managed="[false]"/>
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/metric/ws/ListActionTest/list_metrics.json b/server/sonar-server/src/test/resources/org/sonar/server/metric/ws/ListActionTest/list_metrics.json
new file mode 100644 (file)
index 0000000..4f5049c
--- /dev/null
@@ -0,0 +1,25 @@
+{
+  "metrics":[
+    {
+      "key":"custom-key-1",
+      "name":"custom-name-1",
+      "type":"Integer",
+      "domain":"custom-domain-1",
+      "description":"custom-description-1"
+    },
+    {
+      "key":"custom-key-2",
+      "name":"custom-name-2",
+      "type":"Integer",
+      "domain":"custom-domain-2",
+      "description":"custom-description-2"
+    },
+    {
+      "key":"custom-key-3",
+      "name":"custom-name-3",
+      "type":"Integer",
+      "domain":"custom-domain-3",
+      "description":"custom-description-3"
+    }
+  ]
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/db/MetricDto.java b/sonar-core/src/main/java/org/sonar/core/measure/db/MetricDto.java
deleted file mode 100644 (file)
index e23be81..0000000
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.measure.db;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-public class MetricDto {
-
-  private Integer id;
-
-  private String name;
-
-  private String shortName;
-
-  private String valueType;
-
-  private String description;
-
-  private String domain;
-
-  private int direction;
-
-  private boolean qualitative;
-
-  private boolean userManaged;
-
-  private Double worstValue;
-
-  private Double bestValue;
-
-  private Boolean optimizedBestValue;
-
-  private String origin;
-
-  private Boolean hidden;
-
-  private Boolean deleteHistoricalData;
-
-  private boolean enabled;
-
-  public Integer getId() {
-    return id;
-  }
-
-  public MetricDto setId(Integer id) {
-    this.id = id;
-    return this;
-  }
-
-  public String getKey() {
-    return name;
-  }
-
-  public MetricDto setKey(String name) {
-    this.name = name;
-    return this;
-  }
-
-  public String getShortName() {
-    return shortName;
-  }
-
-  public MetricDto setShortName(String shortName) {
-    this.shortName = shortName;
-    return this;
-  }
-
-  public String getValueType() {
-    return valueType;
-  }
-
-  public MetricDto setValueType(String valueType) {
-    this.valueType = valueType;
-    return this;
-  }
-
-  /**
-   * @return null for manual metrics
-   */
-  @CheckForNull
-  public String getDescription() {
-    return description;
-  }
-
-  public MetricDto setDescription(@Nullable String description) {
-    this.description = description;
-    return this;
-  }
-
-  public String getDomain() {
-    return domain;
-  }
-
-  public MetricDto setDomain(String domain) {
-    this.domain = domain;
-    return this;
-  }
-
-  public int getDirection() {
-    return direction;
-  }
-
-  public MetricDto setDirection(int direction) {
-    this.direction = direction;
-    return this;
-  }
-
-  public boolean isQualitative() {
-    return qualitative;
-  }
-
-  public MetricDto setQualitative(boolean qualitative) {
-    this.qualitative = qualitative;
-    return this;
-  }
-
-  public boolean isUserManaged() {
-    return userManaged;
-  }
-
-  public MetricDto setUserManaged(boolean userManaged) {
-    this.userManaged = userManaged;
-    return this;
-  }
-
-  @CheckForNull
-  public Double getWorstValue() {
-    return worstValue;
-  }
-
-  public MetricDto setWorstValue(@Nullable Double worstValue) {
-    this.worstValue = worstValue;
-    return this;
-  }
-
-  @CheckForNull
-  public Double getBestValue() {
-    return bestValue;
-  }
-
-  public MetricDto setBestValue(@Nullable Double bestValue) {
-    this.bestValue = bestValue;
-    return this;
-  }
-
-  /**
-   * @return null for manual metrics
-   */
-  @CheckForNull
-  public Boolean isOptimizedBestValue() {
-    return optimizedBestValue;
-  }
-
-  public MetricDto setOptimizedBestValue(@Nullable Boolean optimizedBestValue) {
-    this.optimizedBestValue = optimizedBestValue;
-    return this;
-  }
-
-  public String getOrigin() {
-    return origin;
-  }
-
-  public MetricDto setOrigin(String origin) {
-    this.origin = origin;
-    return this;
-  }
-
-  /**
-   * @return null for manual metrics
-   */
-  @CheckForNull
-  public Boolean isHidden() {
-    return hidden;
-  }
-
-  public MetricDto setHidden(@Nullable Boolean hidden) {
-    this.hidden = hidden;
-    return this;
-  }
-
-  /**
-   * @return null for manual metrics
-   */
-  @CheckForNull
-  public Boolean isDeleteHistoricalData() {
-    return deleteHistoricalData;
-  }
-
-  public MetricDto setDeleteHistoricalData(@Nullable Boolean deleteHistoricalData) {
-    this.deleteHistoricalData = deleteHistoricalData;
-    return this;
-  }
-
-  public boolean isEnabled() {
-    return enabled;
-  }
-
-  public MetricDto setEnabled(boolean enabled) {
-    this.enabled = enabled;
-    return this;
-  }
-
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/db/MetricMapper.java b/sonar-core/src/main/java/org/sonar/core/measure/db/MetricMapper.java
deleted file mode 100644 (file)
index 16b7378..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.measure.db;
-
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.session.RowBounds;
-
-import java.util.List;
-import java.util.Map;
-
-public interface MetricMapper {
-
-  MetricDto selectByKey(@Param("key") String key);
-  List<MetricDto> selectAllEnabled();
-  List<MetricDto> selectAllEnabled(Map<String, Object> properties, RowBounds rowBounds);
-  void insert(MetricDto dto);
-
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/metric/db/MetricDto.java b/sonar-core/src/main/java/org/sonar/core/metric/db/MetricDto.java
new file mode 100644 (file)
index 0000000..d2131c9
--- /dev/null
@@ -0,0 +1,222 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.metric.db;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class MetricDto {
+
+  private Integer id;
+
+  private String name;
+
+  private String shortName;
+
+  private String valueType;
+
+  private String description;
+
+  private String domain;
+
+  private int direction;
+
+  private boolean qualitative;
+
+  private boolean userManaged;
+
+  private Double worstValue;
+
+  private Double bestValue;
+
+  private Boolean optimizedBestValue;
+
+  private String origin;
+
+  private Boolean hidden;
+
+  private Boolean deleteHistoricalData;
+
+  private boolean enabled;
+
+  public Integer getId() {
+    return id;
+  }
+
+  public MetricDto setId(Integer id) {
+    this.id = id;
+    return this;
+  }
+
+  public String getKey() {
+    return name;
+  }
+
+  public MetricDto setKey(String name) {
+    this.name = name;
+    return this;
+  }
+
+  public String getShortName() {
+    return shortName;
+  }
+
+  public MetricDto setShortName(String shortName) {
+    this.shortName = shortName;
+    return this;
+  }
+
+  public String getValueType() {
+    return valueType;
+  }
+
+  public MetricDto setValueType(String valueType) {
+    this.valueType = valueType;
+    return this;
+  }
+
+  /**
+   * @return null for manual metrics
+   */
+  @CheckForNull
+  public String getDescription() {
+    return description;
+  }
+
+  public MetricDto setDescription(@Nullable String description) {
+    this.description = description;
+    return this;
+  }
+
+  public String getDomain() {
+    return domain;
+  }
+
+  public MetricDto setDomain(String domain) {
+    this.domain = domain;
+    return this;
+  }
+
+  public int getDirection() {
+    return direction;
+  }
+
+  public MetricDto setDirection(int direction) {
+    this.direction = direction;
+    return this;
+  }
+
+  public boolean isQualitative() {
+    return qualitative;
+  }
+
+  public MetricDto setQualitative(boolean qualitative) {
+    this.qualitative = qualitative;
+    return this;
+  }
+
+  public boolean isUserManaged() {
+    return userManaged;
+  }
+
+  public MetricDto setUserManaged(boolean userManaged) {
+    this.userManaged = userManaged;
+    return this;
+  }
+
+  @CheckForNull
+  public Double getWorstValue() {
+    return worstValue;
+  }
+
+  public MetricDto setWorstValue(@Nullable Double worstValue) {
+    this.worstValue = worstValue;
+    return this;
+  }
+
+  @CheckForNull
+  public Double getBestValue() {
+    return bestValue;
+  }
+
+  public MetricDto setBestValue(@Nullable Double bestValue) {
+    this.bestValue = bestValue;
+    return this;
+  }
+
+  /**
+   * @return null for manual metrics
+   */
+  @CheckForNull
+  public Boolean isOptimizedBestValue() {
+    return optimizedBestValue;
+  }
+
+  public MetricDto setOptimizedBestValue(@Nullable Boolean optimizedBestValue) {
+    this.optimizedBestValue = optimizedBestValue;
+    return this;
+  }
+
+  public String getOrigin() {
+    return origin;
+  }
+
+  public MetricDto setOrigin(String origin) {
+    this.origin = origin;
+    return this;
+  }
+
+  /**
+   * @return null for manual metrics
+   */
+  @CheckForNull
+  public Boolean isHidden() {
+    return hidden;
+  }
+
+  public MetricDto setHidden(@Nullable Boolean hidden) {
+    this.hidden = hidden;
+    return this;
+  }
+
+  /**
+   * @return null for manual metrics
+   */
+  @CheckForNull
+  public Boolean isDeleteHistoricalData() {
+    return deleteHistoricalData;
+  }
+
+  public MetricDto setDeleteHistoricalData(@Nullable Boolean deleteHistoricalData) {
+    this.deleteHistoricalData = deleteHistoricalData;
+    return this;
+  }
+
+  public boolean isEnabled() {
+    return enabled;
+  }
+
+  public MetricDto setEnabled(boolean enabled) {
+    this.enabled = enabled;
+    return this;
+  }
+
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/metric/db/MetricMapper.java b/sonar-core/src/main/java/org/sonar/core/metric/db/MetricMapper.java
new file mode 100644 (file)
index 0000000..e7b4d2c
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.metric.db;
+
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.session.RowBounds;
+
+import java.util.List;
+import java.util.Map;
+
+public interface MetricMapper {
+
+  MetricDto selectByKey(@Param("key") String key);
+  List<MetricDto> selectAllEnabled();
+  List<MetricDto> selectAllEnabled(Map<String, Object> properties, RowBounds rowBounds);
+  void insert(MetricDto dto);
+
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/metric/db/package-info.java b/sonar-core/src/main/java/org/sonar/core/metric/db/package-info.java
new file mode 100644 (file)
index 0000000..77b704b
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.core.metric.db;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
index c933f606dcb956fd8c616dacc9b2cd71781614ea..abf18b7ef4cfb7a5bdf8d286cfbe5b586b274596 100644 (file)
@@ -82,7 +82,7 @@ import org.sonar.core.measure.db.MeasureDto;
 import org.sonar.core.measure.db.MeasureFilterDto;
 import org.sonar.core.measure.db.MeasureFilterMapper;
 import org.sonar.core.measure.db.MeasureMapper;
-import org.sonar.core.measure.db.MetricMapper;
+import org.sonar.core.metric.db.MetricMapper;
 import org.sonar.core.notification.db.NotificationQueueDto;
 import org.sonar.core.notification.db.NotificationQueueMapper;
 import org.sonar.core.permission.GroupWithPermissionDto;
diff --git a/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shared.xml b/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shared.xml
new file mode 100644 (file)
index 0000000..94d2292
--- /dev/null
@@ -0,0 +1,23 @@
+<dataset>
+
+  <measure_filters
+    id="1"
+    name="Projects"
+    user_id="[null]"
+    shared="[true]"
+    description="All projects"
+    data="qualifiers=TRK"
+    created_at="2012-12-25"
+    updated_at="2012-12-25" />
+
+  <measure_filters
+    id="2"
+    name="Files"
+    user_id="[null]"
+    shared="[true]"
+    description="All files"
+    data="qualifiers=FIL"
+    created_at="2012-01-25"
+    updated_at="2012-01-25" />
+
+</dataset>
diff --git a/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shouldInsert-result.xml b/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shouldInsert-result.xml
new file mode 100644 (file)
index 0000000..1100b16
--- /dev/null
@@ -0,0 +1,34 @@
+<dataset>
+
+  <measure_filters
+    id="1"
+    name="Projects"
+    user_id="[null]"
+    shared="[true]"
+    description="All projects"
+    data="qualifiers=TRK"
+    created_at="2012-12-25"
+    updated_at="2012-12-25"/>
+
+  <measure_filters
+    id="2"
+    name="Files"
+    user_id="[null]"
+    shared="[true]"
+    description="All files"
+    data="qualifiers=FIL"
+    created_at="2012-01-25"
+    updated_at="2012-01-25"/>
+
+
+  <measure_filters
+    id="3"
+    name="Project Treemap"
+    user_id="123"
+    shared="[true]"
+    description="Treemap of projects"
+    data="qualifiers=TRK|display=treemap"
+    created_at="2012-12-25"
+    updated_at="2012-12-25"/>
+
+</dataset>
diff --git a/sonar-core/src/main/resources/org/sonar/core/measure/db/MetricMapper.xml b/sonar-core/src/main/resources/org/sonar/core/measure/db/MetricMapper.xml
deleted file mode 100644 (file)
index 7775749..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.core.measure.db.MetricMapper">
-
-  <sql id="metricColumns">
-    m.id,
-    m.name,
-    m.description,
-    m.direction,
-    m.domain,
-    m.short_name as shortName,
-    m.qualitative,
-    m.val_type as valueType,
-    m.user_managed as userManaged,
-    m.enabled,
-    m.origin,
-    m.worst_value as worstValue,
-    m.best_value as bestValue,
-    m.optimized_best_value as optimizedBestValue,
-    m.hidden,
-    m.delete_historical_data as deleteHistoricalData
-  </sql>
-
-  <select id="selectByKey" parameterType="map" resultType="org.sonar.core.measure.db.MetricDto">
-    SELECT
-    <include refid="metricColumns"/>
-    FROM metrics m
-    <where>
-      AND m.name=#{key}
-    </where>
-  </select>
-
-  <select id="selectAllEnabled" parameterType="map" resultType="org.sonar.core.measure.db.MetricDto">
-    SELECT
-    <include refid="metricColumns"/>
-    FROM metrics m
-    <where>
-      AND m.enabled=${_true}
-      <if test="isCustom!=null">
-        <if test="isCustom.equals(true)">
-          AND m.user_managed=${_true}
-        </if>
-        <if test="isCustom.equals(false)">
-          AND m.user_managed=${_false}
-        </if>
-      </if>
-    </where>
-    ORDER BY UPPER(m.short_name)
-  </select>
-
-  <insert id="insert" parameterType="org.sonar.core.measure.db.MetricDto" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
-    INSERT INTO metrics (
-      name, description, direction, domain, short_name, qualitative, val_type, user_managed, enabled, origin, worst_value, best_value, optimized_best_value, hidden, delete_historical_data)
-    VALUES (
-    #{name, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, #{direction, jdbcType=INTEGER},
-    #{domain, jdbcType=VARCHAR}, #{shortName, jdbcType=VARCHAR}, #{qualitative, jdbcType=BOOLEAN},
-    #{valueType, jdbcType=VARCHAR}, #{userManaged, jdbcType=BOOLEAN}, #{enabled, jdbcType=BOOLEAN},
-    #{origin, jdbcType=VARCHAR}, #{worstValue, jdbcType=DOUBLE}, #{bestValue, jdbcType=DOUBLE},
-    #{optimizedBestValue, jdbcType=BOOLEAN}, #{hidden, jdbcType=BOOLEAN}, #{deleteHistoricalData, jdbcType=BOOLEAN}
-    )
-  </insert>
-
-</mapper>
diff --git a/sonar-core/src/main/resources/org/sonar/core/metric/db/MetricMapper.xml b/sonar-core/src/main/resources/org/sonar/core/metric/db/MetricMapper.xml
new file mode 100644 (file)
index 0000000..0f07acb
--- /dev/null
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.metric.db.MetricMapper">
+
+  <sql id="metricColumns">
+    m.id,
+    m.name,
+    m.description,
+    m.direction,
+    m.domain,
+    m.short_name as shortName,
+    m.qualitative,
+    m.val_type as valueType,
+    m.user_managed as userManaged,
+    m.enabled,
+    m.origin,
+    m.worst_value as worstValue,
+    m.best_value as bestValue,
+    m.optimized_best_value as optimizedBestValue,
+    m.hidden,
+    m.delete_historical_data as deleteHistoricalData
+  </sql>
+
+  <select id="selectByKey" parameterType="map" resultType="org.sonar.core.metric.db.MetricDto">
+    SELECT
+    <include refid="metricColumns"/>
+    FROM metrics m
+    <where>
+      AND m.name=#{key}
+    </where>
+  </select>
+
+  <select id="selectAllEnabled" parameterType="map" resultType="org.sonar.core.metric.db.MetricDto">
+    SELECT
+    <include refid="metricColumns"/>
+    FROM metrics m
+    <where>
+      AND m.enabled=${_true}
+      <if test="isCustom!=null">
+        <if test="isCustom.equals(true)">
+          AND m.user_managed=${_true}
+        </if>
+        <if test="isCustom.equals(false)">
+          AND m.user_managed=${_false}
+        </if>
+      </if>
+    </where>
+    ORDER BY UPPER(m.short_name)
+  </select>
+
+  <insert id="insert" parameterType="org.sonar.core.metric.db.MetricDto" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
+    INSERT INTO metrics (
+      name, description, direction, domain, short_name, qualitative, val_type, user_managed, enabled, origin, worst_value, best_value, optimized_best_value, hidden, delete_historical_data)
+    VALUES (
+    #{name, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, #{direction, jdbcType=INTEGER},
+    #{domain, jdbcType=VARCHAR}, #{shortName, jdbcType=VARCHAR}, #{qualitative, jdbcType=BOOLEAN},
+    #{valueType, jdbcType=VARCHAR}, #{userManaged, jdbcType=BOOLEAN}, #{enabled, jdbcType=BOOLEAN},
+    #{origin, jdbcType=VARCHAR}, #{worstValue, jdbcType=DOUBLE}, #{bestValue, jdbcType=DOUBLE},
+    #{optimizedBestValue, jdbcType=BOOLEAN}, #{hidden, jdbcType=BOOLEAN}, #{deleteHistoricalData, jdbcType=BOOLEAN}
+    )
+  </insert>
+
+</mapper>
diff --git a/sonar-core/src/test/java/org/sonar/core/measure/db/MetricDtoTest.java b/sonar-core/src/test/java/org/sonar/core/measure/db/MetricDtoTest.java
deleted file mode 100644 (file)
index 93ce3e3..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.core.measure.db;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class MetricDtoTest {
-
-  @Test
-  public void getters_and_setters() {
-    MetricDto metricDto = new MetricDto()
-      .setId(1)
-      .setKey("coverage")
-      .setShortName("Coverage")
-      .setDescription("Coverage by unit tests")
-      .setDomain("Tests")
-      .setValueType("PERCENT")
-      .setQualitative(true)
-      .setUserManaged(false)
-      .setWorstValue(0d)
-      .setBestValue(100d)
-      .setOptimizedBestValue(true)
-      .setDirection(1)
-      .setOrigin("JAV")
-      .setHidden(true)
-      .setDeleteHistoricalData(true)
-      .setEnabled(true);
-
-    assertThat(metricDto.getId()).isEqualTo(1);
-    assertThat(metricDto.getKey()).isEqualTo("coverage");
-    assertThat(metricDto.getShortName()).isEqualTo("Coverage");
-    assertThat(metricDto.getDescription()).isEqualTo("Coverage by unit tests");
-    assertThat(metricDto.getDomain()).isEqualTo("Tests");
-    assertThat(metricDto.getValueType()).isEqualTo("PERCENT");
-    assertThat(metricDto.isQualitative()).isTrue();
-    assertThat(metricDto.isUserManaged()).isFalse();
-    assertThat(metricDto.getWorstValue()).isEqualTo(0d);
-    assertThat(metricDto.getBestValue()).isEqualTo(100d);
-    assertThat(metricDto.isOptimizedBestValue()).isTrue();
-    assertThat(metricDto.getDirection()).isEqualTo(1);
-    assertThat(metricDto.getOrigin()).isEqualTo("JAV");
-    assertThat(metricDto.isHidden()).isTrue();
-    assertThat(metricDto.isDeleteHistoricalData()).isTrue();
-    assertThat(metricDto.isEnabled()).isTrue();
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/metric/db/MetricDtoTest.java b/sonar-core/src/test/java/org/sonar/core/metric/db/MetricDtoTest.java
new file mode 100644 (file)
index 0000000..5c7b9eb
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.core.metric.db;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MetricDtoTest {
+
+  @Test
+  public void getters_and_setters() {
+    MetricDto metricDto = new MetricDto()
+      .setId(1)
+      .setKey("coverage")
+      .setShortName("Coverage")
+      .setDescription("Coverage by unit tests")
+      .setDomain("Tests")
+      .setValueType("PERCENT")
+      .setQualitative(true)
+      .setUserManaged(false)
+      .setWorstValue(0d)
+      .setBestValue(100d)
+      .setOptimizedBestValue(true)
+      .setDirection(1)
+      .setOrigin("JAV")
+      .setHidden(true)
+      .setDeleteHistoricalData(true)
+      .setEnabled(true);
+
+    assertThat(metricDto.getId()).isEqualTo(1);
+    assertThat(metricDto.getKey()).isEqualTo("coverage");
+    assertThat(metricDto.getShortName()).isEqualTo("Coverage");
+    assertThat(metricDto.getDescription()).isEqualTo("Coverage by unit tests");
+    assertThat(metricDto.getDomain()).isEqualTo("Tests");
+    assertThat(metricDto.getValueType()).isEqualTo("PERCENT");
+    assertThat(metricDto.isQualitative()).isTrue();
+    assertThat(metricDto.isUserManaged()).isFalse();
+    assertThat(metricDto.getWorstValue()).isEqualTo(0d);
+    assertThat(metricDto.getBestValue()).isEqualTo(100d);
+    assertThat(metricDto.isOptimizedBestValue()).isTrue();
+    assertThat(metricDto.getDirection()).isEqualTo(1);
+    assertThat(metricDto.getOrigin()).isEqualTo("JAV");
+    assertThat(metricDto.isHidden()).isTrue();
+    assertThat(metricDto.isDeleteHistoricalData()).isTrue();
+    assertThat(metricDto.isEnabled()).isTrue();
+  }
+}
diff --git a/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shared.xml
deleted file mode 100644 (file)
index 94d2292..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<dataset>
-
-  <measure_filters
-    id="1"
-    name="Projects"
-    user_id="[null]"
-    shared="[true]"
-    description="All projects"
-    data="qualifiers=TRK"
-    created_at="2012-12-25"
-    updated_at="2012-12-25" />
-
-  <measure_filters
-    id="2"
-    name="Files"
-    user_id="[null]"
-    shared="[true]"
-    description="All files"
-    data="qualifiers=FIL"
-    created_at="2012-01-25"
-    updated_at="2012-01-25" />
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shouldInsert-result.xml b/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shouldInsert-result.xml
deleted file mode 100644 (file)
index 1100b16..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<dataset>
-
-  <measure_filters
-    id="1"
-    name="Projects"
-    user_id="[null]"
-    shared="[true]"
-    description="All projects"
-    data="qualifiers=TRK"
-    created_at="2012-12-25"
-    updated_at="2012-12-25"/>
-
-  <measure_filters
-    id="2"
-    name="Files"
-    user_id="[null]"
-    shared="[true]"
-    description="All files"
-    data="qualifiers=FIL"
-    created_at="2012-01-25"
-    updated_at="2012-01-25"/>
-
-
-  <measure_filters
-    id="3"
-    name="Project Treemap"
-    user_id="123"
-    shared="[true]"
-    description="Treemap of projects"
-    data="qualifiers=TRK|display=treemap"
-    created_at="2012-12-25"
-    updated_at="2012-12-25"/>
-
-</dataset>