3 * Copyright (C) 2009-2023 SonarSource SA
4 * mailto:info AT sonarsource DOT com
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.
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.
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.
20 package org.sonar.ce.task.projectanalysis.step;
22 import java.text.SimpleDateFormat;
23 import java.util.Date;
24 import java.util.Optional;
26 import java.util.function.Consumer;
27 import java.util.stream.Stream;
28 import org.junit.Before;
29 import org.junit.Rule;
30 import org.junit.Test;
31 import org.sonar.api.utils.DateUtils;
32 import org.sonar.api.utils.System2;
33 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
34 import org.sonar.ce.task.projectanalysis.analysis.TestBranch;
35 import org.sonar.ce.task.projectanalysis.component.BranchPersister;
36 import org.sonar.ce.task.projectanalysis.component.Component;
37 import org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl;
38 import org.sonar.ce.task.projectanalysis.component.FileAttributes;
39 import org.sonar.ce.task.projectanalysis.component.MutableDisabledComponentsHolder;
40 import org.sonar.ce.task.projectanalysis.component.ProjectPersister;
41 import org.sonar.ce.task.projectanalysis.component.ReportComponent;
42 import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule;
43 import org.sonar.ce.task.step.ComputationStep;
44 import org.sonar.ce.task.step.TestComputationStepContext;
45 import org.sonar.db.DbClient;
46 import org.sonar.db.DbTester;
47 import org.sonar.db.component.ComponentDto;
48 import org.sonar.db.component.ComponentTesting;
49 import org.sonar.server.project.Project;
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.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
56 import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
57 import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
58 import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
59 import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
60 import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
61 import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
62 import static org.sonar.db.component.ComponentTesting.newDirectory;
64 public class ReportPersistComponentsStepIT extends BaseStepTest {
66 private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
67 private static final String PROJECT_KEY = "PROJECT_KEY";
70 public DbTester db = DbTester.create(System2.INSTANCE);
72 public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
74 public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
76 private final System2 system2 = mock(System2.class);
77 private final DbClient dbClient = db.getDbClient();
79 private final MutableDisabledComponentsHolder disabledComponentsHolder = mock(MutableDisabledComponentsHolder.class, RETURNS_DEEP_STUBS);
80 private PersistComponentsStep underTest;
83 public void setup() throws Exception {
84 now = DATE_FORMAT.parse("2015-06-02");
85 when(system2.now()).thenReturn(now.getTime());
87 BranchPersister branchPersister = mock(BranchPersister.class);
88 ProjectPersister projectPersister = mock(ProjectPersister.class);
89 underTest = new PersistComponentsStep(dbClient, treeRootHolder, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister);
93 protected ComputationStep step() {
98 public void persist_components() {
99 ComponentDto projectDto = prepareProject();
100 Component file = builder(FILE, 4).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java")
101 .setName("src/main/java/dir/Foo.java")
102 .setShortName("Foo.java")
103 .setFileAttributes(new FileAttributes(false, "java", 1))
105 Component directory = builder(DIRECTORY, 3).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir")
106 .setName("src/main/java/dir")
110 Component treeRoot = asTreeRoot(projectDto)
111 .addChildren(directory)
113 treeRootHolder.setRoot(treeRoot);
115 underTest.execute(new TestComputationStepContext());
117 assertThat(db.countRowsOfTable("components")).isEqualTo(3);
119 ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
120 assertThat(directoryDto.name()).isEqualTo("dir");
121 assertThat(directoryDto.longName()).isEqualTo("src/main/java/dir");
122 assertThat(directoryDto.description()).isNull();
123 assertThat(directoryDto.path()).isEqualTo("src/main/java/dir");
124 assertThat(directoryDto.uuid()).isEqualTo("CDEF");
125 assertThat(directoryDto.getUuidPath()).isEqualTo(UUID_PATH_SEPARATOR + projectDto.uuid() + UUID_PATH_SEPARATOR);
126 assertThat(directoryDto.branchUuid()).isEqualTo(projectDto.uuid());
127 assertThat(directoryDto.qualifier()).isEqualTo("DIR");
128 assertThat(directoryDto.scope()).isEqualTo("DIR");
129 assertThat(directoryDto.getCreatedAt()).isEqualTo(now);
131 ComponentDto fileDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
132 assertThat(fileDto.name()).isEqualTo("Foo.java");
133 assertThat(fileDto.longName()).isEqualTo("src/main/java/dir/Foo.java");
134 assertThat(fileDto.description()).isNull();
135 assertThat(fileDto.path()).isEqualTo("src/main/java/dir/Foo.java");
136 assertThat(fileDto.language()).isEqualTo("java");
137 assertThat(fileDto.uuid()).isEqualTo("DEFG");
138 assertThat(fileDto.getUuidPath()).isEqualTo(directoryDto.getUuidPath() + directoryDto.uuid() + UUID_PATH_SEPARATOR);
139 assertThat(fileDto.branchUuid()).isEqualTo(projectDto.uuid());
140 assertThat(fileDto.qualifier()).isEqualTo("FIL");
141 assertThat(fileDto.scope()).isEqualTo("FIL");
142 assertThat(fileDto.getCreatedAt()).isEqualTo(now);
146 public void persist_components_of_existing_branch() {
147 ComponentDto branch = prepareBranch("feature/foo");
148 Component file = builder(FILE, 4).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java")
149 .setName("src/main/java/dir/Foo.java")
150 .setShortName("Foo.java")
151 .setFileAttributes(new FileAttributes(false, "java", 1))
153 Component directory = builder(DIRECTORY, 3).setUuid("CDEF")
154 .setKey("PROJECT_KEY:src/main/java/dir")
155 .setName("src/main/java/dir")
159 Component treeRoot = asTreeRoot(branch)
160 .addChildren(directory)
162 treeRootHolder.setRoot(treeRoot);
164 underTest.execute(new TestComputationStepContext());
166 // 3 in this branch plus the project
167 assertThat(db.countRowsOfTable("components")).isEqualTo(4);
169 ComponentDto directoryDto = dbClient.componentDao().selectByKeyAndBranch(db.getSession(), "PROJECT_KEY:src/main/java/dir", "feature/foo").get();
170 assertThat(directoryDto.name()).isEqualTo("dir");
171 assertThat(directoryDto.longName()).isEqualTo("src/main/java/dir");
172 assertThat(directoryDto.description()).isNull();
173 assertThat(directoryDto.path()).isEqualTo("src/main/java/dir");
174 assertThat(directoryDto.uuid()).isEqualTo("CDEF");
175 assertThat(directoryDto.getUuidPath()).isEqualTo(UUID_PATH_SEPARATOR + branch.uuid() + UUID_PATH_SEPARATOR);
176 assertThat(directoryDto.branchUuid()).isEqualTo(branch.uuid());
177 assertThat(directoryDto.qualifier()).isEqualTo("DIR");
178 assertThat(directoryDto.scope()).isEqualTo("DIR");
179 assertThat(directoryDto.getCreatedAt()).isEqualTo(now);
181 ComponentDto fileDto = dbClient.componentDao().selectByKeyAndBranch(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java", "feature/foo").get();
182 assertThat(fileDto.name()).isEqualTo("Foo.java");
183 assertThat(fileDto.longName()).isEqualTo("src/main/java/dir/Foo.java");
184 assertThat(fileDto.description()).isNull();
185 assertThat(fileDto.path()).isEqualTo("src/main/java/dir/Foo.java");
186 assertThat(fileDto.language()).isEqualTo("java");
187 assertThat(fileDto.uuid()).isEqualTo("DEFG");
188 assertThat(fileDto.getUuidPath()).isEqualTo(directoryDto.getUuidPath() + directoryDto.uuid() + UUID_PATH_SEPARATOR);
189 assertThat(fileDto.branchUuid()).isEqualTo(branch.uuid());
190 assertThat(fileDto.qualifier()).isEqualTo("FIL");
191 assertThat(fileDto.scope()).isEqualTo("FIL");
192 assertThat(fileDto.getCreatedAt()).isEqualTo(now);
196 public void persist_file_directly_attached_on_root_directory() {
197 ComponentDto projectDto = prepareProject();
198 treeRootHolder.setRoot(
199 asTreeRoot(projectDto)
201 builder(FILE, 2).setUuid("DEFG").setKey(projectDto.getKey() + ":pom.xml")
206 underTest.execute(new TestComputationStepContext());
208 assertThat(dbClient.componentDao().selectByKey(db.getSession(), projectDto.getKey() + ":/")).isNotPresent();
210 ComponentDto file = dbClient.componentDao().selectByKey(db.getSession(), projectDto.getKey() + ":pom.xml").get();
211 assertThat(file.name()).isEqualTo("pom.xml");
212 assertThat(file.path()).isEqualTo("pom.xml");
216 public void persist_unit_test() {
217 ComponentDto projectDto = prepareProject();
218 treeRootHolder.setRoot(
219 asTreeRoot(projectDto)
221 builder(DIRECTORY, 2).setUuid("CDEF").setKey(PROJECT_KEY + ":src/test/java/dir")
222 .setName("src/test/java/dir")
224 builder(FILE, 3).setUuid("DEFG").setKey(PROJECT_KEY + ":src/test/java/dir/FooTest.java")
225 .setName("src/test/java/dir/FooTest.java")
226 .setShortName("FooTest.java")
227 .setFileAttributes(new FileAttributes(true, null, 1))
232 underTest.execute(new TestComputationStepContext());
234 ComponentDto file = dbClient.componentDao().selectByKey(db.getSession(), PROJECT_KEY + ":src/test/java/dir/FooTest.java").get();
235 assertThat(file.name()).isEqualTo("FooTest.java");
236 assertThat(file.longName()).isEqualTo("src/test/java/dir/FooTest.java");
237 assertThat(file.path()).isEqualTo("src/test/java/dir/FooTest.java");
238 assertThat(file.qualifier()).isEqualTo("UTS");
239 assertThat(file.scope()).isEqualTo("FIL");
243 public void update_file_to_directory_change_scope() {
244 ComponentDto project = prepareProject();
245 ComponentDto directory = ComponentTesting.newDirectory(project, "src").setUuid("CDEF").setKey("PROJECT_KEY:src");
246 ComponentDto file = ComponentTesting.newFileDto(project, directory, "DEFG").setPath("src/foo").setName("foo")
247 .setKey("PROJECT_KEY:src/foo");
248 dbClient.componentDao().insert(db.getSession(), Set.of(directory, file), true);
249 db.getSession().commit();
251 assertThat(dbClient.componentDao().selectByKey(db.getSession(), PROJECT_KEY + ":src/foo").get().scope()).isEqualTo("FIL");
253 treeRootHolder.setRoot(
256 builder(DIRECTORY, 2).setUuid("CDEF").setKey(PROJECT_KEY + ":src")
259 builder(DIRECTORY, 3).setUuid("DEFG").setKey(PROJECT_KEY + ":src/foo")
262 builder(FILE, 4).setUuid("HIJK").setKey(PROJECT_KEY + ":src/foo/FooTest.java")
263 .setName("src/foo/FooTest.java")
264 .setShortName("FooTest.java")
265 .setFileAttributes(new FileAttributes(false, null, 1))
271 underTest.execute(new TestComputationStepContext());
273 // commit the functional transaction
274 dbClient.componentDao().applyBChangesForBranchUuid(db.getSession(), project.uuid());
277 assertThat(dbClient.componentDao().selectByKey(db.getSession(), PROJECT_KEY + ":src/foo").get().scope()).isEqualTo("DIR");
281 public void persist_only_new_components() {
282 // Project and module already exists
283 ComponentDto project = prepareProject();
284 db.getSession().commit();
286 treeRootHolder.setRoot(
287 builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey())
290 builder(DIRECTORY, 3).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir")
291 .setName("src/main/java/dir")
293 builder(FILE, 4).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java")
294 .setName("src/main/java/dir/Foo.java")
295 .setShortName("Foo.java")
300 underTest.execute(new TestComputationStepContext());
302 assertThat(db.countRowsOfTable("components")).isEqualTo(3);
304 ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getKey()).get();
305 assertThat(projectReloaded.uuid()).isEqualTo(project.uuid());
306 assertThat(projectReloaded.getUuidPath()).isEqualTo(UUID_PATH_OF_ROOT);
308 ComponentDto directory = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
309 assertThat(directory.getUuidPath()).isEqualTo(directory.getUuidPath());
310 assertThat(directory.branchUuid()).isEqualTo(project.uuid());
312 ComponentDto file = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
313 assertThat(file.getUuidPath()).isEqualTo(file.getUuidPath());
314 assertThat(file.branchUuid()).isEqualTo(project.uuid());
318 public void nothing_to_persist() {
319 ComponentDto project = prepareProject();
320 ComponentDto directory = ComponentTesting.newDirectory(project, "src/main/java/dir").setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir");
321 ComponentDto file = ComponentTesting.newFileDto(project, directory, "DEFG").setPath("src/main/java/dir/Foo.java").setName("Foo.java")
322 .setKey("PROJECT_KEY:src/main/java/dir/Foo.java");
323 dbClient.componentDao().insert(db.getSession(), Set.of(directory, file), true);
324 db.getSession().commit();
326 treeRootHolder.setRoot(
327 builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey())
330 builder(DIRECTORY, 3).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir")
331 .setName("src/main/java/dir")
333 builder(FILE, 4).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java")
334 .setName("src/main/java/dir/Foo.java")
339 underTest.execute(new TestComputationStepContext());
341 assertThat(db.countRowsOfTable("components")).isEqualTo(3);
342 assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getKey()).get().uuid()).isEqualTo(project.uuid());
343 assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get().uuid()).isEqualTo(directory.uuid());
344 assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get().uuid()).isEqualTo(file.uuid());
346 ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getKey()).get();
347 assertThat(projectReloaded.uuid()).isEqualTo(project.uuid());
348 assertThat(projectReloaded.branchUuid()).isEqualTo(project.branchUuid());
350 ComponentDto directoryReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
351 assertThat(directoryReloaded.uuid()).isEqualTo(directory.uuid());
352 assertThat(directoryReloaded.getUuidPath()).isEqualTo(directory.getUuidPath());
353 assertThat(directoryReloaded.branchUuid()).isEqualTo(directory.branchUuid());
354 assertThat(directoryReloaded.name()).isEqualTo(directory.name());
355 assertThat(directoryReloaded.path()).isEqualTo(directory.path());
357 ComponentDto fileReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
358 assertThat(fileReloaded.uuid()).isEqualTo(file.uuid());
359 assertThat(fileReloaded.getUuidPath()).isEqualTo(file.getUuidPath());
360 assertThat(fileReloaded.branchUuid()).isEqualTo(file.branchUuid());
361 assertThat(fileReloaded.name()).isEqualTo(file.name());
362 assertThat(fileReloaded.path()).isEqualTo(file.path());
366 public void do_not_update_created_at_on_existing_component() {
367 Date oldDate = DateUtils.parseDate("2015-01-01");
368 ComponentDto project = prepareProject(p -> p.setCreatedAt(oldDate));
369 db.getSession().commit();
371 treeRootHolder.setRoot(
372 builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey())
375 underTest.execute(new TestComputationStepContext());
377 Optional<ComponentDto> projectReloaded = dbClient.componentDao().selectByUuid(db.getSession(), project.uuid());
378 assertThat(projectReloaded.get().getCreatedAt()).isNotEqualTo(now);
382 public void persist_components_that_were_previously_removed() {
383 ComponentDto project = prepareProject();
384 ComponentDto removedDirectory = ComponentTesting.newDirectory(project, "src/main/java/dir")
385 .setLongName("src/main/java/dir")
388 .setKey("PROJECT_KEY:src/main/java/dir")
390 ComponentDto removedFile = ComponentTesting.newFileDto(project, removedDirectory, "DEFG")
391 .setPath("src/main/java/dir/Foo.java")
392 .setLongName("src/main/java/dir/Foo.java")
394 .setKey("PROJECT_KEY:src/main/java/dir/Foo.java")
396 dbClient.componentDao().insert(db.getSession(), Set.of(removedDirectory, removedFile), true);
397 db.getSession().commit();
399 treeRootHolder.setRoot(
400 builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey())
403 builder(DIRECTORY, 3).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir")
404 .setName("src/main/java/dir")
407 builder(FILE, 4).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java")
408 .setName("src/main/java/dir/Foo.java")
409 .setShortName("Foo.java")
414 underTest.execute(new TestComputationStepContext());
416 assertThat(db.countRowsOfTable("components")).isEqualTo(3);
417 assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getKey()).get().uuid()).isEqualTo(project.uuid());
418 assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get().uuid()).isEqualTo(removedDirectory.uuid());
419 assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get().uuid()).isEqualTo(removedFile.uuid());
420 assertExistButDisabled(removedDirectory.getKey(), removedFile.getKey());
422 // commit the functional transaction
423 dbClient.componentDao().applyBChangesForBranchUuid(db.getSession(), project.uuid());
425 ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getKey()).get();
426 assertThat(projectReloaded.uuid()).isEqualTo(project.uuid());
427 assertThat(projectReloaded.getUuidPath()).isEqualTo(project.getUuidPath());
428 assertThat(projectReloaded.branchUuid()).isEqualTo(project.branchUuid());
429 assertThat(projectReloaded.isEnabled()).isTrue();
431 ComponentDto directoryReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
432 assertThat(directoryReloaded.uuid()).isEqualTo(removedDirectory.uuid());
433 assertThat(directoryReloaded.getUuidPath()).isEqualTo(removedDirectory.getUuidPath());
434 assertThat(directoryReloaded.branchUuid()).isEqualTo(removedDirectory.branchUuid());
435 assertThat(directoryReloaded.name()).isEqualTo(removedDirectory.name());
436 assertThat(directoryReloaded.longName()).isEqualTo(removedDirectory.longName());
437 assertThat(directoryReloaded.path()).isEqualTo(removedDirectory.path());
438 assertThat(directoryReloaded.isEnabled()).isTrue();
440 ComponentDto fileReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
441 assertThat(fileReloaded.uuid()).isEqualTo(removedFile.uuid());
442 assertThat(fileReloaded.getUuidPath()).isEqualTo(removedFile.getUuidPath());
443 assertThat(fileReloaded.branchUuid()).isEqualTo(removedFile.branchUuid());
444 assertThat(fileReloaded.name()).isEqualTo(removedFile.name());
445 assertThat(fileReloaded.path()).isEqualTo(removedFile.path());
446 assertThat(fileReloaded.isEnabled()).isTrue();
449 private void assertExistButDisabled(String... keys) {
450 for (String key : keys) {
451 ComponentDto dto = dbClient.componentDao().selectByKey(db.getSession(), key).get();
452 assertThat(dto.isEnabled()).isFalse();
457 public void persists_existing_components_with_visibility_of_root_in_db_out_of_functional_transaction() {
458 ComponentDto project = prepareProject(p -> p.setPrivate(true));
459 ComponentDto dir = db.components().insertComponent(newDirectory(project, "DEFG", "Directory").setKey("DIR").setPrivate(true));
460 treeRootHolder.setRoot(createSampleProjectComponentTree(project));
462 underTest.execute(new TestComputationStepContext());
464 Stream.of(project.uuid(), dir.uuid())
465 .forEach(uuid -> assertThat(dbClient.componentDao().selectByUuid(db.getSession(), uuid).get().isPrivate())
466 .describedAs("for uuid " + uuid)
470 private ReportComponent createSampleProjectComponentTree(ComponentDto project) {
471 return createSampleProjectComponentTree(project.uuid(), project.getKey());
474 private ReportComponent createSampleProjectComponentTree(String projectUuid, String projectKey) {
475 return builder(PROJECT, 1).setUuid(projectUuid).setKey(projectKey)
478 builder(Component.Type.DIRECTORY, 3).setUuid("DEFG").setKey("DIR")
479 .setName("Directory")
481 builder(FILE, 4).setUuid("CDEF").setKey("FILE")
488 private ReportComponent.Builder asTreeRoot(ComponentDto project) {
489 return builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()).setName(project.name());
492 private ComponentDto prepareProject() {
493 return prepareProject(defaults());
496 private ComponentDto prepareProject(Consumer<ComponentDto> populators) {
497 ComponentDto dto = db.components().insertPrivateProject(populators).getMainBranchComponent();
498 analysisMetadataHolder.setProject(Project.from(dto));
499 analysisMetadataHolder.setBranch(new DefaultBranchImpl(DEFAULT_MAIN_BRANCH_NAME));
503 private ComponentDto prepareBranch(String branchName) {
504 ComponentDto projectDto = db.components().insertPublicProject().getMainBranchComponent();
505 ComponentDto branchDto = db.components().insertProjectBranch(projectDto, b -> b.setKey(branchName));
506 analysisMetadataHolder.setProject(Project.from(projectDto));
507 analysisMetadataHolder.setBranch(new TestBranch(branchName));
511 private static <T> Consumer<T> defaults() {