use of org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001 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());
}
Aggregations