@Test public void empty_response() { project = db.components().insertPrivateProject(); userSession.addProjectPermission(UserRole.USER, project); wsRequest .setComponent(project.getDbKey()) .setMetrics(singletonList(complexityMetric.getKey())); SearchHistoryResponse result = call(); assertThat(result.getMeasuresList()).hasSize(1); assertThat(result.getMeasures(0).getHistoryCount()).isEqualTo(0); assertThat(result.getPaging()).extracting(Paging::getPageIndex, Paging::getPageSize, Paging::getTotal) // pagination is applied to the number of analyses .containsExactly(1, 100, 0); }
@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(); }