Search in sources :

Example 1 with KEY_PROJECT_EXAMPLE_002

use of org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_002 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)

Aggregations

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