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

How to use
MeasureDbTester
in
org.sonar.db.measure

Best Java code snippets using org.sonar.db.measure.MeasureDbTester (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 return_measures() {
 ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
 userSession.addProjectPermission(UserRole.USER, project);
 MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
 db.measures().insertLiveMeasure(project, coverage, m -> m.setValue(15.5d));
 SearchWsResponse result = call(singletonList(project.getDbKey()), singletonList(coverage.getKey()));
 List<Measure> measures = result.getMeasuresList();
 assertThat(measures).hasSize(1);
 Measure measure = measures.get(0);
 assertThat(measure.getMetric()).isEqualTo(coverage.getKey());
 assertThat(measure.getValue()).isEqualTo("15.5");
}
origin: SonarSource/sonarqube

@Test
public void delete_by_metric_id() {
 UserDto user = db.users().insertUser();
 ComponentDto project = db.components().insertPrivateProject();
 MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true));
 CustomMeasureDto measure = db.measures().insertCustomMeasure(user, project, metric);
 underTest.deleteByMetricIds(session, singletonList(measure.getMetricId()));
 assertThat(underTest.selectById(session, measure.getId())).isNull();
}
origin: SonarSource/sonarqube

@Test
public void fail_if_more_than_100_project_keys() {
 List<String> keys = IntStream.rangeClosed(1, 101)
  .mapToObj(i -> db.components().insertPrivateProject())
  .map(ComponentDto::getDbKey)
  .collect(Collectors.toList());
 MetricDto metric = db.measures().insertMetric();
 expectedException.expect(IllegalArgumentException.class);
 expectedException.expectMessage("101 projects provided, more than maximum authorized (100)");
 call(keys, singletonList(metric.getKey()));
}
origin: SonarSource/sonarqube

private void insertMeasure(double value, ComponentDto componentDto, MetricDto metric) {
 db.measures().insertLiveMeasure(componentDto, metric, m -> m.setValue(value));
}
origin: SonarSource/sonarqube

@Test
public void branch() {
 ComponentDto project = db.components().insertPrivateProject();
 userSession.addProjectPermission(UserRole.USER, project);
 ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
 ComponentDto file = db.components().insertComponent(newFileDto(branch));
 SnapshotDto analysis = db.components().insertSnapshot(branch);
 MeasureDto measure = db.measures().insertMeasure(file, analysis, nclocMetric, m -> m.setValue(2d));
 SearchHistoryResponse result = ws.newRequest()
  .setParam(PARAM_COMPONENT, file.getKey())
  .setParam(PARAM_BRANCH, "my_branch")
  .setParam(PARAM_METRICS, "ncloc")
  .executeProtobuf(SearchHistoryResponse.class);
 assertThat(result.getMeasuresList()).extracting(HistoryMeasure::getMetric).hasSize(1);
 HistoryMeasure historyMeasure = result.getMeasures(0);
 assertThat(historyMeasure.getMetric()).isEqualTo(nclocMetric.getKey());
 assertThat(historyMeasure.getHistoryList())
  .extracting(m -> parseDouble(m.getValue()))
  .containsExactlyInAnyOrder(measure.getValue());
}
origin: SonarSource/sonarqube

@Test
public void selectOrganizationsWithNcloc_with_not_existing_uuid() {
 MetricDto ncloc = db.measures().insertMetric(m -> m.setKey(CoreMetrics.NCLOC_KEY));
 OrganizationDto org1 = db.organizations().insert();
 assertThat(underTest.selectOrganizationsWithNcloc(dbSession, Lists.newArrayList("xxxx")))
  .isEmpty();
}
origin: SonarSource/sonarqube

private ComponentDto insertProject(OrganizationDto organizationDto, Consumer<ComponentDto> projectConsumer, Measure... measures) {
 ComponentDto project = db.components().insertPublicProject(organizationDto, projectConsumer);
 Arrays.stream(measures).forEach(m -> db.measures().insertLiveMeasure(project, m.metric, m.consumer));
 authorizationIndexerTester.allowOnlyAnyone(project);
 projectMeasuresIndexer.indexOnAnalysis(project.uuid());
 return project;
}
origin: SonarSource/sonarqube

@Test
public void pull_request() {
 ComponentDto project = db.components().insertPrivateProject();
 userSession.addProjectPermission(UserRole.USER, project);
 ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
 ComponentDto file = db.components().insertComponent(newFileDto(branch));
 SnapshotDto analysis = db.components().insertSnapshot(branch);
 MeasureDto measure = db.measures().insertMeasure(file, analysis, nclocMetric, m -> m.setValue(2d));
 SearchHistoryResponse result = ws.newRequest()
  .setParam(PARAM_COMPONENT, file.getKey())
  .setParam(PARAM_PULL_REQUEST, "pr-123")
  .setParam(PARAM_METRICS, "ncloc")
  .executeProtobuf(SearchHistoryResponse.class);
 assertThat(result.getMeasuresList()).extracting(HistoryMeasure::getMetric).hasSize(1);
 HistoryMeasure historyMeasure = result.getMeasures(0);
 assertThat(historyMeasure.getMetric()).isEqualTo(nclocMetric.getKey());
 assertThat(historyMeasure.getHistoryList())
  .extracting(m -> parseDouble(m.getValue()))
  .containsExactlyInAnyOrder(measure.getValue());
}
origin: SonarSource/sonarqube

@Test
public void return_measures_on_application() {
 OrganizationDto organization = db.organizations().insert();
 ComponentDto application = db.components().insertPrivateApplication(organization);
 userSession.addProjectPermission(UserRole.USER, application);
 MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
 db.measures().insertLiveMeasure(application, coverage, m -> m.setValue(15.5d));
 SearchWsResponse result = call(singletonList(application.getDbKey()), singletonList(coverage.getKey()));
 List<Measure> measures = result.getMeasuresList();
 assertThat(measures).hasSize(1);
 Measure measure = measures.get(0);
 assertThat(measure.getMetric()).isEqualTo(coverage.getKey());
 assertThat(measure.getValue()).isEqualTo("15.5");
}
origin: SonarSource/sonarqube

 @Test
 public void select_by_metric_key_and_text_value() {
  UserDto user = db.users().insertUser();
  ComponentDto project = db.components().insertPrivateProject();
  MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true));
  CustomMeasureDto customMeasure1 = db.measures().insertCustomMeasure(user, project, metric, m -> m.setTextValue("value"));
  CustomMeasureDto customMeasure2 = db.measures().insertCustomMeasure(user, project, metric, m -> m.setTextValue("value"));
  CustomMeasureDto customMeasure3 = db.measures().insertCustomMeasure(user, project, metric, m -> m.setTextValue("other value"));

  assertThat(underTest.selectByMetricKeyAndTextValue(session, metric.getKey(), "value"))
   .extracting(CustomMeasureDto::getId)
   .containsExactlyInAnyOrder(customMeasure1.getId(), customMeasure2.getId())
   .doesNotContain(customMeasure3.getId());

  assertThat(underTest.selectByMetricKeyAndTextValue(session, metric.getKey(), "unknown")).isEmpty();
  assertThat(underTest.selectByMetricKeyAndTextValue(session, "unknown", "value")).isEmpty();
 }
}
origin: SonarSource/sonarqube

@Test
public void insert_data() {
 byte[] data = "text_value".getBytes(StandardCharsets.UTF_8);
 MetricDto metric = db.measures().insertMetric();
 ComponentDto project = db.components().insertPrivateProject();
 ComponentDto file = db.components().insertComponent(newFileDto(project));
 LiveMeasureDto measure = newLiveMeasure(file, metric).setData(data);
 underTest.insert(db.getSession(), measure);
 LiveMeasureDto result = underTest.selectMeasure(db.getSession(), file.uuid(), metric.getKey()).orElseThrow(() -> new IllegalArgumentException("Measure not found"));
 assertThat(new String(result.getData(), StandardCharsets.UTF_8)).isEqualTo("text_value");
 assertThat(result.getDataAsString()).isEqualTo("text_value");
}
origin: SonarSource/sonarqube

@Test
public void event_contains_no_previousStatus_if_measure_exists_and_has_no_value() {
 markProjectAsAnalyzed(project);
 db.measures().insertLiveMeasure(project, alertStatusMetric, m -> m.setData((String) null));
 List<QGChangeEvent> result = run(file1);
 assertThat(result)
  .extracting(QGChangeEvent::getPreviousStatus)
  .containsExactly(Optional.empty());
}
origin: SonarSource/sonarqube

@Test
public void do_not_verify_permissions_if_user_is_root() {
 MetricDto metric = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
 ComponentDto project1 = db.components().insertPrivateProject(db.getDefaultOrganization());
 db.measures().insertLiveMeasure(project1, metric, m -> m.setValue(15.5d));
 userSession.setNonRoot();
 SearchWsResponse result = call(singletonList(project1.getDbKey()), singletonList(metric.getKey()));
 assertThat(result.getMeasuresCount()).isEqualTo(0);
 userSession.setRoot();
 result = call(singletonList(project1.getDbKey()), singletonList(metric.getKey()));
 assertThat(result.getMeasuresCount()).isEqualTo(1);
}
origin: SonarSource/sonarqube

@Test
public void update() {
 UserDto user = db.users().insertUser();
 ComponentDto project = db.components().insertPrivateProject();
 MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true));
 CustomMeasureDto measure = db.measures().insertCustomMeasure(user, project, metric, m -> m.setDescription("old-description"));
 underTest.update(session, measure.setDescription("new-description"));
 assertThat(underTest.selectById(session, measure.getId()).getDescription()).isEqualTo("new-description");
}
origin: SonarSource/sonarqube

@Test
public void provided_project() {
 ComponentDto project = db.components().insertPrivateProject();
 userSession.addProjectPermission(UserRole.USER, project);
 MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT"));
 ComponentWsResponse response = newRequest(project.getKey(), metric.getKey());
 assertThat(response.getMetrics().getMetricsCount()).isEqualTo(1);
 assertThat(response.getPeriods().getPeriodsCount()).isEqualTo(0);
 assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey());
}
origin: SonarSource/sonarqube

@Test
public void event_contains_no_previousStatus_if_measure_exists_and_is_empty() {
 markProjectAsAnalyzed(project);
 db.measures().insertLiveMeasure(project, alertStatusMetric, m -> m.setData(""));
 List<QGChangeEvent> result = run(file1);
 assertThat(result)
  .extracting(QGChangeEvent::getPreviousStatus)
  .containsExactly(Optional.empty());
}
origin: SonarSource/sonarqube

@Test
public void return_measures_on_view() {
 OrganizationDto organization = db.organizations().insert();
 ComponentDto view = db.components().insertPrivatePortfolio(organization);
 userSession.addProjectPermission(UserRole.USER, view);
 MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
 db.measures().insertLiveMeasure(view, coverage, m -> m.setValue(15.5d));
 SearchWsResponse result = call(singletonList(view.getDbKey()), singletonList(coverage.getKey()));
 List<Measure> measures = result.getMeasuresList();
 assertThat(measures).hasSize(1);
 Measure measure = measures.get(0);
 assertThat(measure.getMetric()).isEqualTo(coverage.getKey());
 assertThat(measure.getValue()).isEqualTo("15.5");
}
origin: SonarSource/sonarqube

@Test
public void delete() {
 UserDto user = db.users().insertUser();
 ComponentDto project = db.components().insertPrivateProject();
 MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true));
 CustomMeasureDto measure = db.measures().insertCustomMeasure(user, project, metric);
 underTest.delete(session, measure.getId());
 assertThat(underTest.selectById(session, measure.getId())).isNull();
}
origin: SonarSource/sonarqube

 private MetricDto insertMetric() {
  return db.measures().insertMetric(m -> m
   .setValueType(INT.name())
   .setHidden(false)
   .setDirection(0));
 }
}
origin: SonarSource/sonarqube

@Test
public void event_contains_newQualityGate_computed_by_LiveQualityGateComputer() {
 markProjectAsAnalyzed(project);
 db.measures().insertLiveMeasure(project, alertStatusMetric, m -> m.setData(Metric.Level.ERROR.name()));
 db.measures().insertLiveMeasure(project, intMetric, m -> m.setVariation(42.0).setValue(null));
 BranchDto branch = db.getDbClient().branchDao().selectByBranchKey(db.getSession(), project.projectUuid(), "master")
  .orElseThrow(() -> new IllegalStateException("Can't find master branch"));
 List<QGChangeEvent> result = run(file1, newQualifierBasedIntLeakFormula());
 assertThat(result)
  .extracting(QGChangeEvent::getQualityGateSupplier)
  .extracting(Supplier::get)
  .containsExactly(Optional.of(newQualityGate));
 verify(qGateComputer).loadQualityGate(any(DbSession.class), eq(organization), eq(project), eq(branch));
 verify(qGateComputer).getMetricsRelatedTo(qualityGate);
 verify(qGateComputer).refreshGateStatus(eq(project), same(qualityGate), any(MeasureMatrix.class));
}
org.sonar.db.measureMeasureDbTester

Most used methods

  • insertMetric
  • insertCustomMeasure
  • insertLiveMeasure
  • <init>
  • insertMeasure

Popular in Java

  • Reactive rest calls using spring rest template
  • getContentResolver (Context)
  • setRequestProperty (URLConnection)
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • scheduleAtFixedRate (Timer)
    Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.
  • ObjectMapper (com.fasterxml.jackson.databind)
    This mapper (or, data binder, or codec) provides functionality for converting between Java objects (
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • KeyStore (java.security)
    This class represents an in-memory collection of keys and certificates. It manages two types of entr
  • Iterator (java.util)
    An iterator over a collection. Iterator takes the place of Enumeration in the Java Collections Frame
  • LinkedHashMap (java.util)
    Hash table and linked list implementation of the Map interface, with predictable iteration order. Th
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