aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-12-27 18:01:12 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-12-29 17:20:59 +0100
commit3c0c955eb5d529436420cff5c65dcd3ee3118ebe (patch)
treeb6077b3744287ec094e8d403e01f47d8d0cb45f4 /sonar-db/src
parent61686cb47293d5d6f5da78593676de662ac94e55 (diff)
downloadsonarqube-3c0c955eb5d529436420cff5c65dcd3ee3118ebe.tar.gz
sonarqube-3c0c955eb5d529436420cff5c65dcd3ee3118ebe.zip
SONAR-8555 SONAR-8556 Create WS api/notifications/add and remove
Diffstat (limited to 'sonar-db/src')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/property/PropertyQuery.java4
-rw-r--r--sonar-db/src/test/java/org/sonar/db/DbTester.java7
-rw-r--r--sonar-db/src/test/java/org/sonar/db/notification/NotificationDbTester.java65
3 files changed, 75 insertions, 1 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/property/PropertyQuery.java b/sonar-db/src/main/java/org/sonar/db/property/PropertyQuery.java
index 34a8bb5cfe1..45befce078f 100644
--- a/sonar-db/src/main/java/org/sonar/db/property/PropertyQuery.java
+++ b/sonar-db/src/main/java/org/sonar/db/property/PropertyQuery.java
@@ -19,6 +19,8 @@
*/
package org.sonar.db.property;
+import javax.annotation.Nullable;
+
public class PropertyQuery {
private final String key;
@@ -57,7 +59,7 @@ public class PropertyQuery {
return this;
}
- public Builder setComponentId(Long componentId) {
+ public Builder setComponentId(@Nullable Long componentId) {
this.componentId = componentId;
return this;
}
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 48fbd8494c3..970e8756171 100644
--- a/sonar-db/src/test/java/org/sonar/db/DbTester.java
+++ b/sonar-db/src/test/java/org/sonar/db/DbTester.java
@@ -67,6 +67,7 @@ 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.notification.NotificationDbTester;
import org.sonar.db.organization.OrganizationDbTester;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
@@ -110,6 +111,7 @@ public class DbTester extends ExternalResource {
private final QualityGateDbTester qualityGateDbTester;
private final IssueDbTester issueDbTester;
private final RuleDbTester ruleDbTester;
+ private final NotificationDbTester notificationDbTester;
private final RootFlagAssertions rootFlagAssertions;
private DbTester(System2 system2, @Nullable String schemaPath) {
@@ -125,6 +127,7 @@ public class DbTester extends ExternalResource {
this.qualityGateDbTester = new QualityGateDbTester(this);
this.issueDbTester = new IssueDbTester(this);
this.ruleDbTester = new RuleDbTester(this);
+ this.notificationDbTester = new NotificationDbTester(this);
this.rootFlagAssertions = new RootFlagAssertions(this);
}
@@ -225,6 +228,10 @@ public class DbTester extends ExternalResource {
return ruleDbTester;
}
+ public NotificationDbTester notifications() {
+ return notificationDbTester;
+ }
+
@Override
protected void after() {
if (session != null) {
diff --git a/sonar-db/src/test/java/org/sonar/db/notification/NotificationDbTester.java b/sonar-db/src/test/java/org/sonar/db/notification/NotificationDbTester.java
new file mode 100644
index 00000000000..4ad7893ee73
--- /dev/null
+++ b/sonar-db/src/test/java/org/sonar/db/notification/NotificationDbTester.java
@@ -0,0 +1,65 @@
+/*
+ * 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.notification;
+
+import java.util.List;
+import javax.annotation.Nullable;
+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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class NotificationDbTester {
+ private static final String PROP_NOTIFICATION_PREFIX = "notification";
+
+ private final DbTester db;
+ private final DbClient dbClient;
+ private final DbSession dbSession;
+
+ public NotificationDbTester(DbTester db) {
+ this.db = db;
+ this.dbClient = db.getDbClient();
+ this.dbSession = db.getSession();
+ }
+
+ public void assertExists(String channel, String dispatcher, long userId, @Nullable ComponentDto component) {
+ List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
+ .setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel))
+ .setComponentId(component == null ? null : component.getId())
+ .setUserId((int) userId)
+ .build(), dbSession);
+ assertThat(result).hasSize(1);
+ assertThat(result.get(0).getValue()).isEqualTo("true");
+ }
+
+ public void assertDoesNotExist(String channel, String dispatcher, long userId, @Nullable ComponentDto component) {
+ List<PropertyDto> result = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder()
+ .setKey(String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel))
+ .setComponentId(component == null ? null : component.getId())
+ .setUserId((int) userId)
+ .build(), dbSession);
+ assertThat(result).isEmpty();
+ }
+}