private static ComponentDto newFileDto(ComponentDto moduleOrProject, @Nullable ComponentDto directory, int i) { return ComponentTesting.newFileDto(moduleOrProject, directory, "file-uuid-" + i) .setName("file-name-" + i) .setDbKey("file-key-" + i) .setPath("file-path-" + i); }
private ComponentDto newComponentDto(String uuid) { return ComponentTesting.newFileDto(project) .setDbKey("key_" + uuid) .setUuid(uuid) .setPath("path_" + uuid); }
public ComponentDto createForDirectory(Component directory, PathAwareVisitor.Path<ComponentDtoHolder> path) { ComponentDto res = createBase(directory); res.setScope(Scopes.DIRECTORY); res.setQualifier(Qualifiers.DIRECTORY); res.setName(directory.getShortName()); res.setLongName(directory.getName()); res.setPath(directory.getName()); setParentModuleProperties(res, path); return res; }
public ComponentDto createForFile(Component file, PathAwareVisitor.Path<ComponentDtoHolder> path) { ComponentDto res = createBase(file); res.setScope(Scopes.FILE); res.setQualifier(getFileQualifier(file)); res.setName(file.getShortName()); res.setLongName(file.getName()); res.setPath(file.getName()); res.setLanguage(file.getFileAttributes().getLanguageKey()); setParentModuleProperties(res, path); return res; }
private static ComponentDto newComponentWithoutSnapshotId(String name, String qualifier, String path) { return new ComponentDto() .setUuid(Uuids.createFast()) .setName(name) .setQualifier(qualifier) .setPath(path); }
@Test public void filter_by_directories() { ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto file1 = newFileDto(project, null).setPath("src/main/xoo/F1.xoo"); ComponentDto file2 = newFileDto(project, null).setPath("F2.xoo"); indexIssues( newDoc("I1", file1).setDirectoryPath("/src/main/xoo"), newDoc("I2", file2).setDirectoryPath("/")); assertThatSearchReturnsOnly(IssueQuery.builder().directories(singletonList("/src/main/xoo")), "I1"); assertThatSearchReturnsOnly(IssueQuery.builder().directories(singletonList("/")), "I2"); assertThatSearchReturnsEmpty(IssueQuery.builder().directories(singletonList("unknown"))); }
public static ComponentDto newSubView(ComponentDto viewOrSubView, String uuid, String key) { return newModuleDto(uuid, viewOrSubView) .setDbKey(key) .setName(key) .setLongName(key) .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.SUBVIEW) .setPath(null); }
public static ComponentDto newFileDto(ComponentDto module, @Nullable ComponentDto directory, String fileUuid) { String filename = "NAME_" + fileUuid; String path = directory != null ? directory.path() + "/" + filename : module.path() + "/" + filename; return newChildComponent(fileUuid, module, directory == null ? module : directory) .setDbKey(generateKey("FILE_KEY_" + fileUuid, module)) .setName(filename) .setLongName(path) .setScope(Scopes.FILE) .setQualifier(Qualifiers.FILE) .setPath(path) .setCreatedAt(new Date()) .setLanguage("xoo"); }
public static ComponentDto newDirectory(ComponentDto module, String uuid, String path) { String key = !path.equals("/") ? module.getKey() + ":" + path : module.getKey() + ":/"; return newChildComponent(uuid, module, module) .setDbKey(generateKey(key, module)) .setName(path) .setLongName(path) .setPath(path) .setScope(Scopes.DIRECTORY) .setQualifier(Qualifiers.DIRECTORY); }
@Test public void facets_on_directories() { ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto file1 = newFileDto(project, null).setPath("src/main/xoo/F1.xoo"); ComponentDto file2 = newFileDto(project, null).setPath("F2.xoo"); indexIssues( newDoc("I1", file1).setDirectoryPath("/src/main/xoo"), newDoc("I2", file2).setDirectoryPath("/")); assertThatFacetHasOnly(IssueQuery.builder(), "directories", entry("/src/main/xoo", 1L), entry("/", 1L)); }
@Test public void facets_on_directories() { ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto()); ComponentDto file1 = ComponentTesting.newFileDto(project, null).setPath("src/main/xoo/F1.xoo"); ComponentDto file2 = ComponentTesting.newFileDto(project, null).setPath("F2.xoo"); indexIssues( IssueDocTesting.newDoc("I1", file1).setDirectoryPath("/src/main/xoo").setEffort(10L), IssueDocTesting.newDoc("I2", file2).setDirectoryPath("/").setEffort(10L)); Facets facets = search("directories"); assertThat(facets.getNames()).containsOnly("directories", FACET_MODE_EFFORT); assertThat(facets.get("directories")).containsOnly(entry("/src/main/xoo", 10L), entry("/", 10L)); assertThat(facets.get(FACET_MODE_EFFORT)).containsOnly(entry("total", 20L)); }
@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 scrollLineHashes_does_not_scroll_hashes_of_component_without_path() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPrivateProject(organization) : dbTester.components().insertPublicProject(organization); ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project)); FileSourceDto fileSource1 = dbTester.fileSources().insertFileSource(file1); ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project).setPath(null)); FileSourceDto fileSource2 = dbTester.fileSources().insertFileSource(file2); LineHashesWithKeyDtoHandler handler = scrollLineHashes(file2.uuid(), file1.uuid()); assertThat(handler.dtos).hasSize(1); verifyLinesHashes(handler, file1, fileSource1); }
@Test public void execute_detects_no_move_if_content_of_file_has_no_path_in_DB() { analysisMetadataHolder.setBaseAnalysis(ANALYSIS); Component file1 = fileComponent(FILE_1_REF, null); Component file2 = fileComponent(FILE_2_REF, CONTENT1); insertFiles(key -> newComponentDto(key).setPath(null), file1.getDbKey()); insertContentOfFileInDb(file1.getDbKey(), CONTENT1); setFilesInReport(file2); TestComputationStepContext context = new TestComputationStepContext(); underTest.execute(context); assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); assertThat(scoreMatrixDumper.scoreMatrix).isNull(); assertThat(addedFileRepository.getComponents()).containsOnly(file2); verifyStatistics(context, 1, 0, 1, null); }
public static ComponentDto newProjectCopy(String uuid, ComponentDto project, ComponentDto view) { checkNotNull(project.getId(), "The project need to be persisted before creating this technical project."); return newChildComponent(uuid, view, view) .setDbKey(view.getDbKey() + project.getDbKey()) .setName(project.name()) .setLongName(project.longName()) .setCopyComponentUuid(project.uuid()) .setScope(Scopes.FILE) .setQualifier(Qualifiers.PROJECT) .setPath(null) .setLanguage(null); }
public static ComponentDto newModuleDto(String uuid, ComponentDto parentModuleOrProject) { return newChildComponent(uuid, parentModuleOrProject, parentModuleOrProject) .setModuleUuidPath(parentModuleOrProject.moduleUuidPath() + uuid + UUID_PATH_SEPARATOR) .setDbKey(generateKey("MODULE_KEY_" + uuid, parentModuleOrProject)) .setName("NAME_" + uuid) .setLongName("LONG_NAME_" + uuid) .setPath("module") .setScope(Scopes.PROJECT) .setQualifier(Qualifiers.MODULE) .setLanguage(null); }
@Test public void use_db_path_if_module_missing_in_report() { ComponentDto module = dbTester.components().insertComponent(newModuleDto(rootProjectDto).setPath("moduleAInDb")); when(reportModulesPath.get()).thenReturn(Collections.emptyMap()); ComponentDto folder = dbTester.components().insertComponent(newDirectory(module, "src")); IssueDto openIssueOnProject = dbTester.issues().insert(rule, rootProjectDto, rootProjectDto, i -> i.setStatus("OPEN").setResolution(null)); IssueDto openIssueOnModule = dbTester.issues().insert(rule, rootProjectDto, module, i -> i.setStatus("OPEN").setMessage("Issue on module").setResolution(null)); IssueDto openIssueOnDir = dbTester.issues().insert(rule, rootProjectDto, folder, i -> i.setStatus("OPEN").setMessage("Issue on dir").setResolution(null)); assertThat(underTest.loadIssues()).extracting(DefaultIssue::key, DefaultIssue::getMessage) .containsExactlyInAnyOrder( tuple(openIssueOnProject.getKey(), openIssueOnProject.getMessage()), tuple(openIssueOnModule.getKey(), "[moduleAInDb] Issue on module"), tuple(openIssueOnDir.getKey(), "[moduleAInDb/src] Issue on dir")); }
@Test public void empty_path_if_module_missing_in_report_and_db_and_for_slash_folder () { ComponentDto module = dbTester.components().insertComponent(newModuleDto(rootProjectDto).setPath(null)); when(reportModulesPath.get()).thenReturn(Collections.emptyMap()); ComponentDto folder = dbTester.components().insertComponent(newDirectory(module, "/")); IssueDto openIssueOnProject = dbTester.issues().insert(rule, rootProjectDto, rootProjectDto, i -> i.setStatus("OPEN").setResolution(null)); IssueDto openIssueOnModule = dbTester.issues().insert(rule, rootProjectDto, module, i -> i.setStatus("OPEN").setMessage("Issue on module").setResolution(null)); IssueDto openIssueOnDir = dbTester.issues().insert(rule, rootProjectDto, folder, i -> i.setStatus("OPEN").setMessage("Issue on dir").setResolution(null)); assertThat(underTest.loadIssues()).extracting(DefaultIssue::key, DefaultIssue::getMessage) .containsExactlyInAnyOrder( tuple(openIssueOnProject.getKey(), openIssueOnProject.getMessage()), tuple(openIssueOnModule.getKey(), "Issue on module"), tuple(openIssueOnDir.getKey(), "Issue on dir")); } }
@Test public void migrate_and_return_module_and_folder_issues_on_module() { ComponentDto module = dbTester.components().insertComponent(newModuleDto(rootProjectDto).setPath("moduleAInDb")); when(reportModulesPath.get()).thenReturn(ImmutableMap.of(module.getDbKey(), "moduleAInReport")); ComponentDto folder = dbTester.components().insertComponent(newDirectory(module, "src")); ComponentDto file = dbTester.components().insertComponent(newFileDto(module)); IssueDto openIssueOnProject = dbTester.issues().insert(rule, rootProjectDto, rootProjectDto, i -> i.setStatus("OPEN").setResolution(null)); IssueDto openIssueOnModule = dbTester.issues().insert(rule, rootProjectDto, module, i -> i.setStatus("OPEN").setMessage("Issue on module").setResolution(null)); IssueDto openIssueOnDir = dbTester.issues().insert(rule, rootProjectDto, folder, i -> i.setStatus("OPEN").setMessage("Issue on dir").setResolution(null)); IssueDto openIssue1OnFile = dbTester.issues().insert(rule, rootProjectDto, file, i -> i.setStatus("OPEN").setResolution(null)); assertThat(underTest.loadIssues()).extracting(DefaultIssue::key, DefaultIssue::getMessage) .containsExactlyInAnyOrder( tuple(openIssueOnProject.getKey(), openIssueOnProject.getMessage()), tuple(openIssueOnModule.getKey(), "[moduleAInReport] Issue on module"), tuple(openIssueOnDir.getKey(), "[moduleAInReport/src] Issue on dir")); }
@Test public void return_bread_crumbs_on_several_levels() { ComponentDto project = insertOrganizationAndProject(); ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setDbKey("palap").setName("Palap")); ComponentDto directory = componentDbTester.insertComponent(newDirectory(module, "src/main/xoo")); ComponentDto file = componentDbTester.insertComponent(newFileDto(directory, directory, "cdef").setName("Source.xoo") .setDbKey("palap:src/main/xoo/Source.xoo") .setPath(directory.path())); userSession.addProjectPermission(UserRole.USER, project); init(); executeAndVerify(file.getDbKey(), "return_bread_crumbs_on_several_levels.json"); }