]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7129 WS api/components/tree search for project copy 714/head
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 13 Jan 2016 15:37:45 +0000 (16:37 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 13 Jan 2016 16:31:08 +0000 (17:31 +0100)
server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java
sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java

index aaa504649ff2296f50a826f1db3afd3c5a5999f1..59c7c542482927adeb7d5d51071102e76461555b 100644 (file)
@@ -243,10 +243,10 @@ public class TreeActionTest {
   public void direct_children_of_a_view() throws IOException {
     ComponentDto view = newView("view-uuid");
     SnapshotDto viewSnapshot = componentDb.insertViewAndSnapshot(view);
-    ComponentDto project = newProjectDto("project-uuid-1");
+    ComponentDto project = newProjectDto("project-uuid-1").setName("project-name");
     componentDb.insertProjectAndSnapshot(project);
     componentDb.insertComponentAndSnapshot(newProjectCopy("project-uuid-1-copy", project, view), viewSnapshot);
-    componentDb.insertComponentAndSnapshot(newSubView(view, "sub-view-uuid", "sub-view-key"), viewSnapshot);
+    componentDb.insertComponentAndSnapshot(newSubView(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name"), viewSnapshot);
     db.commit();
     componentDb.indexProjects();
 
@@ -254,6 +254,7 @@ public class TreeActionTest {
       .setMediaType(MediaTypes.PROTOBUF)
       .setParam(PARAM_STRATEGY, "children")
       .setParam(PARAM_BASE_COMPONENT_ID, "view-uuid")
+      .setParam(Param.TEXT_QUERY, "name")
       .execute().getInputStream();
     WsComponents.TreeWsResponse response = WsComponents.TreeWsResponse.parseFrom(responseStream);
 
index 96ac077613ae0ff24b0165552a2d89ab2ce17194..42a76c6f65a27bb9da6e9f927727f5637c2bbcf8 100644 (file)
@@ -112,7 +112,7 @@ public class ComponentTreeQuery {
     return Joiner.on(", ").join(sqlSortFields);
   }
 
-  private String buildBaseSnapshotPath(SnapshotDto baseSnapshot) {
+  private static String buildBaseSnapshotPath(SnapshotDto baseSnapshot) {
     String existingSnapshotPath = baseSnapshot.getPath() == null ? "" : baseSnapshot.getPath();
     return buildLikeValue(existingSnapshotPath + baseSnapshot.getId() + ".", WildcardPosition.AFTER);
   }
index 28c94bb38f574bf94dcd9c79cb9b155293750182..6d92ed2c93267317aaf1494f0c6eb2b694904e6f 100644 (file)
       select 1
       from resource_index ri
       where
-      ri.resource_id=p.id
+      (ri.resource_id=p.id OR ri.resource_id=p.copy_resource_id)
       AND ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/')
       OR p.kee like #{query.nameOrKeyQueryToSqlForProjectKey} ESCAPE '/')
     </if>
index 0eaf33e3482685e5cfc1d27b821129e909b4b9ea..65dd56ee2378c99c3275c22c3983984673cc7b54 100644 (file)
@@ -43,7 +43,9 @@ import static org.assertj.guava.api.Assertions.assertThat;
 import static org.sonar.db.component.ComponentTesting.newDeveloper;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newModuleDto;
+import static org.sonar.db.component.ComponentTesting.newProjectCopy;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newSubView;
 import static org.sonar.db.component.ComponentTesting.newView;
 
 @Category(DbTests.class)
@@ -868,6 +870,25 @@ public class ComponentDaoTest {
     assertThat(result).extracting("uuid").containsExactly("file-1-uuid", "file-2-uuid", "module-1-uuid");
   }
 
+  @Test
+  public void select_direct_children_of_a_view() {
+    ComponentDto view = newView("view-uuid");
+    SnapshotDto viewSnapshot = componentDb.insertViewAndSnapshot(view);
+    // one subview
+    ComponentDto subView = newSubView(view, "subview-uuid", "subview-key").setName("subview-name");
+    componentDb.insertComponentAndSnapshot(subView, viewSnapshot);
+    // one project and its copy linked to the view
+    ComponentDto project = newProjectDto("project-uuid").setName("project-name");
+    componentDb.insertProjectAndSnapshot(project);
+    componentDb.insertComponentAndSnapshot(newProjectCopy("project-copy-uuid", project, view), viewSnapshot);
+    componentDb.indexProjects();
+    ComponentTreeQuery dbQuery = newTreeQuery(viewSnapshot).setNameOrKeyQuery("name").build();
+
+    List<ComponentDtoWithSnapshotId> components = underTest.selectDirectChildren(dbSession, dbQuery);
+
+    assertThat(components).extracting("uuid").containsOnly("project-copy-uuid", "subview-uuid");
+  }
+
   @Test
   public void select_all_files_of_a_project_paginated_and_ordered() {
     ComponentDto project = newProjectDto().setKey("project-key").setUuid("project-uuid");
@@ -903,7 +924,6 @@ public class ComponentDaoTest {
       .setPageSize(500)
       .setBaseSnapshot(baseSnapshot)
       .setSortFields(singletonList("name"))
-      .setAsc(true)
-      .setQualifiers(newArrayList(Qualifiers.FILE, Qualifiers.MODULE, Qualifiers.DIRECTORY, Qualifiers.PROJECT));
+      .setAsc(true);
   }
 }