]> source.dussan.org Git - sonarqube.git/commitdiff
refactoring - move custom measures related classes in the measure.custom package
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 8 Jun 2015 14:08:18 +0000 (16:08 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 8 Jun 2015 14:12:08 +0000 (16:12 +0200)
30 files changed:
server/sonar-server/src/main/java/org/sonar/server/custommeasure/persistence/CustomMeasureDao.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/custommeasure/persistence/package-info.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/CustomMeasuresWs.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/CustomMeasuresWsAction.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/CustomMeasuresWsModule.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/DeleteAction.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/package-info.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java
server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/CustomMeasureDao.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/package-info.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CustomMeasuresWs.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CustomMeasuresWsAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CustomMeasuresWsModule.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/DeleteAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/package-info.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/test/java/org/sonar/server/custommeasure/persistence/CustomMeasureDaoTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/custommeasure/persistence/CustomMeasureTesting.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/custommeasure/ws/CustomMeasuresWsModuleTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/custommeasure/ws/CustomMeasuresWsTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/custommeasure/ws/DeleteActionTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureDaoTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureTesting.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CustomMeasuresWsModuleTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CustomMeasuresWsTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java

diff --git a/server/sonar-server/src/main/java/org/sonar/server/custommeasure/persistence/CustomMeasureDao.java b/server/sonar-server/src/main/java/org/sonar/server/custommeasure/persistence/CustomMeasureDao.java
deleted file mode 100644 (file)
index ff92ecd..0000000
+++ /dev/null
@@ -1,79 +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.custommeasure.persistence;
-
-import com.google.common.base.Function;
-import java.util.List;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
-import org.sonar.api.server.ServerSide;
-import org.sonar.core.custommeasure.db.CustomMeasureDto;
-import org.sonar.core.custommeasure.db.CustomMeasureMapper;
-import org.sonar.core.persistence.DaoComponent;
-import org.sonar.core.persistence.DaoUtils;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.server.exceptions.NotFoundException;
-
-@ServerSide
-public class CustomMeasureDao implements DaoComponent {
-  public void insert(DbSession session, CustomMeasureDto customMeasureDto) {
-    mapper(session).insert(customMeasureDto);
-  }
-
-  public void delete(DbSession session, long id) {
-    mapper(session).delete(id);
-  }
-
-  public void deleteByMetricIds(final DbSession session, final List<Integer> metricIds) {
-    DaoUtils.executeLargeInputsWithoutOutput(metricIds, new Function<List<Integer>, Void>() {
-      @Override
-      public Void apply(@Nonnull List<Integer> input) {
-        mapper(session).deleteByMetricIds(metricIds);
-        return null;
-      }
-    });
-  }
-
-  @CheckForNull
-  public CustomMeasureDto selectNullableById(DbSession session, long id) {
-    return mapper(session).selectById(id);
-  }
-
-  public CustomMeasureDto selectById(DbSession session, long id) {
-    CustomMeasureDto customMeasure = selectNullableById(session, id);
-    if (customMeasure == null) {
-      throw new NotFoundException(String.format("CustomMeasure '%d' not found", id));
-    }
-    return customMeasure;
-  }
-
-  public List<CustomMeasureDto> selectByMetricId(DbSession session, int id) {
-    return mapper(session).selectByMetricId(id);
-  }
-
-  public List<CustomMeasureDto> selectByComponentId(DbSession session, long id) {
-    return mapper(session).selectByComponentId(id);
-  }
-
-  private CustomMeasureMapper mapper(DbSession session) {
-    return session.getMapper(CustomMeasureMapper.class);
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/custommeasure/persistence/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/custommeasure/persistence/package-info.java
deleted file mode 100644 (file)
index c236052..0000000
+++ /dev/null
@@ -1,24 +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.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.server.custommeasure.persistence;
-
-import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/CustomMeasuresWs.java b/server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/CustomMeasuresWs.java
deleted file mode 100644 (file)
index f67a62f..0000000
+++ /dev/null
@@ -1,46 +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.custommeasure.ws;
-
-import org.sonar.api.server.ws.WebService;
-
-public class CustomMeasuresWs implements WebService {
-  public static final String ENDPOINT = "api/custom_measures";
-
-  private final CustomMeasuresWsAction[] actions;
-
-  public CustomMeasuresWs(CustomMeasuresWsAction... actions) {
-    this.actions = actions;
-  }
-
-  @Override
-  public void define(Context context) {
-    NewController controller = context.createController(ENDPOINT)
-      .setDescription("Custom measures management")
-      .setSince("5.2");
-
-    for (CustomMeasuresWsAction action : actions) {
-      action.define(controller);
-    }
-
-    controller.done();
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/CustomMeasuresWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/CustomMeasuresWsAction.java
deleted file mode 100644 (file)
index 2fa1a82..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.sonar.server.custommeasure.ws;
-
-import org.sonar.server.ws.WsAction;
-
-public interface CustomMeasuresWsAction extends WsAction {
-  // marker interface
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/CustomMeasuresWsModule.java b/server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/CustomMeasuresWsModule.java
deleted file mode 100644 (file)
index 108cc8c..0000000
+++ /dev/null
@@ -1,32 +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.custommeasure.ws;
-
-import org.sonar.core.component.Module;
-
-public class CustomMeasuresWsModule extends Module {
-  @Override
-  protected void configureModule() {
-    add(
-      CustomMeasuresWs.class,
-      DeleteAction.class);
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/DeleteAction.java b/server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/DeleteAction.java
deleted file mode 100644 (file)
index 56349d0..0000000
+++ /dev/null
@@ -1,87 +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.custommeasure.ws;
-
-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.web.UserRole;
-import org.sonar.core.component.ComponentDto;
-import org.sonar.core.custommeasure.db.CustomMeasureDto;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.user.UserSession;
-
-public class DeleteAction implements CustomMeasuresWsAction {
-
-  private static final String ACTION = "delete";
-  public static final String PARAM_ID = "id";
-
-  private final DbClient dbClient;
-  private final UserSession userSession;
-
-  public DeleteAction(DbClient dbClient, UserSession userSession) {
-    this.dbClient = dbClient;
-    this.userSession = userSession;
-  }
-
-  @Override
-  public void define(WebService.NewController context) {
-    WebService.NewAction action = context.createAction(ACTION)
-      .setPost(true)
-      .setHandler(this)
-      .setSince("5.2")
-      .setDescription("Delete a custom measure.<br /> Requires 'Administer System' permission or 'Administer' permission on the project.");
-
-    action.createParam(PARAM_ID)
-      .setDescription("Id")
-      .setExampleValue("24")
-      .setRequired(true);
-  }
-
-  @Override
-  public void handle(Request request, Response response) throws Exception {
-    long id = request.mandatoryParamAsLong(PARAM_ID);
-
-    DbSession dbSession = dbClient.openSession(false);
-    try {
-      CustomMeasureDto customMeasure = dbClient.customMeasureDao().selectById(dbSession, id);
-      checkPermissions(dbSession, customMeasure);
-      dbClient.customMeasureDao().delete(dbSession, id);
-      dbSession.commit();
-    } finally {
-      MyBatis.closeQuietly(dbSession);
-    }
-
-    response.noContent();
-  }
-
-  private void checkPermissions(DbSession dbSession, CustomMeasureDto customMeasure) {
-    if (userSession.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN)) {
-      return;
-    }
-
-    ComponentDto component = dbClient.componentDao().selectById(customMeasure.getComponentId(), dbSession);
-    userSession.checkLoggedIn().checkProjectUuidPermission(UserRole.ADMIN, component.projectUuid());
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/custommeasure/ws/package-info.java
deleted file mode 100644 (file)
index 29a6629..0000000
+++ /dev/null
@@ -1,24 +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.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.server.custommeasure.ws;
-
-import javax.annotation.ParametersAreNonnullByDefault;
index 29a59dceec7b21c805863a89cfa89b85add4e88b..b4194d6617850e11f8ea3bbad0fa734053ca17ca 100644 (file)
@@ -50,7 +50,7 @@ import org.sonar.server.component.db.ComponentIndexDao;
 import org.sonar.server.component.db.ComponentLinkDao;
 import org.sonar.server.component.db.SnapshotDao;
 import org.sonar.server.computation.db.AnalysisReportDao;
-import org.sonar.server.custommeasure.persistence.CustomMeasureDao;
+import org.sonar.server.measure.custom.persistence.CustomMeasureDao;
 import org.sonar.server.dashboard.db.DashboardDao;
 import org.sonar.server.dashboard.db.WidgetDao;
 import org.sonar.server.dashboard.db.WidgetPropertyDao;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/CustomMeasureDao.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/CustomMeasureDao.java
new file mode 100644 (file)
index 0000000..c18755b
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * 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.custom.persistence;
+
+import com.google.common.base.Function;
+import java.util.List;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+import org.sonar.api.server.ServerSide;
+import org.sonar.core.custommeasure.db.CustomMeasureDto;
+import org.sonar.core.custommeasure.db.CustomMeasureMapper;
+import org.sonar.core.persistence.DaoComponent;
+import org.sonar.core.persistence.DaoUtils;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.server.exceptions.NotFoundException;
+
+@ServerSide
+public class CustomMeasureDao implements DaoComponent {
+  public void insert(DbSession session, CustomMeasureDto customMeasureDto) {
+    mapper(session).insert(customMeasureDto);
+  }
+
+  public void delete(DbSession session, long id) {
+    mapper(session).delete(id);
+  }
+
+  public void deleteByMetricIds(final DbSession session, final List<Integer> metricIds) {
+    DaoUtils.executeLargeInputsWithoutOutput(metricIds, new Function<List<Integer>, Void>() {
+      @Override
+      public Void apply(@Nonnull List<Integer> input) {
+        mapper(session).deleteByMetricIds(metricIds);
+        return null;
+      }
+    });
+  }
+
+  @CheckForNull
+  public CustomMeasureDto selectNullableById(DbSession session, long id) {
+    return mapper(session).selectById(id);
+  }
+
+  public CustomMeasureDto selectById(DbSession session, long id) {
+    CustomMeasureDto customMeasure = selectNullableById(session, id);
+    if (customMeasure == null) {
+      throw new NotFoundException(String.format("CustomMeasure '%d' not found", id));
+    }
+    return customMeasure;
+  }
+
+  public List<CustomMeasureDto> selectByMetricId(DbSession session, int id) {
+    return mapper(session).selectByMetricId(id);
+  }
+
+  public List<CustomMeasureDto> selectByComponentId(DbSession session, long id) {
+    return mapper(session).selectByComponentId(id);
+  }
+
+  private CustomMeasureMapper mapper(DbSession session) {
+    return session.getMapper(CustomMeasureMapper.class);
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/persistence/package-info.java
new file mode 100644 (file)
index 0000000..08372c5
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.server.measure.custom.persistence;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CustomMeasuresWs.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CustomMeasuresWs.java
new file mode 100644 (file)
index 0000000..7659040
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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.custom.ws;
+
+import org.sonar.api.server.ws.WebService;
+
+public class CustomMeasuresWs implements WebService {
+  public static final String ENDPOINT = "api/custom_measures";
+
+  private final CustomMeasuresWsAction[] actions;
+
+  public CustomMeasuresWs(CustomMeasuresWsAction... actions) {
+    this.actions = actions;
+  }
+
+  @Override
+  public void define(Context context) {
+    NewController controller = context.createController(ENDPOINT)
+      .setDescription("Custom measures management")
+      .setSince("5.2");
+
+    for (CustomMeasuresWsAction action : actions) {
+      action.define(controller);
+    }
+
+    controller.done();
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CustomMeasuresWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CustomMeasuresWsAction.java
new file mode 100644 (file)
index 0000000..d6d392c
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.measure.custom.ws;
+
+import org.sonar.server.ws.WsAction;
+
+public interface CustomMeasuresWsAction extends WsAction {
+  // marker interface
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CustomMeasuresWsModule.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CustomMeasuresWsModule.java
new file mode 100644 (file)
index 0000000..f0c981e
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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.custom.ws;
+
+import org.sonar.core.component.Module;
+
+public class CustomMeasuresWsModule extends Module {
+  @Override
+  protected void configureModule() {
+    add(
+      CustomMeasuresWs.class,
+      DeleteAction.class);
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/DeleteAction.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/DeleteAction.java
new file mode 100644 (file)
index 0000000..993db3c
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * 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.custom.ws;
+
+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.web.UserRole;
+import org.sonar.core.component.ComponentDto;
+import org.sonar.core.custommeasure.db.CustomMeasureDto;
+import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.MyBatis;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.user.UserSession;
+
+public class DeleteAction implements CustomMeasuresWsAction {
+
+  private static final String ACTION = "delete";
+  public static final String PARAM_ID = "id";
+
+  private final DbClient dbClient;
+  private final UserSession userSession;
+
+  public DeleteAction(DbClient dbClient, UserSession userSession) {
+    this.dbClient = dbClient;
+    this.userSession = userSession;
+  }
+
+  @Override
+  public void define(WebService.NewController context) {
+    WebService.NewAction action = context.createAction(ACTION)
+      .setPost(true)
+      .setHandler(this)
+      .setSince("5.2")
+      .setDescription("Delete a custom measure.<br /> Requires 'Administer System' permission or 'Administer' permission on the project.");
+
+    action.createParam(PARAM_ID)
+      .setDescription("Id")
+      .setExampleValue("24")
+      .setRequired(true);
+  }
+
+  @Override
+  public void handle(Request request, Response response) throws Exception {
+    long id = request.mandatoryParamAsLong(PARAM_ID);
+
+    DbSession dbSession = dbClient.openSession(false);
+    try {
+      CustomMeasureDto customMeasure = dbClient.customMeasureDao().selectById(dbSession, id);
+      checkPermissions(dbSession, customMeasure);
+      dbClient.customMeasureDao().delete(dbSession, id);
+      dbSession.commit();
+    } finally {
+      MyBatis.closeQuietly(dbSession);
+    }
+
+    response.noContent();
+  }
+
+  private void checkPermissions(DbSession dbSession, CustomMeasureDto customMeasure) {
+    if (userSession.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN)) {
+      return;
+    }
+
+    ComponentDto component = dbClient.componentDao().selectById(customMeasure.getComponentId(), dbSession);
+    userSession.checkLoggedIn().checkProjectUuidPermission(UserRole.ADMIN, component.projectUuid());
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/package-info.java
new file mode 100644 (file)
index 0000000..4fca405
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.server.measure.custom.ws;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index cb582d899aaa8a4d2fd4d5e82613003f62f4f261..9a746002a27b9368517bb8f005a4266c2167909a 100644 (file)
@@ -39,7 +39,7 @@ import org.sonar.server.component.db.ComponentIndexDao;
 import org.sonar.server.component.db.ComponentLinkDao;
 import org.sonar.server.component.db.SnapshotDao;
 import org.sonar.server.computation.db.AnalysisReportDao;
-import org.sonar.server.custommeasure.persistence.CustomMeasureDao;
+import org.sonar.server.measure.custom.persistence.CustomMeasureDao;
 import org.sonar.server.dashboard.db.DashboardDao;
 import org.sonar.server.dashboard.db.WidgetDao;
 import org.sonar.server.dashboard.db.WidgetPropertyDao;
index 21f69f49d6526dabfd662280b6fbb20d18eba087..5d816942ad3295343013c2fca24fa9309f2aa04a 100644 (file)
@@ -75,7 +75,7 @@ import org.sonar.server.computation.ws.HistoryAction;
 import org.sonar.server.computation.ws.IsQueueEmptyWs;
 import org.sonar.server.computation.ws.QueueAction;
 import org.sonar.server.config.ws.PropertiesWs;
-import org.sonar.server.custommeasure.ws.CustomMeasuresWsModule;
+import org.sonar.server.measure.custom.ws.CustomMeasuresWsModule;
 import org.sonar.server.dashboard.template.GlobalDefaultDashboard;
 import org.sonar.server.dashboard.template.ProjectDefaultDashboard;
 import org.sonar.server.dashboard.template.ProjectIssuesDashboard;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/custommeasure/persistence/CustomMeasureDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/custommeasure/persistence/CustomMeasureDaoTest.java
deleted file mode 100644 (file)
index 60c6a02..0000000
+++ /dev/null
@@ -1,102 +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.custommeasure.persistence;
-
-import java.util.Arrays;
-import java.util.List;
-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.custommeasure.db.CustomMeasureDto;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.DbTester;
-import org.sonar.server.db.DbClient;
-import org.sonar.test.DbTests;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.offset;
-import static org.sonar.server.custommeasure.persistence.CustomMeasureTesting.newCustomMeasureDto;
-
-@Category(DbTests.class)
-public class CustomMeasureDaoTest {
-  @ClassRule
-  public static DbTester db = new DbTester();
-
-  CustomMeasureDao sut;
-  DbSession session;
-
-  @Before
-  public void setUp() {
-    DbClient dbClient = new DbClient(db.database(), db.myBatis(), new CustomMeasureDao());
-    session = dbClient.openSession(false);
-    sut = dbClient.customMeasureDao();
-    db.truncateTables();
-  }
-
-  @After
-  public void tearDown() {
-    session.close();
-  }
-
-  @Test
-  public void insert() {
-    CustomMeasureDto measure = newCustomMeasureDto();
-
-    sut.insert(session, measure);
-
-    CustomMeasureDto result = sut.selectNullableById(session, measure.getId());
-    assertThat(result.getId()).isEqualTo(measure.getId());
-    assertThat(result.getMetricId()).isEqualTo(measure.getMetricId());
-    assertThat(result.getComponentId()).isEqualTo(measure.getComponentId());
-    assertThat(result.getDescription()).isEqualTo(measure.getDescription());
-    assertThat(result.getUserLogin()).isEqualTo(measure.getUserLogin());
-    assertThat(result.getTextValue()).isEqualTo(measure.getTextValue());
-    assertThat(result.getValue()).isCloseTo(measure.getValue(), offset(0.001d));
-    assertThat(result.getCreatedAt()).isEqualTo(measure.getCreatedAt());
-    assertThat(result.getUpdatedAt()).isEqualTo(measure.getUpdatedAt());
-  }
-
-  @Test
-  public void delete() {
-    CustomMeasureDto measure = newCustomMeasureDto();
-    sut.insert(session, measure);
-    assertThat(sut.selectNullableById(session, measure.getId())).isNotNull();
-
-    sut.deleteByMetricIds(session, Arrays.asList(measure.getMetricId()));
-
-    assertThat(sut.selectNullableById(session, measure.getId())).isNull();
-  }
-
-  @Test
-  public void select_by_component_id() {
-    sut.insert(session, newCustomMeasureDto().setComponentId(1));
-    sut.insert(session, newCustomMeasureDto().setComponentId(1));
-    sut.insert(session, newCustomMeasureDto().setComponentId(2));
-    session.commit();
-
-    List<CustomMeasureDto> result = sut.selectByComponentId(session, 1L);
-
-    assertThat(result).hasSize(2);
-    assertThat(result).extracting("componentId").containsOnly(1L);
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/custommeasure/persistence/CustomMeasureTesting.java b/server/sonar-server/src/test/java/org/sonar/server/custommeasure/persistence/CustomMeasureTesting.java
deleted file mode 100644 (file)
index 23c94cb..0000000
+++ /dev/null
@@ -1,45 +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.custommeasure.persistence;
-
-import org.apache.commons.lang.RandomStringUtils;
-import org.apache.commons.lang.math.RandomUtils;
-import org.sonar.api.utils.System2;
-import org.sonar.core.custommeasure.db.CustomMeasureDto;
-
-public class CustomMeasureTesting {
-  private CustomMeasureTesting() {
-    // static stuff only
-  }
-
-  public static CustomMeasureDto newCustomMeasureDto() {
-    return new CustomMeasureDto()
-      .setDescription(RandomStringUtils.randomAlphanumeric(255))
-      .setTextValue(RandomStringUtils.randomAlphanumeric(255))
-      .setUserLogin(RandomStringUtils.randomAlphanumeric(255))
-      .setValue(RandomUtils.nextDouble())
-      .setMetricId(RandomUtils.nextInt())
-      .setComponentId(RandomUtils.nextInt())
-      .setCreatedAt(System2.INSTANCE.now())
-      .setUpdatedAt(System2.INSTANCE.now())
-      ;
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/custommeasure/ws/CustomMeasuresWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/custommeasure/ws/CustomMeasuresWsModuleTest.java
deleted file mode 100644 (file)
index caff479..0000000
+++ /dev/null
@@ -1,35 +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.custommeasure.ws;
-
-import org.junit.Test;
-import org.sonar.core.platform.ComponentContainer;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class CustomMeasuresWsModuleTest {
-  @Test
-  public void verify_count_of_added_components() {
-    ComponentContainer container = new ComponentContainer();
-    new CustomMeasuresWsModule().configure(container);
-    assertThat(container.size()).isEqualTo(4);
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/custommeasure/ws/CustomMeasuresWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/custommeasure/ws/CustomMeasuresWsTest.java
deleted file mode 100644 (file)
index 085ef9b..0000000
+++ /dev/null
@@ -1,58 +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.custommeasure.ws;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.user.UserSession;
-import org.sonar.server.ws.WsTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class CustomMeasuresWsTest {
-  WsTester ws;
-
-  @Before
-  public void setUp() {
-    DbClient dbClient = mock(DbClient.class);
-    UserSession userSession = mock(UserSession.class);
-    ws = new WsTester(new CustomMeasuresWs(
-      new DeleteAction(dbClient, userSession)
-      ));
-  }
-
-  @Test
-  public void define_ws() {
-    WebService.Controller controller = ws.controller("api/custom_measures");
-    assertThat(controller).isNotNull();
-    assertThat(controller.description()).isNotEmpty();
-    assertThat(controller.actions()).hasSize(1);
-  }
-
-  @Test
-  public void delete_action_properties() {
-    WebService.Action deleteAction = ws.controller("api/custom_measures").action("delete");
-    assertThat(deleteAction.isPost()).isTrue();
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/custommeasure/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/custommeasure/ws/DeleteActionTest.java
deleted file mode 100644 (file)
index b31a733..0000000
+++ /dev/null
@@ -1,129 +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.custommeasure.ws;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.web.UserRole;
-import org.sonar.core.component.ComponentDto;
-import org.sonar.core.custommeasure.db.CustomMeasureDto;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.DbTester;
-import org.sonar.server.component.ComponentTesting;
-import org.sonar.server.component.db.ComponentDao;
-import org.sonar.server.custommeasure.persistence.CustomMeasureDao;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.tester.UserSessionRule;
-import org.sonar.server.ws.WsTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.custommeasure.persistence.CustomMeasureTesting.newCustomMeasureDto;
-import static org.sonar.server.custommeasure.ws.DeleteAction.PARAM_ID;
-
-public class DeleteActionTest {
-
-  public static final String ACTION = "delete";
-
-  @ClassRule
-  public static DbTester db = new DbTester();
-  @Rule
-  public UserSessionRule userSessionRule = UserSessionRule.standalone();
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-  WsTester ws;
-  DbClient dbClient;
-  DbSession dbSession;
-
-  @Before
-  public void setUp() {
-    dbClient = new DbClient(db.database(), db.myBatis(), new CustomMeasureDao(), new ComponentDao());
-    dbSession = dbClient.openSession(false);
-    ws = new WsTester(new CustomMeasuresWs(new DeleteAction(dbClient, userSessionRule)));
-    userSessionRule.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
-    db.truncateTables();
-  }
-
-  @After
-  public void tearDown() {
-    dbSession.close();
-  }
-
-  @Test
-  public void delete_in_db() throws Exception {
-    long id = insertCustomMeasure(newCustomMeasureDto());
-    long anotherId = insertCustomMeasure(newCustomMeasureDto());
-    assertThat(dbClient.customMeasureDao().selectNullableById(dbSession, id)).isNotNull();
-
-    WsTester.Result response = newRequest().setParam(PARAM_ID, String.valueOf(id)).execute();
-    dbSession.commit();
-
-    assertThat(dbClient.customMeasureDao().selectNullableById(dbSession, id)).isNull();
-    assertThat(dbClient.customMeasureDao().selectNullableById(dbSession, anotherId)).isNotNull();
-    response.assertNoContent();
-  }
-
-  @Test
-  public void delete_in_db_when_admin_on_project() throws Exception {
-    ComponentDto project = ComponentTesting.newProjectDto("project-uuid");
-    dbClient.componentDao().insert(dbSession, project);
-    userSessionRule.login("login").addProjectUuidPermissions(UserRole.ADMIN, "project-uuid");
-    long id = insertCustomMeasure(newCustomMeasureDto().setComponentId(project.getId()));
-
-    newRequest().setParam(PARAM_ID, String.valueOf(id)).execute();
-
-    assertThat(dbClient.customMeasureDao().selectNullableById(dbSession, id)).isNull();
-  }
-
-  @Test
-  public void fail_when_not_found_in_db() throws Exception {
-    expectedException.expect(NotFoundException.class);
-
-    newRequest().setParam(PARAM_ID, "42").execute();
-  }
-
-  @Test
-  public void fail_when_insufficient_permissions() throws Exception {
-    expectedException.expect(ForbiddenException.class);
-    userSessionRule.login("login");
-    ComponentDto project = ComponentTesting.newProjectDto("any-uuid");
-    dbClient.componentDao().insert(dbSession, project);
-    long id = insertCustomMeasure(newCustomMeasureDto().setComponentId(project.getId()));
-
-    newRequest().setParam(PARAM_ID, String.valueOf(id)).execute();
-  }
-
-  private long insertCustomMeasure(CustomMeasureDto customMeasure) {
-    dbClient.customMeasureDao().insert(dbSession, customMeasure);
-    dbSession.commit();
-    return customMeasure.getId();
-  }
-
-  private WsTester.TestRequest newRequest() {
-    return ws.newPostRequest(CustomMeasuresWs.ENDPOINT, ACTION);
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureDaoTest.java
new file mode 100644 (file)
index 0000000..2d8e7e3
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * 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.custom.persistence;
+
+import java.util.Arrays;
+import java.util.List;
+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.custommeasure.db.CustomMeasureDto;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.DbTester;
+import org.sonar.server.db.DbClient;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.offset;
+import static org.sonar.server.measure.custom.persistence.CustomMeasureTesting.newCustomMeasureDto;
+
+@Category(DbTests.class)
+public class CustomMeasureDaoTest {
+  @ClassRule
+  public static DbTester db = new DbTester();
+
+  CustomMeasureDao sut;
+  DbSession session;
+
+  @Before
+  public void setUp() {
+    DbClient dbClient = new DbClient(db.database(), db.myBatis(), new CustomMeasureDao());
+    session = dbClient.openSession(false);
+    sut = dbClient.customMeasureDao();
+    db.truncateTables();
+  }
+
+  @After
+  public void tearDown() {
+    session.close();
+  }
+
+  @Test
+  public void insert() {
+    CustomMeasureDto measure = newCustomMeasureDto();
+
+    sut.insert(session, measure);
+
+    CustomMeasureDto result = sut.selectNullableById(session, measure.getId());
+    assertThat(result.getId()).isEqualTo(measure.getId());
+    assertThat(result.getMetricId()).isEqualTo(measure.getMetricId());
+    assertThat(result.getComponentId()).isEqualTo(measure.getComponentId());
+    assertThat(result.getDescription()).isEqualTo(measure.getDescription());
+    assertThat(result.getUserLogin()).isEqualTo(measure.getUserLogin());
+    assertThat(result.getTextValue()).isEqualTo(measure.getTextValue());
+    assertThat(result.getValue()).isCloseTo(measure.getValue(), offset(0.001d));
+    assertThat(result.getCreatedAt()).isEqualTo(measure.getCreatedAt());
+    assertThat(result.getUpdatedAt()).isEqualTo(measure.getUpdatedAt());
+  }
+
+  @Test
+  public void delete() {
+    CustomMeasureDto measure = newCustomMeasureDto();
+    sut.insert(session, measure);
+    assertThat(sut.selectNullableById(session, measure.getId())).isNotNull();
+
+    sut.deleteByMetricIds(session, Arrays.asList(measure.getMetricId()));
+
+    assertThat(sut.selectNullableById(session, measure.getId())).isNull();
+  }
+
+  @Test
+  public void select_by_component_id() {
+    sut.insert(session, newCustomMeasureDto().setComponentId(1));
+    sut.insert(session, newCustomMeasureDto().setComponentId(1));
+    sut.insert(session, newCustomMeasureDto().setComponentId(2));
+    session.commit();
+
+    List<CustomMeasureDto> result = sut.selectByComponentId(session, 1L);
+
+    assertThat(result).hasSize(2);
+    assertThat(result).extracting("componentId").containsOnly(1L);
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureTesting.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/persistence/CustomMeasureTesting.java
new file mode 100644 (file)
index 0000000..20868a9
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.custom.persistence;
+
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang.math.RandomUtils;
+import org.sonar.api.utils.System2;
+import org.sonar.core.custommeasure.db.CustomMeasureDto;
+
+public class CustomMeasureTesting {
+  private CustomMeasureTesting() {
+    // static stuff only
+  }
+
+  public static CustomMeasureDto newCustomMeasureDto() {
+    return new CustomMeasureDto()
+      .setDescription(RandomStringUtils.randomAlphanumeric(255))
+      .setTextValue(RandomStringUtils.randomAlphanumeric(255))
+      .setUserLogin(RandomStringUtils.randomAlphanumeric(255))
+      .setValue(RandomUtils.nextDouble())
+      .setMetricId(RandomUtils.nextInt())
+      .setComponentId(RandomUtils.nextInt())
+      .setCreatedAt(System2.INSTANCE.now())
+      .setUpdatedAt(System2.INSTANCE.now())
+      ;
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CustomMeasuresWsModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CustomMeasuresWsModuleTest.java
new file mode 100644 (file)
index 0000000..c0ed75c
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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.custom.ws;
+
+import org.junit.Test;
+import org.sonar.core.platform.ComponentContainer;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class CustomMeasuresWsModuleTest {
+  @Test
+  public void verify_count_of_added_components() {
+    ComponentContainer container = new ComponentContainer();
+    new CustomMeasuresWsModule().configure(container);
+    assertThat(container.size()).isEqualTo(4);
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CustomMeasuresWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CustomMeasuresWsTest.java
new file mode 100644 (file)
index 0000000..d0a5028
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * 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.custom.ws;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.user.UserSession;
+import org.sonar.server.ws.WsTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+public class CustomMeasuresWsTest {
+  WsTester ws;
+
+  @Before
+  public void setUp() {
+    DbClient dbClient = mock(DbClient.class);
+    UserSession userSession = mock(UserSession.class);
+    ws = new WsTester(new CustomMeasuresWs(
+      new DeleteAction(dbClient, userSession)
+      ));
+  }
+
+  @Test
+  public void define_ws() {
+    WebService.Controller controller = ws.controller("api/custom_measures");
+    assertThat(controller).isNotNull();
+    assertThat(controller.description()).isNotEmpty();
+    assertThat(controller.actions()).hasSize(1);
+  }
+
+  @Test
+  public void delete_action_properties() {
+    WebService.Action deleteAction = ws.controller("api/custom_measures").action("delete");
+    assertThat(deleteAction.isPost()).isTrue();
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java
new file mode 100644 (file)
index 0000000..67c43d5
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * 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.custom.ws;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.web.UserRole;
+import org.sonar.core.component.ComponentDto;
+import org.sonar.core.custommeasure.db.CustomMeasureDto;
+import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.DbTester;
+import org.sonar.server.component.ComponentTesting;
+import org.sonar.server.component.db.ComponentDao;
+import org.sonar.server.measure.custom.persistence.CustomMeasureDao;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.exceptions.ForbiddenException;
+import org.sonar.server.exceptions.NotFoundException;
+import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.WsTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.measure.custom.persistence.CustomMeasureTesting.newCustomMeasureDto;
+import static org.sonar.server.measure.custom.ws.DeleteAction.PARAM_ID;
+
+public class DeleteActionTest {
+
+  public static final String ACTION = "delete";
+
+  @ClassRule
+  public static DbTester db = new DbTester();
+  @Rule
+  public UserSessionRule userSessionRule = UserSessionRule.standalone();
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+  WsTester ws;
+  DbClient dbClient;
+  DbSession dbSession;
+
+  @Before
+  public void setUp() {
+    dbClient = new DbClient(db.database(), db.myBatis(), new CustomMeasureDao(), new ComponentDao());
+    dbSession = dbClient.openSession(false);
+    ws = new WsTester(new CustomMeasuresWs(new DeleteAction(dbClient, userSessionRule)));
+    userSessionRule.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+    db.truncateTables();
+  }
+
+  @After
+  public void tearDown() {
+    dbSession.close();
+  }
+
+  @Test
+  public void delete_in_db() throws Exception {
+    long id = insertCustomMeasure(newCustomMeasureDto());
+    long anotherId = insertCustomMeasure(newCustomMeasureDto());
+    assertThat(dbClient.customMeasureDao().selectNullableById(dbSession, id)).isNotNull();
+
+    WsTester.Result response = newRequest().setParam(PARAM_ID, String.valueOf(id)).execute();
+    dbSession.commit();
+
+    assertThat(dbClient.customMeasureDao().selectNullableById(dbSession, id)).isNull();
+    assertThat(dbClient.customMeasureDao().selectNullableById(dbSession, anotherId)).isNotNull();
+    response.assertNoContent();
+  }
+
+  @Test
+  public void delete_in_db_when_admin_on_project() throws Exception {
+    ComponentDto project = ComponentTesting.newProjectDto("project-uuid");
+    dbClient.componentDao().insert(dbSession, project);
+    userSessionRule.login("login").addProjectUuidPermissions(UserRole.ADMIN, "project-uuid");
+    long id = insertCustomMeasure(newCustomMeasureDto().setComponentId(project.getId()));
+
+    newRequest().setParam(PARAM_ID, String.valueOf(id)).execute();
+
+    assertThat(dbClient.customMeasureDao().selectNullableById(dbSession, id)).isNull();
+  }
+
+  @Test
+  public void fail_when_not_found_in_db() throws Exception {
+    expectedException.expect(NotFoundException.class);
+
+    newRequest().setParam(PARAM_ID, "42").execute();
+  }
+
+  @Test
+  public void fail_when_insufficient_permissions() throws Exception {
+    expectedException.expect(ForbiddenException.class);
+    userSessionRule.login("login");
+    ComponentDto project = ComponentTesting.newProjectDto("any-uuid");
+    dbClient.componentDao().insert(dbSession, project);
+    long id = insertCustomMeasure(newCustomMeasureDto().setComponentId(project.getId()));
+
+    newRequest().setParam(PARAM_ID, String.valueOf(id)).execute();
+  }
+
+  private long insertCustomMeasure(CustomMeasureDto customMeasure) {
+    dbClient.customMeasureDao().insert(dbSession, customMeasure);
+    dbSession.commit();
+    return customMeasure.getId();
+  }
+
+  private WsTester.TestRequest newRequest() {
+    return ws.newPostRequest(CustomMeasuresWs.ENDPOINT, ACTION);
+  }
+}
index 7a2f8e59a1f55717d94ffd78e4c57eeab412370e..5b33efe6e9fe1bfbde1b77b273ffdad7cd2240bb 100644 (file)
@@ -32,8 +32,8 @@ import org.sonar.core.metric.db.MetricDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.persistence.DbTester;
-import org.sonar.server.custommeasure.persistence.CustomMeasureDao;
-import org.sonar.server.custommeasure.persistence.CustomMeasureTesting;
+import org.sonar.server.measure.custom.persistence.CustomMeasureDao;
+import org.sonar.server.measure.custom.persistence.CustomMeasureTesting;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.ServerException;
index 2f8a108b48cbc759b31dab4bdca0ffdf778d194e..2175ff6c5946b92ffc57dda6d4c0e55f34f248fb 100644 (file)
@@ -34,8 +34,8 @@ import org.sonar.core.metric.db.MetricDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.persistence.DbTester;
-import org.sonar.server.custommeasure.persistence.CustomMeasureDao;
-import org.sonar.server.custommeasure.persistence.CustomMeasureTesting;
+import org.sonar.server.measure.custom.persistence.CustomMeasureDao;
+import org.sonar.server.measure.custom.persistence.CustomMeasureTesting;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.metric.persistence.MetricDao;
index 8a8a9d75bc8562b7198303cbcbcc00d12e3e9841..92365534125c5ad7cd5fb739e79f6bcd09a12769 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.core.metric.db.MetricDto;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.persistence.DbTester;
-import org.sonar.server.custommeasure.persistence.CustomMeasureDao;
+import org.sonar.server.measure.custom.persistence.CustomMeasureDao;
 import org.sonar.server.db.DbClient;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.ServerException;
@@ -42,7 +42,7 @@ import org.sonar.server.ws.WsTester;
 import org.sonar.test.DbTests;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.custommeasure.persistence.CustomMeasureTesting.newCustomMeasureDto;
+import static org.sonar.server.measure.custom.persistence.CustomMeasureTesting.newCustomMeasureDto;
 import static org.sonar.server.metric.ws.UpdateAction.PARAM_DESCRIPTION;
 import static org.sonar.server.metric.ws.UpdateAction.PARAM_DOMAIN;
 import static org.sonar.server.metric.ws.UpdateAction.PARAM_ID;