private Map<String, DbComponent> getDbFilesByUuid() { try (DbSession dbSession = dbClient.openSession(false)) { ImmutableList.Builder<DbComponent> builder = ImmutableList.builder(); dbClient.componentDao().scrollAllFilesForFileMove(dbSession, rootHolder.getRoot().getUuid(), resultContext -> { FileMoveRowDto row = resultContext.getResultObject(); builder.add(new DbComponent(row.getId(), row.getKey(), row.getUuid(), row.getPath(), row.getLineCount())); }); return builder.build().stream() .collect(MoreCollectors.uniqueIndex(DbComponent::getUuid)); } }
@Test public void scrollAllFilesForFileMove_has_no_effect_if_project_does_not_exist() { String nonExistingProjectUuid = randomAlphabetic(10); underTest.scrollAllFilesForFileMove(dbSession, nonExistingProjectUuid, resultContext -> fail("handler should not be called")); }
@Test public void scrollAllFilesForFileMove_scrolls_large_number_of_files_and_uts() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization); List<ComponentAndSource> files = IntStream.range(0, 300 + random.nextInt(500)) .mapToObj(i -> { String qualifier = random.nextBoolean() ? FILE : UNIT_TEST_FILE; ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project).setDbKey("f_" + i).setQualifier(qualifier)); FileSourceDto fileSource = db.fileSources().insertFileSource(file); return new ComponentAndSource(file, fileSource); }) .collect(Collectors.toList()); RecordingResultHandler resultHandler = new RecordingResultHandler(); underTest.scrollAllFilesForFileMove(dbSession, project.uuid(), resultHandler); assertThat(resultHandler.dtos).hasSize(files.size()); files.forEach(f -> verifyFileMoveRowDto(resultHandler, f)); }
@Test public void scrollAllFilesForFileMove_scrolls_unit_tests_of_project() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization); ComponentAndSource ut = insertFileAndSource(project, UNIT_TEST_FILE); RecordingResultHandler resultHandler = new RecordingResultHandler(); underTest.scrollAllFilesForFileMove(dbSession, project.uuid(), resultHandler); assertThat(resultHandler.dtos).hasSize(1); verifyFileMoveRowDto(resultHandler, ut); }
@Test public void scrollAllFilesForFileMove_has_no_effect_if_project_has_no_file() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization); underTest.scrollAllFilesForFileMove(dbSession, project.uuid(), resultContext -> fail("handler should not be called")); }
@Test @UseDataProvider("branchTypes") public void scrollAllFilesForFileMove_scrolls_files_and_unit_tests_of_branch(BranchType branchType) { OrganizationDto organization = db.organizations().insert(); ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization); ComponentDto branch = db.components().insertProjectBranch(project, t -> t.setBranchType(branchType)); ComponentAndSource file = insertFileAndSource(branch, FILE); ComponentAndSource ut = insertFileAndSource(branch, UNIT_TEST_FILE); RecordingResultHandler resultHandler = new RecordingResultHandler(); underTest.scrollAllFilesForFileMove(dbSession, branch.uuid(), resultHandler); assertThat(resultHandler.dtos).hasSize(2); verifyFileMoveRowDto(resultHandler, file); verifyFileMoveRowDto(resultHandler, ut); }
@Test public void scrollAllFilesForFileMove_ignores_files_without_source() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization); ComponentAndSource file = insertFileAndSource(project, FILE); ComponentAndSource ut = insertFileAndSource(project, UNIT_TEST_FILE); ComponentDto fileNoSource = db.components().insertComponent(ComponentTesting.newFileDto(project).setPath(null).setQualifier(FILE)); ComponentDto utNoSource = db.components().insertComponent(ComponentTesting.newFileDto(project).setPath(null).setQualifier(UNIT_TEST_FILE)); RecordingResultHandler resultHandler = new RecordingResultHandler(); underTest.scrollAllFilesForFileMove(dbSession, project.uuid(), resultHandler); assertThat(resultHandler.dtos).hasSize(2); verifyFileMoveRowDto(resultHandler, file); verifyFileMoveRowDto(resultHandler, ut); }
@Test public void scrollAllFilesForFileMove_scrolls_files_of_project() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization); ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)); ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1)); ComponentAndSource file1 = insertFileAndSource(project, FILE); ComponentAndSource file2 = insertFileAndSource(module1, FILE); ComponentAndSource file3 = insertFileAndSource(module2, FILE); RecordingResultHandler resultHandler = new RecordingResultHandler(); underTest.scrollAllFilesForFileMove(dbSession, project.uuid(), resultHandler); assertThat(resultHandler.dtos).hasSize(3); verifyFileMoveRowDto(resultHandler, file1); verifyFileMoveRowDto(resultHandler, file2); verifyFileMoveRowDto(resultHandler, file3); }
@Test public void scrollAllFilesForFileMove_ignores_non_file_and_non_ut_component_with_source() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization); db.fileSources().insertFileSource(project); ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project)); db.fileSources().insertFileSource(module); ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(module, "foo")); db.fileSources().insertFileSource(dir); ComponentAndSource file = insertFileAndSource(module, FILE); ComponentAndSource ut = insertFileAndSource(dir, UNIT_TEST_FILE); ComponentDto portfolio = random.nextBoolean() ? db.components().insertPublicPortfolio(organization) : db.components().insertPrivatePortfolio(organization); db.fileSources().insertFileSource(portfolio); ComponentDto subView = db.components().insertSubView(portfolio); db.fileSources().insertFileSource(subView); ComponentDto application = random.nextBoolean() ? db.components().insertPrivateApplication(organization) : db.components().insertPublicApplication(organization); db.fileSources().insertFileSource(application); RecordingResultHandler resultHandler = new RecordingResultHandler(); underTest.scrollAllFilesForFileMove(dbSession, project.uuid(), resultHandler); underTest.scrollAllFilesForFileMove(dbSession, portfolio.uuid(), resultHandler); underTest.scrollAllFilesForFileMove(dbSession, application.uuid(), resultHandler); assertThat(resultHandler.dtos).hasSize(2); verifyFileMoveRowDto(resultHandler, file); verifyFileMoveRowDto(resultHandler, ut); }
@Test public void scrollAllFilesForFileMove_ignores_files_with_null_path() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization); ComponentAndSource file = insertFileAndSource(project, FILE); ComponentAndSource ut = insertFileAndSource(project, UNIT_TEST_FILE); ComponentDto fileNoPath = db.components().insertComponent(ComponentTesting.newFileDto(project).setPath(null).setQualifier(FILE)); db.fileSources().insertFileSource(fileNoPath); ComponentDto utNoPath = db.components().insertComponent(ComponentTesting.newFileDto(project).setPath(null).setQualifier(UNIT_TEST_FILE)); db.fileSources().insertFileSource(utNoPath); RecordingResultHandler resultHandler = new RecordingResultHandler(); underTest.scrollAllFilesForFileMove(dbSession, project.uuid(), resultHandler); assertThat(resultHandler.dtos).hasSize(2); verifyFileMoveRowDto(resultHandler, file); verifyFileMoveRowDto(resultHandler, ut); }
private Map<String, DbComponent> getDbFilesByKey() { try (DbSession dbSession = dbClient.openSession(false)) { ImmutableList.Builder<DbComponent> builder = ImmutableList.builder(); dbClient.componentDao().scrollAllFilesForFileMove(dbSession, rootHolder.getRoot().getUuid(), resultContext -> { FileMoveRowDto row = resultContext.getResultObject(); builder.add(new DbComponent(row.getId(), row.getKey(), row.getUuid(), row.getPath(), row.getLineCount())); }); return builder.build().stream() .collect(MoreCollectors.uniqueIndex(DbComponent::getKey)); } }