From a47d4a1f0a15b34581364f2a45faee2544f92132 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Mon, 16 Oct 2017 14:50:36 +0200 Subject: [PATCH] SONAR-9986 Add back id to WS api/components/search_projects --- .../component/ws/SearchProjectsAction.java | 4 ++-- .../component/ws/search_projects-example.json | 3 +++ .../component/ws/SearchProjectsActionTest.java | 17 ++++++++--------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java index 3aabfa94b70..d6faf28ef75 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java @@ -115,8 +115,7 @@ public class SearchProjectsAction implements ComponentsWsAction { new Change("6.4", "The 'visibility' field is added"), new Change("6.5", "The 'filter' parameter now allows 'NO_DATA' as value for numeric metrics"), new Change("6.5", "Added the option 'analysisDate' for the 'sort' parameter"), - new Change("6.5", format("Value '%s' is added to parameter '%s'", LEAK_PERIOD_DATE, FIELDS)), - new Change("6.6", "The 'id' field is removed from the response")) + new Change("6.5", format("Value '%s' is added to parameter '%s'", LEAK_PERIOD_DATE, FIELDS))) .setHandler(this); action.createFieldsParam(POSSIBLE_FIELDS) @@ -424,6 +423,7 @@ public class SearchProjectsAction implements ComponentsWsAction { wsComponent .clear() .setOrganization(organizationDto.getKey()) + .setId(dbComponent.uuid()) .setKey(dbComponent.getDbKey()) .setName(dbComponent.name()) .setVisibility(Visibility.getLabel(dbComponent.isPrivate())); diff --git a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search_projects-example.json b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search_projects-example.json index ddb458d04ac..41d9cfa4c75 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search_projects-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/search_projects-example.json @@ -7,6 +7,7 @@ "components": [ { "organization": "my-org-key-1", + "id": "AU-Tpxb--iU5OvuD2FLy", "key": "my_project", "name": "My Project 1", "isFavorite": true, @@ -18,6 +19,7 @@ }, { "organization": "my-org-key-1", + "id": "AU-TpxcA-iU5OvuD2FLz", "key": "another_project", "name": "My Project 2", "isFavorite": false, @@ -26,6 +28,7 @@ }, { "organization": "my-org-key-2", + "id": "AU-TpxcA-iU5OvuD2FL0", "key": "third_project", "name": "My Project 3", "isFavorite": false, diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java index 0f1c5e3989c..1428b905147 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java @@ -151,8 +151,7 @@ public class SearchProjectsActionTest { tuple("6.4", "The 'visibility' field is added"), tuple("6.5", "The 'filter' parameter now allows 'NO_DATA' as value for numeric metrics"), tuple("6.5", "Added the option 'analysisDate' for the 'sort' parameter"), - tuple("6.5", "Value 'leakPeriodDate' is added to parameter 'f'"), - tuple("6.6", "The 'id' field is removed from the response")); + tuple("6.5", "Value 'leakPeriodDate' is added to parameter 'f'")); Param organization = def.param("organization"); assertThat(organization.isRequired()).isFalse(); @@ -205,23 +204,23 @@ public class SearchProjectsActionTest { .setName("My Project 1") .setTagsString("finance, java"), new Measure(coverage, c -> c.setValue(80d))); - insertProject(organization1Dto, c -> c + ComponentDto project2 = insertProject(organization1Dto, c -> c .setDbKey(KeyExamples.KEY_PROJECT_EXAMPLE_002) .setName("My Project 2"), new Measure(coverage, c -> c.setValue(90d))); - insertProject(organization2Dto, c -> c + ComponentDto project3 = insertProject(organization2Dto, c -> c .setDbKey(KeyExamples.KEY_PROJECT_EXAMPLE_003) .setName("My Project 3") .setTagsString("sales, offshore, java"), new Measure(coverage, c -> c.setValue(20d))); addFavourite(project1); - String result = ws.newRequest() - .setParam(Param.FACETS, COVERAGE) - .execute().getInput(); + String jsonResult = ws.newRequest().setParam(Param.FACETS, COVERAGE).execute().getInput(); + SearchProjectsWsResponse protobufResult = ws.newRequest().setParam(Param.FACETS, COVERAGE).executeProtobuf(SearchProjectsWsResponse.class); - assertJson(result).withStrictArrayOrder().isSimilarTo(ws.getDef().responseExampleAsString()); - assertJson(ws.getDef().responseExampleAsString()).withStrictArrayOrder().isSimilarTo(result); + assertJson(jsonResult).withStrictArrayOrder().ignoreFields("id").isSimilarTo(ws.getDef().responseExampleAsString()); + assertJson(ws.getDef().responseExampleAsString()).ignoreFields("id").withStrictArrayOrder().isSimilarTo(jsonResult); + assertThat(protobufResult.getComponentsList()).extracting(Component::getId).containsExactly(project1.uuid(), project2.uuid(), project3.uuid()); } @Test -- 2.39.5