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

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

Best Java code snippets using org.sonar.db.source.FileSourceTester (Showing top 20 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

@SafeVarargs
public final FileSourceDto insertFileSource(ComponentDto file, Consumer<FileSourceDto>... dtoPopulators) {
 FileSourceDto dto = new FileSourceDto()
  .setProjectUuid(file.projectUuid())
  .setFileUuid(file.uuid())
  .setSrcHash(randomAlphanumeric(50))
  .setDataHash(randomAlphanumeric(50))
  .setLineHashes(IntStream.range(0, new Random().nextInt(21)).mapToObj(String::valueOf).collect(MoreCollectors.toList()))
  .setRevision(randomAlphanumeric(100))
  .setSourceData(newRandomData(3).build())
  .setCreatedAt(new Date().getTime())
  .setUpdatedAt(new Date().getTime());
 Arrays.stream(dtoPopulators).forEach(c -> c.accept(dto));
 db.getDbClient().fileSourceDao().insert(db.getSession(), dto);
 db.commit();
 return dto;
}
origin: SonarSource/sonarqube

private DbTester(System2 system2, @Nullable String schemaPath, MyBatisConfExtension... confExtensions) {
 super(TestDb.create(schemaPath, confExtensions));
 this.system2 = system2;
 initDbClient();
 this.userTester = new UserDbTester(this);
 this.componentTester = new ComponentDbTester(this);
 this.componentLinkTester = new ProjectLinkDbTester(this);
 this.favoriteTester = new FavoriteDbTester(this);
 this.eventTester = new EventDbTester(this);
 this.organizationTester = new OrganizationDbTester(this);
 this.permissionTemplateTester = new PermissionTemplateDbTester(this);
 this.propertyTester = new PropertyDbTester(this);
 this.qualityGateDbTester = new QualityGateDbTester(this);
 this.issueDbTester = new IssueDbTester(this);
 this.ruleDbTester = new RuleDbTester(this);
 this.notificationDbTester = new NotificationDbTester(this);
 this.rootFlagAssertions = new RootFlagAssertions(this);
 this.qualityProfileDbTester = new QualityProfileDbTester(this);
 this.measureDbTester = new MeasureDbTester(this);
 this.fileSourceTester = new FileSourceTester(this);
 this.pluginDbTester = new PluginDbTester(this);
 this.webhookDbTester = new WebhookDbTester(this);
 this.webhookDeliveryDbTester = new WebhookDeliveryDbTester(this);
 this.almDbTester = new AlmDbTester(this);
}
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 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 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 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.sourceFileSourceTester

Most used methods

  • insertFileSource
  • <init>
  • newRandomData

Popular in Java

  • Parsing JSON documents to java classes using gson
  • requestLocationUpdates (LocationManager)
  • onCreateOptionsMenu (Activity)
  • orElseThrow (Optional)
  • BufferedReader (java.io)
    Reads text from a character-input stream, buffering characters so as to provide for the efficient re
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • URLConnection (java.net)
    The abstract class URLConnection is the superclass of all classes that represent a communications li
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
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