]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9551 Persist applications with APP qualifier
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 19 Jul 2017 13:30:48 +0000 (15:30 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 31 Jul 2017 09:27:51 +0000 (11:27 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistComponentsStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ViewsComponent.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ViewsPersistComponentsStepTest.java

index dfc37c2930522328a1c0d3733d1afb3863000cf9..387e1b4816ce27714210254eaa662a857d2249dc 100644 (file)
@@ -317,7 +317,7 @@ public class PersistComponentsStep implements ComputationStep {
     ComponentDto res = createBase(view);
 
     res.setScope(Scopes.PROJECT);
-    res.setQualifier(Qualifiers.VIEW);
+    res.setQualifier(view.getViewAttributes().getType().getQualifier());
     res.setName(view.getName());
     res.setDescription(view.getDescription());
     res.setLongName(res.name());
index e129eea122224977f6ca49b756bf577a7a21d298..9f9824dce02eb93cd58c37676d0ab517213fcf19 100644 (file)
@@ -37,18 +37,12 @@ import static java.util.Objects.requireNonNull;
 public class ViewsComponent implements Component {
   private final Type type;
   private final String key;
-  @CheckForNull
   private final String uuid;
-  @CheckForNull
   private final String name;
-  @CheckForNull
   private final String description;
   private final List<Component> children;
-  @CheckForNull
   private final ProjectViewAttributes projectViewAttributes;
-  @CheckForNull
   private final SubViewAttributes subViewAttributes;
-  @CheckForNull
   private final ViewAttributes viewAttributes;
 
   private ViewsComponent(Type type, String key, @Nullable String uuid, @Nullable String name, @Nullable String description,
@@ -77,18 +71,12 @@ public class ViewsComponent implements Component {
   public static final class Builder {
     private final Type type;
     private final String key;
-    @CheckForNull
     private String uuid;
-    @CheckForNull
     private String name;
-    @CheckForNull
     private String description;
     private List<Component> children = new ArrayList<>();
-    @CheckForNull
     private ProjectViewAttributes projectViewAttributes;
-    @CheckForNull
     private SubViewAttributes subViewAttributes;
-    @CheckForNull
     private ViewAttributes viewAttributes;
 
     private Builder(Type type, String key) {
index cc0d1a52f1d618b5fc74dc5498f9fd6ab67fc928..e3a912378ac53a8378797b6e5f6181ad55f257b5 100644 (file)
@@ -42,6 +42,7 @@ import org.sonar.server.computation.task.projectanalysis.component.MutableDisabl
 import org.sonar.server.computation.task.projectanalysis.component.ProjectViewAttributes;
 import org.sonar.server.computation.task.projectanalysis.component.SubViewAttributes;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
+import org.sonar.server.computation.task.projectanalysis.component.ViewAttributes;
 import org.sonar.server.computation.task.projectanalysis.component.ViewsComponent;
 import org.sonar.server.computation.task.step.ComputationStep;
 
@@ -55,6 +56,8 @@ import static org.sonar.db.component.ComponentTesting.newSubView;
 import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.PROJECT_VIEW;
 import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.SUBVIEW;
 import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.VIEW;
+import static org.sonar.server.computation.task.projectanalysis.component.ViewAttributes.Type.APPLICATION;
+import static org.sonar.server.computation.task.projectanalysis.component.ViewAttributes.Type.PORTFOLIO;
 import static org.sonar.server.computation.task.projectanalysis.component.ViewsComponent.builder;
 
 public class ViewsPersistComponentsStepTest extends BaseStepTest {
@@ -107,7 +110,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
 
   @Test
   public void persist_empty_view() {
-    treeRootHolder.setRoot(createViewBuilder().build());
+    treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build());
 
     underTest.execute();
 
@@ -122,7 +125,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
     // most of the time view already exists since its supposed to be created when config is uploaded
     persistComponents(newViewDto(dbTester.organizations().insert()));
 
-    treeRootHolder.setRoot(createViewBuilder().build());
+    treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build());
 
     underTest.execute();
 
@@ -137,7 +140,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
     persistComponents(project);
 
     treeRootHolder.setRoot(
-      createViewBuilder()
+      createViewBuilder(PORTFOLIO)
         .addChildren(createProjectView1Builder(project, null).build())
         .build());
 
@@ -152,10 +155,31 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
     assertDtoIsProjectView1(pv1Dto, viewDto, viewDto, project);
   }
 
+  @Test
+  public void persist_application_with_projectView() {
+    ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert());
+    persistComponents(project);
+
+    treeRootHolder.setRoot(
+      createViewBuilder(APPLICATION)
+        .addChildren(createProjectView1Builder(project, null).build())
+        .build());
+
+    underTest.execute();
+
+    assertRowsCountInTableProjects(3);
+
+    ComponentDto applicationDto = getComponentFromDb(VIEW_KEY);
+    assertDtoIsApplication(applicationDto);
+
+    ComponentDto pv1Dto = getComponentFromDb(PROJECT_VIEW_1_KEY);
+    assertDtoIsProjectView1(pv1Dto, applicationDto, applicationDto, project);
+  }
+
   @Test
   public void persist_empty_subview() {
     treeRootHolder.setRoot(
-      createViewBuilder()
+      createViewBuilder(PORTFOLIO)
         .addChildren(
           createSubView1Builder(null).build())
         .build());
@@ -174,7 +198,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
   @Test
   public void persist_empty_subview_having_original_view_uuid() {
     treeRootHolder.setRoot(
-      createViewBuilder()
+      createViewBuilder(PORTFOLIO)
         .addChildren(
           createSubView1Builder("ORIGINAL_UUID").build())
         .build());
@@ -194,7 +218,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
     persistComponents(ComponentTesting.newSubView(viewDto, SUBVIEW_1_UUID, SUBVIEW_1_KEY).setName(SUBVIEW_1_NAME));
 
     treeRootHolder.setRoot(
-      createViewBuilder()
+      createViewBuilder(PORTFOLIO)
         .addChildren(
           createSubView1Builder(null).build())
         .build());
@@ -212,7 +236,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
     persistComponents(newViewDto(dbTester.organizations().insert()));
 
     treeRootHolder.setRoot(
-      createViewBuilder()
+      createViewBuilder(PORTFOLIO)
         .addChildren(
           createSubView1Builder(null).build())
         .build());
@@ -231,7 +255,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
     persistComponents(project);
 
     treeRootHolder.setRoot(
-      createViewBuilder()
+      createViewBuilder(PORTFOLIO)
         .addChildren(
           createSubView1Builder(null)
             .addChildren(
@@ -256,7 +280,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
     ComponentDto viewDto = newViewDto(dbTester.organizations().insert()).setLongName("another long name").setCreatedAt(now);
     persistComponents(viewDto);
 
-    treeRootHolder.setRoot(createViewBuilder().build());
+    treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build());
 
     underTest.execute();
 
@@ -283,7 +307,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
     persistComponents(projectView);
 
     treeRootHolder.setRoot(
-      createViewBuilder()
+      createViewBuilder(PORTFOLIO)
         .addChildren(createProjectView1Builder(project, null).build())
         .build());
 
@@ -313,7 +337,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
     persistComponents(projectView);
 
     treeRootHolder.setRoot(
-      createViewBuilder()
+      createViewBuilder(PORTFOLIO)
         // Project view in the View is linked to the first project2
         .addChildren(createProjectView1Builder(project2, null).build())
         .build());
@@ -337,7 +361,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
     persistComponents(view, subView);
 
     treeRootHolder.setRoot(
-      createViewBuilder()
+      createViewBuilder(PORTFOLIO)
         .addChildren(
           createSubView1Builder("NEW_COPY").build())
         .build());
@@ -356,7 +380,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
   public void persists_new_components_as_public_if_root_does_not_exist_yet_out_of_functional_transaction() {
     ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
     treeRootHolder.setRoot(
-      createViewBuilder()
+      createViewBuilder(PORTFOLIO)
         .addChildren(
           createSubView1Builder(null)
             .addChildren(
@@ -378,7 +402,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
     ComponentDto view = newViewDto(organization).setUuid(VIEW_UUID).setKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate);
     dbTester.components().insertComponent(view);
     treeRootHolder.setRoot(
-      createViewBuilder()
+      createViewBuilder(PORTFOLIO)
         .addChildren(
           createSubView1Builder(null)
             .addChildren(
@@ -405,7 +429,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
     dbTester.components().insertComponent(subView);
     dbTester.components().insertComponent(newProjectCopy("DEFG", project, view).setKey("DIR").setPrivate(isRootPrivate));
     treeRootHolder.setRoot(
-      createViewBuilder()
+      createViewBuilder(PORTFOLIO)
         .addChildren(
           createSubView1Builder(null)
             .addChildren(
@@ -421,11 +445,12 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
         .isEqualTo(isRootPrivate));
   }
 
-  private static ViewsComponent.Builder createViewBuilder() {
+  private static ViewsComponent.Builder createViewBuilder(ViewAttributes.Type viewType) {
     return builder(VIEW, VIEW_KEY)
       .setUuid(VIEW_UUID)
       .setName(VIEW_NAME)
-      .setDescription(VIEW_DESCRIPTION);
+      .setDescription(VIEW_DESCRIPTION)
+      .setViewAttributes(new ViewAttributes(viewType));
   }
 
   private ViewsComponent.Builder createSubView1Builder(@Nullable String originalViewUuid) {
@@ -473,23 +498,43 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
   }
 
   /**
-   * Assertions to verify the DTO created from {@link #createViewBuilder()}
+   * Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()}
+   */
+  private void assertDtoIsView(ComponentDto dto) {
+    assertThat(dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
+    assertThat(dto.name()).isEqualTo(VIEW_NAME);
+    assertThat(dto.longName()).isEqualTo(VIEW_NAME);
+    assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION);
+    assertThat(dto.path()).isNull();
+    assertThat(dto.uuid()).isEqualTo(VIEW_UUID);
+    assertThat(dto.projectUuid()).isEqualTo(VIEW_UUID);
+    assertThat(dto.getRootUuid()).isEqualTo(VIEW_UUID);
+    assertThat(dto.moduleUuid()).isNull();
+    assertThat(dto.moduleUuidPath()).isEqualTo("." + dto.uuid() + ".");
+    assertThat(dto.qualifier()).isEqualTo(Qualifiers.VIEW);
+    assertThat(dto.scope()).isEqualTo(Scopes.PROJECT);
+    assertThat(dto.getCopyResourceUuid()).isNull();
+    assertThat(dto.getCreatedAt()).isEqualTo(now);
+  }
+
+  /**
+   * Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()}
    */
-  private void assertDtoIsView(ComponentDto projectDto) {
-    assertThat(projectDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
-    assertThat(projectDto.name()).isEqualTo(VIEW_NAME);
-    assertThat(projectDto.longName()).isEqualTo(VIEW_NAME);
-    assertThat(projectDto.description()).isEqualTo(VIEW_DESCRIPTION);
-    assertThat(projectDto.path()).isNull();
-    assertThat(projectDto.uuid()).isEqualTo(VIEW_UUID);
-    assertThat(projectDto.projectUuid()).isEqualTo(VIEW_UUID);
-    assertThat(projectDto.getRootUuid()).isEqualTo(VIEW_UUID);
-    assertThat(projectDto.moduleUuid()).isNull();
-    assertThat(projectDto.moduleUuidPath()).isEqualTo("." + projectDto.uuid() + ".");
-    assertThat(projectDto.qualifier()).isEqualTo(Qualifiers.VIEW);
-    assertThat(projectDto.scope()).isEqualTo(Scopes.PROJECT);
-    assertThat(projectDto.getCopyResourceUuid()).isNull();
-    assertThat(projectDto.getCreatedAt()).isEqualTo(now);
+  private void assertDtoIsApplication(ComponentDto dto) {
+    assertThat(dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
+    assertThat(dto.name()).isEqualTo(VIEW_NAME);
+    assertThat(dto.longName()).isEqualTo(VIEW_NAME);
+    assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION);
+    assertThat(dto.path()).isNull();
+    assertThat(dto.uuid()).isEqualTo(VIEW_UUID);
+    assertThat(dto.projectUuid()).isEqualTo(VIEW_UUID);
+    assertThat(dto.getRootUuid()).isEqualTo(VIEW_UUID);
+    assertThat(dto.moduleUuid()).isNull();
+    assertThat(dto.moduleUuidPath()).isEqualTo("." + dto.uuid() + ".");
+    assertThat(dto.qualifier()).isEqualTo(Qualifiers.APP);
+    assertThat(dto.scope()).isEqualTo(Scopes.PROJECT);
+    assertThat(dto.getCopyResourceUuid()).isNull();
+    assertThat(dto.getCreatedAt()).isEqualTo(now);
   }
 
   /**