Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-10087 Move some logic from QualityGates to ListAction
- Loading branch information
1 parent
69b830f
commit c157750
Showing
7 changed files
with
181 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/example-list.json
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
server/sonar-server/src/main/resources/org/sonar/server/qualitygate/ws/list-example.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
{ | |||
"qualitygates": [ | |||
{ | |||
"id": 2, | |||
"name": "Sonar way", | |||
"isDefault": true | |||
}, | |||
{ | |||
"id": 4, | |||
"name": "Sonar way - Without Coverage", | |||
"isDefault": false | |||
} | |||
], | |||
"default": 2 | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ListActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,132 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2017 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.server.qualitygate.ws; | |||
|
|||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.server.ws.Change; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.qualitygate.QualityGateDto; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import org.sonar.server.ws.WsActionTester; | |||
|
|||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.AssertionsForClassTypes.tuple; | |||
import static org.sonar.test.JsonAssert.assertJson; | |||
|
|||
public class ListActionTest { | |||
|
|||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public UserSessionRule userSession = UserSessionRule.standalone(); | |||
@Rule | |||
public DbTester db = DbTester.create(); | |||
|
|||
private WsActionTester ws = new WsActionTester(new ListAction(db.getDbClient())); | |||
|
|||
@Test | |||
public void verify_definition() { | |||
WebService.Action action = ws.getDef(); | |||
assertThat(action.since()).isEqualTo("4.3"); | |||
assertThat(action.key()).isEqualTo("list"); | |||
assertThat(action.isPost()).isFalse(); | |||
assertThat(action.isInternal()).isFalse(); | |||
assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription) | |||
.containsExactlyInAnyOrder( | |||
tuple("7.0", "'isDefault' field is added on quality gate level"), | |||
tuple("7.0", "'default' field on root level is deprecated")); | |||
assertThat(action.params()).isEmpty(); | |||
} | |||
|
|||
@Test | |||
public void json_example() { | |||
QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate("Sonar way"); | |||
db.qualityGates().insertQualityGate("Sonar way - Without Coverage"); | |||
db.qualityGates().setDefaultQualityGate(defaultQualityGate); | |||
|
|||
String response = ws.newRequest() | |||
.execute() | |||
.getInput(); | |||
|
|||
assertJson(response).ignoreFields("id", "default") | |||
.isSimilarTo(getClass().getResource("list-example.json")); | |||
} | |||
|
|||
@Test | |||
public void list_quality_gates() { | |||
QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate("Sonar way"); | |||
db.qualityGates().insertQualityGate("Sonar way - Without Coverage"); | |||
db.qualityGates().setDefaultQualityGate(defaultQualityGate); | |||
|
|||
String response = ws.newRequest() | |||
.execute() | |||
.getInput(); | |||
|
|||
assertJson(response).ignoreFields("id", "default") | |||
.isSimilarTo("{\n" + | |||
" \"qualitygates\": [\n" + | |||
" {\n" + | |||
" \"name\": \"Sonar way\",\n" + | |||
" \"isDefault\": true\n" + | |||
" },\n" + | |||
" {\n" + | |||
" \"id\": 4,\n" + | |||
" \"name\": \"Sonar way - Without Coverage\",\n" + | |||
" \"isDefault\": false\n" + | |||
" }\n" + | |||
" ]\n" + | |||
"}\n"); | |||
} | |||
|
|||
@Test | |||
public void no_default_quality_gate() { | |||
db.qualityGates().insertQualityGate("Sonar way"); | |||
|
|||
String response = ws.newRequest() | |||
.execute() | |||
.getInput(); | |||
|
|||
assertJson(response).ignoreFields("id", "default") | |||
.isSimilarTo("{\n" + | |||
" \"qualitygates\": [\n" + | |||
" {\n" + | |||
" \"name\": \"Sonar way\",\n" + | |||
" \"isDefault\": false\n" + | |||
" }\n" + | |||
" ]\n" + | |||
"}\n"); | |||
} | |||
|
|||
@Test | |||
public void empty() { | |||
String response = ws.newRequest() | |||
.execute() | |||
.getInput(); | |||
|
|||
assertJson(response).ignoreFields("id", "default") | |||
.isSimilarTo("{\n" + | |||
" \"qualitygates\": []\n" + | |||
"}\n"); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters