aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src/test/java
diff options
context:
space:
mode:
authorHavoc Pennington <hp@pobox.com>2025-03-01 16:37:17 -0500
committersonartech <sonartech@sonarsource.com>2025-03-04 20:03:22 +0000
commit859a87748a1f005d8d565da6f526f7d5bc45d0ea (patch)
treebea7cf34ad1b97cf7e01adb34963f2594afd1d3b /server/sonar-db-dao/src/test/java
parentce5ddb53701c4715b28ebb6c644d8309d00800ec (diff)
downloadsonarqube-859a87748a1f005d8d565da6f526f7d5bc45d0ea.tar.gz
sonarqube-859a87748a1f005d8d565da6f526f7d5bc45d0ea.zip
SQRP-299 Add query with filter/sort to ScaIssuesReleasesDetailsDao
Diffstat (limited to 'server/sonar-db-dao/src/test/java')
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/sca/ScaIssueReleaseDetailsDtoTest.java44
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/sca/ScaIssuesReleasesDetailsQueryTest.java55
2 files changed, 99 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/sca/ScaIssueReleaseDetailsDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/sca/ScaIssueReleaseDetailsDtoTest.java
new file mode 100644
index 00000000000..893f191389f
--- /dev/null
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/sca/ScaIssueReleaseDetailsDtoTest.java
@@ -0,0 +1,44 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2025 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.db.sca;
+
+import java.math.BigDecimal;
+import java.util.List;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+
+class ScaIssueReleaseDetailsDtoTest {
+ @Test
+ void test_toBuilder_build_shouldRoundTrip() {
+ var dto = new ScaIssueReleaseDetailsDto("scaIssueReleaseUuid",
+ ScaSeverity.INFO,
+ "scaIssueUuid",
+ "scaReleaseUuid",
+ ScaIssueType.VULNERABILITY,
+ "packageUrl",
+ "vulnerabilityId",
+ "spdxLicenseId",
+ ScaSeverity.BLOCKER,
+ List.of("cwe1"),
+ BigDecimal.ONE);
+ assertThat(dto.toBuilder().build()).isEqualTo(dto);
+ }
+}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/sca/ScaIssuesReleasesDetailsQueryTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/sca/ScaIssuesReleasesDetailsQueryTest.java
new file mode 100644
index 00000000000..6d9f67b14eb
--- /dev/null
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/sca/ScaIssuesReleasesDetailsQueryTest.java
@@ -0,0 +1,55 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2025 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.db.sca;
+
+import java.util.List;
+import org.assertj.core.api.AssertionsForClassTypes;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class ScaIssuesReleasesDetailsQueryTest {
+
+ @Test
+ void test_toBuilder_build_shouldRoundTrip() {
+ var query = new ScaIssuesReleasesDetailsQuery("branchUuid", ScaIssuesReleasesDetailsQuery.Sort.IDENTITY_ASC,
+ "vulnerabilityIdSubstring", "packageNameSubstring",
+ List.of(ScaIssueType.VULNERABILITY), List.of(ScaSeverity.BLOCKER), List.of(PackageManager.NPM));
+ AssertionsForClassTypes.assertThat(query.toBuilder().build()).isEqualTo(query);
+ }
+
+ @Test
+ void test_queryParameterValues() {
+ for (var value : ScaIssuesReleasesDetailsQuery.Sort.values()) {
+ var queryParameterValue = value.queryParameterValue();
+ var fromQueryParameterValue = ScaIssuesReleasesDetailsQuery.Sort.fromQueryParameterValue(queryParameterValue);
+ assertThat(fromQueryParameterValue).contains(value);
+ assertThat((queryParameterValue.startsWith("+") && value.name().endsWith("_ASC")) ||
+ (queryParameterValue.startsWith("-") && value.name().endsWith("_DESC")))
+ .as("+/- prefix and ASC/DESC suffix line up")
+ .isTrue();
+ }
+ }
+
+ @Test
+ void test_whenValueIsInvalid_fromQueryParameterValue() {
+ assertThat(ScaIssuesReleasesDetailsQuery.Sort.fromQueryParameterValue("invalid")).isEmpty();
+ }
+}