]> source.dussan.org Git - sonarqube.git/commitdiff
Refactor projects search of project permission management in order to specify what...
authorJulien Lancelot <julien.lancelot@gmail.com>
Tue, 27 Aug 2013 15:49:59 +0000 (17:49 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Tue, 27 Aug 2013 15:51:07 +0000 (17:51 +0200)
sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java
sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java
sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml
sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java
sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture-including-technical-project-and-not-finished-projects.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/technical-project.xml [deleted file]
sonar-server/src/main/java/org/sonar/server/component/DefaultComponentFinder.java
sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/roles_controller.rb
sonar-server/src/test/java/org/sonar/server/component/DefaultComponentFinderTest.java
sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java

index 6d68359fe07a61ea4735be3bb3c7686f9f74b89a..db0ce0dca7b8ff9a2490b622159e915d3e191217 100644 (file)
@@ -207,12 +207,22 @@ public class ResourceDao {
     }
     SqlSession session = mybatis.openSession();
     try {
-      List<ResourceDto> resourceDtos = session.getMapper(ResourceMapper.class).selectComponentsByQualifiers(qualifiers);
-      List<Component> components = newArrayList();
-      for (ResourceDto resourceDto : resourceDtos) {
-        components.add(toComponent(resourceDto));
-      }
-      return components;
+      return toComponents(session.getMapper(ResourceMapper.class).selectComponentsByQualifiers(qualifiers));
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+  /**
+   * Return enabled components including not completed ones, ie without snapshots or without snapshot having islast=true
+   */
+  public List<Component> selectComponentsIncludingNotCompletedOnesByQualifiers(Collection<String> qualifiers) {
+    if (qualifiers.isEmpty()) {
+      return Collections.emptyList();
+    }
+    SqlSession session = mybatis.openSession();
+    try {
+      return toComponents(session.getMapper(ResourceMapper.class).selectComponentsIncludingNotCompletedOnesByQualifiers(qualifiers));
     } finally {
       MyBatis.closeQuietly(session);
     }
@@ -227,10 +237,10 @@ public class ResourceDao {
       .setQualifier(resourceDto.getQualifier());
   }
 
-  public static List<ComponentDto> toComponents(List<ResourceDto> resourceDto){
-    return newArrayList(Iterables.transform(resourceDto, new Function<ResourceDto, ComponentDto>() {
+  public static List<Component> toComponents(List<ResourceDto> resourceDto){
+    return newArrayList(Iterables.transform(resourceDto, new Function<ResourceDto, Component>() {
       @Override
-      public ComponentDto apply(@Nullable ResourceDto resourceDto) {
+      public Component apply(@Nullable ResourceDto resourceDto) {
         return resourceDto == null ? null : toComponent(resourceDto);
       }
     }));
index c8a811080fb5a31f7e674e508a018e1edd4a9f4a..5b947c7bfa8d810d4eaa98b98f63cc7c7bcb7904 100644 (file)
@@ -74,11 +74,10 @@ public interface ResourceMapper {
   List<Integer> selectAuthorizedChildrenComponentIds(@Param("componentRootKeys") Collection<String> componentRootKeys,
                                                      @Param("userId") @Nullable Integer userId, @Param("role") String role);
 
-  /**
-   * @since 3.7
-   */
   List<ResourceDto> selectComponentsByQualifiers(@Param("qualifiers") Collection<String> qualifier);
 
+  List<ResourceDto> selectComponentsIncludingNotCompletedOnesByQualifiers(@Param("qualifiers") Collection<String> qualifier);
+
   void insert(ResourceDto resource);
 
   void update(ResourceDto resource);
index d0978802a67ddf05113f0a621348ac2ddc1a2428..83f8185faea8d055119165819893f6384120bc10 100644 (file)
   </select>
 
   <select id="selectComponentsByQualifiers" parameterType="map" resultMap="resourceResultMap">
+    select * from projects p
+    inner join snapshots s on s.project_id=p.id
+    <where>
+      <if test="qualifiers != null and qualifiers.size() > 0">
+        and <foreach item="qualifier" index="index" collection="qualifiers" open="(" separator=" or " close=")">p.qualifier=#{qualifier}
+      </foreach>
+      </if>
+      and p.enabled=${_true}
+      and p.copy_resource_id is null
+      and s.islast=${_true}
+    </where>
+  </select>
+
+  <select id="selectComponentsIncludingNotCompletedOnesByQualifiers" parameterType="map" resultMap="resourceResultMap">
     select * from projects p
     <where>
       <if test="qualifiers != null and qualifiers.size() > 0">
index 2b38ad2e31f23429bb293877a74a28f6fab157b0..cd77a7eed8ad1e4d13f7515a123294c7991046d1 100644 (file)
@@ -312,14 +312,25 @@ public class ResourceDaoTest extends AbstractDaoTestCase {
 
   @Test
   public void should_select_components_by_qualifiers(){
-    setupData("fixture", "technical-project");
+    setupData("fixture-including-technical-project-and-not-finished-projects");
 
     List<Component> components = dao.selectComponentsByQualifiers(newArrayList("TRK"));
     assertThat(components).hasSize(1);
     assertThat(components.get(0).key()).isEqualTo("org.struts:struts");
     assertThat(((ComponentDto)components.get(0)).getId()).isEqualTo(1L);
 
-    assertThat(dao.selectComponentsByQualifiers(newArrayList("unknown"))).isEmpty();
-    assertThat(dao.selectComponentsByQualifiers(Collections.<String>emptyList())).isEmpty();
+    assertThat(dao.selectComponentsIncludingNotCompletedOnesByQualifiers(newArrayList("unknown"))).isEmpty();
+    assertThat(dao.selectComponentsIncludingNotCompletedOnesByQualifiers(Collections.<String>emptyList())).isEmpty();
+  }
+
+  @Test
+  public void should_select_components_including_not_finished_by_qualifiers(){
+    setupData("fixture-including-technical-project-and-not-finished-projects");
+
+    List<Component> components = dao.selectComponentsIncludingNotCompletedOnesByQualifiers(newArrayList("TRK"));
+    assertThat(components).hasSize(3);
+
+    assertThat(dao.selectComponentsIncludingNotCompletedOnesByQualifiers(newArrayList("unknown"))).isEmpty();
+    assertThat(dao.selectComponentsIncludingNotCompletedOnesByQualifiers(Collections.<String>emptyList())).isEmpty();
   }
 }
diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture-including-technical-project-and-not-finished-projects.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture-including-technical-project-and-not-finished-projects.xml
new file mode 100644 (file)
index 0000000..07f813b
--- /dev/null
@@ -0,0 +1,111 @@
+<dataset>
+
+  <!-- root project -->
+  <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+            description="the description" long_name="Apache Struts"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+  <snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+               status="P" islast="[true]" purge_status="[null]"
+               period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+               period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+               period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+               period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+               period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+               depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
+               version="[null]" path=""/>
+  <snapshots id="10" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             status="P" islast="[false]" purge_status="[null]"
+             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+             depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-01 13:58:00.00" build_date="2008-12-01 13:58:00.00"
+             version="[null]" path=""/>
+
+  <!-- project -->
+  <projects id="2" root_id="1" kee="org.struts:struts-core" name="Struts Core"
+            scope="PRJ" qualifier="BRC" long_name="Struts Core"
+            description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+  <snapshots id="2" project_id="2" parent_snapshot_id="1" root_project_id="1" root_snapshot_id="1"
+               status="P" islast="[true]" purge_status="[null]"
+               period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+               period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+               period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+               period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+               period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+               depth="[null]" scope="PRJ" qualifier="BRC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
+               version="[null]" path="1."/>
+
+  <!-- directory -->
+  <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts"
+              name="org.struts" root_id="1"
+              description="[null]"
+              enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+  <snapshots id="3" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+               status="P" islast="[true]" purge_status="[null]"
+               period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+               period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+               period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+               period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+               period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+               depth="[null]" scope="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
+               version="[null]" path="1.2."/>
+
+  <!-- file -->
+  <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="org.struts:struts:org.struts.RequestContext"
+            name="RequestContext" root_id="1"
+            description="[null]"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <snapshots id="4" project_id="4" parent_snapshot_id="3" root_project_id="1" root_snapshot_id="1"
+               status="P" islast="[true]" purge_status="[null]"
+               period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+               period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+               period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+               period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+               period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+               depth="[null]" scope="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
+               version="[null]" path="1.2.3."/>
+
+  <!-- technical project -->
+  <projects id="5" root_id="[null]" scope="PRJ" qualifier="TRK" kee="COPYorg.struts:struts" name="Struts"
+            description="the description" long_name="Apache Struts"
+            enabled="[true]" language="java" copy_resource_id="1" person_id="[null]"/>
+
+  <!-- project without snapshot islast=true-->
+  <projects id="6" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.apache.shindig" name="Shinding"
+            description="the description" long_name="Shinding"
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+  <snapshots id="6" project_id="6" parent_snapshot_id="[null]" root_project_id="6" root_snapshot_id="[null]"
+             status="P" islast="[false]" purge_status="[null]"
+             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+             depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
+             version="[null]" path=""/>
+
+  <!-- project without snapshot -->
+  <projects id="7" root_id="[null]" kee="org.sample:sample" name="Sample"
+            scope="PRJ" qualifier="TRK" long_name="Sample"
+            description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+
+  <!-- project not enabled -->
+  <projects id="8" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.apache:tika" name="Tika"
+            description="the description" long_name="Tika"
+            enabled="[false]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+  <snapshots id="8" project_id="8" parent_snapshot_id="[null]" root_project_id="8" root_snapshot_id="[null]"
+             status="P" islast="[true]" purge_status="[null]"
+             period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+             period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+             period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+             period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+             period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+             depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
+             version="[null]" path=""/>
+
+
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/technical-project.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/technical-project.xml
deleted file mode 100644 (file)
index ba8298a..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<dataset>
-
-  <!-- technical project -->
-  <projects id="5" root_id="[null]" scope="PRJ" qualifier="TRK" kee="COPYorg.struts:struts" name="Struts"
-            description="the description" long_name="Apache Struts"
-            enabled="[true]" language="java" copy_resource_id="1" person_id="[null]"/>
-
-
-</dataset>
index ac199cbb23bfc5b693c598833ae3277fea7a0a81..e594bca195259268ab530adbbccf03d64c59a9d4 100644 (file)
@@ -26,7 +26,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.component.Component;
 import org.sonar.api.utils.Paging;
-import org.sonar.core.resource.ResourceDao;
 
 import java.util.Collection;
 import java.util.List;
@@ -40,35 +39,21 @@ import static com.google.common.collect.Lists.newArrayList;
 public class DefaultComponentFinder {
 
   private static final Logger LOG = LoggerFactory.getLogger(DefaultComponentFinder.class);
-  private final ResourceDao resourceDao;
 
-  public DefaultComponentFinder(ResourceDao resourceDao) {
-    this.resourceDao = resourceDao;
-  }
-
-  public DefaultComponentQueryResult find(ComponentQuery query) {
+  public DefaultComponentQueryResult find(ComponentQuery query, List<Component> allComponents) {
     LOG.debug("ComponentQuery : {}", query);
-    long start = System.currentTimeMillis();
-    try {
-      // 1. Search components for selected qualifiers
-      List<Component> components = resourceDao.selectComponentsByQualifiers(query.qualifiers());
-      Collection<Component> foundComponents = search(query, components);
-
-      // 2. Sort components
-      Collection<? extends Component> sortedComponents = new ComponentsFinderSort(foundComponents, query).sort();
-
-      if(ComponentQuery.NO_PAGINATION == query.pageSize()) {
-        return new DefaultComponentQueryResult(sortedComponents).setQuery(query);
-      } else {
-        // 3. Apply pagination
-        Paging paging = Paging.create(query.pageSize(), query.pageIndex(), foundComponents.size());
-        Collection<? extends Component> pagedComponents = pagedComponents(sortedComponents, paging);
-
-        return new DefaultComponentQueryResult(pagedComponents).setPaging(paging).setQuery(query);
-      }
-
-    } finally {
-      LOG.debug("ComponentQuery execution time : {} ms", System.currentTimeMillis() - start);
+    Collection<Component> foundComponents = search(query, allComponents);
+
+    // Sort components
+    Collection<? extends Component> sortedComponents = new ComponentsFinderSort(foundComponents, query).sort();
+
+    // Apply pagination if needed
+    if (ComponentQuery.NO_PAGINATION == query.pageSize()) {
+      return new DefaultComponentQueryResult(sortedComponents).setQuery(query);
+    } else {
+      Paging paging = Paging.create(query.pageSize(), query.pageIndex(), foundComponents.size());
+      Collection<? extends Component> pagedComponents = pagedComponents(sortedComponents, paging);
+      return new DefaultComponentQueryResult(pagedComponents).setPaging(paging).setQuery(query);
     }
   }
 
index 2dce322b90a969a900932d9b3e3087cdca6b7bf0..cd6aff52739d30319389a92f7805a693b90a9eb1 100644 (file)
@@ -25,6 +25,7 @@ import org.sonar.api.component.RubyComponentService;
 import org.sonar.core.resource.ResourceDao;
 import org.sonar.server.util.RubyUtils;
 
+import java.util.List;
 import java.util.Map;
 
 public class DefaultRubyComponentService implements RubyComponentService {
@@ -43,7 +44,15 @@ public class DefaultRubyComponentService implements RubyComponentService {
   }
 
   public DefaultComponentQueryResult find(Map<String, Object> params) {
-    return finder.find(toQuery(params));
+    ComponentQuery query = toQuery(params);
+    List<Component> components = resourceDao.selectComponentsByQualifiers(query.qualifiers());
+    return finder.find(query, components);
+  }
+
+  public DefaultComponentQueryResult findWithUncompleteProjects(Map<String, Object> params) {
+    ComponentQuery query = toQuery(params);
+    List<Component> components = resourceDao.selectComponentsIncludingNotCompletedOnesByQualifiers(query.qualifiers());
+    return finder.find(query, components);
   }
 
   static ComponentQuery toQuery(Map<String, Object> props) {
index b0466bce768f4a8e9f2ce8ae94c078d9a3ab0e36..0b744b897164d1bc928bc82fa1b52c82c0b515f6 100644 (file)
@@ -34,7 +34,7 @@ class RolesController < ApplicationController
   def projects
     params['pageSize'] = 25
     params['qualifiers'] ||= 'TRK'
-    @query_result = Internal.component_api.find(params)
+    @query_result = Internal.component_api.findWithUncompleteProjects(params)
 
     @available_qualifiers = java_facade.getQualifiersWithProperty('hasRolePolicy').collect { |qualifier| [message("qualifiers.#{qualifier}"), qualifier] }.sort
 
@@ -97,7 +97,7 @@ class RolesController < ApplicationController
 
     if params['components'].blank?
       params['pageSize'] = -1
-      components = Internal.component_api.find(params).components().to_a
+      components = Internal.component_api.findWithUncompleteProjects(params).components().to_a
       params['components'] = components.collect{|component| component.getId()}.join(',')
     end
 
index d94bb819c0125b9a7864c648c7a22b1aedf15698..3a7963d115a0497390987738553b9eb19568c523 100644 (file)
@@ -23,32 +23,27 @@ package org.sonar.server.component;
 import org.junit.Test;
 import org.sonar.api.component.Component;
 import org.sonar.api.resources.Project;
-import org.sonar.core.resource.ResourceDao;
 
 import java.util.Iterator;
+import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.anyCollection;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 public class DefaultComponentFinderTest {
 
-  ResourceDao dao = mock(ResourceDao.class);
-  DefaultComponentFinder finder = new DefaultComponentFinder(dao);
-
+  DefaultComponentFinder finder = new DefaultComponentFinder();
 
   @Test
   public void should_return_all_components_when_no_parameter() {
-    when(dao.selectComponentsByQualifiers(anyCollection())).thenReturn(newArrayList(
+    List<Component> components = newArrayList(
       createProject("org.codehaus.sonar", "Sonar"),
       createProject("org.apache.tika:tika", "Apache Tika"),
       createProject("org.picocontainer:picocontainer-parent", "PicoContainer Parent")
-    ));
+    );
 
     ComponentQuery query = ComponentQuery.builder().build();
-    DefaultComponentQueryResult results = finder.find(query);
+    DefaultComponentQueryResult results = finder.find(query, components);
 
     assertThat(results.components()).hasSize(3);
     Component component = results.components().iterator().next();
@@ -59,38 +54,38 @@ public class DefaultComponentFinderTest {
 
   @Test
   public void should_find_components_by_key_pattern() {
-    when(dao.selectComponentsByQualifiers(anyCollection())).thenReturn(newArrayList(
+    List<Component> components = newArrayList(
       createProject("org.codehaus.sonar", "Sonar"),
       createProject("org.apache.tika:tika", "Apache Tika"),
       createProject("org.apache.jackrabbit:jackrabbit", "Apache Jackrabbit")
-    ));
+    );
 
     ComponentQuery query = ComponentQuery.builder().keys(newArrayList("org.apache")).build();
-    assertThat(finder.find(query).components()).hasSize(2);
+    assertThat(finder.find(query, components).components()).hasSize(2);
   }
 
   @Test
   public void should_find_components_by_name_pattern() {
-    when(dao.selectComponentsByQualifiers(anyCollection())).thenReturn(newArrayList(
+    List<Component> components = newArrayList(
       createProject("org.codehaus.sonar", "Sonar"),
       createProject("org.apache.tika:tika", "Apache Tika"),
       createProject("org.apache.jackrabbit:jackrabbit", "Apache Jackrabbit")
-    ));
+    );
 
     ComponentQuery query = ComponentQuery.builder().names(newArrayList("Apache")).build();
-    assertThat(finder.find(query).components()).hasSize(2);
+    assertThat(finder.find(query, components).components()).hasSize(2);
   }
 
   @Test
   public void should_sort_result_by_name() {
-    when(dao.selectComponentsByQualifiers(anyCollection())).thenReturn(newArrayList(
+    List<Component> components = newArrayList(
       createProject("org.codehaus.sonar", "Sonar"),
       createProject("org.apache.tika:tika", "Apache Tika"),
       createProject("org.picocontainer:picocontainer-parent", "PicoContainer Parent")
-    ));
+    );
 
     ComponentQuery query = ComponentQuery.builder().build();
-    DefaultComponentQueryResult results = finder.find(query);
+    DefaultComponentQueryResult results = finder.find(query, components);
 
     assertThat(results.components()).hasSize(3);
     Iterator<? extends Component> iterator = results.components().iterator();
@@ -103,13 +98,13 @@ public class DefaultComponentFinderTest {
   public void should_find_paginate_result() {
     ComponentQuery query = ComponentQuery.builder().pageSize(1).pageIndex(1).build();
 
-    when(dao.selectComponentsByQualifiers(anyCollection())).thenReturn(newArrayList(
+    List<Component> components = newArrayList(
       createProject("org.codehaus.sonar", "Sonar"),
       createProject("org.apache.tika:tika", "Apache Tika"),
       createProject("org.picocontainer:picocontainer-parent", "PicoContainer Parent")
-    ));
+    );
 
-    DefaultComponentQueryResult results = finder.find(query);
+    DefaultComponentQueryResult results = finder.find(query, components);
     assertThat(results.paging().offset()).isEqualTo(0);
     assertThat(results.paging().pages()).isEqualTo(3);
     assertThat(results.paging().total()).isEqualTo(3);
@@ -120,18 +115,18 @@ public class DefaultComponentFinderTest {
     ComponentQuery query = ComponentQuery.builder().pageSize(ComponentQuery.NO_PAGINATION)
       .pageIndex(ComponentQuery.DEFAULT_PAGE_INDEX).build();
 
-    when(dao.selectComponentsByQualifiers(anyCollection())).thenReturn(newArrayList(
+    List<Component> components = newArrayList(
       createProject("org.codehaus.sonar", "Sonar"),
       createProject("org.apache.tika:tika", "Apache Tika"),
       createProject("org.picocontainer:picocontainer-parent", "PicoContainer Parent")
-    ));
+    );
 
-    DefaultComponentQueryResult results = finder.find(query);
+    DefaultComponentQueryResult results = finder.find(query, components);
     assertThat(results.paging()).isNull();
     assertThat(results.components().size()).isEqualTo(3);
   }
 
-  private Component createProject(String key, String name){
+  private Component createProject(String key, String name) {
     return new Project(key, null, name);
   }
 
index af5de1e4429121e3c46ce6a9f6131f306bedcb04..3b166fd94265292ef36302b8e8abe78da4db28d0 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.Test;
 import org.sonar.api.component.Component;
 import org.sonar.core.resource.ResourceDao;
 
+import java.util.List;
 import java.util.Map;
 
 import static com.google.common.collect.Lists.newArrayList;
@@ -54,19 +55,40 @@ public class DefaultRubyComponentServiceTest {
     assertThat(componentService.findByKey("struts")).isEqualTo(component);
   }
 
+  @Test
+  public void should_find_with_uncomplete_projects() {
+    List<String> qualifiers = newArrayList("TRK");
+
+    Map<String, Object> map = newHashMap();
+    map.put("keys", newArrayList("org.codehaus.sonar"));
+    map.put("names", newArrayList("Sonar"));
+    map.put("qualifiers", qualifiers);
+    map.put("pageSize", 10l);
+    map.put("pageIndex", 50);
+    map.put("sort", "NAME");
+    map.put("asc", true);
+
+    componentService.findWithUncompleteProjects(map);
+    verify(resourceDao).selectComponentsIncludingNotCompletedOnesByQualifiers(anyListOf(String.class));
+    verify(finder).find(any(ComponentQuery.class), anyListOf(Component.class));
+  }
+
   @Test
   public void should_find() {
+    List<String> qualifiers = newArrayList("TRK");
+
     Map<String, Object> map = newHashMap();
     map.put("keys", newArrayList("org.codehaus.sonar"));
     map.put("names", newArrayList("Sonar"));
-    map.put("qualifiers", newArrayList("TRK"));
+    map.put("qualifiers", qualifiers);
     map.put("pageSize", 10l);
     map.put("pageIndex", 50);
     map.put("sort", "NAME");
     map.put("asc", true);
 
     componentService.find(map);
-    verify(finder).find(any(ComponentQuery.class));
+    verify(resourceDao).selectComponentsByQualifiers(anyListOf(String.class));
+    verify(finder).find(any(ComponentQuery.class), anyListOf(Component.class));
   }
 
   @Test