aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-12-16 15:27:24 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-12-19 10:12:54 +0100
commit95ab6f6776c4b8e4ead3a4f6215c9c03c9b475c5 (patch)
tree6c5fc22660b58ba557cab2be13c7d2f9789f79df /sonar-db
parent6a94b3b976758fb094488c36b9c178e6ef811f81 (diff)
downloadsonarqube-95ab6f6776c4b8e4ead3a4f6215c9c03c9b475c5.tar.gz
sonarqube-95ab6f6776c4b8e4ead3a4f6215c9c03c9b475c5.zip
SONAR-7288 Create WS api/favorites/remove
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/test/java/org/sonar/db/DbTester.java9
-rw-r--r--sonar-db/src/test/java/org/sonar/db/favorite/FavoriteDbTester.java61
2 files changed, 69 insertions, 1 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/DbTester.java b/sonar-db/src/test/java/org/sonar/db/DbTester.java
index 9d4a3e2bd1c..48fbd8494c3 100644
--- a/sonar-db/src/test/java/org/sonar/db/DbTester.java
+++ b/sonar-db/src/test/java/org/sonar/db/DbTester.java
@@ -65,6 +65,7 @@ import org.sonar.api.utils.log.Loggers;
import org.sonar.core.util.SequenceUuidFactory;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.event.EventDbTester;
+import org.sonar.db.favorite.FavoriteDbTester;
import org.sonar.db.issue.IssueDbTester;
import org.sonar.db.organization.OrganizationDbTester;
import org.sonar.db.organization.OrganizationDto;
@@ -102,6 +103,7 @@ public class DbTester extends ExternalResource {
private final UserDbTester userTester;
private final ComponentDbTester componentTester;
+ private final FavoriteDbTester favoriteTester;
private final EventDbTester eventTester;
private final OrganizationDbTester organizationTester;
private final PermissionTemplateDbTester permissionTemplateTester;
@@ -116,6 +118,7 @@ public class DbTester extends ExternalResource {
initDbClient();
this.userTester = new UserDbTester(this);
this.componentTester = new ComponentDbTester(this);
+ this.favoriteTester = new FavoriteDbTester(this);
this.eventTester = new EventDbTester(this);
this.organizationTester = new OrganizationDbTester(this);
this.permissionTemplateTester = new PermissionTemplateDbTester(this);
@@ -190,6 +193,10 @@ public class DbTester extends ExternalResource {
return componentTester;
}
+ public FavoriteDbTester favorites() {
+ return favoriteTester;
+ }
+
public EventDbTester events() {
return eventTester;
}
@@ -587,7 +594,7 @@ public class DbTester extends ExternalResource {
*/
public void assertIndexDoesNotExist(String tableName, String indexName) {
try (Connection connection = getConnection();
- ResultSet rs = connection.getMetaData().getIndexInfo(null, null, tableName.toUpperCase(Locale.ENGLISH), false, false)) {
+ ResultSet rs = connection.getMetaData().getIndexInfo(null, null, tableName.toUpperCase(Locale.ENGLISH), false, false)) {
List<String> indices = new ArrayList<>();
while (rs.next()) {
indices.add(rs.getString("INDEX_NAME").toLowerCase(Locale.ENGLISH));
diff --git a/sonar-db/src/test/java/org/sonar/db/favorite/FavoriteDbTester.java b/sonar-db/src/test/java/org/sonar/db/favorite/FavoriteDbTester.java
new file mode 100644
index 00000000000..452bfbac197
--- /dev/null
+++ b/sonar-db/src/test/java/org/sonar/db/favorite/FavoriteDbTester.java
@@ -0,0 +1,61 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.db.favorite;
+
+import java.util.List;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.property.PropertyDto;
+import org.sonar.db.property.PropertyQuery;
+
+public class FavoriteDbTester {
+ private static final String PROP_FAVORITE_KEY = "favourite";
+
+ private final DbTester db;
+ private final DbClient dbClient;
+ private final DbSession dbSession;
+
+ public FavoriteDbTester(DbTester db) {
+ this.db = db;
+ this.dbClient = db.getDbClient();
+ this.dbSession = db.getSession();
+ }
+
+ public void add(ComponentDto componentDto, long userId) {
+ dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto()
+ .setKey(PROP_FAVORITE_KEY)
+ .setUserId(userId)
+ .setResourceId(componentDto.getId()));
+ dbSession.commit();
+ }
+
+ public boolean hasFavorite(ComponentDto componentDto, long userId) {
+ List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
+ .setKey(PROP_FAVORITE_KEY)
+ .setComponentId(componentDto.getId())
+ .setUserId((int) userId)
+ .build(), dbSession);
+
+ return !result.isEmpty();
+ }
+}