3 * Copyright (C) 2009-2024 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.dismissmessage.ws;
22 import java.util.Arrays;
23 import java.util.Collection;
24 import javax.annotation.Nullable;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.Parameterized;
29 import org.sonar.api.utils.System2;
30 import org.sonar.db.DbTester;
31 import org.sonar.db.dismissmessage.MessageType;
32 import org.sonar.db.component.ProjectData;
33 import org.sonar.db.user.UserDto;
34 import org.sonar.server.component.TestComponentFinder;
35 import org.sonar.server.tester.UserSessionRule;
36 import org.sonar.server.ws.TestRequest;
37 import org.sonar.server.ws.TestResponse;
38 import org.sonar.server.ws.WsActionTester;
40 import static org.assertj.core.api.Assertions.assertThat;
41 import static org.assertj.core.api.Assertions.assertThatThrownBy;
43 @RunWith(Parameterized.class)
44 public class DismissActionParameterizedIT {
47 public UserSessionRule userSession = UserSessionRule.standalone();
50 public DbTester db = DbTester.create(System2.INSTANCE);
53 private final boolean isProjectKeyNull;
55 private final MessageType messageType;
57 private final Class<? extends Throwable> expectedException;
58 private final WsActionTester underTest = new WsActionTester(new DismissAction(userSession, db.getDbClient(), TestComponentFinder.from(db)));
60 public DismissActionParameterizedIT(boolean isProjectKeyNull, MessageType messageType, Class<? extends Throwable> expectedException) {
61 this.isProjectKeyNull = isProjectKeyNull;
62 this.messageType = messageType;
63 this.expectedException = expectedException;
67 public void test_verifyProjectKeyAndMessageType() {
68 UserDto user = db.users().insertUser();
69 userSession.logIn(user);
71 TestRequest request = underTest.newRequest()
72 .setParam("messageType", messageType.name());
74 if(!isProjectKeyNull) {
75 ProjectData project = db.components().insertPrivateProject();
76 request.setParam("projectKey", project.projectKey());
79 if(expectedException != null) {
80 assertThatThrownBy(request::execute)
81 .isInstanceOf(expectedException);
83 TestResponse response = request.execute();
84 assertThat(response.getStatus()).isEqualTo(204);
88 @Parameterized.Parameters
89 public static Collection<Object[]> parameterCombination() {
90 return Arrays.asList(new Object[][]{
91 {true, MessageType.INFO, IllegalArgumentException.class},
92 {true, MessageType.GENERIC, IllegalArgumentException.class},
93 {true, MessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE, IllegalArgumentException.class},
94 {false, MessageType.GLOBAL_NCD_90, IllegalArgumentException.class},
95 {false, MessageType.GLOBAL_NCD_PAGE_90, IllegalArgumentException.class},
96 {true, MessageType.PROJECT_NCD_90, IllegalArgumentException.class},
97 {true, MessageType.PROJECT_NCD_PAGE_90, IllegalArgumentException.class},
98 {true, MessageType.BRANCH_NCD_90, IllegalArgumentException.class},
99 {true, MessageType.GLOBAL_NCD_90, null},
100 {true, MessageType.GLOBAL_NCD_PAGE_90, null},
101 {false, MessageType.PROJECT_NCD_90, null},
102 {false, MessageType.PROJECT_NCD_PAGE_90, null},
103 {false, MessageType.BRANCH_NCD_90, null},