From 52a2649016ebacf94edd3be73e24b7579d78fb8b Mon Sep 17 00:00:00 2001 From: Alain Kermis Date: Thu, 19 Sep 2024 11:56:15 +0200 Subject: [PATCH] SONAR-23064 Add new dismissible message type --- .../sonar/db/dismissmessage/MessageType.java | 3 +- .../ws/DismissActionParameterizedIT.java | 79 ++++++++----------- .../ws/DismissMessageWsAction.java | 2 +- 3 files changed, 36 insertions(+), 48 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/dismissmessage/MessageType.java b/server/sonar-db-dao/src/main/java/org/sonar/db/dismissmessage/MessageType.java index 649da104ea5..8b2001aea4c 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/dismissmessage/MessageType.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/dismissmessage/MessageType.java @@ -27,7 +27,8 @@ public enum MessageType { GLOBAL_NCD_PAGE_90(true, false), PROJECT_NCD_90(true, false), PROJECT_NCD_PAGE_90(true, false), - BRANCH_NCD_90(true, false); + BRANCH_NCD_90(true, false), + UNRESOLVED_FINDINGS_IN_AI_GENERATED_CODE(true, true); private final boolean dismissible; private final boolean isWarning; diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/dismissmessage/ws/DismissActionParameterizedIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/dismissmessage/ws/DismissActionParameterizedIT.java index 2f19d44cd22..129798ef541 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/dismissmessage/ws/DismissActionParameterizedIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/dismissmessage/ws/DismissActionParameterizedIT.java @@ -19,17 +19,15 @@ */ package org.sonar.server.dismissmessage.ws; -import java.util.Arrays; -import java.util.Collection; -import javax.annotation.Nullable; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import java.util.stream.Stream; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; -import org.sonar.db.dismissmessage.MessageType; import org.sonar.db.component.ProjectData; +import org.sonar.db.dismissmessage.MessageType; import org.sonar.db.user.UserDto; import org.sonar.server.component.TestComponentFinder; import org.sonar.server.tester.UserSessionRule; @@ -40,31 +38,19 @@ import org.sonar.server.ws.WsActionTester; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -@RunWith(Parameterized.class) -public class DismissActionParameterizedIT { - - @Rule - public UserSessionRule userSession = UserSessionRule.standalone(); +class DismissActionParameterizedIT { - @Rule - public DbTester db = DbTester.create(System2.INSTANCE); + @RegisterExtension + private final UserSessionRule userSession = UserSessionRule.standalone(); - @Nullable - private final boolean isProjectKeyNull; + @RegisterExtension + private final DbTester db = DbTester.create(System2.INSTANCE); - private final MessageType messageType; - - private final Class expectedException; private final WsActionTester underTest = new WsActionTester(new DismissAction(userSession, db.getDbClient(), TestComponentFinder.from(db))); - public DismissActionParameterizedIT(boolean isProjectKeyNull, MessageType messageType, Class expectedException) { - this.isProjectKeyNull = isProjectKeyNull; - this.messageType = messageType; - this.expectedException = expectedException; - } - - @Test - public void test_verifyProjectKeyAndMessageType() { + @ParameterizedTest + @MethodSource("combinations") + void execute(boolean isProjectKeyNull, MessageType messageType, Class expectedException) { UserDto user = db.users().insertUser(); userSession.logIn(user); @@ -79,28 +65,29 @@ public class DismissActionParameterizedIT { if(expectedException != null) { assertThatThrownBy(request::execute) .isInstanceOf(expectedException); - } else { + } else { TestResponse response = request.execute(); assertThat(response.getStatus()).isEqualTo(204); } } - @Parameterized.Parameters - public static Collection parameterCombination() { - return Arrays.asList(new Object[][]{ - {true, MessageType.INFO, IllegalArgumentException.class}, - {true, MessageType.GENERIC, IllegalArgumentException.class}, - {true, MessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE, IllegalArgumentException.class}, - {false, MessageType.GLOBAL_NCD_90, IllegalArgumentException.class}, - {false, MessageType.GLOBAL_NCD_PAGE_90, IllegalArgumentException.class}, - {true, MessageType.PROJECT_NCD_90, IllegalArgumentException.class}, - {true, MessageType.PROJECT_NCD_PAGE_90, IllegalArgumentException.class}, - {true, MessageType.BRANCH_NCD_90, IllegalArgumentException.class}, - {true, MessageType.GLOBAL_NCD_90, null}, - {true, MessageType.GLOBAL_NCD_PAGE_90, null}, - {false, MessageType.PROJECT_NCD_90, null}, - {false, MessageType.PROJECT_NCD_PAGE_90, null}, - {false, MessageType.BRANCH_NCD_90, null}, - }); + private static Stream combinations() { + return Stream.of( + Arguments.of(true, MessageType.INFO, IllegalArgumentException.class), + Arguments.of(true, MessageType.GENERIC, IllegalArgumentException.class), + Arguments.of(true, MessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE, IllegalArgumentException.class), + Arguments.of(false, MessageType.GLOBAL_NCD_90, IllegalArgumentException.class), + Arguments.of(false, MessageType.GLOBAL_NCD_PAGE_90, IllegalArgumentException.class), + Arguments.of(true, MessageType.PROJECT_NCD_90, IllegalArgumentException.class), + Arguments.of(true, MessageType.PROJECT_NCD_PAGE_90, IllegalArgumentException.class), + Arguments.of(true, MessageType.BRANCH_NCD_90, IllegalArgumentException.class), + Arguments.of(true, MessageType.GLOBAL_NCD_90, null), + Arguments.of(true, MessageType.GLOBAL_NCD_PAGE_90, null), + Arguments.of(false, MessageType.PROJECT_NCD_90, null), + Arguments.of(false, MessageType.PROJECT_NCD_PAGE_90, null), + Arguments.of(false, MessageType.BRANCH_NCD_90, null), + Arguments.of(false, MessageType.UNRESOLVED_FINDINGS_IN_AI_GENERATED_CODE, null), + Arguments.of(true, MessageType.UNRESOLVED_FINDINGS_IN_AI_GENERATED_CODE, IllegalArgumentException.class) + ); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/dismissmessage/ws/DismissMessageWsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/dismissmessage/ws/DismissMessageWsAction.java index 3acfe87400e..3981007ea75 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/dismissmessage/ws/DismissMessageWsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/dismissmessage/ws/DismissMessageWsAction.java @@ -42,7 +42,7 @@ public interface DismissMessageWsAction extends WsAction { throw new IllegalArgumentException("The 'projectKey' parameter is not expected for message type: " + type); } } - case PROJECT_NCD_90, PROJECT_NCD_PAGE_90, BRANCH_NCD_90 -> { + case PROJECT_NCD_90, PROJECT_NCD_PAGE_90, BRANCH_NCD_90, UNRESOLVED_FINDINGS_IN_AI_GENERATED_CODE -> { if(projectKey == null) { throw new IllegalArgumentException("The 'projectKey' parameter is missing for message type: " + type); } -- 2.39.5