]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4301 Set maxResultsReached parameter from IssueDao
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 22 May 2013 16:56:37 +0000 (18:56 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 22 May 2013 16:56:37 +0000 (18:56 +0200)
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueQueryResult.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java
sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java
sonar-server/src/main/java/org/sonar/server/issue/DefaultIssueFinder.java
sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java
sonar-server/src/test/java/org/sonar/server/issue/IssuesFinderSortTest.java

diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueQueryResult.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueQueryResult.java
new file mode 100644 (file)
index 0000000..5b2b562
--- /dev/null
@@ -0,0 +1,178 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.core.issue;
+
+import com.google.common.collect.Maps;
+import org.sonar.api.component.Component;
+import org.sonar.api.issue.ActionPlan;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.IssueQueryResult;
+import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.user.User;
+import org.sonar.api.utils.Paging;
+
+import javax.annotation.CheckForNull;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+public class DefaultIssueQueryResult implements IssueQueryResult {
+
+  private List<Issue> issues;
+  private final Map<RuleKey, Rule> rulesByKey = Maps.newHashMap();
+  private final Map<String, Component> componentsByKey = Maps.newHashMap();
+  private final Map<String, Component> projectsByKey = Maps.newHashMap();
+  private final Map<String, ActionPlan> actionPlansByKey = Maps.newHashMap();
+  private final Map<String, User> usersByLogin = Maps.newHashMap();
+  private boolean securityExclusions;
+  private boolean maxResultsReached;
+  private Paging paging;
+
+  public DefaultIssueQueryResult setIssues(List<Issue> issues){
+    this.issues = issues;
+    return this;
+  }
+
+  public DefaultIssueQueryResult addRules(Collection<Rule> rules){
+    for (Rule rule : rules) {
+      rulesByKey.put(rule.ruleKey(), rule);
+    }
+    return this;
+  }
+
+  public DefaultIssueQueryResult addComponents(Collection<Component> components){
+    for (Component component : components) {
+      componentsByKey.put(component.key(), component);
+    }
+    return this;
+  }
+
+  public DefaultIssueQueryResult addProjects(Collection<Component> projects){
+    for (Component project : projects) {
+      projectsByKey.put(project.key(), project);
+    }
+    return this;
+  }
+
+  public DefaultIssueQueryResult addActionPlans(Collection<ActionPlan> actionPlans){
+    for (ActionPlan actionPlan : actionPlans) {
+      actionPlansByKey.put(actionPlan.key(), actionPlan);
+    }
+    return this;
+  }
+
+  public DefaultIssueQueryResult addUsers(Collection<User> users){
+    for (User user : users) {
+      usersByLogin.put(user.login(), user);
+    }
+    return this;
+  }
+
+  public DefaultIssueQueryResult setSecurityExclusions(boolean securityExclusions){
+    this.securityExclusions = securityExclusions;
+    return this;
+  }
+
+  public DefaultIssueQueryResult setMaxResultsReached(boolean maxResultsReached){
+    this.maxResultsReached = maxResultsReached;
+    return this;
+  }
+
+  public DefaultIssueQueryResult setPaging(Paging paging){
+    this.paging = paging;
+    return this;
+  }
+
+  @Override
+  public List<Issue> issues() {
+    return issues;
+  }
+
+  @Override
+  public Rule rule(Issue issue) {
+    return rulesByKey.get(issue.ruleKey());
+  }
+
+  @Override
+  public Collection<Rule> rules() {
+    return rulesByKey.values();
+  }
+
+  @Override
+  public Component component(Issue issue) {
+    return componentsByKey.get(issue.componentKey());
+  }
+
+  @Override
+  public Collection<Component> components() {
+    return componentsByKey.values();
+  }
+
+  @Override
+  public Component project(Issue issue) {
+    return projectsByKey.get(issue.projectKey());
+  }
+
+  @Override
+  public Collection<Component> projects() {
+    return projectsByKey.values();
+  }
+
+  @Override
+  public ActionPlan actionPlan(Issue issue) {
+    return actionPlansByKey.get(issue.actionPlanKey());
+  }
+
+  @Override
+  public Collection<ActionPlan> actionPlans() {
+    return actionPlansByKey.values();
+  }
+
+  @Override
+  public Collection<User> users() {
+    return usersByLogin.values();
+  }
+
+  @Override
+  @CheckForNull
+  public User user(String login) {
+    return usersByLogin.get(login);
+  }
+
+  @Override
+  public boolean securityExclusions() {
+    return securityExclusions;
+  }
+
+  @Override
+  public boolean maxResultsReached() {
+    return maxResultsReached;
+  }
+
+  @Override
+  public Paging paging() {
+    return paging;
+  }
+
+
+}
index 89043f3791c64e9352161a9ecbe243766ac25ca1..aeeb37bf5020a8dcbf530e921dc2eb9cd96678ef 100644 (file)
@@ -28,6 +28,7 @@ import org.apache.ibatis.session.SqlSession;
 import org.sonar.api.BatchComponent;
 import org.sonar.api.ServerComponent;
 import org.sonar.api.issue.IssueQuery;
+import org.sonar.core.issue.DefaultIssueQueryResult;
 import org.sonar.core.persistence.MyBatis;
 
 import javax.annotation.CheckForNull;
@@ -83,28 +84,11 @@ public class IssueDao implements BatchComponent, ServerComponent {
   }
 
   @VisibleForTesting
-  List<IssueDto> selectIssueAndComponentIds(IssueQuery query) {
+  List<IssueDto> selectIssueAndProjectIds(final IssueQuery query, final DefaultIssueQueryResult defaultIssueQueryResult,
+                                          final Collection<Integer> authorizedRootProjectIds) {
     SqlSession session = mybatis.openSession();
     try {
-      return selectIssueAndComponentIds(query, session);
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  /**
-   * The returned IssueDto list contains only the issue id and the resource id
-   */
-  public List<IssueDto> selectIssueAndComponentIds(IssueQuery query, SqlSession session) {
-    IssueMapper mapper = session.getMapper(IssueMapper.class);
-    return mapper.selectIssueAndComponentIds(query);
-  }
-
-  @VisibleForTesting
-  List<IssueDto> selectIssueAndProjectIds(IssueQuery query, Collection<Integer> authorizedRootProjectIds, Integer maxResults) {
-    SqlSession session = mybatis.openSession();
-    try {
-      return selectIssueAndProjectIds(query, authorizedRootProjectIds, maxResults, session);
+      return selectIssueAndProjectIds(query, defaultIssueQueryResult, authorizedRootProjectIds, session);
     } finally {
       MyBatis.closeQuietly(session);
     }
@@ -113,28 +97,26 @@ public class IssueDao implements BatchComponent, ServerComponent {
   /**
    * The returned IssueDto list contains only the issue id, the project id and the sort column
    */
-  public List<IssueDto> selectIssueAndProjectIds(final IssueQuery query, final Collection<Integer> authorizedRootProjectIds, SqlSession session) {
-    return selectIssueAndProjectIds(query, authorizedRootProjectIds, query.maxResults(), session);
-  }
-
-  private List<IssueDto> selectIssueAndProjectIds(final IssueQuery query, final Collection<Integer> authorizedRootProjectIds, final Integer maxResults, SqlSession session) {
-    final List<IssueDto> issues = newArrayList();
+  public List<IssueDto> selectIssueAndProjectIds(final IssueQuery query, final DefaultIssueQueryResult defaultIssueQueryResult,
+                                                  final Collection<Integer> authorizedRootProjectIds, SqlSession sqlSession){
+    final List<IssueDto> authorizedIssues = newArrayList();
     ResultHandler resultHandler = new ResultHandler(){
       @Override
       public void handleResult(ResultContext context) {
         IssueDto issueDto = (IssueDto) context.getResultObject();
         if (authorizedRootProjectIds.contains(issueDto.getProjectId())) {
-          issues.add(issueDto);
+          authorizedIssues.add(issueDto);
         } else {
-          // reject because user not authorized
+          defaultIssueQueryResult.setSecurityExclusions(true);
         }
-        if (issues.size() >= maxResults) {
+        if (authorizedIssues.size() >= query.maxResults()) {
+          defaultIssueQueryResult.setMaxResultsReached(true);
           context.stop();
         }
       }
     };
-    session.select("selectIssueAndProjectIds", query, resultHandler);
-    return issues;
+    sqlSession.select("selectIssueAndProjectIds", query, resultHandler);
+    return authorizedIssues;
   }
 
   @VisibleForTesting
index 478a66da8945227e43eb7cf2dd4fa358e3f08a5d..a08f85530a9f8df2692504952be30ec70a202598 100644 (file)
@@ -27,8 +27,6 @@ public interface IssueMapper {
 
   IssueDto selectByKey(String key);
 
-  List<IssueDto> selectIssueAndComponentIds(IssueQuery query);
-
   List<IssueDto> select(IssueQuery query);
 
   List<IssueDto> selectNonClosedIssues(int rootComponentId);
index 19aea4a64af7e8ca5da4628d488597833b3ea168..dce3b71c648b53a52e5779e5e7bbc4d5e705f4be 100644 (file)
     </where>
   </select>
 
-  <select id="selectIssueAndComponentIds" parameterType="map" resultType="Issue">
-    select i.id, i.resource_id as resourceId
-    <include refid="selectQueryConditions"/>
-  </select>
-
   <select id="selectIssueAndProjectIds" parameterType="map" resultType="Issue" fetchSize="500">
     select i.id, i.project_id as projectId
     <include refid="sortColumn"/>
index 73b04ef1796d40220c232b349bfef8f6903db062..ce6ddabde51d5e20d7de582f5867c3281b29a86e 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.Test;
 import org.sonar.api.issue.IssueQuery;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.utils.DateUtils;
+import org.sonar.core.issue.DefaultIssueQueryResult;
 import org.sonar.core.persistence.AbstractDaoTestCase;
 
 import java.util.Collections;
@@ -32,6 +33,8 @@ import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 
 public class IssueDaoTest extends AbstractDaoTestCase {
@@ -224,60 +227,62 @@ public class IssueDaoTest extends AbstractDaoTestCase {
     assertThat(dao.select(query)).hasSize(3);
   }
 
-  @Test
-  public void should_select_issue_and_component_ids() {
-    setupData("shared", "should_select_issue_and_component_ids");
-
-    IssueQuery query = IssueQuery.builder().build();
-    List<IssueDto> results = dao.selectIssueAndComponentIds(query);
-    assertThat(results).hasSize(3);
-  }
-
   @Test
   public void should_select_issue_and_project_ids() {
     setupData("shared", "should_select_issue_and_project_ids");
 
-    IssueQuery query = IssueQuery.builder().build();
-    List<IssueDto> results = dao.selectIssueAndProjectIds(query, newArrayList(399), 1000);
+    DefaultIssueQueryResult defaultIssueQueryResult = new DefaultIssueQueryResult();
+    IssueQuery query = mock(IssueQuery.class);
+    when(query.maxResults()).thenReturn(1000);
+    List<IssueDto> results = dao.selectIssueAndProjectIds(query, defaultIssueQueryResult, newArrayList(399));
     assertThat(results).hasSize(3);
+    assertThat(defaultIssueQueryResult.maxResultsReached()).isFalse();
+    assertThat(defaultIssueQueryResult.securityExclusions()).isFalse();
 
     IssueDto issueDto = results.get(0);
     assertThat(issueDto.getId()).isNotNull();
     assertThat(issueDto.getProjectId()).isNotNull();
 
-    results = dao.selectIssueAndProjectIds(query, newArrayList(399), 2);
-    assertThat(results).hasSize(2);
-
-    results = dao.selectIssueAndProjectIds(query, Collections.<Integer>emptyList(), 1000);
+    results = dao.selectIssueAndProjectIds(query, defaultIssueQueryResult, Collections.<Integer>emptyList());
     assertThat(results).isEmpty();
+    assertThat(defaultIssueQueryResult.maxResultsReached()).isFalse();
+    assertThat(defaultIssueQueryResult.securityExclusions()).isTrue();
+
+    when(query.maxResults()).thenReturn(2);
+    results = dao.selectIssueAndProjectIds(query, defaultIssueQueryResult, newArrayList(399));
+    assertThat(results).hasSize(2);
+    assertThat(defaultIssueQueryResult.maxResultsReached()).isTrue();
+    assertThat(defaultIssueQueryResult.securityExclusions()).isTrue();
   }
 
   @Test
   public void should_select_issue_and_project_ids_with_sort_column() {
     setupData("shared", "should_select_issue_and_project_ids");
 
+    DefaultIssueQueryResult defaultIssueQueryResult = new DefaultIssueQueryResult();
+
     IssueQuery query = IssueQuery.builder().sort(IssueQuery.Sort.ASSIGNEE).build();
-    List<IssueDto> results = dao.selectIssueAndProjectIds(query, newArrayList(399), 1000);
+    List<IssueDto> results = dao.selectIssueAndProjectIds(query, defaultIssueQueryResult, newArrayList(399));
     assertThat(results.get(0).getAssignee()).isNotNull();
 
     query = IssueQuery.builder().sort(IssueQuery.Sort.SEVERITY).build();
-    results = dao.selectIssueAndProjectIds(query, newArrayList(399), 1000);
+    results = dao.selectIssueAndProjectIds(query, defaultIssueQueryResult, newArrayList(399));
     assertThat(results.get(0).getSeverity()).isNotNull();
 
     query = IssueQuery.builder().sort(IssueQuery.Sort.STATUS).build();
-    results = dao.selectIssueAndProjectIds(query, newArrayList(399), 1000);
+    results = dao.selectIssueAndProjectIds(query, defaultIssueQueryResult, newArrayList(399));
     assertThat(results.get(0).getStatus()).isNotNull();
 
     query = IssueQuery.builder().sort(IssueQuery.Sort.CREATION_DATE).build();
-    results = dao.selectIssueAndProjectIds(query, newArrayList(399), 1000);
+    results = dao.selectIssueAndProjectIds(query, defaultIssueQueryResult, newArrayList(399));
     assertThat(results.get(0).getIssueCreationDate()).isNotNull();
 
     query = IssueQuery.builder().sort(IssueQuery.Sort.UPDATE_DATE).build();
-    results = dao.selectIssueAndProjectIds(query, newArrayList(399), 1000);
+    results = dao.selectIssueAndProjectIds(query, defaultIssueQueryResult, newArrayList(399));
     assertThat(results.get(0).getIssueUpdateDate()).isNotNull();
 
     query = IssueQuery.builder().sort(IssueQuery.Sort.CLOSE_DATE).build();
-    results = dao.selectIssueAndProjectIds(query, newArrayList(399), 1000);
+    results = dao.selectIssueAndProjectIds(query, defaultIssueQueryResult, newArrayList(399));
     assertThat(results.get(0).getIssueCloseDate()).isNotNull();
   }
 
@@ -300,8 +305,5 @@ public class IssueDaoTest extends AbstractDaoTestCase {
 
     List<IssueDto> results = newArrayList(dao.selectByIds(newArrayList(100l, 101l, 102l)));
     assertThat(results).hasSize(3);
-    assertThat(results.get(0).getId()).isEqualTo(100);
-    assertThat(results.get(1).getId()).isEqualTo(101);
-    assertThat(results.get(2).getId()).isEqualTo(102);
   }
 }
index 985bae3d4cf94b3d005027e82a781e0f572f89ec..eb8d42731a3380d315552a4c31d27ff3ac924210 100644 (file)
 package org.sonar.server.issue;
 
 import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import org.apache.ibatis.session.SqlSession;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.component.Component;
 import org.sonar.api.issue.*;
-import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.user.User;
 import org.sonar.api.user.UserFinder;
 import org.sonar.api.utils.Paging;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.DefaultIssueComment;
+import org.sonar.core.issue.DefaultIssueQueryResult;
 import org.sonar.core.issue.db.IssueChangeDao;
 import org.sonar.core.issue.db.IssueDao;
 import org.sonar.core.issue.db.IssueDto;
@@ -43,8 +42,6 @@ import org.sonar.core.rule.DefaultRuleFinder;
 import org.sonar.core.user.AuthorizationDao;
 import org.sonar.server.platform.UserSession;
 
-import javax.annotation.CheckForNull;
-
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -100,11 +97,13 @@ public class DefaultIssueFinder implements IssueFinder {
     LOG.debug("IssueQuery : {}", query);
     SqlSession sqlSession = myBatis.openSession();
     try {
+      DefaultIssueQueryResult defaultIssueQueryResult = new DefaultIssueQueryResult();
+
       // 1. Select all authorized root project ids for the user
       Collection<Integer> rootProjectIds = authorizationDao.selectAuthorizedRootProjectsIds(UserSession.get().userId(), query.requiredRole(), sqlSession);
 
       // 2. Select the authorized ids of all the issues that match the query
-      List<IssueDto> authorizedIssues = issueDao.selectIssueAndProjectIds(query, rootProjectIds, sqlSession);
+      List<IssueDto> authorizedIssues = issueDao.selectIssueAndProjectIds(query, defaultIssueQueryResult, rootProjectIds, sqlSession);
 
       // 3. Sort all authorized issues
       List<IssueDto> authorizedSortedIssues = sort(authorizedIssues, query, authorizedIssues.size());
@@ -148,24 +147,21 @@ public class DefaultIssueFinder implements IssueFinder {
         }
       }
 
-      return new DefaultResults(issues,
-                                 findRules(ruleIds),
-                                 findComponents(componentIds),
-                                 findProjects(projectIds),
-                                 findActionPlans(actionPlanKeys),
-                                 findUsers(users),
-                                 paging,
-                                 false,
-                                 authorizedIssues.size() >= query.maxResults()
-                                 // TODO
-//        authorizedIssues.size() != allIssues.size()
-      );
+      defaultIssueQueryResult.setIssues(issues)
+        .addRules(findRules(ruleIds))
+        .addComponents(findComponents(componentIds))
+        .addProjects(findProjects(projectIds))
+        .addActionPlans(findActionPlans(actionPlanKeys))
+        .addUsers(findUsers(users))
+        .setPaging(paging);
+
+      return defaultIssueQueryResult;
     } finally {
       MyBatis.closeQuietly(sqlSession);
     }
   }
 
-  private List<IssueDto> sort(List<IssueDto> issues, IssueQuery query, int allIssuesSize){
+  private List<IssueDto> sort(List<IssueDto> issues, IssueQuery query, int allIssuesSize) {
     if (allIssuesSize < query.maxResults()) {
       return new IssuesFinderSort(issues, query).sort();
     }
@@ -211,114 +207,4 @@ public class DefaultIssueFinder implements IssueFinder {
     return dto != null ? dto.toDefaultIssue() : null;
   }
 
-  static class DefaultResults implements IssueQueryResult {
-    private final List<Issue> issues;
-    private final Map<RuleKey, Rule> rulesByKey = Maps.newHashMap();
-    private final Map<String, Component> componentsByKey = Maps.newHashMap();
-    private final Map<String, Component> projectsByKey = Maps.newHashMap();
-    private final Map<String, ActionPlan> actionPlansByKey = Maps.newHashMap();
-    private final Map<String, User> usersByLogin = Maps.newHashMap();
-    private final boolean securityExclusions;
-    private final boolean maxResultsReached;
-    private final Paging paging;
-
-    DefaultResults(List<Issue> issues,
-                   Collection<Rule> rules,
-                   Collection<Component> components,
-                   Collection<Component> projects,
-                   Collection<ActionPlan> actionPlans,
-                   Collection<User> users,
-                   Paging paging, boolean securityExclusions, boolean maxResultsReached) {
-      this.issues = issues;
-      for (Rule rule : rules) {
-        rulesByKey.put(rule.ruleKey(), rule);
-      }
-      for (Component component : components) {
-        componentsByKey.put(component.key(), component);
-      }
-      for (Component project : projects) {
-        projectsByKey.put(project.key(), project);
-      }
-      for (ActionPlan actionPlan : actionPlans) {
-        actionPlansByKey.put(actionPlan.key(), actionPlan);
-      }
-      for (User user : users) {
-        usersByLogin.put(user.login(), user);
-      }
-      this.paging = paging;
-      this.securityExclusions = securityExclusions;
-      this.maxResultsReached = maxResultsReached;
-    }
-
-    @Override
-    public List<Issue> issues() {
-      return issues;
-    }
-
-    @Override
-    public Rule rule(Issue issue) {
-      return rulesByKey.get(issue.ruleKey());
-    }
-
-    @Override
-    public Collection<Rule> rules() {
-      return rulesByKey.values();
-    }
-
-    @Override
-    public Component component(Issue issue) {
-      return componentsByKey.get(issue.componentKey());
-    }
-
-    @Override
-    public Collection<Component> components() {
-      return componentsByKey.values();
-    }
-
-    @Override
-    public Component project(Issue issue) {
-      return projectsByKey.get(issue.projectKey());
-    }
-
-    @Override
-    public Collection<Component> projects() {
-      return projectsByKey.values();
-    }
-
-    @Override
-    public ActionPlan actionPlan(Issue issue) {
-      return actionPlansByKey.get(issue.actionPlanKey());
-    }
-
-    @Override
-    public Collection<ActionPlan> actionPlans() {
-      return actionPlansByKey.values();
-    }
-
-    @Override
-    public Collection<User> users() {
-      return usersByLogin.values();
-    }
-
-    @Override
-    @CheckForNull
-    public User user(String login) {
-      return usersByLogin.get(login);
-    }
-
-    @Override
-    public boolean securityExclusions() {
-      return securityExclusions;
-    }
-
-    @Override
-    public boolean maxResultsReached() {
-      return maxResultsReached;
-    }
-
-    @Override
-    public Paging paging() {
-      return paging;
-    }
-  }
 }
index fbb71cc901b2a1728ae12d627bd76cd55d77e119..15908508a8aaf8928626f8e3fe7ed16d60037587 100644 (file)
@@ -28,9 +28,9 @@ import org.sonar.api.issue.IssueQuery;
 import org.sonar.api.issue.IssueQueryResult;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.user.UserFinder;
-import org.sonar.api.web.UserRole;
 import org.sonar.core.component.ComponentDto;
 import org.sonar.core.issue.DefaultActionPlan;
+import org.sonar.core.issue.DefaultIssueQueryResult;
 import org.sonar.core.issue.db.IssueChangeDao;
 import org.sonar.core.issue.db.IssueDao;
 import org.sonar.core.issue.db.IssueDto;
@@ -84,7 +84,7 @@ public class DefaultIssueFinderTest {
     when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(dtoList);
 
     IssueQueryResult results = finder.find(query);
-    verify(issueDao).selectIssueAndProjectIds(eq(query), eq(newHashSet(100)), any(SqlSession.class));
+    verify(issueDao).selectIssueAndProjectIds(eq(query), any(DefaultIssueQueryResult.class), eq(newHashSet(100)), any(SqlSession.class));
 
     assertThat(results.issues()).hasSize(2);
     Issue issue = results.issues().iterator().next();
@@ -94,26 +94,6 @@ public class DefaultIssueFinderTest {
     assertThat(results.securityExclusions()).isFalse();
   }
 
-  @Test
-  public void should_find_only_authorized_issues() {
-    when(authorizationDao.selectAuthorizedRootProjectsIds(anyInt(), anyString(), any(SqlSession.class)))
-      .thenReturn(Collections.<Integer>emptySet());
-    IssueQuery query = IssueQuery.builder().pageSize(100).requiredRole(UserRole.USER).build();
-
-    IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setResourceId(123).setProjectId(100)
-      .setComponentKey_unit_test_only("Action.java")
-      .setProjectKey_unit_test_only("struts")
-      .setRuleKey_unit_test_only("squid", "AvoidCycle")
-      .setStatus("OPEN").setResolution("OPEN");
-    when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(newArrayList(issue1));
-
-    finder.find(query);
-    verify(issueDao).selectIssueAndProjectIds(eq(query), eq(Collections.<Integer>emptySet()), any(SqlSession.class));
-
-    // TODO
-//    assertThat(results.securityExclusions()).isTrue();
-  }
-
   @Test
   public void should_find_paginate_result() {
     when(authorizationDao.selectAuthorizedRootProjectsIds(anyInt(), anyString(), any(SqlSession.class)))
@@ -132,7 +112,7 @@ public class DefaultIssueFinderTest {
       .setRuleKey_unit_test_only("squid", "AvoidCycle")
       .setStatus("OPEN").setResolution("OPEN");
     List<IssueDto> dtoList = newArrayList(issue1, issue2);
-    when(issueDao.selectIssueAndProjectIds(eq(query), eq(newHashSet(100)), any(SqlSession.class))).thenReturn(dtoList);
+    when(issueDao.selectIssueAndProjectIds(eq(query), any(DefaultIssueQueryResult.class), eq(newHashSet(100)), any(SqlSession.class))).thenReturn(dtoList);
     when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(dtoList);
 
     IssueQueryResult results = finder.find(query);
@@ -273,7 +253,7 @@ public class DefaultIssueFinderTest {
   public void should_get_empty_result_when_no_issue() {
     grantAccessRights();
     IssueQuery query = IssueQuery.builder().build();
-    when(issueDao.selectIssueAndProjectIds(eq(query), anyCollection(), any(SqlSession.class))).thenReturn(Collections.<IssueDto>emptyList());
+    when(issueDao.selectIssueAndProjectIds(eq(query), any(DefaultIssueQueryResult.class), anyCollection(), any(SqlSession.class))).thenReturn(Collections.<IssueDto>emptyList());
     when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(Collections.<IssueDto>emptyList());
 
     IssueQueryResult results = finder.find(query);
index d7a458965fd51a5e226a15c6a2071f76795d5ea7..0b7a18690425a272277d49a41a0bcaafc708bea0 100644 (file)
@@ -21,6 +21,7 @@
 package org.sonar.server.issue;
 
 import org.apache.commons.lang.time.DateUtils;
+import org.fest.assertions.Assertions;
 import org.junit.Test;
 import org.sonar.api.issue.IssueQuery;
 import org.sonar.core.issue.db.IssueDto;
@@ -65,10 +66,10 @@ public class IssuesFinderSortTest {
 
     List<IssueDto> result = newArrayList(issuesFinderSort.sort());
 
-    assertThat(result).hasSize(3);
-    assertThat(result.get(0).getStatus()).isEqualTo("REOPENED");
-    assertThat(result.get(1).getStatus()).isEqualTo("OPEN");
-    assertThat(result.get(2).getStatus()).isEqualTo("CLOSED");
+    Assertions.assertThat(result).hasSize(3);
+    Assertions.assertThat(result.get(0).getStatus()).isEqualTo("REOPENED");
+    Assertions.assertThat(result.get(1).getStatus()).isEqualTo("OPEN");
+    Assertions.assertThat(result.get(2).getStatus()).isEqualTo("CLOSED");
   }
 
   @Test
@@ -83,10 +84,10 @@ public class IssuesFinderSortTest {
 
     List<IssueDto> result = newArrayList(issuesFinderSort.sort());
 
-    assertThat(result).hasSize(3);
-    assertThat(result.get(0).getSeverity()).isEqualTo("INFO");
-    assertThat(result.get(1).getSeverity()).isEqualTo("MAJOR");
-    assertThat(result.get(2).getSeverity()).isEqualTo("BLOCKER");
+    Assertions.assertThat(result).hasSize(3);
+    Assertions.assertThat(result.get(0).getSeverity()).isEqualTo("INFO");
+    Assertions.assertThat(result.get(1).getSeverity()).isEqualTo("MAJOR");
+    Assertions.assertThat(result.get(2).getSeverity()).isEqualTo("BLOCKER");
   }
 
   @Test
@@ -105,10 +106,10 @@ public class IssuesFinderSortTest {
 
     List<IssueDto> result = newArrayList(issuesFinderSort.sort());
 
-    assertThat(result).hasSize(3);
-    assertThat(result.get(0).getIssueCreationDate()).isEqualTo(date3);
-    assertThat(result.get(1).getIssueCreationDate()).isEqualTo(date2);
-    assertThat(result.get(2).getIssueCreationDate()).isEqualTo(date1);
+    Assertions.assertThat(result).hasSize(3);
+    Assertions.assertThat(result.get(0).getIssueCreationDate()).isEqualTo(date3);
+    Assertions.assertThat(result.get(1).getIssueCreationDate()).isEqualTo(date2);
+    Assertions.assertThat(result.get(2).getIssueCreationDate()).isEqualTo(date1);
   }
 
   @Test
@@ -127,10 +128,10 @@ public class IssuesFinderSortTest {
 
     List<IssueDto> result = newArrayList(issuesFinderSort.sort());
 
-    assertThat(result).hasSize(3);
-    assertThat(result.get(0).getIssueUpdateDate()).isEqualTo(date3);
-    assertThat(result.get(1).getIssueUpdateDate()).isEqualTo(date2);
-    assertThat(result.get(2).getIssueUpdateDate()).isEqualTo(date1);
+    Assertions.assertThat(result).hasSize(3);
+    Assertions.assertThat(result.get(0).getIssueUpdateDate()).isEqualTo(date3);
+    Assertions.assertThat(result.get(1).getIssueUpdateDate()).isEqualTo(date2);
+    Assertions.assertThat(result.get(2).getIssueUpdateDate()).isEqualTo(date1);
   }
 
   @Test
@@ -149,10 +150,10 @@ public class IssuesFinderSortTest {
 
     List<IssueDto> result = newArrayList(issuesFinderSort.sort());
 
-    assertThat(result).hasSize(3);
-    assertThat(result.get(0).getIssueCloseDate()).isEqualTo(date3);
-    assertThat(result.get(1).getIssueCloseDate()).isEqualTo(date2);
-    assertThat(result.get(2).getIssueCloseDate()).isEqualTo(date1);
+    Assertions.assertThat(result).hasSize(3);
+    Assertions.assertThat(result.get(0).getIssueCloseDate()).isEqualTo(date3);
+    Assertions.assertThat(result.get(1).getIssueCloseDate()).isEqualTo(date2);
+    Assertions.assertThat(result.get(2).getIssueCloseDate()).isEqualTo(date1);
   }
 
 }