@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()); }
@Test public void return_best_values_for_files() { dbClient.metricDao().insert(dbSession, newMetricDto().setKey("optimized").setValueType(ValueType.INT.name()).setOptimizedBestValue(true).setBestValue(456d)); dbClient.metricDao().insert(dbSession, newMetricDto().setKey("new_optimized").setValueType(ValueType.INT.name()).setOptimizedBestValue(true).setBestValue(789d)); db.commit(); ComponentDto file = db.components().insertComponent(newFileDto(project)); wsRequest.setComponent(file.getDbKey()).setMetrics(Arrays.asList("optimized", "new_optimized")); SearchHistoryResponse result = call(); assertThat(result.getMeasuresCount()).isEqualTo(2); assertThat(result.getMeasuresList().get(0).getHistoryList()).extracting(HistoryValue::getValue).containsExactly("789"); assertThat(result.getMeasuresList().get(1).getHistoryList()).extracting(HistoryValue::getValue).containsExactly("456"); // Best value is not applied to project wsRequest.setComponent(project.getDbKey()); result = call(); assertThat(result.getMeasuresList().get(0).getHistoryCount()).isEqualTo(1); assertThat(result.getMeasuresList().get(0).getHistory(0).hasDate()).isTrue(); assertThat(result.getMeasuresList().get(0).getHistory(0).hasValue()).isFalse(); }
SearchHistoryResponseFactory(SearchHistoryResult result) { this.result = result; this.measure = HistoryMeasure.newBuilder(); this.value = HistoryValue.newBuilder(); }
@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()); }
SearchHistoryResponseFactory(SearchHistoryResult result) { this.result = result; this.measure = HistoryMeasure.newBuilder(); this.value = HistoryValue.newBuilder(); }