Search in sources :

Example 6 with Component

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))));
}
Also used : FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) Arrays(java.util.Arrays) PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) SORT(org.sonar.api.server.ws.WebService.Param.SORT) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DbSession(org.sonar.db.DbSession) RequestBuilder(org.sonar.server.component.ws.SearchProjectsAction.RequestBuilder) Collections.singletonList(java.util.Collections.singletonList) NEW_SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY) PAGE(org.sonar.api.server.ws.WebService.Param.PAGE) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) ProjectsInWarning(org.sonar.server.qualitygate.ProjectsInWarning) Arrays.asList(java.util.Arrays.asList) NEW_MAINTAINABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY) PARAM_FILTER(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) FILTER_LANGUAGES(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES) RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Set(java.util.Set) NEW_DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY) LEVEL(org.sonar.api.measures.Metric.ValueType.LEVEL) FILTER_QUALIFIER(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_QUALIFIER) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) NEW_RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Stream(java.util.stream.Stream) SQALE_RATING_KEY(org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY) ProjectDto(org.sonar.db.project.ProjectDto) Optional(java.util.Optional) PAGE_SIZE(org.sonar.api.server.ws.WebService.Param.PAGE_SIZE) FIELDS(org.sonar.api.server.ws.WebService.Param.FIELDS) PropertyDto(org.sonar.db.property.PropertyDto) Component(org.sonarqube.ws.Components.Component) Joiner(com.google.common.base.Joiner) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) NCLOC_LANGUAGE_DISTRIBUTION_KEY(org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY) EsTester(org.sonar.server.es.EsTester) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) ProjectMeasuresIndexer(org.sonar.server.measure.index.ProjectMeasuresIndexer) HashSet(java.util.HashSet) ProjectMeasuresIndex(org.sonar.server.measure.index.ProjectMeasuresIndex) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchProjectsRequest(org.sonar.server.component.ws.SearchProjectsAction.SearchProjectsRequest) DATA(org.sonar.api.measures.Metric.ValueType.DATA) Nullable(javax.annotation.Nullable) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY) NEW_LINES_KEY(org.sonar.api.measures.CoreMetrics.NEW_LINES_KEY) Assertions.tuple(org.assertj.core.api.Assertions.tuple) PlatformEditionProvider(org.sonar.core.platform.PlatformEditionProvider) Optional.ofNullable(java.util.Optional.ofNullable) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY_KEY) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) Qualifiers(org.sonar.api.resources.Qualifiers) Edition(org.sonar.core.platform.EditionProvider.Edition) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) INT(org.sonar.api.measures.Metric.ValueType.INT) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) ASCENDING(org.sonar.api.server.ws.WebService.Param.ASCENDING) KEY_PROJECT_EXAMPLE_002(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_002) KEY_PROJECT_EXAMPLE_001(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001) KEY_PROJECT_EXAMPLE_003(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_003) FILTER_TAGS(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS) Metric(org.sonar.api.measures.Metric) MetricDto(org.sonar.db.metric.MetricDto) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Date(java.util.Date) Test(org.junit.Test)

Example 7 with Component

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());
}
Also used : FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) Arrays(java.util.Arrays) PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) SORT(org.sonar.api.server.ws.WebService.Param.SORT) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DbSession(org.sonar.db.DbSession) RequestBuilder(org.sonar.server.component.ws.SearchProjectsAction.RequestBuilder) Collections.singletonList(java.util.Collections.singletonList) NEW_SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY) PAGE(org.sonar.api.server.ws.WebService.Param.PAGE) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) ProjectsInWarning(org.sonar.server.qualitygate.ProjectsInWarning) Arrays.asList(java.util.Arrays.asList) NEW_MAINTAINABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY) PARAM_FILTER(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) FILTER_LANGUAGES(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES) RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Set(java.util.Set) NEW_DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY) LEVEL(org.sonar.api.measures.Metric.ValueType.LEVEL) FILTER_QUALIFIER(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_QUALIFIER) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) NEW_RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Stream(java.util.stream.Stream) SQALE_RATING_KEY(org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY) ProjectDto(org.sonar.db.project.ProjectDto) Optional(java.util.Optional) PAGE_SIZE(org.sonar.api.server.ws.WebService.Param.PAGE_SIZE) FIELDS(org.sonar.api.server.ws.WebService.Param.FIELDS) PropertyDto(org.sonar.db.property.PropertyDto) Component(org.sonarqube.ws.Components.Component) Joiner(com.google.common.base.Joiner) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) NCLOC_LANGUAGE_DISTRIBUTION_KEY(org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY) EsTester(org.sonar.server.es.EsTester) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) ProjectMeasuresIndexer(org.sonar.server.measure.index.ProjectMeasuresIndexer) HashSet(java.util.HashSet) ProjectMeasuresIndex(org.sonar.server.measure.index.ProjectMeasuresIndex) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchProjectsRequest(org.sonar.server.component.ws.SearchProjectsAction.SearchProjectsRequest) DATA(org.sonar.api.measures.Metric.ValueType.DATA) Nullable(javax.annotation.Nullable) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY) NEW_LINES_KEY(org.sonar.api.measures.CoreMetrics.NEW_LINES_KEY) Assertions.tuple(org.assertj.core.api.Assertions.tuple) PlatformEditionProvider(org.sonar.core.platform.PlatformEditionProvider) Optional.ofNullable(java.util.Optional.ofNullable) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY_KEY) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) Qualifiers(org.sonar.api.resources.Qualifiers) Edition(org.sonar.core.platform.EditionProvider.Edition) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) INT(org.sonar.api.measures.Metric.ValueType.INT) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) ASCENDING(org.sonar.api.server.ws.WebService.Param.ASCENDING) KEY_PROJECT_EXAMPLE_002(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_002) KEY_PROJECT_EXAMPLE_001(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001) KEY_PROJECT_EXAMPLE_003(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_003) FILTER_TAGS(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS) Metric(org.sonar.api.measures.Metric) MetricDto(org.sonar.db.metric.MetricDto) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 8 with Component

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");
}
Also used : FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) Arrays(java.util.Arrays) PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) SORT(org.sonar.api.server.ws.WebService.Param.SORT) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DbSession(org.sonar.db.DbSession) RequestBuilder(org.sonar.server.component.ws.SearchProjectsAction.RequestBuilder) Collections.singletonList(java.util.Collections.singletonList) NEW_SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY) PAGE(org.sonar.api.server.ws.WebService.Param.PAGE) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) ProjectsInWarning(org.sonar.server.qualitygate.ProjectsInWarning) Arrays.asList(java.util.Arrays.asList) NEW_MAINTAINABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY) PARAM_FILTER(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) FILTER_LANGUAGES(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES) RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Set(java.util.Set) NEW_DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY) LEVEL(org.sonar.api.measures.Metric.ValueType.LEVEL) FILTER_QUALIFIER(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_QUALIFIER) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) NEW_RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Stream(java.util.stream.Stream) SQALE_RATING_KEY(org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY) ProjectDto(org.sonar.db.project.ProjectDto) Optional(java.util.Optional) PAGE_SIZE(org.sonar.api.server.ws.WebService.Param.PAGE_SIZE) FIELDS(org.sonar.api.server.ws.WebService.Param.FIELDS) PropertyDto(org.sonar.db.property.PropertyDto) Component(org.sonarqube.ws.Components.Component) Joiner(com.google.common.base.Joiner) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) NCLOC_LANGUAGE_DISTRIBUTION_KEY(org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY) EsTester(org.sonar.server.es.EsTester) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) ProjectMeasuresIndexer(org.sonar.server.measure.index.ProjectMeasuresIndexer) HashSet(java.util.HashSet) ProjectMeasuresIndex(org.sonar.server.measure.index.ProjectMeasuresIndex) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchProjectsRequest(org.sonar.server.component.ws.SearchProjectsAction.SearchProjectsRequest) DATA(org.sonar.api.measures.Metric.ValueType.DATA) Nullable(javax.annotation.Nullable) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY) NEW_LINES_KEY(org.sonar.api.measures.CoreMetrics.NEW_LINES_KEY) Assertions.tuple(org.assertj.core.api.Assertions.tuple) PlatformEditionProvider(org.sonar.core.platform.PlatformEditionProvider) Optional.ofNullable(java.util.Optional.ofNullable) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY_KEY) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) Qualifiers(org.sonar.api.resources.Qualifiers) Edition(org.sonar.core.platform.EditionProvider.Edition) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) INT(org.sonar.api.measures.Metric.ValueType.INT) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) ASCENDING(org.sonar.api.server.ws.WebService.Param.ASCENDING) KEY_PROJECT_EXAMPLE_002(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_002) KEY_PROJECT_EXAMPLE_001(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001) KEY_PROJECT_EXAMPLE_003(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_003) FILTER_TAGS(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS) Metric(org.sonar.api.measures.Metric) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) Test(org.junit.Test)

Example 9 with Component

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());
}
Also used : FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) Arrays(java.util.Arrays) PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) SORT(org.sonar.api.server.ws.WebService.Param.SORT) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DbSession(org.sonar.db.DbSession) RequestBuilder(org.sonar.server.component.ws.SearchProjectsAction.RequestBuilder) Collections.singletonList(java.util.Collections.singletonList) NEW_SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY) PAGE(org.sonar.api.server.ws.WebService.Param.PAGE) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) ProjectsInWarning(org.sonar.server.qualitygate.ProjectsInWarning) Arrays.asList(java.util.Arrays.asList) NEW_MAINTAINABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY) PARAM_FILTER(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) FILTER_LANGUAGES(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES) RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Set(java.util.Set) NEW_DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY) LEVEL(org.sonar.api.measures.Metric.ValueType.LEVEL) FILTER_QUALIFIER(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_QUALIFIER) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) NEW_RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Stream(java.util.stream.Stream) SQALE_RATING_KEY(org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY) ProjectDto(org.sonar.db.project.ProjectDto) Optional(java.util.Optional) PAGE_SIZE(org.sonar.api.server.ws.WebService.Param.PAGE_SIZE) FIELDS(org.sonar.api.server.ws.WebService.Param.FIELDS) PropertyDto(org.sonar.db.property.PropertyDto) Component(org.sonarqube.ws.Components.Component) Joiner(com.google.common.base.Joiner) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) NCLOC_LANGUAGE_DISTRIBUTION_KEY(org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY) EsTester(org.sonar.server.es.EsTester) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) ProjectMeasuresIndexer(org.sonar.server.measure.index.ProjectMeasuresIndexer) HashSet(java.util.HashSet) ProjectMeasuresIndex(org.sonar.server.measure.index.ProjectMeasuresIndex) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchProjectsRequest(org.sonar.server.component.ws.SearchProjectsAction.SearchProjectsRequest) DATA(org.sonar.api.measures.Metric.ValueType.DATA) Nullable(javax.annotation.Nullable) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY) NEW_LINES_KEY(org.sonar.api.measures.CoreMetrics.NEW_LINES_KEY) Assertions.tuple(org.assertj.core.api.Assertions.tuple) PlatformEditionProvider(org.sonar.core.platform.PlatformEditionProvider) Optional.ofNullable(java.util.Optional.ofNullable) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY_KEY) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) Qualifiers(org.sonar.api.resources.Qualifiers) Edition(org.sonar.core.platform.EditionProvider.Edition) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) INT(org.sonar.api.measures.Metric.ValueType.INT) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) ASCENDING(org.sonar.api.server.ws.WebService.Param.ASCENDING) KEY_PROJECT_EXAMPLE_002(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_002) KEY_PROJECT_EXAMPLE_001(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001) KEY_PROJECT_EXAMPLE_003(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_003) FILTER_TAGS(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS) Metric(org.sonar.api.measures.Metric) MetricDto(org.sonar.db.metric.MetricDto) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 10 with Component

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());
}
Also used : FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) Arrays(java.util.Arrays) PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) SORT(org.sonar.api.server.ws.WebService.Param.SORT) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DbSession(org.sonar.db.DbSession) RequestBuilder(org.sonar.server.component.ws.SearchProjectsAction.RequestBuilder) Collections.singletonList(java.util.Collections.singletonList) NEW_SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY) PAGE(org.sonar.api.server.ws.WebService.Param.PAGE) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) ProjectsInWarning(org.sonar.server.qualitygate.ProjectsInWarning) Arrays.asList(java.util.Arrays.asList) NEW_MAINTAINABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY) PARAM_FILTER(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) FILTER_LANGUAGES(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES) RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Set(java.util.Set) NEW_DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY) LEVEL(org.sonar.api.measures.Metric.ValueType.LEVEL) FILTER_QUALIFIER(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_QUALIFIER) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) NEW_RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Stream(java.util.stream.Stream) SQALE_RATING_KEY(org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY) ProjectDto(org.sonar.db.project.ProjectDto) Optional(java.util.Optional) PAGE_SIZE(org.sonar.api.server.ws.WebService.Param.PAGE_SIZE) FIELDS(org.sonar.api.server.ws.WebService.Param.FIELDS) PropertyDto(org.sonar.db.property.PropertyDto) Component(org.sonarqube.ws.Components.Component) Joiner(com.google.common.base.Joiner) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) NCLOC_LANGUAGE_DISTRIBUTION_KEY(org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY) EsTester(org.sonar.server.es.EsTester) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) ProjectMeasuresIndexer(org.sonar.server.measure.index.ProjectMeasuresIndexer) HashSet(java.util.HashSet) ProjectMeasuresIndex(org.sonar.server.measure.index.ProjectMeasuresIndex) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchProjectsRequest(org.sonar.server.component.ws.SearchProjectsAction.SearchProjectsRequest) DATA(org.sonar.api.measures.Metric.ValueType.DATA) Nullable(javax.annotation.Nullable) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY) NEW_LINES_KEY(org.sonar.api.measures.CoreMetrics.NEW_LINES_KEY) Assertions.tuple(org.assertj.core.api.Assertions.tuple) PlatformEditionProvider(org.sonar.core.platform.PlatformEditionProvider) Optional.ofNullable(java.util.Optional.ofNullable) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY_KEY) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) Qualifiers(org.sonar.api.resources.Qualifiers) Edition(org.sonar.core.platform.EditionProvider.Edition) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) INT(org.sonar.api.measures.Metric.ValueType.INT) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) ASCENDING(org.sonar.api.server.ws.WebService.Param.ASCENDING) KEY_PROJECT_EXAMPLE_002(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_002) KEY_PROJECT_EXAMPLE_001(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001) KEY_PROJECT_EXAMPLE_003(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_003) FILTER_TAGS(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS) Metric(org.sonar.api.measures.Metric) MetricDto(org.sonar.db.metric.MetricDto) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

Joiner (com.google.common.base.Joiner)20 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)20 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)20 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)20 Arrays (java.util.Arrays)20 Arrays.asList (java.util.Arrays.asList)20 Collections.singletonList (java.util.Collections.singletonList)20 Date (java.util.Date)20 HashSet (java.util.HashSet)20 List (java.util.List)20 Optional (java.util.Optional)20 Optional.ofNullable (java.util.Optional.ofNullable)20 Set (java.util.Set)20 Consumer (java.util.function.Consumer)20 IntStream (java.util.stream.IntStream)20 Stream (java.util.stream.Stream)20 Nullable (javax.annotation.Nullable)20 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)20 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)20 Assertions.tuple (org.assertj.core.api.Assertions.tuple)20