From: Teryk Bellahsene Date: Fri, 22 May 2015 15:54:41 +0000 (+0200) Subject: move metric related classes in a specific package - SONAR-6570 X-Git-Tag: 5.2-RC1~1846 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F325%2Fhead;p=sonarqube.git move metric related classes in a specific package - SONAR-6570 --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/GlobalAction.java b/server/sonar-server/src/main/java/org/sonar/server/batch/GlobalAction.java index 84529cae0b7..23956d9bbba 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/batch/GlobalAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/batch/GlobalAction.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MetricCache.java b/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MetricCache.java index febaaf9e6a3..ac130fda554 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MetricCache.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/measure/MetricCache.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationsStep.java index fd678891c96..e6cb38a50fa 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationsStep.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java b/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java index 56334b663af..6e6df811f34 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java @@ -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 index 32bf681229d..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/persistence/MetricDao.java +++ /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 selectEnabled(DbSession session) { - return session.getMapper(MetricMapper.class).selectAllEnabled(); - } - - public List selectEnabled(DbSession session, @Nullable Boolean isCustom, SearchOptions searchOptions) { - Map 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 index 9ba67c1f013..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/ListAction.java +++ /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 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:" + - "
    " + - "
  • true: only custom metrics are returned
  • " + - "
  • false: only non custom metrics are returned
  • " + - "
  • not specified: all metrics are returned
  • " + - "
"); - } - - @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 metrics = dbClient.metricDao().selectEnabled(dbSession, isCustom, searchOptions); - JsonWriter json = response.newJsonWriter(); - json.beginObject(); - Set desiredFields = desiredFields(request.paramAsStrings(Param.FIELDS)); - writeMetrics(json, metrics, desiredFields); - json.endObject(); - json.close(); - } finally { - MyBatis.closeQuietly(dbSession); - } - } - - private Set desiredFields(@Nullable List fields) { - if (fields == null || fields.isEmpty()) { - return POSSIBLE_FIELDS; - } - - return newHashSet(fields); - } - - private void writeMetrics(JsonWriter json, List metrics, Set 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 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 index 2f352ef3bc6..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/MetricsWs.java +++ /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 here") - .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 index 61b28ba802b..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/ws/MetricsWsAction.java +++ /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 index 00000000000..ae463280213 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/persistence/MetricDao.java @@ -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 selectEnabled(DbSession session) { + return session.getMapper(MetricMapper.class).selectAllEnabled(); + } + + public List selectEnabled(DbSession session, @Nullable Boolean isCustom, SearchOptions searchOptions) { + Map 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 index 00000000000..2b47d5bda85 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/persistence/package-info.java @@ -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 index 00000000000..d77523a52be --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/ListAction.java @@ -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 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:" + + "
    " + + "
  • true: only custom metrics are returned
  • " + + "
  • false: only non custom metrics are returned
  • " + + "
  • not specified: all metrics are returned
  • " + + "
"); + } + + @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 metrics = dbClient.metricDao().selectEnabled(dbSession, isCustom, searchOptions); + JsonWriter json = response.newJsonWriter(); + json.beginObject(); + Set desiredFields = desiredFields(request.paramAsStrings(Param.FIELDS)); + writeMetrics(json, metrics, desiredFields); + json.endObject(); + json.close(); + } finally { + MyBatis.closeQuietly(dbSession); + } + } + + private Set desiredFields(@Nullable List fields) { + if (fields == null || fields.isEmpty()) { + return POSSIBLE_FIELDS; + } + + return newHashSet(fields); + } + + private void writeMetrics(JsonWriter json, List metrics, Set 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 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 index 00000000000..0d6f060fafc --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/MetricsWs.java @@ -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 here") + .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 index 00000000000..e9a6f0ea048 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/metric/ws/MetricsWsAction.java @@ -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 +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java index 0be187f699d..4fa1e41d2aa 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java @@ -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; diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index a7af1692d96..192c9fecd65 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -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 index 3a7a4ddd8d7..00000000000 --- a/server/sonar-server/src/main/resources/org/sonar/server/measure/ws/example-list.json +++ /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 index 00000000000..3a7a4ddd8d7 --- /dev/null +++ b/server/sonar-server/src/main/resources/org/sonar/server/metric/ws/example-list.json @@ -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 +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/GlobalActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/GlobalActionTest.java index b9ffed89f19..3f26d051c4f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/GlobalActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/GlobalActionTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MetricCacheTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MetricCacheTest.java index ef27d3ba663..8670bb1821e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MetricCacheTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/measure/MetricCacheTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java index 2b96c2b4b6a..67c9dfc2781 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java @@ -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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java index 4a75cd23e32..cc0acaff668 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java @@ -20,11 +20,6 @@ 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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java index 884c854b79a..b764fed9939 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java @@ -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 index 06039d91cdb..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/persistence/MetricDaoTest.java +++ /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 index 4bbcb9b1406..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/ListActionTest.java +++ /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 index 753faf4689c..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/MetricTesting.java +++ /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 index 030a28e021a..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/ws/MetricsWsTest.java +++ /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 index 00000000000..ee5913e8ff1 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/persistence/MetricDaoTest.java @@ -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 index 00000000000..66ad2d8bd8e --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/ListActionTest.java @@ -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 index 00000000000..c991e27318e --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/MetricTesting.java @@ -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 index 00000000000..3dc57d56e3c --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/metric/ws/MetricsWsTest.java @@ -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 index 630722c4d75..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MetricDaoTest/manual_metric.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - 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 index 82b23eead28..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/persistence/MetricDaoTest/shared.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - 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 index 4f5049c8aeb..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/ws/ListActionTest/list_metrics.json +++ /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 index 00000000000..630722c4d75 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/metric/persistence/MetricDaoTest/manual_metric.xml @@ -0,0 +1,7 @@ + + + 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 index 00000000000..82b23eead28 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/metric/persistence/MetricDaoTest/shared.xml @@ -0,0 +1,15 @@ + + + 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 index 00000000000..4f5049c8aeb --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/metric/ws/ListActionTest/list_metrics.json @@ -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 index e23be8104a5..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/measure/db/MetricDto.java +++ /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 index 16b737866fc..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/measure/db/MetricMapper.java +++ /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 selectAllEnabled(); - List selectAllEnabled(Map 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 index 00000000000..d2131c9008b --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/metric/db/MetricDto.java @@ -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 index 00000000000..e7b4d2cde68 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/metric/db/MetricMapper.java @@ -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 selectAllEnabled(); + List selectAllEnabled(Map 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 index 00000000000..77b704b45d7 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/metric/db/package-info.java @@ -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; + diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index c933f606dcb..abf18b7ef4c 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -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 index 00000000000..94d22922788 --- /dev/null +++ b/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shared.xml @@ -0,0 +1,23 @@ + + + + + + + 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 index 00000000000..1100b166b82 --- /dev/null +++ b/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shouldInsert-result.xml @@ -0,0 +1,34 @@ + + + + + + + + + + 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 index 77757491d88..00000000000 --- a/sonar-core/src/main/resources/org/sonar/core/measure/db/MetricMapper.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - - - - - 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 - - - - - - - - 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} - ) - - - 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 index 00000000000..0f07acb06d0 --- /dev/null +++ b/sonar-core/src/main/resources/org/sonar/core/metric/db/MetricMapper.xml @@ -0,0 +1,64 @@ + + + + + + + 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 + + + + + + + + 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} + ) + + + 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 index 93ce3e37163..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/measure/db/MetricDtoTest.java +++ /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 index 00000000000..5c7b9ebfd40 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/metric/db/MetricDtoTest.java @@ -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 index 94d22922788..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shared.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - 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 index 1100b166b82..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/measure/db/MeasureFilterDaoTest/shouldInsert-result.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - -