diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-10-06 08:54:26 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-10-06 11:18:46 +0200 |
commit | d20713782db677b348fd0a4bf99a939191c6c481 (patch) | |
tree | a3c7d9d71396ac3c9c7e1aba6d8b7c035be8b3eb /server/sonar-server | |
parent | 790ce0a67f245c3c8d6f95f6f2323846aa069914 (diff) | |
download | sonarqube-d20713782db677b348fd0a4bf99a939191c6c481.tar.gz sonarqube-d20713782db677b348fd0a4bf99a939191c6c481.zip |
SONAR-6903 Rename WS api/usergroups/* to api/user_groups/*
Diffstat (limited to 'server/sonar-server')
12 files changed, 108 insertions, 149 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java index 7788423296b..c2da27123e6 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java @@ -34,10 +34,10 @@ import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService.NewController; import org.sonar.api.server.ws.WebService.Param; import org.sonar.api.utils.text.JsonWriter; +import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.MyBatis; import org.sonar.db.user.GroupDto; -import org.sonar.server.db.DbClient; import org.sonar.server.es.SearchOptions; public class SearchAction implements UserGroupsWsAction { diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java index eb5b66210f0..175e4c5f2be 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UpdateAction.java @@ -26,9 +26,9 @@ import org.sonar.api.server.ws.WebService.NewAction; import org.sonar.api.server.ws.WebService.NewController; import org.sonar.api.utils.text.JsonWriter; import org.sonar.core.permission.GlobalPermissions; +import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.user.GroupDto; -import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.user.UserSession; diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupUpdater.java index 9924563740a..10d5744f9b0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupUpdater.java @@ -23,9 +23,9 @@ import com.google.common.base.Preconditions; import org.sonar.api.security.DefaultGroups; import org.sonar.api.server.ServerSide; import org.sonar.api.utils.text.JsonWriter; +import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.user.GroupDto; -import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.BadRequestException; @ServerSide diff --git a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupsWs.java b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupsWs.java index 8ace6844681..87f590f430b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupsWs.java +++ b/server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupsWs.java @@ -31,7 +31,7 @@ public class UserGroupsWs implements WebService { @Override public void define(Context context) { - NewController controller = context.createController("api/usergroups") + NewController controller = context.createController("api/user_groups") .setDescription("User groups management") .setSince("5.2"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java index 7a107b95343..3cb6c5cb35a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/AddUserActionTest.java @@ -201,7 +201,7 @@ public class AddUserActionTest { } private WsTester.TestRequest newRequest() { - return ws.newPostRequest("api/usergroups", "add_user"); + return ws.newPostRequest("api/user_groups", "add_user"); } private GroupDto insertGroup(String groupName) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java index 2411ad91327..36a014ee4ec 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/CreateActionTest.java @@ -22,7 +22,6 @@ package org.sonar.server.usergroups.ws; import java.net.HttpURLConnection; import org.apache.commons.lang.StringUtils; -import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -30,14 +29,14 @@ import org.junit.experimental.categories.Category; import org.junit.rules.ExpectedException; import org.sonar.api.utils.System2; import org.sonar.core.permission.GlobalPermissions; +import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.user.GroupDao; import org.sonar.db.user.GroupDto; -import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.ServerException; import org.sonar.server.tester.UserSessionRule; -import org.sonar.db.user.GroupDao; import org.sonar.server.ws.WsTester; import org.sonar.test.DbTests; @@ -45,42 +44,29 @@ import org.sonar.test.DbTests; public class CreateActionTest { @Rule - public DbTester dbTester = DbTester.create(System2.INSTANCE); - + public DbTester db = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSession = UserSessionRule.standalone(); - @Rule public ExpectedException expectedException = ExpectedException.none(); - private WsTester tester; - + private WsTester ws; private GroupDao groupDao; - - private DbSession session; + private DbSession dbSession; @Before public void setUp() { - dbTester.truncateTables(); - - groupDao = new GroupDao(System2.INSTANCE); + DbClient dbClient = db.getDbClient(); + groupDao = dbClient.groupDao(); + dbSession = db.getSession(); - DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), groupDao); - - tester = new WsTester(new UserGroupsWs(new CreateAction(dbClient, userSession, new UserGroupUpdater(dbClient)))); - - session = dbClient.openSession(false); - } - - @After - public void after() { - session.close(); + ws = new WsTester(new UserGroupsWs(new CreateAction(dbClient, userSession, new UserGroupUpdater(dbClient)))); } @Test public void create_nominal() throws Exception { loginAsAdmin(); - tester.newPostRequest("api/usergroups", "create") + newRequest() .setParam("name", "some-product-bu") .setParam("description", "Business Unit for Some Awesome Product") .execute().assertJson("{" + @@ -95,7 +81,7 @@ public class CreateActionTest { @Test(expected = ForbiddenException.class) public void require_admin_permission() throws Exception { userSession.login("not-admin"); - tester.newPostRequest("api/usergroups", "create") + newRequest() .setParam("name", "some-product-bu") .setParam("description", "Business Unit for Some Awesome Product") .execute(); @@ -104,7 +90,7 @@ public class CreateActionTest { @Test(expected = IllegalArgumentException.class) public void name_too_short() throws Exception { loginAsAdmin(); - tester.newPostRequest("api/usergroups", "create") + newRequest() .setParam("name", "") .execute(); } @@ -112,7 +98,7 @@ public class CreateActionTest { @Test(expected = IllegalArgumentException.class) public void name_too_long() throws Exception { loginAsAdmin(); - tester.newPostRequest("api/usergroups", "create") + newRequest() .setParam("name", StringUtils.repeat("a", 255 + 1)) .execute(); } @@ -120,7 +106,7 @@ public class CreateActionTest { @Test(expected = IllegalArgumentException.class) public void forbidden_name() throws Exception { loginAsAdmin(); - tester.newPostRequest("api/usergroups", "create") + newRequest() .setParam("name", "AnYoNe") .execute(); } @@ -128,15 +114,15 @@ public class CreateActionTest { @Test public void non_unique_name() throws Exception { String groupName = "conflicting-name"; - groupDao.insert(session, new GroupDto() + groupDao.insert(dbSession, new GroupDto() .setName(groupName)); - session.commit(); + db.commit(); expectedException.expect(ServerException.class); expectedException.expectMessage("already taken"); loginAsAdmin(); - tester.newPostRequest("api/usergroups", "create") + newRequest() .setParam("name", groupName) .execute().assertStatus(HttpURLConnection.HTTP_CONFLICT); } @@ -144,12 +130,16 @@ public class CreateActionTest { @Test(expected = IllegalArgumentException.class) public void description_too_long() throws Exception { loginAsAdmin(); - tester.newPostRequest("api/usergroups", "create") + newRequest() .setParam("name", "long-group-description-is-looooooooooooong") .setParam("description", StringUtils.repeat("a", 200 + 1)) .execute(); } + private WsTester.TestRequest newRequest() { + return ws.newPostRequest("api/user_groups", "create"); + } + private void loginAsAdmin() { userSession.login("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java index e835f5b1598..066056627d7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/DeleteActionTest.java @@ -176,6 +176,6 @@ public class DeleteActionTest { } private WsTester.TestRequest newRequest() { - return ws.newPostRequest("api/usergroups", "delete"); + return ws.newPostRequest("api/user_groups", "delete"); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java index d710ed9a766..04df677336b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/RemoveUserActionTest.java @@ -182,7 +182,7 @@ public class RemoveUserActionTest { } private WsTester.TestRequest newRequest() { - return ws.newPostRequest("api/usergroups", "remove_user"); + return ws.newPostRequest("api/user_groups", "remove_user"); } private GroupDto insertGroup(String groupName) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java index 24ab3083066..d6735607ff6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/SearchActionTest.java @@ -21,21 +21,20 @@ package org.sonar.server.usergroups.ws; import org.apache.commons.lang.StringUtils; -import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonar.api.server.ws.WebService.Param; import org.sonar.api.utils.System2; +import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.user.GroupDao; import org.sonar.db.user.GroupDto; import org.sonar.db.user.GroupMembershipDao; import org.sonar.db.user.UserGroupDao; import org.sonar.db.user.UserGroupDto; -import org.sonar.server.db.DbClient; -import org.sonar.db.user.GroupDao; import org.sonar.server.ws.WsTester; import org.sonar.test.DbTests; @@ -45,49 +44,37 @@ import static org.assertj.core.api.Assertions.assertThat; public class SearchActionTest { @Rule - public DbTester dbTester = DbTester.create(System2.INSTANCE); - - private WsTester tester; + public DbTester db = DbTester.create(System2.INSTANCE); + private WsTester ws; private GroupDao groupDao; - private GroupMembershipDao groupMembershipDao; - private UserGroupDao userGroupDao; - - private DbSession session; + private DbSession dbSession; @Before public void setUp() { - dbTester.truncateTables(); + DbClient dbClient = db.getDbClient(); + groupDao = dbClient.groupDao(); + groupMembershipDao = dbClient.groupMembershipDao(); + userGroupDao = dbClient.userGroupDao(); - groupDao = new GroupDao(System2.INSTANCE); - groupMembershipDao = new GroupMembershipDao(dbTester.myBatis()); - userGroupDao = new UserGroupDao(); + ws = new WsTester(new UserGroupsWs(new SearchAction(dbClient))); - DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), groupDao, groupMembershipDao); - - tester = new WsTester(new UserGroupsWs(new SearchAction(dbClient))); - - session = dbClient.openSession(false); - } - - @After - public void after() { - session.close(); + dbSession = dbClient.openSession(false); } @Test public void search_empty() throws Exception { - tester.newGetRequest("api/usergroups", "search").execute().assertJson(getClass(), "empty.json"); + newRequest().execute().assertJson(getClass(), "empty.json"); } @Test public void search_without_parameters() throws Exception { insertGroups("users", "admins", "customer1", "customer2", "customer3"); - session.commit(); + dbSession.commit(); - tester.newGetRequest("api/usergroups", "search").execute().assertJson(getClass(), "five_groups.json"); + newRequest().execute().assertJson(getClass(), "five_groups.json"); } @Test @@ -96,80 +83,84 @@ public class SearchActionTest { insertMembers("users", 5); insertMembers("admins", 1); insertMembers("customer2", 4); - session.commit(); + dbSession.commit(); - tester.newGetRequest("api/usergroups", "search").execute().assertJson(getClass(), "with_members.json"); + newRequest().execute().assertJson(getClass(), "with_members.json"); } @Test public void search_with_query() throws Exception { insertGroups("users", "admins", "customer1", "customer2", "customer3"); - session.commit(); + dbSession.commit(); - tester.newGetRequest("api/usergroups", "search").setParam(Param.TEXT_QUERY, "custom").execute().assertJson(getClass(), "customers.json"); + newRequest().setParam(Param.TEXT_QUERY, "custom").execute().assertJson(getClass(), "customers.json"); } @Test public void search_with_paging() throws Exception { insertGroups("users", "admins", "customer1", "customer2", "customer3"); - session.commit(); + dbSession.commit(); - tester.newGetRequest("api/usergroups", "search") + newRequest() .setParam(Param.PAGE_SIZE, "3").execute().assertJson(getClass(), "page_1.json"); - tester.newGetRequest("api/usergroups", "search") + newRequest() .setParam(Param.PAGE_SIZE, "3").setParam(Param.PAGE, "2").execute().assertJson(getClass(), "page_2.json"); - tester.newGetRequest("api/usergroups", "search") + newRequest() .setParam(Param.PAGE_SIZE, "3").setParam(Param.PAGE, "3").execute().assertJson(getClass(), "page_3.json"); } @Test public void search_with_fields() throws Exception { insertGroups("sonar-users"); - session.commit(); + dbSession.commit(); - assertThat(tester.newGetRequest("api/usergroups", "search").execute().outputAsString()) + assertThat(newRequest().execute().outputAsString()) .contains("id") .contains("name") .contains("description") .contains("membersCount"); - assertThat(tester.newGetRequest("api/usergroups", "search").setParam(Param.FIELDS, "").execute().outputAsString()) + assertThat(newRequest().setParam(Param.FIELDS, "").execute().outputAsString()) .contains("id") .contains("name") .contains("description") .contains("membersCount"); - assertThat(tester.newGetRequest("api/usergroups", "search").setParam(Param.FIELDS, "name").execute().outputAsString()) + assertThat(newRequest().setParam(Param.FIELDS, "name").execute().outputAsString()) .contains("id") .contains("name") .doesNotContain("description") .doesNotContain("membersCount"); - assertThat(tester.newGetRequest("api/usergroups", "search").setParam(Param.FIELDS, "description").execute().outputAsString()) + assertThat(newRequest().setParam(Param.FIELDS, "description").execute().outputAsString()) .contains("id") .doesNotContain("name") .contains("description") .doesNotContain("membersCount"); - assertThat(tester.newGetRequest("api/usergroups", "search").setParam(Param.FIELDS, "membersCount").execute().outputAsString()) + assertThat(newRequest().setParam(Param.FIELDS, "membersCount").execute().outputAsString()) .contains("id") .doesNotContain("name") .doesNotContain("description") .contains("membersCount"); } + private WsTester.TestRequest newRequest() { + return ws.newGetRequest("api/user_groups", "search"); + } + private void insertGroups(String... groupNames) { for (String groupName : groupNames) { - groupDao.insert(session, new GroupDto() + groupDao.insert(dbSession, new GroupDto() .setName(groupName) .setDescription(StringUtils.capitalize(groupName))); } } private void insertMembers(String groupName, int count) { - long groupId = groupDao.selectOrFailByName(session, groupName).getId(); + long groupId = groupDao.selectOrFailByName(dbSession, groupName).getId(); for (int i = 0; i < count; i++) { - userGroupDao.insert(session, new UserGroupDto().setGroupId(groupId).setUserId((long) i + 1)); + userGroupDao.insert(dbSession, new UserGroupDto().setGroupId(groupId).setUserId((long) i + 1)); } } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java index 9cc1145e08a..6dc0de268c5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UpdateActionTest.java @@ -22,7 +22,6 @@ package org.sonar.server.usergroups.ws; import java.net.HttpURLConnection; import org.apache.commons.lang.StringUtils; -import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -30,18 +29,17 @@ import org.junit.experimental.categories.Category; import org.junit.rules.ExpectedException; import org.sonar.api.utils.System2; import org.sonar.core.permission.GlobalPermissions; +import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.user.GroupDao; import org.sonar.db.user.GroupDto; -import org.sonar.db.user.GroupMembershipDao; import org.sonar.db.user.UserGroupDao; import org.sonar.db.user.UserGroupDto; -import org.sonar.server.db.DbClient; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.exceptions.ServerException; import org.sonar.server.tester.UserSessionRule; -import org.sonar.db.user.GroupDao; import org.sonar.server.ws.WsTester; import org.sonar.test.DbTests; @@ -49,52 +47,36 @@ import org.sonar.test.DbTests; public class UpdateActionTest { @Rule - public DbTester dbTester = DbTester.create(System2.INSTANCE); - + public DbTester db = DbTester.create(System2.INSTANCE); @Rule public UserSessionRule userSession = UserSessionRule.standalone(); - @Rule public ExpectedException expectedException = ExpectedException.none(); - private WsTester tester; - + private WsTester ws; + private DbSession dbSession; private GroupDao groupDao; - - private DbSession session; - private UserGroupDao userGroupDao; @Before public void setUp() { - dbTester.truncateTables(); - - groupDao = new GroupDao(System2.INSTANCE); + DbClient dbClient = db.getDbClient(); + dbSession = db.getSession(); + groupDao = dbClient.groupDao(); + userGroupDao = dbClient.userGroupDao(); - userGroupDao = new UserGroupDao(); - - DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), - groupDao, new GroupMembershipDao(dbTester.myBatis()), userGroupDao); - - tester = new WsTester(new UserGroupsWs(new UpdateAction(dbClient, userSession, new UserGroupUpdater(dbClient)))); - - session = dbClient.openSession(false); - } - - @After - public void after() { - session.close(); + ws = new WsTester(new UserGroupsWs(new UpdateAction(dbClient, userSession, new UserGroupUpdater(dbClient)))); } @Test public void update_nominal() throws Exception { - GroupDto existingGroup = groupDao.insert(session, new GroupDto().setName("old-name").setDescription("Old Description")); - userGroupDao.insert(session, new UserGroupDto().setGroupId(existingGroup.getId()).setUserId(42L)); + GroupDto existingGroup = groupDao.insert(dbSession, new GroupDto().setName("old-name").setDescription("Old Description")); + userGroupDao.insert(dbSession, new UserGroupDto().setGroupId(existingGroup.getId()).setUserId(42L)); - session.commit(); + dbSession.commit(); loginAsAdmin(); - tester.newPostRequest("api/usergroups", "update") + newRequest() .setParam("id", existingGroup.getId().toString()) .setParam("name", "new-name") .setParam("description", "New Description") @@ -109,11 +91,11 @@ public class UpdateActionTest { @Test public void update_only_name() throws Exception { - GroupDto existingGroup = groupDao.insert(session, new GroupDto().setName("old-name").setDescription("Old Description")); - session.commit(); + GroupDto existingGroup = groupDao.insert(dbSession, new GroupDto().setName("old-name").setDescription("Old Description")); + dbSession.commit(); loginAsAdmin(); - tester.newPostRequest("api/usergroups", "update") + newRequest() .setParam("id", existingGroup.getId().toString()) .setParam("name", "new-name") .execute().assertJson("{" + @@ -127,11 +109,11 @@ public class UpdateActionTest { @Test public void update_only_description() throws Exception { - GroupDto existingGroup = groupDao.insert(session, new GroupDto().setName("old-name").setDescription("Old Description")); - session.commit(); + GroupDto existingGroup = groupDao.insert(dbSession, new GroupDto().setName("old-name").setDescription("Old Description")); + dbSession.commit(); loginAsAdmin(); - tester.newPostRequest("api/usergroups", "update") + newRequest() .setParam("id", existingGroup.getId().toString()) .setParam("description", "New Description") .execute().assertJson("{" + @@ -148,7 +130,7 @@ public class UpdateActionTest { expectedException.expect(ForbiddenException.class); userSession.login("not-admin"); - tester.newPostRequest("api/usergroups", "update") + newRequest() .setParam("id", "42") .setParam("name", "some-product-bu") .setParam("description", "Business Unit for Some Awesome Product") @@ -157,13 +139,13 @@ public class UpdateActionTest { @Test public void name_too_short() throws Exception { - GroupDto existingGroup = groupDao.insert(session, new GroupDto().setName("old-name").setDescription("Old Description")); - session.commit(); + GroupDto existingGroup = groupDao.insert(dbSession, new GroupDto().setName("old-name").setDescription("Old Description")); + dbSession.commit(); expectedException.expect(IllegalArgumentException.class); loginAsAdmin(); - tester.newPostRequest("api/usergroups", "update") + newRequest() .setParam("id", existingGroup.getId().toString()) .setParam("name", "") .execute(); @@ -171,13 +153,13 @@ public class UpdateActionTest { @Test public void name_too_long() throws Exception { - GroupDto existingGroup = groupDao.insert(session, new GroupDto().setName("old-name").setDescription("Old Description")); - session.commit(); + GroupDto existingGroup = groupDao.insert(dbSession, new GroupDto().setName("old-name").setDescription("Old Description")); + dbSession.commit(); expectedException.expect(IllegalArgumentException.class); loginAsAdmin(); - tester.newPostRequest("api/usergroups", "update") + newRequest() .setParam("id", existingGroup.getId().toString()) .setParam("name", StringUtils.repeat("a", 255 + 1)) .execute(); @@ -185,13 +167,13 @@ public class UpdateActionTest { @Test public void forbidden_name() throws Exception { - GroupDto existingGroup = groupDao.insert(session, new GroupDto().setName("old-name").setDescription("Old Description")); - session.commit(); + GroupDto existingGroup = groupDao.insert(dbSession, new GroupDto().setName("old-name").setDescription("Old Description")); + dbSession.commit(); expectedException.expect(IllegalArgumentException.class); loginAsAdmin(); - tester.newPostRequest("api/usergroups", "update") + newRequest() .setParam("id", existingGroup.getId().toString()) .setParam("name", "AnYoNe") .execute(); @@ -199,17 +181,17 @@ public class UpdateActionTest { @Test public void non_unique_name() throws Exception { - GroupDto existingGroup = groupDao.insert(session, new GroupDto().setName("old-name").setDescription("Old Description")); + GroupDto existingGroup = groupDao.insert(dbSession, new GroupDto().setName("old-name").setDescription("Old Description")); String groupName = "conflicting-name"; - groupDao.insert(session, new GroupDto() + groupDao.insert(dbSession, new GroupDto() .setName(groupName)); - session.commit(); + dbSession.commit(); expectedException.expect(ServerException.class); expectedException.expectMessage("already taken"); loginAsAdmin(); - tester.newPostRequest("api/usergroups", "update") + newRequest() .setParam("id", existingGroup.getId().toString()) .setParam("name", groupName) .execute().assertStatus(HttpURLConnection.HTTP_CONFLICT); @@ -217,13 +199,13 @@ public class UpdateActionTest { @Test public void description_too_long() throws Exception { - GroupDto existingGroup = groupDao.insert(session, new GroupDto().setName("old-name").setDescription("Old Description")); - session.commit(); + GroupDto existingGroup = groupDao.insert(dbSession, new GroupDto().setName("old-name").setDescription("Old Description")); + dbSession.commit(); expectedException.expect(IllegalArgumentException.class); loginAsAdmin(); - tester.newPostRequest("api/usergroups", "update") + newRequest() .setParam("id", existingGroup.getId().toString()) .setParam("name", "long-group-description-is-looooooooooooong") .setParam("description", StringUtils.repeat("a", 200 + 1)) @@ -235,11 +217,15 @@ public class UpdateActionTest { expectedException.expect(NotFoundException.class); loginAsAdmin(); - tester.newPostRequest("api/usergroups", "update") + newRequest() .setParam("id", "42") .execute(); } + private WsTester.TestRequest newRequest() { + return ws.newPostRequest("api/user_groups", "update"); + } + private void loginAsAdmin() { userSession.login("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UserGroupsWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UserGroupsWsTest.java index 88e66c1a01a..af1ccb16608 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UserGroupsWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UserGroupsWsTest.java @@ -42,7 +42,7 @@ public class UserGroupsWsTest { WsTester tester = new WsTester(new UserGroupsWs( new SearchAction(mock(DbClient.class)), new CreateAction(mock(DbClient.class), mock(UserSession.class), mock(UserGroupUpdater.class)))); - controller = tester.controller("api/usergroups"); + controller = tester.controller("api/user_groups"); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java index 607ab97c9c9..195da695d18 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/usergroups/ws/UsersActionTest.java @@ -31,12 +31,8 @@ import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.user.GroupDao; import org.sonar.db.user.GroupDto; -import org.sonar.db.user.GroupMembershipDao; -import org.sonar.db.user.UserDao; import org.sonar.db.user.UserDto; -import org.sonar.db.user.UserGroupDao; import org.sonar.db.user.UserGroupDto; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -64,10 +60,6 @@ public class UsersActionTest { public void setUp() { dbClient = db.getDbClient(); dbSession = db.getSession(); - UserDao userDao = dbClient.userDao(); - GroupDao groupDao = dbClient.groupDao(); - UserGroupDao userGroupDao = dbClient.userGroupDao(); - GroupMembershipDao groupMembershipDao = dbClient.groupMembershipDao(); wsTester = new WsTester(new UserGroupsWs( new UsersAction( @@ -218,7 +210,7 @@ public class UsersActionTest { } private TestRequest newUsersRequest() { - return wsTester.newGetRequest("api/usergroups", "users"); + return wsTester.newGetRequest("api/user_groups", "users"); } private GroupDto insertGroup() { |