use of org.sonarqube.ws.Components.Component in project sonarqube by SonarSource.
the class SearchProjectsActionTest method return_leak_period_date.
@Test
public void return_leak_period_date() {
when(editionProviderMock.get()).thenReturn(Optional.of(Edition.ENTERPRISE));
userSession.logIn();
ComponentDto project1 = db.components().insertPublicProject();
db.components().insertSnapshot(project1, snapshot -> snapshot.setPeriodDate(10_000_000_000L));
authorizationIndexerTester.allowOnlyAnyone(project1);
// No leak period
ComponentDto project2 = db.components().insertPublicProject();
db.components().insertSnapshot(project2, snapshot -> snapshot.setPeriodDate(null));
authorizationIndexerTester.allowOnlyAnyone(project2);
// No snapshot on project 3
ComponentDto project3 = db.components().insertPublicProject();
authorizationIndexerTester.allowOnlyAnyone(project3);
MetricDto leakProjects = db.measures().insertMetric(c -> c.setKey(LEAK_PROJECTS_KEY).setValueType(DATA.name()));
ComponentDto application1 = insertApplication(new Measure(leakProjects, c -> c.setData("{\"leakProjects\":[{\"id\": 1, \"leak\":20000000000}, {\"id\": 2, \"leak\":10000000000}]}")));
db.components().insertSnapshot(application1);
authorizationIndexerTester.allowOnlyAnyone(application1);
index();
SearchProjectsWsResponse result = call(request.setAdditionalFields(singletonList("leakPeriodDate")));
assertThat(result.getComponentsList()).extracting(Component::getKey, Component::hasLeakPeriodDate, Component::getLeakPeriodDate).containsOnly(tuple(project1.getDbKey(), true, formatDateTime(new Date(10_000_000_000L))), tuple(project2.getDbKey(), false, ""), tuple(project3.getDbKey(), false, ""), tuple(application1.getDbKey(), true, formatDateTime(new Date(10_000_000_000L))));
}
use of org.sonarqube.ws.Components.Component 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.Component 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.Component 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.Component 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());
}
Aggregations