aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-api
diff options
context:
space:
mode:
authorKlaudio Sinani <klaudio.sinani@sonarsource.com>2021-11-08 17:56:58 +0100
committersonartech <sonartech@sonarsource.com>2021-11-09 20:03:15 +0000
commit5819bd5d7d0cbe13cd2ceda0650032f8009ef0d4 (patch)
tree38019c9868edfe31849281c0986d67850924fbe8 /server/sonar-webserver-api
parent669cbe8ddd36e5b5a9d9067f237ee3031fa33eba (diff)
downloadsonarqube-5819bd5d7d0cbe13cd2ceda0650032f8009ef0d4.tar.gz
sonarqube-5819bd5d7d0cbe13cd2ceda0650032f8009ef0d4.zip
SONAR-15579 Improve error verbosity on permission template matching key collision + unit test
Diffstat (limited to 'server/sonar-webserver-api')
-rw-r--r--server/sonar-webserver-api/src/main/java/org/sonar/server/exceptions/TemplateMatchingKeyException.java51
-rw-r--r--server/sonar-webserver-api/src/test/java/org/sonar/server/exceptions/TemplateMatchingKeyExceptionTest.java35
2 files changed, 86 insertions, 0 deletions
diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/exceptions/TemplateMatchingKeyException.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/exceptions/TemplateMatchingKeyException.java
new file mode 100644
index 00000000000..b296dd6f282
--- /dev/null
+++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/exceptions/TemplateMatchingKeyException.java
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info 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.server.exceptions;
+
+ import com.google.common.base.MoreObjects;
+ import java.util.List;
+
+ import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
+ import static java.util.Collections.singletonList;
+
+/**
+ * Provided request is not valid due to Permission template matching key collision.
+ */
+public class TemplateMatchingKeyException extends ServerException {
+ private final transient List<String> errors;
+
+ public TemplateMatchingKeyException(String errorMessage) {
+ super(HTTP_BAD_REQUEST, errorMessage);
+ this.errors = singletonList(errorMessage);
+ }
+
+ public List<String> errors() {
+ return this.errors;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("errors", this.errors())
+ .toString();
+ }
+
+}
+
diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/exceptions/TemplateMatchingKeyExceptionTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/exceptions/TemplateMatchingKeyExceptionTest.java
new file mode 100644
index 00000000000..e68355a8839
--- /dev/null
+++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/exceptions/TemplateMatchingKeyExceptionTest.java
@@ -0,0 +1,35 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info 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.server.exceptions;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class TemplateMatchingKeyExceptionTest {
+
+ @Test
+ public void testMethods() {
+ TemplateMatchingKeyException ex = new TemplateMatchingKeyException("error");
+
+ assertThat(ex).hasToString("TemplateMatchingKeyException{errors=[error]}");
+ }
+
+}