Codota Logo
FileSourceTester.insertFileSource
Code IndexAdd Codota to your IDE (free)

How to use
insertFileSource
method
in
org.sonar.db.source.FileSourceTester

Best Java code snippets using org.sonar.db.source.FileSourceTester.insertFileSource (Showing top 18 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
LocalDateTime l =
  • Codota Iconnew LocalDateTime()
  • Codota IconLocalDateTime.now()
  • Codota IconDateTimeFormatter formatter;String text;formatter.parseLocalDateTime(text)
  • Smart code suggestions by Codota
}
origin: SonarSource/sonarqube

@Test
public void scrollLineHashes_handles_scrolling_more_than_1000_files() {
 OrganizationDto organization = dbTester.organizations().insert();
 ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPrivateProject(organization) : dbTester.components().insertPublicProject(organization);
 List<ComponentDto> files = IntStream.range(0, 1001 + new Random().nextInt(5))
  .mapToObj(i -> {
   ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
   dbTester.fileSources().insertFileSource(file);
   return file;
  })
  .collect(Collectors.toList());
 LineHashesWithKeyDtoHandler handler = new LineHashesWithKeyDtoHandler();
 underTest.scrollLineHashes(dbSession, files.stream().map(ComponentDto::uuid).collect(Collectors.toSet()), handler);
 assertThat(handler.dtos).hasSize(files.size());
 files.forEach(t -> assertThat(handler.getByUuid(t.uuid())).isPresent());
}
origin: SonarSource/sonarqube

@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));
}
origin: SonarSource/sonarqube

@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);
}
origin: SonarSource/sonarqube

private ComponentAndSource insertFileAndSource(ComponentDto parent, String qualifier) {
 ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(parent).setQualifier(qualifier));
 FileSourceDto fileSource = db.fileSources().insertFileSource(file);
 return new ComponentAndSource(file, fileSource);
}
origin: SonarSource/sonarqube

 @Test
 public void should_cache_line_hash_version_from_db() {
  ComponentDto project = db.components().insertPublicProject();
  ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project));

  db.fileSources().insertFileSource(file, dto -> dto.setLineHashesVersion(LineHashVersion.WITH_SIGNIFICANT_CODE.getDbValue()));
  Component component = ReportComponent.builder(Component.Type.FILE, 1).setKey("key").setUuid(file.uuid()).build();
  assertThat(underTest.hasLineHashesWithSignificantCode(component)).isTrue();

  assertThat(db.countRowsOfTable("file_sources")).isOne();
  db.executeUpdateSql("delete from file_sources");
  db.commit();
  assertThat(db.countRowsOfTable("file_sources")).isZero();

  // still true because it uses cache
  assertThat(underTest.hasLineHashesWithSignificantCode(component)).isTrue();
 }
}
origin: SonarSource/sonarqube

@Test
public void scrollLineHashes_scrolls_hashes_of_specific_keys() {
 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));
 FileSourceDto fileSource2 = dbTester.fileSources().insertFileSource(file2);
 ComponentDto file3 = dbTester.components().insertComponent(newFileDto(project));
 FileSourceDto fileSource3 = dbTester.fileSources().insertFileSource(file3);
 LineHashesWithKeyDtoHandler handler = scrollLineHashes(file1.uuid());
 assertThat(handler.dtos).hasSize(1);
 verifyLinesHashes(handler, file1, fileSource1);
 handler = scrollLineHashes(file2.uuid());
 assertThat(handler.dtos).hasSize(1);
 verifyLinesHashes(handler, file2, fileSource2);
 handler = scrollLineHashes(file2.uuid(), file1.uuid(), file3.uuid());
 assertThat(handler.dtos).hasSize(3);
 verifyLinesHashes(handler, file1, fileSource1);
 verifyLinesHashes(handler, file2, fileSource2);
 verifyLinesHashes(handler, file3, fileSource3);
}
origin: SonarSource/sonarqube

@Test
public void show_hashes() {
 OrganizationDto organizationDto = db.organizations().insert();
 ComponentDto project = db.components().insertPrivateProject(organizationDto);
 ComponentDto file = db.components().insertComponent(newFileDto(project));
 FileSourceDto fileSource = db.fileSources().insertFileSource(file, f -> f.setLineHashes(singletonList("ABC")));
 loginAsProjectViewer(project);
 TestRequest request = tester.newRequest().setParam("key", file.getDbKey());
 assertThat(request.execute().getInput()).isEqualTo("ABC");
}
origin: SonarSource/sonarqube

@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);
}
origin: SonarSource/sonarqube

@Test
public void hasLineHashWithSignificantCode_should_return_true() {
 ComponentDto project = db.components().insertPublicProject();
 ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project));
 db.fileSources().insertFileSource(file, dto -> dto.setLineHashesVersion(LineHashVersion.WITH_SIGNIFICANT_CODE.getDbValue()));
 Component component = ReportComponent.builder(Component.Type.FILE, 1).setKey("key").setUuid(file.uuid()).build();
 assertThat(underTest.hasLineHashesWithSignificantCode(component)).isTrue();
}
origin: SonarSource/sonarqube

@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);
}
origin: SonarSource/sonarqube

@Test
public void select_enabled_module_files_tree_from_project() {
 ComponentDto project = db.components().insertPrivateProject();
 ComponentDto module = db.components().insertComponent(newModuleDto(project));
 ComponentDto fileDirectlyOnModule = db.components().insertComponent(newFileDto(module));
 FileSourceDto fileSourceDirectlyOnModule = db.fileSources().insertFileSource(fileDirectlyOnModule);
 ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
 ComponentDto directory = db.components().insertComponent(newDirectory(subModule, "src"));
 ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory));
 FileSourceDto fileSource = db.fileSources().insertFileSource(file);
 // From root project
 assertThat(underTest.selectEnabledFilesFromProject(dbSession, project.uuid()))
  .extracting(FilePathWithHashDto::getUuid, FilePathWithHashDto::getModuleUuid, FilePathWithHashDto::getSrcHash, FilePathWithHashDto::getPath, FilePathWithHashDto::getRevision)
  .containsExactlyInAnyOrder(
   tuple(fileDirectlyOnModule.uuid(), module.uuid(), fileSourceDirectlyOnModule.getSrcHash(), fileDirectlyOnModule.path(), fileSourceDirectlyOnModule.getRevision()),
   tuple(file.uuid(), subModule.uuid(), fileSource.getSrcHash(), file.path(), fileSource.getRevision()));
 // From module
 assertThat(underTest.selectEnabledFilesFromProject(dbSession, module.uuid())).isEmpty();
 // From sub module
 assertThat(underTest.selectEnabledFilesFromProject(dbSession, subModule.uuid())).isEmpty();
 // From directory
 assertThat(underTest.selectEnabledFilesFromProject(dbSession, directory.uuid())).isEmpty();
 assertThat(underTest.selectEnabledFilesFromProject(dbSession, "unknown")).isEmpty();
}
origin: SonarSource/sonarqube

@Test
public void fail_when_using_branch_db_key() throws Exception {
 ComponentDto project = db.components().insertMainBranch();
 userSession.addProjectPermission(UserRole.CODEVIEWER, project);
 ComponentDto branch = db.components().insertProjectBranch(project);
 ComponentDto file = db.components().insertComponent(newFileDto(branch));
 db.fileSources().insertFileSource(file);
 expectedException.expect(NotFoundException.class);
 expectedException.expectMessage(format("Component key '%s' not found", file.getDbKey()));
 ws.newRequest()
  .setParam("key", file.getDbKey())
  .execute();
}
origin: SonarSource/sonarqube

assertThat(db.countSql("select count(*) from issues where resolution = 'REMOVED'")).isEqualTo(0);
db.fileSources().insertFileSource(srcFile);
FileSourceDto nonSelectedFileSource = db.fileSources().insertFileSource(nonSelectedFile);
assertThat(db.countRowsOfTable("file_sources")).isEqualTo(2);
origin: SonarSource/sonarqube

@Test
public void fail_on_unknown_branch() {
 ComponentDto project = db.components().insertMainBranch();
 userSession.addProjectPermission(UserRole.CODEVIEWER, project);
 ComponentDto branch = db.components().insertProjectBranch(project);
 ComponentDto file = db.components().insertComponent(newFileDto(branch));
 db.fileSources().insertFileSource(file);
 expectedException.expect(NotFoundException.class);
 expectedException.expectMessage(format("Component '%s' on branch 'unknown' not found", file.getKey()));
 ws.newRequest()
  .setParam("key", file.getKey())
  .setParam("branch", "unknown")
  .execute();
}
origin: SonarSource/sonarqube

@Test
public void raw_from_file() {
 ComponentDto project = db.components().insertPrivateProject();
 userSession.addProjectPermission(UserRole.CODEVIEWER, project);
 ComponentDto file = db.components().insertComponent(newFileDto(project));
 db.fileSources().insertFileSource(file, s -> s.setSourceData(
  Data.newBuilder()
   .addLines(Line.newBuilder().setLine(1).setSource("public class HelloWorld {").build())
   .addLines(Line.newBuilder().setLine(2).setSource("}").build())
   .build()));
 String result = ws.newRequest()
  .setParam("key", file.getKey())
  .execute().getInput();
 assertThat(result).isEqualTo("public class HelloWorld {\n}\n");
}
origin: SonarSource/sonarqube

@Test
public void fail_on_missing_permission() {
 OrganizationDto organizationDto = db.organizations().insert();
 ComponentDto project = db.components().insertPrivateProject(organizationDto);
 ComponentDto file = db.components().insertComponent(newFileDto(project));
 FileSourceDto fileSource = db.fileSources().insertFileSource(file);
 userSessionRule.logIn(db.users().insertUser());
 expectedException.expect(ForbiddenException.class);
 tester.newRequest().setParam("key", file.getKey()).execute();
}
origin: SonarSource/sonarqube

@Test
public void raw_from_branch_file() {
 ComponentDto project = db.components().insertMainBranch();
 userSession.addProjectPermission(UserRole.CODEVIEWER, project);
 ComponentDto branch = db.components().insertProjectBranch(project);
 ComponentDto file = db.components().insertComponent(newFileDto(branch));
 db.fileSources().insertFileSource(file, s -> s.setSourceData(
  Data.newBuilder()
   .addLines(Line.newBuilder().setLine(1).setSource("public class HelloWorld {").build())
   .addLines(Line.newBuilder().setLine(2).setSource("}").build())
   .build()));
 String result = ws.newRequest()
  .setParam("key", file.getKey())
  .setParam("branch", file.getBranch())
  .execute().getInput();
 assertThat(result).isEqualTo("public class HelloWorld {\n}\n");
}
origin: SonarSource/sonarqube

ComponentDto module = db.components().insertComponent(newModuleDto(project));
ComponentDto fileDirectlyOnModule = db.components().insertComponent(newFileDto(module));
FileSourceDto fileSourceDirectlyOnModule = db.fileSources().insertFileSource(fileDirectlyOnModule);
ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
ComponentDto directory = db.components().insertComponent(newDirectory(subModule, "src"));
ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory));
FileSourceDto fileSource = db.fileSources().insertFileSource(file);
org.sonar.db.sourceFileSourceTesterinsertFileSource

Popular methods of FileSourceTester

  • <init>
  • newRandomData

Popular in Java

  • Making http requests using okhttp
  • setScale (BigDecimal)
  • getSystemService (Context)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • BufferedInputStream (java.io)
    Wraps an existing InputStream and buffers the input. Expensive interaction with the underlying input
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • HashSet (java.util)
    This class implements the Set interface, backed by a hash table (actually a HashMap instance). It m
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now