diff options
author | Klaudio Sinani <klaudio.sinani@sonarsource.com> | 2022-03-09 10:10:29 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-03-09 20:02:58 +0000 |
commit | 0fe19fcf4e8236de5206bfb0fabd22f97065c374 (patch) | |
tree | 92fd9a08301cde137cd3457f5f88ac967bcd4458 /server/sonar-webserver-webapi | |
parent | de1309d1e8294bcd16490b0f7c5d6251fd301b4f (diff) | |
download | sonarqube-0fe19fcf4e8236de5206bfb0fabd22f97065c374.tar.gz sonarqube-0fe19fcf4e8236de5206bfb0fabd22f97065c374.zip |
SONAR-16101 Introduce new `acknowledged` resolution type for reviewed hotspots
Diffstat (limited to 'server/sonar-webserver-webapi')
4 files changed, 35 insertions, 13 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ChangeStatusAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ChangeStatusAction.java index 766f77ad82e..1229b3685a0 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ChangeStatusAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/ChangeStatusAction.java @@ -39,6 +39,7 @@ import org.sonar.server.issue.ws.IssueUpdater; import static com.google.common.base.Preconditions.checkArgument; import static org.apache.commons.lang.StringUtils.trimToNull; +import static org.sonar.api.issue.Issue.RESOLUTION_ACKNOWLEDGED; import static org.sonar.api.issue.Issue.RESOLUTION_FIXED; import static org.sonar.api.issue.Issue.SECURITY_HOTSPOT_RESOLUTIONS; import static org.sonar.api.issue.Issue.STATUS_REVIEWED; @@ -132,9 +133,15 @@ public class ChangeStatusAction implements HotspotsWsAction { if (STATUS_TO_REVIEW.equals(newStatus)) { return DefaultTransitions.RESET_AS_TO_REVIEW; } + if (STATUS_REVIEWED.equals(newStatus) && RESOLUTION_FIXED.equals(newResolution)) { return DefaultTransitions.RESOLVE_AS_REVIEWED; } + + if (STATUS_REVIEWED.equals(newStatus) && RESOLUTION_ACKNOWLEDGED.equals(newResolution)) { + return DefaultTransitions.RESOLVE_AS_ACKNOWLEDGED; + } + return DefaultTransitions.RESOLVE_AS_SAFE; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java index 96053a46560..578784ec865 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java @@ -74,6 +74,7 @@ import static java.lang.String.format; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; import static java.util.Optional.ofNullable; +import static org.sonar.api.issue.Issue.RESOLUTION_ACKNOWLEDGED; import static org.sonar.api.issue.Issue.RESOLUTION_FIXED; import static org.sonar.api.issue.Issue.RESOLUTION_SAFE; import static org.sonar.api.issue.Issue.STATUS_REVIEWED; @@ -216,7 +217,7 @@ public class SearchAction implements HotspotsWsAction { .setDescription(format( "If '%s' is provided and if status is '%s', only Security Hotspots with the specified resolution are returned.", PARAM_PROJECT_KEY, STATUS_REVIEWED)) - .setPossibleValues(RESOLUTION_FIXED, RESOLUTION_SAFE) + .setPossibleValues(RESOLUTION_FIXED, RESOLUTION_SAFE, RESOLUTION_ACKNOWLEDGED) .setRequired(false); action.createParam(PARAM_SINCE_LEAK_PERIOD) .setDescription("If '%s' is provided, only Security Hotspots created since the leak period are returned.") diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java index 6c18fbff8cf..b3daf475aa8 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/ChangeStatusActionTest.java @@ -68,6 +68,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; +import static org.sonar.api.issue.Issue.RESOLUTION_ACKNOWLEDGED; import static org.sonar.api.issue.Issue.RESOLUTION_FIXED; import static org.sonar.api.issue.Issue.RESOLUTION_SAFE; import static org.sonar.api.issue.Issue.STATUS_CLOSED; @@ -80,6 +81,7 @@ import static org.sonar.db.component.ComponentTesting.newFileDto; public class ChangeStatusActionTest { private static final Random RANDOM = new Random(); private static final String NO_COMMENT = null; + private static final List<String> RESOLUTION_TYPES = List.of(RESOLUTION_FIXED, RESOLUTION_SAFE, RESOLUTION_ACKNOWLEDGED); @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); @@ -170,16 +172,15 @@ public class ChangeStatusActionTest { assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("Value of parameter 'resolution' (" + badResolution + ") must be one of: [FIXED, SAFE]"); + .hasMessage("Value of parameter 'resolution' (" + badResolution + ") must be one of: [FIXED, SAFE, ACKNOWLEDGED]"); } @DataProvider public static Object[][] badResolutions() { return Stream.of(STATUS_TO_REVIEW, STATUS_REVIEWED) .flatMap(t -> Stream.concat(Issue.RESOLUTIONS.stream(), Issue.SECURITY_HOTSPOT_RESOLUTIONS.stream()) - .filter(r -> !r.equals(RESOLUTION_FIXED)) - .filter(r -> !r.equals(RESOLUTION_SAFE)) - .map(r -> new Object[] {t, r})) + .filter(r -> !RESOLUTION_TYPES.contains(r)) + .map(r -> new Object[] {t, r})) .toArray(Object[][]::new); } @@ -202,7 +203,8 @@ public class ChangeStatusActionTest { public static Object[][] validResolutions() { return new Object[][] { {RESOLUTION_FIXED}, - {RESOLUTION_SAFE} + {RESOLUTION_SAFE}, + {RESOLUTION_ACKNOWLEDGED} }; } @@ -260,7 +262,8 @@ public class ChangeStatusActionTest { return new Object[][] { {STATUS_TO_REVIEW, null}, {STATUS_REVIEWED, RESOLUTION_FIXED}, - {STATUS_REVIEWED, RESOLUTION_SAFE} + {STATUS_REVIEWED, RESOLUTION_SAFE}, + {STATUS_REVIEWED, RESOLUTION_ACKNOWLEDGED} }; } @@ -429,7 +432,9 @@ public class ChangeStatusActionTest { {RESOLUTION_FIXED, DefaultTransitions.RESOLVE_AS_REVIEWED, true}, {RESOLUTION_FIXED, DefaultTransitions.RESOLVE_AS_REVIEWED, false}, {RESOLUTION_SAFE, DefaultTransitions.RESOLVE_AS_SAFE, true}, - {RESOLUTION_SAFE, DefaultTransitions.RESOLVE_AS_SAFE, false} + {RESOLUTION_SAFE, DefaultTransitions.RESOLVE_AS_SAFE, false}, + {RESOLUTION_ACKNOWLEDGED, DefaultTransitions.RESOLVE_AS_ACKNOWLEDGED, true}, + {RESOLUTION_ACKNOWLEDGED, DefaultTransitions.RESOLVE_AS_ACKNOWLEDGED, false} }; } @@ -476,7 +481,9 @@ public class ChangeStatusActionTest { {RESOLUTION_FIXED, true}, {RESOLUTION_FIXED, false}, {RESOLUTION_SAFE, true}, - {RESOLUTION_SAFE, false} + {RESOLUTION_SAFE, false}, + {RESOLUTION_ACKNOWLEDGED, true}, + {RESOLUTION_ACKNOWLEDGED, false} }; } @@ -521,10 +528,16 @@ public class ChangeStatusActionTest { {STATUS_TO_REVIEW, null, STATUS_REVIEWED, RESOLUTION_FIXED}, {STATUS_TO_REVIEW, null, STATUS_REVIEWED, RESOLUTION_FIXED}, {STATUS_TO_REVIEW, null, STATUS_REVIEWED, RESOLUTION_SAFE}, + {STATUS_TO_REVIEW, null, STATUS_REVIEWED, RESOLUTION_ACKNOWLEDGED}, {STATUS_REVIEWED, RESOLUTION_FIXED, STATUS_REVIEWED, RESOLUTION_SAFE}, + {STATUS_REVIEWED, RESOLUTION_FIXED, STATUS_REVIEWED, RESOLUTION_ACKNOWLEDGED}, {STATUS_REVIEWED, RESOLUTION_FIXED, STATUS_TO_REVIEW, null}, {STATUS_REVIEWED, RESOLUTION_SAFE, STATUS_REVIEWED, RESOLUTION_FIXED}, - {STATUS_REVIEWED, RESOLUTION_SAFE, STATUS_TO_REVIEW, null} + {STATUS_REVIEWED, RESOLUTION_SAFE, STATUS_REVIEWED, RESOLUTION_ACKNOWLEDGED}, + {STATUS_REVIEWED, RESOLUTION_SAFE, STATUS_TO_REVIEW, null}, + {STATUS_REVIEWED, RESOLUTION_ACKNOWLEDGED, STATUS_REVIEWED, RESOLUTION_FIXED}, + {STATUS_REVIEWED, RESOLUTION_ACKNOWLEDGED, STATUS_REVIEWED, RESOLUTION_SAFE}, + {STATUS_REVIEWED, RESOLUTION_ACKNOWLEDGED, STATUS_TO_REVIEW, null} }; return Arrays.stream(changingStatuses) .flatMap(b -> Stream.of( diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java index 94d6aa45873..2dbdee2ee72 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java @@ -92,6 +92,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.sonar.api.issue.Issue.RESOLUTION_ACKNOWLEDGED; import static org.sonar.api.issue.Issue.RESOLUTION_FIXED; import static org.sonar.api.issue.Issue.RESOLUTION_SAFE; import static org.sonar.api.issue.Issue.STATUSES; @@ -112,6 +113,7 @@ import static org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH; public class SearchActionTest { private static final Random RANDOM = new Random(); private static final int ONE_MINUTE = 60_000; + private static final List<String> RESOLUTION_TYPES = List.of(RESOLUTION_FIXED, RESOLUTION_SAFE, RESOLUTION_ACKNOWLEDGED); @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); @@ -243,7 +245,7 @@ public class SearchActionTest { assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("Value of parameter 'resolution' (" + badResolution + ") must be one of: [FIXED, SAFE]"); + .hasMessage("Value of parameter 'resolution' (" + badResolution + ") must be one of: [FIXED, SAFE, ACKNOWLEDGED]"); } @DataProvider @@ -253,8 +255,7 @@ public class SearchActionTest { Issue.SECURITY_HOTSPOT_RESOLUTIONS.stream(), Stream.of(randomAlphabetic(4))) .flatMap(t -> t) - .filter(t -> !RESOLUTION_FIXED.equals(t)) - .filter(t -> !RESOLUTION_SAFE.equals(t)) + .filter(t -> !RESOLUTION_TYPES.contains(t)) .map(t -> new Object[]{t}) .toArray(Object[][]::new); } |