aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>2017-04-06 14:30:30 +0200
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>2017-04-20 09:48:52 +0200
commit49b8e41fd5ff06a68bcaa9d1c4e4438037902298 (patch)
tree9e610efc53b8f908421f5ce615d5f44fb918d262 /server
parent9cfb8d03356a690b25f1048a313f9467719bb1c2 (diff)
downloadsonarqube-49b8e41fd5ff06a68bcaa9d1c4e4438037902298.tar.gz
sonarqube-49b8e41fd5ff06a68bcaa9d1c4e4438037902298.zip
SONAR-9071 refactor ws test of api/components/suggestions
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java17
2 files changed, 13 insertions, 6 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
index 37801d92205..abf3e5703b5 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java
@@ -48,7 +48,7 @@ import static org.sonarqube.ws.client.component.ComponentsWsParameters.ACTION_SU
public class SuggestionsAction implements ComponentsWsAction {
- private static final String URL_PARAM_QUERY = "s";
+ static final String URL_PARAM_QUERY = "s";
private static final String[] QUALIFIERS = {
Qualifiers.VIEW,
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
index 0831417824a..65aafbb04fe 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.component.ws;
+import java.io.IOException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -35,12 +36,15 @@ import org.sonar.server.es.EsTester;
import org.sonar.server.permission.index.AuthorizationTypeSupport;
import org.sonar.server.permission.index.PermissionIndexerTester;
import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.WsActionTester;
import org.sonarqube.ws.WsComponents;
import org.sonarqube.ws.WsComponents.SuggestionsWsResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.groups.Tuple.tuple;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.server.component.ws.SuggestionsAction.URL_PARAM_QUERY;
+import static org.sonarqube.ws.MediaTypes.PROTOBUF;
public class SuggestionsActionTest {
@@ -52,25 +56,28 @@ public class SuggestionsActionTest {
public UserSessionRule userSessionRule = UserSessionRule.standalone();
private ComponentIndexer componentIndexer = new ComponentIndexer(db.getDbClient(), es.client());
- private SuggestionsAction action;
+ ComponentIndex index = new ComponentIndex(es.client(), new AuthorizationTypeSupport(userSessionRule));
+ private SuggestionsAction underTest = new SuggestionsAction(db.getDbClient(), index);
private OrganizationDto organization;
private PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, componentIndexer);
+ private WsActionTester actionTester = new WsActionTester(underTest);
@Before
public void setUp() {
- ComponentIndex index = new ComponentIndex(es.client(), new AuthorizationTypeSupport(userSessionRule));
- action = new SuggestionsAction(db.getDbClient(), index);
organization = db.organizations().insert();
}
@Test
- public void exact_match_in_one_qualifier() {
+ public void exact_match_in_one_qualifier() throws Exception {
ComponentDto project = db.components().insertComponent(newProjectDto(organization));
componentIndexer.indexOnStartup(null);
authorizationIndexerTester.allowOnlyAnyone(project);
- SuggestionsWsResponse response = action.doHandle(project.getKey());
+ SuggestionsWsResponse response = actionTester.newRequest()
+ .setMethod("POST")
+ .setParam(URL_PARAM_QUERY, project.getKey())
+ .executeProtobuf(SuggestionsWsResponse.class);
// assert match in qualifier "TRK"
assertThat(response.getResultsList())