private static Map<String, WsProjectResponse.FileData> buildFileDataByPath(SingleProjectRepository data) { return data.fileData().entrySet() .stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> toFileDataResponse(e.getValue()))); }
@Test public void add_file_data() { FileData fileData = new FileData("123", "456"); repository.addFileData("/Abc.java", fileData); assertThat(repository.fileData()).hasSize(1); assertThat(repository.fileData()).contains(Maps.immutableEntry("/Abc.java", fileData)); assertThat(repository.fileDataByPath("/Abc.java")).isEqualTo(fileData); }
@Test public void return_file_data_from_single_project() { OrganizationDto organizationDto = db.organizations().insert(); ComponentDto project = db.components().insertPrivateProject(organizationDto); userSession.logIn().addProjectPermission(SCAN_EXECUTION, project); ComponentDto file = db.components().insertComponent(newFileDto(project)); dbClient.fileSourceDao().insert(dbSession, newFileSourceDto(file).setSrcHash("123456")); db.commit(); ProjectRepositories ref = underTest.load(ProjectDataQuery.create().setProjectKey(project.getKey())); assertTrue(ref instanceof SingleProjectRepository); SingleProjectRepository singleProjectRepository = ((SingleProjectRepository) ref); assertThat(singleProjectRepository.fileData()).hasSize(1); FileData fileData = singleProjectRepository.fileDataByPath(file.path()); assertThat(fileData).isNotNull(); assertThat(fileData.hash()).isEqualTo("123456"); }
private static Map<String, WsProjectResponse.FileDataByPath> buildFileDataByModuleAndPath(MultiModuleProjectRepository data) { return data.repositoriesByModule().entrySet() .stream() .map(entry -> Maps.immutableEntry(entry.getKey(), buildFileDataByPath(entry.getValue().fileData()))) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); }
@Test public void add_file_data_doesnt_add_the_file_without_path() { FileData fileData = new FileData("123", "456"); repository.addFileData(null, fileData); assertThat(repository.fileData()).hasSize(0); }
@Test public void add_file_data_doesnt_add_the_file_without_revision_and_hash() { FileData fileData = new FileData(null, null); repository.addFileData("/Abc.java", fileData); assertThat(repository.fileData()).hasSize(0); } }