use of org.sonarqube.ws.Components.SearchProjectsWsResponse in project sonarqube by SonarSource.
the class SearchProjectsActionTest method json_example.
@Test
public void json_example() {
userSession.logIn();
MetricDto coverage = db.measures().insertMetric(c -> c.setKey(COVERAGE).setValueType("PERCENT"));
ComponentDto project1 = insertProject(c -> c.setDbKey(KEY_PROJECT_EXAMPLE_001).setName("My Project 1"), p -> p.setTagsString("finance, java"), new Measure(coverage, c -> c.setValue(80d)));
db.components().insertProjectBranch(db.components().getProjectDto(project1), branchDto -> branchDto.setNeedIssueSync(true));
ComponentDto project2 = insertProject(c -> c.setDbKey(KEY_PROJECT_EXAMPLE_002).setName("My Project 2"), new Measure(coverage, c -> c.setValue(90d)));
ComponentDto project3 = insertProject(c -> c.setDbKey(KEY_PROJECT_EXAMPLE_003).setName("My Project 3"), p -> p.setTagsString("sales, offshore, java"), new Measure(coverage, c -> c.setValue(20d)));
addFavourite(project1);
index();
String jsonResult = ws.newRequest().setParam(FACETS, COVERAGE).setParam(FIELDS, "_all").execute().getInput();
assertJson(jsonResult).ignoreFields("id").isSimilarTo(ws.getDef().responseExampleAsString());
assertJson(ws.getDef().responseExampleAsString()).ignoreFields("id").isSimilarTo(jsonResult);
SearchProjectsWsResponse protobufResult = ws.newRequest().setParam(FACETS, COVERAGE).executeProtobuf(SearchProjectsWsResponse.class);
assertThat(protobufResult.getComponentsList()).extracting(Component::getKey).containsExactly(project1.getDbKey(), project2.getDbKey(), project3.getDbKey());
}
use of org.sonarqube.ws.Components.SearchProjectsWsResponse in project sonarqube by SonarSource.
the class SearchProjectsActionTest method paginate_result.
@Test
public void paginate_result() {
userSession.logIn();
IntStream.rangeClosed(1, 9).forEach(i -> insertProject(c -> c.setName("PROJECT-" + i)));
index();
SearchProjectsWsResponse result = call(request.setPage(2).setPageSize(3));
assertThat(result.getPaging().getPageIndex()).isEqualTo(2);
assertThat(result.getPaging().getPageSize()).isEqualTo(3);
assertThat(result.getPaging().getTotal()).isEqualTo(9);
assertThat(result.getComponentsCount()).isEqualTo(3);
assertThat(result.getComponentsList()).extracting(Component::getName).containsExactly("PROJECT-4", "PROJECT-5", "PROJECT-6");
}
use of org.sonarqube.ws.Components.SearchProjectsWsResponse in project sonarqube by SonarSource.
the class SearchProjectsActionTest method filter_projects_by_new_coverage.
@Test
public void filter_projects_by_new_coverage() {
userSession.logIn();
MetricDto coverage = db.measures().insertMetric(c -> c.setKey(NEW_COVERAGE).setValueType("PERCENT"));
ComponentDto project1 = insertProject(new Measure(coverage, c -> c.setVariation(80d)));
ComponentDto project2 = insertProject(new Measure(coverage, c -> c.setVariation(85d)));
ComponentDto project3 = insertProject(new Measure(coverage, c -> c.setVariation(10d)));
index();
SearchProjectsWsResponse result = call(request.setFilter("new_coverage <= 80"));
assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getDbKey(), project3.getDbKey());
}
use of org.sonarqube.ws.Components.SearchProjectsWsResponse in project sonarqube by SonarSource.
the class SearchProjectsActionTest method filter_projects_by_languages.
@Test
public void filter_projects_by_languages() {
userSession.logIn();
MetricDto languagesDistribution = db.measures().insertMetric(c -> c.setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY).setValueType("DATA"));
ComponentDto project1 = insertProject(new Measure(languagesDistribution, c -> c.setValue(null).setData("<null>=2;java=6;xoo=18")));
ComponentDto project2 = insertProject(new Measure(languagesDistribution, c -> c.setValue(null).setData("java=3;xoo=9")));
ComponentDto project3 = insertProject(new Measure(languagesDistribution, c -> c.setValue(null).setData("xoo=1")));
ComponentDto project4 = insertProject(new Measure(languagesDistribution, c -> c.setValue(null).setData("<null>=1;java=5;xoo=13")));
index();
SearchProjectsWsResponse result = call(request.setFilter("languages IN (java, js, <null>)"));
assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getDbKey(), project2.getDbKey(), project4.getDbKey());
}
use of org.sonarqube.ws.Components.SearchProjectsWsResponse in project sonarqube by SonarSource.
the class SearchProjectsActionTest method filter_projects_and_apps_by_TRK_qualifier_when_ee_or_dc.
@Test
@UseDataProvider("enterprise_or_datacenter_edition")
public void filter_projects_and_apps_by_TRK_qualifier_when_ee_or_dc(Edition edition) {
when(editionProviderMock.get()).thenReturn(Optional.of(edition));
userSession.logIn();
insertApplication();
insertApplication();
insertApplication();
ComponentDto project1 = insertProject();
ComponentDto project2 = insertProject();
ComponentDto project3 = insertProject();
index();
SearchProjectsWsResponse result = call(request.setFilter("qualifier = TRK"));
assertThat(result.getComponentsCount()).isEqualTo(3);
assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(Stream.of(project1, project2, project3).map(ComponentDto::getDbKey).toArray(String[]::new));
}
Aggregations