]> source.dussan.org Git - sonarqube.git/commitdiff
Remove useless dependency on authorization dao
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 17 Jul 2013 14:02:17 +0000 (16:02 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 17 Jul 2013 14:02:46 +0000 (16:02 +0200)
sonar-server/src/main/java/org/sonar/server/issue/IssueFilterService.java
sonar-server/src/test/java/org/sonar/server/issue/IssueFilterServiceTest.java

index a9ae87ab0d3b7fec013003354cf48841df14a6f5..78f71582b01af842deca31d21abc7e72a34b948c 100644 (file)
@@ -35,7 +35,6 @@ import org.sonar.core.issue.db.IssueFilterDto;
 import org.sonar.core.issue.db.IssueFilterFavouriteDao;
 import org.sonar.core.issue.db.IssueFilterFavouriteDto;
 import org.sonar.core.permission.Permission;
-import org.sonar.core.user.AuthorizationDao;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
@@ -57,15 +56,13 @@ public class IssueFilterService implements ServerComponent {
   private final IssueFilterDao filterDao;
   private final IssueFilterFavouriteDao favouriteDao;
   private final IssueFinder finder;
-  private final AuthorizationDao authorizationDao;
   private final IssueFilterSerializer serializer;
 
-  public IssueFilterService(IssueFilterDao filterDao, IssueFilterFavouriteDao favouriteDao, IssueFinder finder, AuthorizationDao authorizationDao,
+  public IssueFilterService(IssueFilterDao filterDao, IssueFilterFavouriteDao favouriteDao, IssueFinder finder,
       IssueFilterSerializer serializer) {
     this.filterDao = filterDao;
     this.favouriteDao = favouriteDao;
     this.finder = finder;
-    this.authorizationDao = authorizationDao;
     this.serializer = serializer;
   }
 
index 16f5948ae1b9dd7e8d3f84d00b739f7bd924e41b..41f8a8c806ebd8c33ab6bcdfb2900b1504edf65b 100644 (file)
@@ -29,7 +29,6 @@ import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 import org.sonar.api.issue.IssueFinder;
 import org.sonar.api.issue.IssueQuery;
-import org.sonar.api.web.UserRole;
 import org.sonar.core.issue.DefaultIssueFilter;
 import org.sonar.core.issue.IssueFilterSerializer;
 import org.sonar.core.issue.db.IssueFilterDao;
@@ -37,7 +36,6 @@ import org.sonar.core.issue.db.IssueFilterDto;
 import org.sonar.core.issue.db.IssueFilterFavouriteDao;
 import org.sonar.core.issue.db.IssueFilterFavouriteDto;
 import org.sonar.core.permission.Permission;
-import org.sonar.core.user.AuthorizationDao;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
@@ -67,7 +65,6 @@ public class IssueFilterServiceTest {
   private IssueFilterDao issueFilterDao;
   private IssueFilterFavouriteDao issueFilterFavouriteDao;
   private IssueFinder issueFinder;
-  private AuthorizationDao authorizationDao;
   private IssueFilterSerializer issueFilterSerializer;
 
   private UserSession userSession;
@@ -79,10 +76,9 @@ public class IssueFilterServiceTest {
     issueFilterDao = mock(IssueFilterDao.class);
     issueFilterFavouriteDao = mock(IssueFilterFavouriteDao.class);
     issueFinder = mock(IssueFinder.class);
-    authorizationDao = mock(AuthorizationDao.class);
     issueFilterSerializer = mock(IssueFilterSerializer.class);
 
-    service = new IssueFilterService(issueFilterDao, issueFilterFavouriteDao, issueFinder, authorizationDao, issueFilterSerializer);
+    service = new IssueFilterService(issueFilterDao, issueFilterFavouriteDao, issueFinder, issueFilterSerializer);
   }
 
   @Test
@@ -334,7 +330,7 @@ public class IssueFilterServiceTest {
 
   @Test
   public void should_not_update_if_shared_and_not_admin() {
-    when(authorizationDao.selectGlobalPermissions("john")).thenReturn(newArrayList(UserRole.USER));
+    UserSession userSession = MockUserSession.create().setLogin("john").setPermissions();
     when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Old Filter").setUserLogin("arthur").setShared(true));
 
     try {
@@ -396,12 +392,12 @@ public class IssueFilterServiceTest {
     String currentUser = "dave.loper";
     IssueFilterDto sharedFilter = new IssueFilterDto().setId(1L).setName("My filter").setUserLogin(currentUser).setShared(true);
 
-    when(authorizationDao.selectGlobalPermissions(currentUser)).thenReturn(newArrayList(Permission.DRY_RUN_EXECUTION.key()));
+    UserSession userSession = MockUserSession.create().setLogin(currentUser).setUserId(1).setPermissions();
     when(issueFilterDao.selectById(1L)).thenReturn(sharedFilter);
 
     try {
       DefaultIssueFilter issueFilter = new DefaultIssueFilter().setId(1L).setName("My filter").setShared(true).setUser("new.owner");
-      service.update(issueFilter, MockUserSession.create().setUserId(1).setLogin(currentUser));
+      service.update(issueFilter, userSession);
       fail();
     } catch (Exception e) {
       assertThat(e).isInstanceOf(ForbiddenException.class).hasMessage("User is not authorized to change the owner of this filter");
@@ -455,7 +451,7 @@ public class IssueFilterServiceTest {
 
   @Test
   public void should_not_delete_not_shared_filter_if_user_is_admin() {
-    when(authorizationDao.selectGlobalPermissions("john")).thenReturn(newArrayList(Permission.SYSTEM_ADMIN.key()));
+    UserSession userSession = MockUserSession.create().setLogin("john").setUserId(1).setPermissions(Permission.SYSTEM_ADMIN);
     when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("arthur").setShared(false));
 
     try {
@@ -469,7 +465,7 @@ public class IssueFilterServiceTest {
 
   @Test
   public void should_not_delete_shared_filter_if_not_admin() {
-    when(authorizationDao.selectGlobalPermissions("john")).thenReturn(newArrayList(UserRole.USER));
+    UserSession userSession = MockUserSession.create().setLogin("john").setUserId(1).setPermissions();
     when(issueFilterDao.selectById(1L)).thenReturn(new IssueFilterDto().setId(1L).setName("My Issues").setUserLogin("arthur").setShared(true));
 
     try {