Skip to content

Commit

Permalink
SONAR-6405 Introduce marker interface for users WS
Browse files Browse the repository at this point in the history
  • Loading branch information
jblievremont committed Apr 13, 2015
1 parent 20a2771 commit d953ac3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
@@ -0,0 +1,27 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2014 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube 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.
*
* SonarQube 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.user.ws;

import org.sonar.server.ws.WsAction;

public interface BaseUsersWsAction extends WsAction {

// Marker interface for UsersWs actions
}
Expand Up @@ -22,7 +22,6 @@

import org.sonar.api.i18n.I18n;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.text.JsonWriter;
Expand All @@ -31,7 +30,7 @@
import org.sonar.server.user.UserSession;
import org.sonar.server.user.index.UserDoc;

public class CreateAction implements RequestHandler {
public class CreateAction implements BaseUsersWsAction {

private static final String PARAM_LOGIN = "login";
private static final String PARAM_PASSWORD = "password";
Expand All @@ -48,7 +47,8 @@ public CreateAction(UserService service, I18n i18n) {
this.i18n = i18n;
}

void define(WebService.NewController controller) {
@Override
public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction("create")
.setDescription("Create a user. Requires Administer System permission")
.setSince("3.7")
Expand Down
Expand Up @@ -21,15 +21,14 @@
package org.sonar.server.user.ws;

import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.server.user.UpdateUser;
import org.sonar.server.user.UserService;
import org.sonar.server.user.index.UserDoc;

public class UpdateAction implements RequestHandler {
public class UpdateAction implements BaseUsersWsAction {

private static final String PARAM_LOGIN = "login";
private static final String PARAM_PASSWORD = "password";
Expand All @@ -44,7 +43,8 @@ public UpdateAction(UserService service) {
this.service = service;
}

void define(WebService.NewController controller) {
@Override
public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction("update")
.setDescription("Update a user. Requires Administer System permission")
.setSince("3.7")
Expand Down
Expand Up @@ -26,12 +26,10 @@

public class UsersWs implements WebService {

private final CreateAction createAction;
private final UpdateAction updateAction;
private final BaseUsersWsAction[] actions;

public UsersWs(CreateAction createAction, UpdateAction updateAction) {
this.createAction = createAction;
this.updateAction = updateAction;
public UsersWs(BaseUsersWsAction... actions) {
this.actions = actions;
}

@Override
Expand All @@ -41,9 +39,10 @@ public void define(Context context) {
.setDescription("Users management");

defineSearchAction(controller);
createAction.define(controller);
updateAction.define(controller);
defineDeactivateAction(controller);
for (BaseUsersWsAction action : actions) {
action.define(controller);
}

controller.done();
}
Expand Down
Expand Up @@ -63,7 +63,7 @@ public class CreateActionTest {

@Before
public void setUp() throws Exception {
tester = new WsTester(new UsersWs(new CreateAction(service, i18n), new UpdateAction(service)));
tester = new WsTester(new UsersWs(new CreateAction(service, i18n)));
controller = tester.controller("api/users");
}

Expand Down
Expand Up @@ -27,7 +27,6 @@
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.sonar.api.i18n.I18n;
import org.sonar.api.server.ws.WebService;
import org.sonar.server.user.UpdateUser;
import org.sonar.server.user.UserService;
Expand All @@ -39,7 +38,6 @@
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -58,7 +56,7 @@ public class UpdateActionTest {

@Before
public void setUp() throws Exception {
tester = new WsTester(new UsersWs(new CreateAction(service, mock(I18n.class)), new UpdateAction(service)));
tester = new WsTester(new UsersWs(new UpdateAction(service)));
controller = tester.controller("api/users");
}

Expand Down

0 comments on commit d953ac3

Please sign in to comment.