]> source.dussan.org Git - sonarqube.git/blob
62dd7f293cbd08dff160417a9658edd13a742061
[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.BranchPersister;
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 BranchPersister 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());
107     branchPersister = mock(BranchPersister.class);
108     underTest = new PersistComponentsStep(dbClient, treeRootHolder, dbIdsRepository, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister);
109   }
110
111   @Override
112   protected ComputationStep step() {
113     return underTest;
114   }
115
116   @Test
117   public void persist_empty_view() {
118     treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build());
119
120     underTest.execute();
121
122     assertRowsCountInTableProjects(1);
123
124     ComponentDto projectDto = getComponentFromDb(VIEW_KEY);
125     assertDtoIsView(projectDto);
126   }
127
128   @Test
129   public void persist_existing_empty_view() {
130     // most of the time view already exists since its supposed to be created when config is uploaded
131     persistComponents(newViewDto(dbTester.organizations().insert()));
132
133     treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build());
134
135     underTest.execute();
136
137     assertRowsCountInTableProjects(1);
138
139     assertDtoNotUpdated(VIEW_KEY);
140   }
141
142   @Test
143   public void persist_view_with_projectView() {
144     ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert());
145     persistComponents(project);
146
147     treeRootHolder.setRoot(
148       createViewBuilder(PORTFOLIO)
149         .addChildren(createProjectView1Builder(project, null).build())
150         .build());
151
152     underTest.execute();
153
154     assertRowsCountInTableProjects(3);
155
156     ComponentDto viewDto = getComponentFromDb(VIEW_KEY);
157     assertDtoIsView(viewDto);
158
159     ComponentDto pv1Dto = getComponentFromDb(PROJECT_VIEW_1_KEY);
160     assertDtoIsProjectView1(pv1Dto, viewDto, viewDto, project);
161   }
162
163   @Test
164   public void persist_application_with_projectView() {
165     ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert());
166     persistComponents(project);
167
168     treeRootHolder.setRoot(
169       createViewBuilder(APPLICATION)
170         .addChildren(createProjectView1Builder(project, null).build())
171         .build());
172
173     underTest.execute();
174
175     assertRowsCountInTableProjects(3);
176
177     ComponentDto applicationDto = getComponentFromDb(VIEW_KEY);
178     assertDtoIsApplication(applicationDto);
179
180     ComponentDto pv1Dto = getComponentFromDb(PROJECT_VIEW_1_KEY);
181     assertDtoIsProjectView1(pv1Dto, applicationDto, applicationDto, project);
182   }
183
184   @Test
185   public void persist_empty_subview() {
186     treeRootHolder.setRoot(
187       createViewBuilder(PORTFOLIO)
188         .addChildren(
189           createSubView1Builder(null).build())
190         .build());
191
192     underTest.execute();
193
194     assertRowsCountInTableProjects(2);
195
196     ComponentDto viewDto = getComponentFromDb(VIEW_KEY);
197     assertDtoIsView(viewDto);
198
199     ComponentDto sv1Dto = getComponentFromDb(SUBVIEW_1_KEY);
200     assertDtoIsSubView1(viewDto, sv1Dto);
201   }
202
203   @Test
204   public void persist_empty_subview_having_original_view_uuid() {
205     treeRootHolder.setRoot(
206       createViewBuilder(PORTFOLIO)
207         .addChildren(
208           createSubView1Builder("ORIGINAL_UUID").build())
209         .build());
210
211     underTest.execute();
212
213     assertRowsCountInTableProjects(2);
214
215     ComponentDto subView = getComponentFromDb(SUBVIEW_1_KEY);
216     assertThat(subView.getCopyResourceUuid()).isEqualTo("ORIGINAL_UUID");
217   }
218
219   @Test
220   public void persist_existing_empty_subview_under_existing_view() {
221     ComponentDto viewDto = newViewDto(dbTester.organizations().insert());
222     persistComponents(viewDto);
223     persistComponents(ComponentTesting.newSubView(viewDto, SUBVIEW_1_UUID, SUBVIEW_1_KEY).setName(SUBVIEW_1_NAME));
224
225     treeRootHolder.setRoot(
226       createViewBuilder(PORTFOLIO)
227         .addChildren(
228           createSubView1Builder(null).build())
229         .build());
230
231     underTest.execute();
232
233     assertRowsCountInTableProjects(2);
234
235     assertDtoNotUpdated(VIEW_KEY);
236     assertDtoNotUpdated(SUBVIEW_1_KEY);
237   }
238
239   @Test
240   public void persist_empty_subview_under_existing_view() {
241     persistComponents(newViewDto(dbTester.organizations().insert()));
242
243     treeRootHolder.setRoot(
244       createViewBuilder(PORTFOLIO)
245         .addChildren(
246           createSubView1Builder(null).build())
247         .build());
248
249     underTest.execute();
250
251     assertRowsCountInTableProjects(2);
252
253     assertDtoNotUpdated(VIEW_KEY);
254     assertDtoIsSubView1(getComponentFromDb(VIEW_KEY), getComponentFromDb(SUBVIEW_1_KEY));
255   }
256
257   @Test
258   public void persist_project_view_under_subview() {
259     ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert());
260     persistComponents(project);
261
262     treeRootHolder.setRoot(
263       createViewBuilder(PORTFOLIO)
264         .addChildren(
265           createSubView1Builder(null)
266             .addChildren(
267               createProjectView1Builder(project, null).build())
268             .build())
269         .build());
270
271     underTest.execute();
272
273     assertRowsCountInTableProjects(4);
274
275     ComponentDto viewDto = getComponentFromDb(VIEW_KEY);
276     assertDtoIsView(viewDto);
277     ComponentDto subView1Dto = getComponentFromDb(SUBVIEW_1_KEY);
278     assertDtoIsSubView1(viewDto, subView1Dto);
279     ComponentDto pv1Dto = getComponentFromDb(PROJECT_VIEW_1_KEY);
280     assertDtoIsProjectView1(pv1Dto, viewDto, subView1Dto, project);
281   }
282
283   @Test
284   public void update_view_name_and_longName() {
285     ComponentDto viewDto = newViewDto(dbTester.organizations().insert()).setLongName("another long name").setCreatedAt(now);
286     persistComponents(viewDto);
287
288     treeRootHolder.setRoot(createViewBuilder(PORTFOLIO).build());
289
290     underTest.execute();
291
292     // commit functional transaction -> copies B-fields to A-fields
293     dbClient.componentDao().applyBChangesForRootComponentUuid(dbTester.getSession(), viewDto.uuid());
294     dbTester.commit();
295
296     assertRowsCountInTableProjects(1);
297     ComponentDto newViewDto = getComponentFromDb(VIEW_KEY);
298     assertDtoIsView(newViewDto);
299   }
300
301   @Test
302   public void update_project_view() {
303     OrganizationDto organizationDto = dbTester.organizations().insert();
304     ComponentDto view = newViewDto(organizationDto);
305     ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto);
306     persistComponents(view, project);
307     ComponentDto projectView = ComponentTesting.newProjectCopy(PROJECT_VIEW_1_UUID, project, view)
308       .setOrganizationUuid(ORGANIZATION_UUID)
309       .setDbKey(PROJECT_VIEW_1_KEY)
310       .setName("Old name")
311       .setCreatedAt(now);
312     persistComponents(projectView);
313
314     treeRootHolder.setRoot(
315       createViewBuilder(PORTFOLIO)
316         .addChildren(createProjectView1Builder(project, null).build())
317         .build());
318
319     underTest.execute();
320
321     // commit functional transaction -> copies B-fields to A-fields
322     dbClient.componentDao().applyBChangesForRootComponentUuid(dbTester.getSession(), view.uuid());
323     dbTester.commit();
324
325     assertRowsCountInTableProjects(3);
326     ComponentDto pv1Dto = getComponentFromDb(PROJECT_VIEW_1_KEY);
327     assertDtoIsProjectView1(pv1Dto, view, view, project);
328   }
329
330   @Test
331   public void update_copy_component_uuid_of_project_view() {
332     OrganizationDto organizationDto = dbTester.organizations().insert();
333     ComponentDto view = newViewDto(organizationDto);
334     ComponentDto project1 = newPrivateProjectDto(organizationDto, "P1");
335     ComponentDto project2 = newPrivateProjectDto(organizationDto, "P2");
336     persistComponents(view, project1, project2);
337
338     // Project view in DB is associated to project1
339     ComponentDto projectView = ComponentTesting.newProjectCopy(PROJECT_VIEW_1_UUID, project1, view)
340       .setDbKey(PROJECT_VIEW_1_KEY)
341       .setCreatedAt(now);
342     persistComponents(projectView);
343
344     treeRootHolder.setRoot(
345       createViewBuilder(PORTFOLIO)
346         // Project view in the View is linked to the first project2
347         .addChildren(createProjectView1Builder(project2, null).build())
348         .build());
349
350     underTest.execute();
351
352     // commit functional transaction -> copies B-fields to A-fields
353     dbClient.componentDao().applyBChangesForRootComponentUuid(dbTester.getSession(), view.uuid());
354     dbTester.commit();
355
356     ComponentDto pv1Dto = getComponentFromDb(PROJECT_VIEW_1_KEY);
357     // Project view should now be linked to project2
358     assertDtoIsProjectView1(pv1Dto, view, view, project2);
359   }
360
361   @Test
362   public void update_copy_component_uuid_of_sub_view() {
363     OrganizationDto organizationDto = dbTester.organizations().insert();
364     ComponentDto view = newViewDto(organizationDto);
365     ComponentDto subView = newSubViewDto(view).setCopyComponentUuid("OLD_COPY");
366     persistComponents(view, subView);
367
368     treeRootHolder.setRoot(
369       createViewBuilder(PORTFOLIO)
370         .addChildren(
371           createSubView1Builder("NEW_COPY").build())
372         .build());
373
374     underTest.execute();
375
376     // commit functional transaction -> copies B-fields to A-fields
377     dbClient.componentDao().applyBChangesForRootComponentUuid(dbTester.getSession(), view.uuid());
378     dbTester.commit();
379
380     ComponentDto subViewReloaded = getComponentFromDb(SUBVIEW_1_KEY);
381     assertThat(subViewReloaded.getCopyResourceUuid()).isEqualTo("NEW_COPY");
382   }
383
384   @Test
385   public void persists_new_components_as_public_if_root_does_not_exist_yet_out_of_functional_transaction() {
386     ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
387     treeRootHolder.setRoot(
388       createViewBuilder(PORTFOLIO)
389         .addChildren(
390           createSubView1Builder(null)
391             .addChildren(
392               createProjectView1Builder(project, null).build())
393             .build())
394         .build());
395
396     underTest.execute();
397
398     Stream.of(VIEW_UUID, SUBVIEW_1_UUID, PROJECT_VIEW_1_UUID)
399       .forEach(uuid -> assertThat(dbClient.componentDao().selectByUuid(dbTester.getSession(), uuid).get().isPrivate()).isFalse());
400   }
401
402   @Test
403   public void persists_new_components_with_visibility_of_root_in_db_out_of_functional_transaction() {
404     boolean isRootPrivate = new Random().nextBoolean();
405     ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
406     OrganizationDto organization = dbTester.organizations().insert();
407     ComponentDto view = newViewDto(organization).setUuid(VIEW_UUID).setDbKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate);
408     dbTester.components().insertComponent(view);
409     treeRootHolder.setRoot(
410       createViewBuilder(PORTFOLIO)
411         .addChildren(
412           createSubView1Builder(null)
413             .addChildren(
414               createProjectView1Builder(project, null).build())
415             .build())
416         .build());
417
418     underTest.execute();
419
420     Stream.of(VIEW_UUID, SUBVIEW_1_UUID, PROJECT_VIEW_1_UUID)
421       .forEach(uuid -> assertThat(dbClient.componentDao().selectByUuid(dbTester.getSession(), uuid).get().isPrivate())
422         .describedAs("for uuid " + uuid)
423         .isEqualTo(isRootPrivate));
424   }
425
426   @Test
427   public void persists_existing_components_with_visibility_of_root_in_db_out_of_functional_transaction() {
428     boolean isRootPrivate = new Random().nextBoolean();
429     ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
430     OrganizationDto organization = dbTester.organizations().insert();
431     ComponentDto view = newViewDto(organization).setUuid(VIEW_UUID).setDbKey(VIEW_KEY).setName("View").setPrivate(isRootPrivate);
432     dbTester.components().insertComponent(view);
433     ComponentDto subView = newSubView(view).setUuid("BCDE").setDbKey("MODULE").setPrivate(!isRootPrivate);
434     dbTester.components().insertComponent(subView);
435     dbTester.components().insertComponent(newProjectCopy("DEFG", project, view).setDbKey("DIR").setPrivate(isRootPrivate));
436     treeRootHolder.setRoot(
437       createViewBuilder(PORTFOLIO)
438         .addChildren(
439           createSubView1Builder(null)
440             .addChildren(
441               createProjectView1Builder(project, null).build())
442             .build())
443         .build());
444
445     underTest.execute();
446
447     Stream.of(VIEW_UUID, SUBVIEW_1_UUID, PROJECT_VIEW_1_UUID, subView.uuid(), "DEFG")
448       .forEach(uuid -> assertThat(dbClient.componentDao().selectByUuid(dbTester.getSession(), uuid).get().isPrivate())
449         .describedAs("for uuid " + uuid)
450         .isEqualTo(isRootPrivate));
451   }
452
453   private static ViewsComponent.Builder createViewBuilder(ViewAttributes.Type viewType) {
454     return builder(VIEW, VIEW_KEY)
455       .setUuid(VIEW_UUID)
456       .setName(VIEW_NAME)
457       .setDescription(VIEW_DESCRIPTION)
458       .setViewAttributes(new ViewAttributes(viewType));
459   }
460
461   private ViewsComponent.Builder createSubView1Builder(@Nullable String originalViewUuid) {
462     return builder(SUBVIEW, SUBVIEW_1_KEY)
463       .setUuid(SUBVIEW_1_UUID)
464       .setName(SUBVIEW_1_NAME)
465       .setDescription(SUBVIEW_1_DESCRIPTION)
466       .setSubViewAttributes(new SubViewAttributes(originalViewUuid));
467   }
468
469   private static ViewsComponent.Builder createProjectView1Builder(ComponentDto project, Long analysisDate) {
470     return builder(PROJECT_VIEW, PROJECT_VIEW_1_KEY)
471       .setUuid(PROJECT_VIEW_1_UUID)
472       .setName(PROJECT_VIEW_1_NAME)
473       .setDescription("project view description is not persisted")
474       .setProjectViewAttributes(new ProjectViewAttributes(project.uuid(), analysisDate));
475   }
476
477   private void persistComponents(ComponentDto... componentDtos) {
478     componentDbTester.insertComponents(componentDtos);
479   }
480
481   private ComponentDto getComponentFromDb(String componentKey) {
482     return dbClient.componentDao().selectByKey(dbTester.getSession(), componentKey).get();
483   }
484
485   private void assertRowsCountInTableProjects(int rowCount) {
486     assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(rowCount);
487   }
488
489   private void assertDtoNotUpdated(String componentKey) {
490     assertThat(getComponentFromDb(componentKey).getCreatedAt()).isNotEqualTo(now);
491   }
492
493   private ComponentDto newViewDto(OrganizationDto organizationDto) {
494     return ComponentTesting.newView(organizationDto, VIEW_UUID)
495       .setOrganizationUuid(ORGANIZATION_UUID)
496       .setDbKey(VIEW_KEY)
497       .setName(VIEW_NAME);
498   }
499
500   private ComponentDto newSubViewDto(ComponentDto rootView) {
501     return ComponentTesting.newSubView(rootView, SUBVIEW_1_UUID, SUBVIEW_1_KEY)
502       .setName(SUBVIEW_1_NAME);
503   }
504
505   /**
506    * Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()}
507    */
508   private void assertDtoIsView(ComponentDto dto) {
509     assertThat(dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
510     assertThat(dto.name()).isEqualTo(VIEW_NAME);
511     assertThat(dto.longName()).isEqualTo(VIEW_NAME);
512     assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION);
513     assertThat(dto.path()).isNull();
514     assertThat(dto.uuid()).isEqualTo(VIEW_UUID);
515     assertThat(dto.projectUuid()).isEqualTo(VIEW_UUID);
516     assertThat(dto.getRootUuid()).isEqualTo(VIEW_UUID);
517     assertThat(dto.moduleUuid()).isNull();
518     assertThat(dto.moduleUuidPath()).isEqualTo("." + dto.uuid() + ".");
519     assertThat(dto.qualifier()).isEqualTo(Qualifiers.VIEW);
520     assertThat(dto.scope()).isEqualTo(Scopes.PROJECT);
521     assertThat(dto.getCopyResourceUuid()).isNull();
522     assertThat(dto.getCreatedAt()).isEqualTo(now);
523   }
524
525   /**
526    * Assertions to verify the DTO created from {@link #createViewBuilder(ViewAttributes.Type)} ()}
527    */
528   private void assertDtoIsApplication(ComponentDto dto) {
529     assertThat(dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
530     assertThat(dto.name()).isEqualTo(VIEW_NAME);
531     assertThat(dto.longName()).isEqualTo(VIEW_NAME);
532     assertThat(dto.description()).isEqualTo(VIEW_DESCRIPTION);
533     assertThat(dto.path()).isNull();
534     assertThat(dto.uuid()).isEqualTo(VIEW_UUID);
535     assertThat(dto.projectUuid()).isEqualTo(VIEW_UUID);
536     assertThat(dto.getRootUuid()).isEqualTo(VIEW_UUID);
537     assertThat(dto.moduleUuid()).isNull();
538     assertThat(dto.moduleUuidPath()).isEqualTo("." + dto.uuid() + ".");
539     assertThat(dto.qualifier()).isEqualTo(Qualifiers.APP);
540     assertThat(dto.scope()).isEqualTo(Scopes.PROJECT);
541     assertThat(dto.getCopyResourceUuid()).isNull();
542     assertThat(dto.getCreatedAt()).isEqualTo(now);
543   }
544
545   /**
546    * Assertions to verify the DTO created from {@link #createProjectView1Builder(ComponentDto, Long)}
547    */
548   private void assertDtoIsSubView1(ComponentDto viewDto, ComponentDto sv1Dto) {
549     assertThat(sv1Dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
550     assertThat(sv1Dto.name()).isEqualTo(SUBVIEW_1_NAME);
551     assertThat(sv1Dto.longName()).isEqualTo(SUBVIEW_1_NAME);
552     assertThat(sv1Dto.description()).isEqualTo(SUBVIEW_1_DESCRIPTION);
553     assertThat(sv1Dto.path()).isNull();
554     assertThat(sv1Dto.uuid()).isEqualTo(SUBVIEW_1_UUID);
555     assertThat(sv1Dto.projectUuid()).isEqualTo(viewDto.uuid());
556     assertThat(sv1Dto.getRootUuid()).isEqualTo(viewDto.uuid());
557     assertThat(sv1Dto.moduleUuid()).isEqualTo(viewDto.uuid());
558     assertThat(sv1Dto.moduleUuidPath()).isEqualTo(viewDto.moduleUuidPath() + sv1Dto.uuid() + ".");
559     assertThat(sv1Dto.qualifier()).isEqualTo(Qualifiers.SUBVIEW);
560     assertThat(sv1Dto.scope()).isEqualTo(Scopes.PROJECT);
561     assertThat(sv1Dto.getCopyResourceUuid()).isNull();
562     assertThat(sv1Dto.getCreatedAt()).isEqualTo(now);
563   }
564
565   private void assertDtoIsProjectView1(ComponentDto pv1Dto, ComponentDto viewDto, ComponentDto parentViewDto, ComponentDto project) {
566     assertThat(pv1Dto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
567     assertThat(pv1Dto.name()).isEqualTo(PROJECT_VIEW_1_NAME);
568     assertThat(pv1Dto.longName()).isEqualTo(PROJECT_VIEW_1_NAME);
569     assertThat(pv1Dto.description()).isNull();
570     assertThat(pv1Dto.path()).isNull();
571     assertThat(pv1Dto.uuid()).isEqualTo(PROJECT_VIEW_1_UUID);
572     assertThat(pv1Dto.projectUuid()).isEqualTo(viewDto.uuid());
573     assertThat(pv1Dto.getRootUuid()).isEqualTo(viewDto.uuid());
574     assertThat(pv1Dto.moduleUuid()).isEqualTo(parentViewDto.uuid());
575     assertThat(pv1Dto.moduleUuidPath()).isEqualTo(parentViewDto.moduleUuidPath() + pv1Dto.uuid() + ".");
576     assertThat(pv1Dto.qualifier()).isEqualTo(Qualifiers.PROJECT);
577     assertThat(pv1Dto.scope()).isEqualTo(Scopes.FILE);
578     assertThat(pv1Dto.getCopyResourceUuid()).isEqualTo(project.uuid());
579     assertThat(pv1Dto.getCreatedAt()).isEqualTo(now);
580   }
581
582 }