]> source.dussan.org Git - sonarqube.git/blob
f3a8804061666e1c3f05eb6b84fe2db8a2204329
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2017 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 3 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20 package org.sonar.server.computation.task.projectanalysis.step;
21
22 import java.text.SimpleDateFormat;
23 import java.util.Date;
24 import java.util.Random;
25 import java.util.stream.Stream;
26 import javax.annotation.Nullable;
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.sonar.api.resources.Qualifiers;
31 import org.sonar.api.resources.Scopes;
32 import org.sonar.api.utils.System2;
33 import org.sonar.db.DbClient;
34 import org.sonar.db.DbTester;
35 import org.sonar.db.component.ComponentDbTester;
36 import org.sonar.db.component.ComponentDto;
37 import org.sonar.db.component.ComponentTesting;
38 import org.sonar.db.organization.OrganizationDto;
39 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
40 import org.sonar.server.computation.task.projectanalysis.component.BranchPersisterDelegate;
41 import org.sonar.server.computation.task.projectanalysis.component.DefaultBranchImpl;
42 import org.sonar.server.computation.task.projectanalysis.component.MutableDbIdsRepositoryRule;
43 import org.sonar.server.computation.task.projectanalysis.component.MutableDisabledComponentsHolder;
44 import org.sonar.server.computation.task.projectanalysis.component.ProjectViewAttributes;
45 import org.sonar.server.computation.task.projectanalysis.component.SubViewAttributes;
46 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
47 import org.sonar.server.computation.task.projectanalysis.component.ViewAttributes;
48 import org.sonar.server.computation.task.projectanalysis.component.ViewsComponent;
49 import org.sonar.server.computation.task.step.ComputationStep;
50
51 import static org.assertj.core.api.Assertions.assertThat;
52 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
53 import static org.mockito.Mockito.mock;
54 import static org.mockito.Mockito.when;
55 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
56 import static org.sonar.db.component.ComponentTesting.newProjectCopy;
57 import static org.sonar.db.component.ComponentTesting.newSubView;
58 import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.PROJECT_VIEW;
59 import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.SUBVIEW;
60 import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.VIEW;
61 import static org.sonar.server.computation.task.projectanalysis.component.ViewAttributes.Type.APPLICATION;
62 import static org.sonar.server.computation.task.projectanalysis.component.ViewAttributes.Type.PORTFOLIO;
63 import static org.sonar.server.computation.task.projectanalysis.component.ViewsComponent.builder;
64
65 public class ViewsPersistComponentsStepTest extends BaseStepTest {
66
67   private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
68
69   private static final String VIEW_KEY = "VIEW_KEY";
70   private static final String VIEW_NAME = "VIEW_NAME";
71   private static final String VIEW_DESCRIPTION = "view description";
72   private static final String VIEW_UUID = "VIEW_UUID";
73   private static final String SUBVIEW_1_KEY = "SUBVIEW_1_KEY";
74   private static final String SUBVIEW_1_NAME = "SUBVIEW_1_NAME";
75   private static final String SUBVIEW_1_DESCRIPTION = "subview 1 description";
76   private static final String SUBVIEW_1_UUID = "SUBVIEW_1_UUID";
77   private static final String PROJECT_VIEW_1_KEY = "PV1_KEY";
78   private static final String PROJECT_VIEW_1_NAME = "PV1_NAME";
79   private static final String PROJECT_VIEW_1_UUID = "PV1_UUID";
80   private static final String ORGANIZATION_UUID = "org1";
81
82   @Rule
83   public DbTester dbTester = DbTester.create(System2.INSTANCE);
84   @Rule
85   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
86   @Rule
87   public MutableDbIdsRepositoryRule dbIdsRepository = MutableDbIdsRepositoryRule.create(treeRootHolder);
88   @Rule
89   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
90     .setOrganizationUuid(ORGANIZATION_UUID);
91
92   private System2 system2 = mock(System2.class);
93   private DbClient dbClient = dbTester.getDbClient();
94   private Date now;
95   private ComponentDbTester componentDbTester = new ComponentDbTester(dbTester);
96   private MutableDisabledComponentsHolder disabledComponentsHolder = mock(MutableDisabledComponentsHolder.class, RETURNS_DEEP_STUBS);
97   private PersistComponentsStep underTest;
98   private BranchPersisterDelegate branchPersister;
99
100   @Before
101   public void setup() throws Exception {
102     now = DATE_FORMAT.parse("2015-06-02");
103     when(system2.now()).thenReturn(now.getTime());
104
105     dbTester.organizations().insertForUuid(ORGANIZATION_UUID);
106     analysisMetadataHolder.setBranch(new DefaultBranchImpl(null));
107     underTest = new PersistComponentsStep(dbClient, treeRootHolder, dbIdsRepository, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister);
108   }
109
110   @Override
111   protected ComputationStep step() {
112     return underTest;
113   }
114
115   @Test
116   public void persist_empty_view() {
117     treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build());
118
119     underTest.execute();
120
121     assertRowsCountInTableProjects(1);
122
123     ComponentDto projectDto = getComponentFromDb(VIEW_KEY);
124     assertDtoIsView(projectDto);
125   }
126
127   @Test
128   public void persist_existing_empty_view() {
129     // most of the time view already exists since its supposed to be created when config is uploaded
130     persistComponents(newViewDto(dbTester.organizations().insert()));
131
132     treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build());
133
134     underTest.execute();
135
136     assertRowsCountInTableProjects(1);
137
138     assertDtoNotUpdated(VIEW_KEY);
139   }
140
141   @Test
142   public void persist_view_with_projectView() {
143     ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert());
144     persistComponents(project);
145
146     treeRootHolder.setRoot(
147       createViewBuilder(PORTFOLIO)
148         .addChildren(createProjectView1Builder(project, null).build())
149         .build());
150
151     underTest.execute();
152
153     assertRowsCountInTableProjects(3);
154
155     ComponentDto viewDto = getComponentFromDb(VIEW_KEY);
156     assertDtoIsView(viewDto);
157
158     ComponentDto pv1Dto = getComponentFromDb(PROJECT_VIEW_1_KEY);
159     assertDtoIsProjectView1(pv1Dto, viewDto, viewDto, project);
160   }
161
162   @Test
163   public void persist_application_with_projectView() {
164     ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert());
165     persistComponents(project);
166
167     treeRootHolder.setRoot(
168       createViewBuilder(APPLICATION)
169         .addChildren(createProjectView1Builder(project, null).build())
170         .build());
171
172     underTest.execute();
173
174     assertRowsCountInTableProjects(3);
175
176     ComponentDto applicationDto = getComponentFromDb(VIEW_KEY);
177     assertDtoIsApplication(applicationDto);
178
179     ComponentDto pv1Dto = getComponentFromDb(PROJECT_VIEW_1_KEY);
180     assertDtoIsProjectView1(pv1Dto, applicationDto, applicationDto, project);
181   }
182
183   @Test
184   public void persist_empty_subview() {
185     treeRootHolder.setRoot(
186       createViewBuilder(PORTFOLIO)
187         .addChildren(
188           createSubView1Builder(null).build())
189         .build());
190
191     underTest.execute();
192
193     assertRowsCountInTableProjects(2);
194
195     ComponentDto viewDto = getComponentFromDb(VIEW_KEY);
196     assertDtoIsView(viewDto);
197
198     ComponentDto sv1Dto = getComponentFromDb(SUBVIEW_1_KEY);
199     assertDtoIsSubView1(viewDto, sv1Dto);
200   }
201
202   @Test
203   public void persist_empty_subview_having_original_view_uuid() {
204     treeRootHolder.setRoot(
205       createViewBuilder(PORTFOLIO)
206         .addChildren(
207           createSubView1Builder("ORIGINAL_UUID").build())
208         .build());
209
210     underTest.execute();
211
212     assertRowsCountInTableProjects(2);
213
214     ComponentDto subView = getComponentFromDb(SUBVIEW_1_KEY);
215     assertThat(subView.getCopyResourceUuid()).isEqualTo("ORIGINAL_UUID");
216   }
217
218   @Test
219   public void persist_existing_empty_subview_under_existing_view() {
220     ComponentDto viewDto = newViewDto(dbTester.organizations().insert());
221     persistComponents(viewDto);
222     persistComponents(ComponentTesting.newSubView(viewDto, SUBVIEW_1_UUID, SUBVIEW_1_KEY).setName(SUBVIEW_1_NAME));
223
224     treeRootHolder.setRoot(
225       createViewBuilder(PORTFOLIO)
226         .addChildren(
227           createSubView1Builder(null).build())
228         .build());
229
230     underTest.execute();
231
232     assertRowsCountInTableProjects(2);
233
234     assertDtoNotUpdated(VIEW_KEY);
235     assertDtoNotUpdated(SUBVIEW_1_KEY);
236   }
237
238   @Test
239   public void persist_empty_subview_under_existing_view() {
240     persistComponents(newViewDto(dbTester.organizations().insert()));
241
242     treeRootHolder.setRoot(
243       createViewBuilder(PORTFOLIO)
244         .addChildren(
245           createSubView1Builder(null).build())
246         .build());
247
248     underTest.execute();
249
250     assertRowsCountInTableProjects(2);
251
252     assertDtoNotUpdated(VIEW_KEY);
253     assertDtoIsSubView1(getComponentFromDb(VIEW_KEY), getComponentFromDb(SUBVIEW_1_KEY));
254   }
255
256   @Test
257   public void persist_project_view_under_subview() {
258     ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert());
259     persistComponents(project);
260
261     treeRootHolder.setRoot(
262       createViewBuilder(PORTFOLIO)
263         .addChildren(
264           createSubView1Builder(null)
265             .addChildren(
266               createProjectView1Builder(project, null).build())
267             .build())
268         .build());
269
270     underTest.execute();
271
272     assertRowsCountInTableProjects(4);
273
274     ComponentDto viewDto = getComponentFromDb(VIEW_KEY);
275     assertDtoIsView(viewDto);
276     ComponentDto subView1Dto = getComponentFromDb(SUBVIEW_1_KEY);
277     assertDtoIsSubView1(viewDto, subView1Dto);
278     ComponentDto pv1Dto = getComponentFromDb(PROJECT_VIEW_1_KEY);
279     assertDtoIsProjectView1(pv1Dto, viewDto, subView1Dto, project);
280   }
281
282   @Test
283   public void update_view_name_and_longName() {
284     ComponentDto viewDto = newViewDto(dbTester.organizations().insert()).setLongName("another long name").setCreatedAt(now);
285     persistComponents(viewDto);
286
287     treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build());
288
289     underTest.execute();
290
291     // commit functional transaction -> copies B-fields to A-fields
292     dbClient.componentDao().applyBChangesForRootComponentUuid(dbTester.getSession(), viewDto.uuid());
293     dbTester.commit();
294
295     assertRowsCountInTableProjects(1);
296     ComponentDto newViewDto = getComponentFromDb(VIEW_KEY);
297     assertDtoIsView(newViewDto);
298   }
299
300   @Test
301   public void update_project_view() {
302     OrganizationDto organizationDto = dbTester.organizations().insert();
303     ComponentDto view = newViewDto(organizationDto);
304     ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
305     persistComponents(view, project);
306     ComponentDto projectView = ComponentTesting.newProjectCopy(PROJECT_VIEW_1_UUID, project, view)
307       .setOrganizationUuid(ORGANIZATION_UUID)
308       .setDbKey(PROJECT_VIEW_1_KEY)
309       .setName("Old name")
310       .setCreatedAt(now);
311     persistComponents(projectView);
312
313     treeRootHolder.setRoot(
314       createViewBuilder(PORTFOLIO)
315         .addChildren(createProjectView1Builder(project, null).build())
316         .build());
317
318     underTest.execute();
319
320     // commit functional transaction -> copies B-fields to A-fields
321     dbClient.componentDao().applyBChangesForRootComponentUuid(dbTester.getSession(), view.uuid());
322     dbTester.commit();
323
324     assertRowsCountInTableProjects(3);
325     ComponentDto pv1Dto = getComponentFromDb(PROJECT_VIEW_1_KEY);
326     assertDtoIsProjectView1(pv1Dto, view, view, project);
327   }
328
329   @Test
330   public void update_copy_component_uuid_of_project_view() {
331     OrganizationDto organizationDto = dbTester.organizations().insert();
332     ComponentDto view = newViewDto(organizationDto);
333     ComponentDto project1 = newPrivateProjectDto(organizationDto, "P1");
334     ComponentDto project2 = newPrivateProjectDto(organizationDto, "P2");
335     persistComponents(view, project1, project2);
336
337     // Project view in DB is associated to project1
338     ComponentDto projectView = ComponentTesting.newProjectCopy(PROJECT_VIEW_1_UUID, project1, view)
339       .setDbKey(PROJECT_VIEW_1_KEY)
340       .setCreatedAt(now);
341     persistComponents(projectView);
342
343     treeRootHolder.setRoot(
344       createViewBuilder(PORTFOLIO)
345         // Project view in the View is linked to the first project2
346         .addChildren(createProjectView1Builder(project2, null).build())
347         .build());
348
349     underTest.execute();
350
351     // commit functional transaction -> copies B-fields to A-fields
352     dbClient.componentDao().applyBChangesForRootComponentUuid(dbTester.getSession(), view.uuid());
353     dbTester.commit();
354
355     ComponentDto pv1Dto = getComponentFromDb(PROJECT_VIEW_1_KEY);
356     // Project view should now be linked to project2
357     assertDtoIsProjectView1(pv1Dto, view, view, project2);
358   }
359
360   @Test
361   public void update_copy_component_uuid_of_sub_view() {
362     OrganizationDto organizationDto = dbTester.organizations().insert();
363     ComponentDto view = newViewDto(organizationDto);
364     ComponentDto subView = newSubViewDto(view).setCopyComponentUuid("OLD_COPY");
365     persistComponents(view, subView);
366
367     treeRootHolder.setRoot(
368       createViewBuilder(PORTFOLIO)
369         .addChildren(
370           createSubView1Builder("NEW_COPY").build())
371         .build());
372
373     underTest.execute();
374
375     // commit functional transaction -> copies B-fields to A-fields
376     dbClient.componentDao().applyBChangesForRootComponentUuid(dbTester.getSession(), view.uuid());
377     dbTester.commit();
378
379     ComponentDto subViewReloaded = getComponentFromDb(SUBVIEW_1_KEY);
380     assertThat(subViewReloaded.getCopyResourceUuid()).isEqualTo("NEW_COPY");
381   }
382
383   @Test
384   public void persists_new_components_as_public_if_root_does_not_exist_yet_out_of_functional_transaction() {
385     ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
386     treeRootHolder.setRoot(
387       createViewBuilder(PORTFOLIO)
388         .addChildren(
389           createSubView1Builder(null)
390             .addChildren(
391               createProjectView1Builder(project, null).build())
392             .build())
393         .build());
394
395     underTest.execute();
396
397     Stream.of(VIEW_UUID, SUBVIEW_1_UUID, PROJECT_VIEW_1_UUID)
398       .forEach(uuid -> assertThat(dbClient.componentDao().selectByUuid(dbTester.getSession(), uuid).get().isPrivate()).isFalse());
399   }
400
401   @Test
402   public void persists_new_components_with_visibility_of_root_in_db_out_of_functional_transaction() {
403     boolean isRootPrivate = new Random().nextBoolean();
404     ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
405     OrganizationDto organization = dbTester.organizations().insert();
406     ComponentDto view = newViewDto(organization).setUuid(VIEW_UUID).setDbKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate);
407     dbTester.components().insertComponent(view);
408     treeRootHolder.setRoot(
409       createViewBuilder(PORTFOLIO)
410         .addChildren(
411           createSubView1Builder(null)
412             .addChildren(
413               createProjectView1Builder(project, null).build())
414             .build())
415         .build());
416
417     underTest.execute();
418
419     Stream.of(VIEW_UUID, SUBVIEW_1_UUID, PROJECT_VIEW_1_UUID)
420       .forEach(uuid -> assertThat(dbClient.componentDao().selectByUuid(dbTester.getSession(), uuid).get().isPrivate())
421         .describedAs("for uuid " + uuid)
422         .isEqualTo(isRootPrivate));
423   }
424
425   @Test
426   public void persists_existing_components_with_visibility_of_root_in_db_out_of_functional_transaction() {
427     boolean isRootPrivate = new Random().nextBoolean();
428     ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
429     OrganizationDto organization = dbTester.organizations().insert();
430     ComponentDto view = newViewDto(organization).setUuid(VIEW_UUID).setDbKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate);
431     dbTester.components().insertComponent(view);
432     ComponentDto subView = newSubView(view).setUuid("BCDE").setDbKey("MODULE").setPrivate(!isRootPrivate);
433     dbTester.components().insertComponent(subView);
434     dbTester.components().insertComponent(newProjectCopy("DEFG", project, view).setDbKey("DIR").setPrivate(isRootPrivate));
435     treeRootHolder.setRoot(
436       createViewBuilder(PORTFOLIO)
437         .addChildren(
438           createSubView1Builder(null)
439             .addChildren(
440               createProjectView1Builder(project, null).build())
441             .build())
442         .build());
443
444     underTest.execute();
445
446     Stream.of(VIEW_UUID, SUBVIEW_1_UUID, PROJECT_VIEW_1_UUID, subView.uuid(), "DEFG")
447       .forEach(uuid -> assertThat(dbClient.componentDao().selectByUuid(dbTester.getSession(), uuid).get().isPrivate())
448         .describedAs("for uuid " + uuid)
449         .isEqualTo(isRootPrivate));
450   }
451
452   private static ViewsComponent.Builder createViewBuilder(ViewAttributes.Type viewType) {
453     return builder(VIEW, VIEW_KEY)
454       .setUuid(VIEW_UUID)
455       .setName(VIEW_NAME)
456       .setDescription(VIEW_DESCRIPTION)
457       .setViewAttributes(new ViewAttributes(viewType));
458   }
459
460   private ViewsComponent.Builder createSubView1Builder(@Nullable String originalViewUuid) {
461     return builder(SUBVIEW, SUBVIEW_1_KEY)
462       .setUuid(SUBVIEW_1_UUID)
463       .setName(SUBVIEW_1_NAME)
464       .setDescription(SUBVIEW_1_DESCRIPTION)
465       .setSubViewAttributes(new SubViewAttributes(originalViewUuid));
466   }
467
468   private static ViewsComponent.Builder createProjectView1Builder(ComponentDto project, Long analysisDate) {
469     return builder(PROJECT_VIEW, PROJECT_VIEW_1_KEY)
470       .setUuid(PROJECT_VIEW_1_UUID)
471       .setName(PROJECT_VIEW_1_NAME)
472       .setDescription("project view description is not persisted")
473       .setProjectViewAttributes(new ProjectViewAttributes(project.uuid(), analysisDate));
474   }
475
476   private void persistComponents(ComponentDto... componentDtos) {
477     componentDbTester.insertComponents(componentDtos);
478   }
479
480   private ComponentDto getComponentFromDb(String componentKey) {
481     return dbClient.componentDao().selectByKey(dbTester.getSession(), componentKey).get();
482   }
483
484   private void assertRowsCountInTableProjects(int rowCount) {
485     assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(rowCount);
486   }
487
488   private void assertDtoNotUpdated(String componentKey) {
489     assertThat(getComponentFromDb(componentKey).getCreatedAt()).isNotEqualTo(now);
490   }
491
492   private ComponentDto newViewDto(OrganizationDto organizationDto) {
493     return ComponentTesting.newView(organizationDto, VIEW_UUID)
494       .setOrganizationUuid(ORGANIZATION_UUID)
495       .setDbKey(VIEW_KEY)
496       .setName(VIEW_NAME);
497   }
498
499   private ComponentDto newSubViewDto(ComponentDto rootView) {
500     return ComponentTesting.newSubView(rootView, SUBVIEW_1_UUID, SUBVIEW_1_KEY)
501       .setName(SUBVIEW_1_NAME);
502   }
503
504   /**
505    * Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()}
506    */
507   private void assertDtoIsView(ComponentDto dto) {
508     assertThat(dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
509     assertThat(dto.name()).isEqualTo(VIEW_NAME);
510     assertThat(dto.longName()).isEqualTo(VIEW_NAME);
511     assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION);
512     assertThat(dto.path()).isNull();
513     assertThat(dto.uuid()).isEqualTo(VIEW_UUID);
514     assertThat(dto.projectUuid()).isEqualTo(VIEW_UUID);
515     assertThat(dto.getRootUuid()).isEqualTo(VIEW_UUID);
516     assertThat(dto.moduleUuid()).isNull();
517     assertThat(dto.moduleUuidPath()).isEqualTo("." + dto.uuid() + ".");
518     assertThat(dto.qualifier()).isEqualTo(Qualifiers.VIEW);
519     assertThat(dto.scope()).isEqualTo(Scopes.PROJECT);
520     assertThat(dto.getCopyResourceUuid()).isNull();
521     assertThat(dto.getCreatedAt()).isEqualTo(now);
522   }
523
524   /**
525    * Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()}
526    */
527   private void assertDtoIsApplication(ComponentDto dto) {
528     assertThat(dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
529     assertThat(dto.name()).isEqualTo(VIEW_NAME);
530     assertThat(dto.longName()).isEqualTo(VIEW_NAME);
531     assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION);
532     assertThat(dto.path()).isNull();
533     assertThat(dto.uuid()).isEqualTo(VIEW_UUID);
534     assertThat(dto.projectUuid()).isEqualTo(VIEW_UUID);
535     assertThat(dto.getRootUuid()).isEqualTo(VIEW_UUID);
536     assertThat(dto.moduleUuid()).isNull();
537     assertThat(dto.moduleUuidPath()).isEqualTo("." + dto.uuid() + ".");
538     assertThat(dto.qualifier()).isEqualTo(Qualifiers.APP);
539     assertThat(dto.scope()).isEqualTo(Scopes.PROJECT);
540     assertThat(dto.getCopyResourceUuid()).isNull();
541     assertThat(dto.getCreatedAt()).isEqualTo(now);
542   }
543
544   /**
545    * Assertions to verify the DTO created from {@link #createProjectView1Builder(ComponentDto, Long)}
546    */
547   private void assertDtoIsSubView1(ComponentDto viewDto, ComponentDto sv1Dto) {
548     assertThat(sv1Dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
549     assertThat(sv1Dto.name()).isEqualTo(SUBVIEW_1_NAME);
550     assertThat(sv1Dto.longName()).isEqualTo(SUBVIEW_1_NAME);
551     assertThat(sv1Dto.description()).isEqualTo(SUBVIEW_1_DESCRIPTION);
552     assertThat(sv1Dto.path()).isNull();
553     assertThat(sv1Dto.uuid()).isEqualTo(SUBVIEW_1_UUID);
554     assertThat(sv1Dto.projectUuid()).isEqualTo(viewDto.uuid());
555     assertThat(sv1Dto.getRootUuid()).isEqualTo(viewDto.uuid());
556     assertThat(sv1Dto.moduleUuid()).isEqualTo(viewDto.uuid());
557     assertThat(sv1Dto.moduleUuidPath()).isEqualTo(viewDto.moduleUuidPath() + sv1Dto.uuid() + ".");
558     assertThat(sv1Dto.qualifier()).isEqualTo(Qualifiers.SUBVIEW);
559     assertThat(sv1Dto.scope()).isEqualTo(Scopes.PROJECT);
560     assertThat(sv1Dto.getCopyResourceUuid()).isNull();
561     assertThat(sv1Dto.getCreatedAt()).isEqualTo(now);
562   }
563
564   private void assertDtoIsProjectView1(ComponentDto pv1Dto, ComponentDto viewDto, ComponentDto parentViewDto, ComponentDto project) {
565     assertThat(pv1Dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
566     assertThat(pv1Dto.name()).isEqualTo(PROJECT_VIEW_1_NAME);
567     assertThat(pv1Dto.longName()).isEqualTo(PROJECT_VIEW_1_NAME);
568     assertThat(pv1Dto.description()).isNull();
569     assertThat(pv1Dto.path()).isNull();
570     assertThat(pv1Dto.uuid()).isEqualTo(PROJECT_VIEW_1_UUID);
571     assertThat(pv1Dto.projectUuid()).isEqualTo(viewDto.uuid());
572     assertThat(pv1Dto.getRootUuid()).isEqualTo(viewDto.uuid());
573     assertThat(pv1Dto.moduleUuid()).isEqualTo(parentViewDto.uuid());
574     assertThat(pv1Dto.moduleUuidPath()).isEqualTo(parentViewDto.moduleUuidPath() + pv1Dto.uuid() + ".");
575     assertThat(pv1Dto.qualifier()).isEqualTo(Qualifiers.PROJECT);
576     assertThat(pv1Dto.scope()).isEqualTo(Scopes.FILE);
577     assertThat(pv1Dto.getCopyResourceUuid()).isEqualTo(project.uuid());
578     assertThat(pv1Dto.getCreatedAt()).isEqualTo(now);
579   }
580
581 }