]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-23064 Add new dismissible message type
authorAlain Kermis <alain.kermis@sonarsource.com>
Thu, 19 Sep 2024 09:56:15 +0000 (11:56 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 25 Sep 2024 20:02:53 +0000 (20:02 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/dismissmessage/MessageType.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/dismissmessage/ws/DismissActionParameterizedIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/dismissmessage/ws/DismissMessageWsAction.java

index 649da104ea5be7e41eae116131bd13495d557d48..8b2001aea4ca029923c3800931642b80bfb3dfd5 100644 (file)
@@ -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;
index 2f19d44cd229ebfc31b088aba112480101afce19..129798ef541d3588fbf3eb760bfd2046a23f1e8b 100644 (file)
  */
 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<? extends Throwable> expectedException;
   private final WsActionTester underTest = new WsActionTester(new DismissAction(userSession, db.getDbClient(), TestComponentFinder.from(db)));
 
-  public DismissActionParameterizedIT(boolean isProjectKeyNull, MessageType messageType, Class<? extends Throwable> 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<? extends Throwable> 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<Object[]> 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<Arguments> 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)
+    );
   }
 }
index 3acfe87400ed8526ec3965d4d4f332f8aa320faa..3981007ea758bbd91cb5a7b30687ef1b8f2fca81 100644 (file)
@@ -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);
         }