From 7309a9853934855092922b340ee94f57243a12b7 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Wed, 21 Dec 2016 11:04:02 +0100 Subject: [PATCH] SONAR-8464 SONAR-8466 WS drop description param to create or udpate an event --- .../projectanalysis/ws/CreateEventAction.java | 7 --- .../projectanalysis/ws/UpdateEventAction.java | 9 +-- .../ws/create_event-example.json | 1 - .../ws/update_event-example.json | 1 - .../ws/CreateEventActionTest.java | 35 ++++------- .../ws/UpdateEventActionTest.java | 59 +++++++------------ .../java/org/sonar/db/event/EventTesting.java | 2 +- .../projectanalysis/CreateEventRequest.java | 18 +----- .../ProjectAnalysesWsParameters.java | 1 - .../projectanalysis/UpdateEventRequest.java | 14 ++--- .../CreateEventRequestTest.java | 11 +++- .../UpdateEventRequestTest.java | 31 +++++----- 12 files changed, 65 insertions(+), 124 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/CreateEventAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/CreateEventAction.java index affcfb36e93..f2359791b87 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/CreateEventAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/CreateEventAction.java @@ -54,7 +54,6 @@ import static org.sonarqube.ws.client.projectanalysis.EventCategory.VERSION; import static org.sonarqube.ws.client.projectanalysis.EventCategory.fromLabel; import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_ANALYSIS; import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_CATEGORY; -import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_DESCRIPTION; import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_NAME; public class CreateEventAction implements ProjectAnalysesWsAction { @@ -98,10 +97,6 @@ public class CreateEventAction implements ProjectAnalysesWsAction { .setDescription("Name") .setExampleValue("5.6") .setRequired(true); - - action.createParam(PARAM_DESCRIPTION) - .setDescription("Description") - .setExampleValue("Version released"); } @Override @@ -151,7 +146,6 @@ public class CreateEventAction implements ProjectAnalysesWsAction { .setAnalysis(request.mandatoryParam(PARAM_ANALYSIS)) .setName(request.mandatoryParam(PARAM_NAME)) .setCategory(request.mandatoryParamAsEnum(PARAM_CATEGORY, EventCategory.class)) - .setDescription(request.param(PARAM_DESCRIPTION)) .build(); } @@ -162,7 +156,6 @@ public class CreateEventAction implements ProjectAnalysesWsAction { .setComponentUuid(analysis.getComponentUuid()) .setCategory(request.getCategory().getLabel()) .setName(request.getName()) - .setDescription(request.getDescription()) .setCreatedAt(system.now()) .setDate(analysis.getCreatedAt()); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/UpdateEventAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/UpdateEventAction.java index 652e02f00c6..49aedaa0dd5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/UpdateEventAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/UpdateEventAction.java @@ -45,7 +45,6 @@ import static org.sonar.server.projectanalysis.ws.EventValidator.checkModifiable import static org.sonar.server.ws.WsUtils.writeProtobuf; import static org.sonarqube.ws.client.projectanalysis.EventCategory.VERSION; import static org.sonarqube.ws.client.projectanalysis.EventCategory.fromLabel; -import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_DESCRIPTION; import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_EVENT; import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_NAME; @@ -79,10 +78,6 @@ public class UpdateEventAction implements ProjectAnalysesWsAction { action.createParam(PARAM_NAME) .setDescription("New name") .setExampleValue("5.6"); - - action.createParam(PARAM_DESCRIPTION) - .setDescription("New description") - .setExampleValue("Version released"); } @Override @@ -152,7 +147,6 @@ public class UpdateEventAction implements ProjectAnalysesWsAction { private static Function updateNameAndDescription(UpdateEventRequest request) { return event -> { setNullable(request.getName(), event::setName); - setNullable(request.getDescription(), event::setDescription); return event; }; } @@ -173,7 +167,6 @@ public class UpdateEventAction implements ProjectAnalysesWsAction { private static Function toUpdateEventRequest() { return request -> new UpdateEventRequest( request.mandatoryParam(PARAM_EVENT), - request.param(PARAM_NAME), - request.param(PARAM_DESCRIPTION)); + request.param(PARAM_NAME)); } } diff --git a/server/sonar-server/src/main/resources/org/sonar/server/projectanalysis/ws/create_event-example.json b/server/sonar-server/src/main/resources/org/sonar/server/projectanalysis/ws/create_event-example.json index 14e486d5b60..2c4917e3e58 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/projectanalysis/ws/create_event-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/projectanalysis/ws/create_event-example.json @@ -4,6 +4,5 @@ "key": "E1", "category": "OTHER", "name": "My Custom Event", - "description": "event description" } } diff --git a/server/sonar-server/src/main/resources/org/sonar/server/projectanalysis/ws/update_event-example.json b/server/sonar-server/src/main/resources/org/sonar/server/projectanalysis/ws/update_event-example.json index 14e486d5b60..2c4917e3e58 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/projectanalysis/ws/update_event-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/projectanalysis/ws/update_event-example.json @@ -4,6 +4,5 @@ "key": "E1", "category": "OTHER", "name": "My Custom Event", - "description": "event description" } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/CreateEventActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/CreateEventActionTest.java index 3070200a401..3a89c856ce3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/CreateEventActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/CreateEventActionTest.java @@ -64,7 +64,6 @@ import static org.sonarqube.ws.client.projectanalysis.EventCategory.OTHER; import static org.sonarqube.ws.client.projectanalysis.EventCategory.VERSION; import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_ANALYSIS; import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_CATEGORY; -import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_DESCRIPTION; import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_NAME; public class CreateEventActionTest { @@ -101,7 +100,6 @@ public class CreateEventActionTest { .setParam(PARAM_ANALYSIS, analysis.getUuid()) .setParam(PARAM_CATEGORY, OTHER.name()) .setParam(PARAM_NAME, "My Custom Event") - .setParam(PARAM_DESCRIPTION, "event description") .execute().getInput(); assertJson(result).isSimilarTo(getClass().getResource("create_event-example.json")); @@ -113,8 +111,7 @@ public class CreateEventActionTest { CreateEventRequest.Builder request = CreateEventRequest.builder() .setAnalysis(analysis.getUuid()) .setCategory(VERSION) - .setName("5.6.3") - .setDescription("LTS version"); + .setName("5.6.3"); when(system.now()).thenReturn(123_456_789L); CreateEventResponse result = call(request); @@ -124,7 +121,7 @@ public class CreateEventActionTest { EventDto dbEvent = dbEvents.get(0); assertThat(dbEvent.getName()).isEqualTo("5.6.3"); assertThat(dbEvent.getCategory()).isEqualTo(VERSION.getLabel()); - assertThat(dbEvent.getDescription()).isEqualTo("LTS version"); + assertThat(dbEvent.getDescription()).isNull(); assertThat(dbEvent.getAnalysisUuid()).isEqualTo(analysis.getUuid()); assertThat(dbEvent.getComponentUuid()).isEqualTo(analysis.getComponentUuid()); assertThat(dbEvent.getUuid()).isEqualTo(result.getEvent().getKey()); @@ -138,8 +135,7 @@ public class CreateEventActionTest { CreateEventRequest.Builder request = CreateEventRequest.builder() .setAnalysis(analysis.getUuid()) .setCategory(VERSION) - .setName("5.6.3") - .setDescription("LTS version"); + .setName("5.6.3"); userSession.anonymous().addProjectUuidPermissions(UserRole.ADMIN, "P1"); CreateEventResponse result = call(request); @@ -153,8 +149,7 @@ public class CreateEventActionTest { CreateEventRequest.Builder request = CreateEventRequest.builder() .setAnalysis(analysis.getUuid()) .setCategory(VERSION) - .setName("5.6.3") - .setDescription("LTS version"); + .setName("5.6.3"); call(request); @@ -167,19 +162,18 @@ public class CreateEventActionTest { SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); CreateEventRequest.Builder request = CreateEventRequest.builder() .setAnalysis(analysis.getUuid()) - .setName("Project Import") - .setDescription("Import from another instance"); + .setName("Project Import"); CreateEventResponse result = call(request); SnapshotDto newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); assertThat(analysis.getVersion()).isEqualTo(newAnalysis.getVersion()); - ProjectAnalyses.Event event = result.getEvent(); - assertThat(event.getKey()).isNotEmpty(); - assertThat(event.getCategory()).isEqualTo(OTHER.name()); - assertThat(event.getName()).isEqualTo("Project Import"); - assertThat(event.getDescription()).isEqualTo("Import from another instance"); - assertThat(event.getAnalysis()).isEqualTo(analysis.getUuid()); + ProjectAnalyses.Event wsEvent = result.getEvent(); + assertThat(wsEvent.getKey()).isNotEmpty(); + assertThat(wsEvent.getCategory()).isEqualTo(OTHER.name()); + assertThat(wsEvent.getName()).isEqualTo("Project Import"); + assertThat(wsEvent.hasDescription()).isFalse(); + assertThat(wsEvent.getAnalysis()).isEqualTo(analysis.getUuid()); } @Test @@ -309,8 +303,7 @@ public class CreateEventActionTest { CreateEventRequest.Builder request = CreateEventRequest.builder() .setAnalysis(analysis.getUuid()) .setCategory(VERSION) - .setName("5.6.3") - .setDescription("LTS version"); + .setName("5.6.3"); userSession.anonymous(); expectedException.expect(ForbiddenException.class); @@ -338,10 +331,6 @@ public class CreateEventActionTest { .setParam(PARAM_NAME, request.getName()) .setParam(PARAM_ANALYSIS, request.getAnalysis()); - if (request.getDescription() != null) { - httpRequest.setParam(PARAM_DESCRIPTION, request.getDescription()); - } - try { return CreateEventResponse.parseFrom(httpRequest.execute().getInputStream()); } catch (IOException e) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/UpdateEventActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/UpdateEventActionTest.java index f9ec5d17055..fb579819010 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/UpdateEventActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/UpdateEventActionTest.java @@ -54,7 +54,6 @@ import static org.sonar.test.JsonAssert.assertJson; import static org.sonarqube.ws.client.WsRequest.Method.POST; import static org.sonarqube.ws.client.projectanalysis.EventCategory.OTHER; import static org.sonarqube.ws.client.projectanalysis.EventCategory.VERSION; -import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_DESCRIPTION; import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_EVENT; import static org.sonarqube.ws.client.projectanalysis.ProjectAnalysesWsParameters.PARAM_NAME; @@ -83,36 +82,35 @@ public class UpdateEventActionTest { String result = ws.newRequest() .setParam(PARAM_EVENT, "E1") .setParam(PARAM_NAME, "My Custom Event") - .setParam(PARAM_DESCRIPTION, "event description") .execute().getInput(); assertJson(result).isSimilarTo(getClass().getResource("update_event-example.json")); } @Test - public void update_name_and_description_in_db() { + public void update_name_in_db() { SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); - EventDto originalEvent = db.events().insertEvent(newEvent(analysis).setUuid("E1").setName("Original Name").setDescription("Original Description")); + EventDto originalEvent = db.events().insertEvent(newEvent(analysis).setUuid("E1").setName("Original Name")); - call("E1", "name", "description"); + call("E1", "name"); EventDto newEvent = dbClient.eventDao().selectByUuid(dbSession, "E1").get(); assertThat(newEvent.getName()).isEqualTo("name"); - assertThat(newEvent.getDescription()).isEqualTo("description"); + assertThat(newEvent.getDescription()).isNull(); assertThat(newEvent.getCategory()).isEqualTo(originalEvent.getCategory()); assertThat(newEvent.getDate()).isEqualTo(originalEvent.getDate()); assertThat(newEvent.getCreatedAt()).isEqualTo(originalEvent.getCreatedAt()); } @Test - public void ws_response_with_updated_name_and_description() { + public void ws_response_with_updated_name() { SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); - EventDto originalEvent = db.events().insertEvent(newEvent(analysis).setUuid("E1").setName("Original Name").setDescription("Original Description")); + EventDto originalEvent = db.events().insertEvent(newEvent(analysis).setUuid("E1").setName("Original Name")); - ProjectAnalyses.Event result = call("E1", "name", "description").getEvent(); + ProjectAnalyses.Event result = call("E1", "name").getEvent(); assertThat(result.getName()).isEqualTo("name"); - assertThat(result.getDescription()).isEqualTo("description"); + assertThat(result.hasDescription()).isFalse(); assertThat(result.getCategory()).isEqualTo(OTHER.name()); assertThat(result.getAnalysis()).isEqualTo(originalEvent.getAnalysisUuid()); assertThat(result.getKey()).isEqualTo("E1"); @@ -124,7 +122,7 @@ public class UpdateEventActionTest { SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setVersion("5.6")); db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel())); - call("E1", "6.3", null); + call("E1", "6.3"); SnapshotDto updatedAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); assertThat(updatedAnalysis.getVersion()).isEqualTo("6.3"); @@ -136,7 +134,7 @@ public class UpdateEventActionTest { SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setVersion("5.6")); db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(OTHER.getLabel())); - call("E1", "6.3", null); + call("E1", "6.3"); SnapshotDto updatedAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get(); assertThat(updatedAnalysis.getVersion()).isEqualTo("5.6"); @@ -147,7 +145,7 @@ public class UpdateEventActionTest { SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); EventDto originalEvent = db.events().insertEvent(newEvent(analysis).setUuid("E1").setName("Original Name").setDescription("Original Description")); - call("E1", "name", null); + call("E1", "name"); EventDto newEvent = dbClient.eventDao().selectByUuid(dbSession, "E1").get(); assertThat(newEvent.getName()).isEqualTo("name"); @@ -157,26 +155,14 @@ public class UpdateEventActionTest { @Test public void update_as_project_admin() { SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto("P1")); - db.events().insertEvent(newEvent(analysis).setUuid("E1").setName("Original Name").setDescription("Original Description")); + db.events().insertEvent(newEvent(analysis).setUuid("E1").setName("Original Name")); userSession.anonymous().addProjectUuidPermissions(UserRole.ADMIN, "P1"); - call("E1", "name", "description"); + call("E1", "name"); EventDto newEvent = dbClient.eventDao().selectByUuid(dbSession, "E1").get(); assertThat(newEvent.getName()).isEqualTo("name"); - assertThat(newEvent.getDescription()).isEqualTo("description"); - } - - @Test - public void update_description_only_in_db() { - SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); - EventDto originalEvent = db.events().insertEvent(newEvent(analysis).setUuid("E1").setName("Original Name").setDescription("Original Description")); - - call("E1", null, "description"); - - EventDto newEvent = dbClient.eventDao().selectByUuid(dbSession, "E1").get(); - assertThat(newEvent.getName()).isEqualTo(originalEvent.getName()); - assertThat(newEvent.getDescription()).isEqualTo("description"); + assertThat(newEvent.getDescription()).isNull(); } @Test @@ -198,7 +184,7 @@ public class UpdateEventActionTest { expectedException.expect(ForbiddenException.class); - call("E1", "name", "description"); + call("E1", "name"); } @Test @@ -206,17 +192,17 @@ public class UpdateEventActionTest { expectedException.expect(NotFoundException.class); expectedException.expectMessage("Event 'E42' not found"); - call("E42", "name", "description"); + call("E42", "name"); } @Test - public void fail_if_no_name_nor_description() { + public void fail_if_no_name() { SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); db.events().insertEvent(newEvent(analysis).setUuid("E1")); - expectedException.expect(IllegalArgumentException.class); + expectedException.expect(NullPointerException.class); - call("E1", null, null); + call("E1", null); } @Test @@ -227,7 +213,7 @@ public class UpdateEventActionTest { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Event of category 'Profile' cannot be modified. Authorized categories: Version, Other"); - call("E1", "name", "description"); + call("E1", "name"); } @Test @@ -239,16 +225,15 @@ public class UpdateEventActionTest { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("An 'Other' event with the same name already exists on analysis '" + analysis.getUuid() + "'"); - call("E2", "E1 name", "description"); + call("E2", "E1 name"); } - private UpdateEventResponse call(@Nullable String eventUuid, @Nullable String name, @Nullable String description) { + private UpdateEventResponse call(@Nullable String eventUuid, @Nullable String name) { TestRequest request = ws.newRequest() .setMethod(POST.name()) .setMediaType(MediaTypes.PROTOBUF); setNullable(eventUuid, e -> request.setParam(PARAM_EVENT, e)); setNullable(name, n -> request.setParam(PARAM_NAME, n)); - setNullable(description, d -> request.setParam(PARAM_DESCRIPTION, d)); try { return UpdateEventResponse.parseFrom(request.execute().getInputStream()); diff --git a/sonar-db/src/test/java/org/sonar/db/event/EventTesting.java b/sonar-db/src/test/java/org/sonar/db/event/EventTesting.java index 74f23358470..49b75a7d9f3 100644 --- a/sonar-db/src/test/java/org/sonar/db/event/EventTesting.java +++ b/sonar-db/src/test/java/org/sonar/db/event/EventTesting.java @@ -36,7 +36,7 @@ public class EventTesting { .setComponentUuid(analysis.getComponentUuid()) .setUuid(randomAlphanumeric(40)) .setName(randomAlphanumeric(400)) - .setDescription(randomAlphanumeric(400)) + .setDescription(null) .setCategory("Other") .setComponentUuid(analysis.getComponentUuid()) .setCreatedAt(System.currentTimeMillis()) diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/CreateEventRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/CreateEventRequest.java index b9299a3be38..0892fed0310 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/CreateEventRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/CreateEventRequest.java @@ -20,22 +20,18 @@ package org.sonarqube.ws.client.projectanalysis; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - import static com.google.common.base.Preconditions.checkArgument; +import static org.apache.commons.lang.StringUtils.isNotBlank; public class CreateEventRequest { private final String analysis; private final EventCategory category; private final String name; - private final String description; private CreateEventRequest(Builder builder) { analysis = builder.analysis; category = builder.category; name = builder.name; - description = builder.description; } public String getAnalysis() { @@ -50,11 +46,6 @@ public class CreateEventRequest { return name; } - @CheckForNull - public String getDescription() { - return description; - } - public static Builder builder() { return new Builder(); } @@ -63,7 +54,6 @@ public class CreateEventRequest { private String analysis; private EventCategory category = EventCategory.OTHER; private String name; - private String description; private Builder() { // enforce static factory method @@ -84,15 +74,11 @@ public class CreateEventRequest { return this; } - public Builder setDescription(@Nullable String description) { - this.description = description; - return this; - } - public CreateEventRequest build() { checkArgument(analysis != null, "Analysis key is required"); checkArgument(category != null, "Category is required"); checkArgument(name != null, "Name is required"); + checkArgument(isNotBlank(name), "A non empty name is required"); return new CreateEventRequest(this); } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java index abf1e0840b8..bf805a00f74 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/ProjectAnalysesWsParameters.java @@ -24,7 +24,6 @@ public class ProjectAnalysesWsParameters { public static final String PARAM_ANALYSIS = "analysis"; public static final String PARAM_CATEGORY = "category"; public static final String PARAM_NAME = "name"; - public static final String PARAM_DESCRIPTION = "description"; public static final String PARAM_EVENT = "event"; public static final String PARAM_PROJECT = "project"; diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/UpdateEventRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/UpdateEventRequest.java index 9afeb37c12d..59e852a0a08 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/UpdateEventRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/projectanalysis/UpdateEventRequest.java @@ -21,21 +21,20 @@ package org.sonarqube.ws.client.projectanalysis; import javax.annotation.CheckForNull; -import javax.annotation.Nullable; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; +import static org.apache.commons.lang.StringUtils.isNotBlank; public class UpdateEventRequest { private final String event; private final String name; - private final String description; - public UpdateEventRequest(String event, @Nullable String name, @Nullable String description) { - checkArgument(name != null || description != null, "Name or description is required"); + public UpdateEventRequest(String event, String name) { + requireNonNull(name, "Name is required"); + checkArgument(isNotBlank(name), "A non empty name is required"); this.event = requireNonNull(event, "Event key is required"); this.name = name; - this.description = description; } public String getEvent() { @@ -46,9 +45,4 @@ public class UpdateEventRequest { public String getName() { return name; } - - @CheckForNull - public String getDescription() { - return description; - } } diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/CreateEventRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/CreateEventRequestTest.java index 1d07f29b1ce..9568c0850f1 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/CreateEventRequestTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/CreateEventRequestTest.java @@ -37,12 +37,11 @@ public class CreateEventRequestTest { @Test public void build_request() { - CreateEventRequest result = underTest.setAnalysis("P1").setCategory(OTHER).setName("name").setDescription("description").build(); + CreateEventRequest result = underTest.setAnalysis("P1").setCategory(OTHER).setName("name").build(); assertThat(result.getAnalysis()).isEqualTo("P1"); assertThat(result.getCategory()).isEqualTo(OTHER); assertThat(result.getName()).isEqualTo("name"); - assertThat(result.getDescription()).isEqualTo("description"); } @Test @@ -75,4 +74,12 @@ public class CreateEventRequestTest { underTest.setAnalysis("P1").setCategory(VERSION).build(); } + + @Test + public void fail_when_blank_name() { + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("A non empty name is required"); + + underTest.setAnalysis("P1").setName(" ").setCategory(VERSION).build(); + } } diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/UpdateEventRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/UpdateEventRequestTest.java index 43e05ad956d..f2dbf27c716 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/UpdateEventRequestTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/projectanalysis/UpdateEventRequestTest.java @@ -34,29 +34,18 @@ public class UpdateEventRequestTest { @Test public void request_with_name_only() { - underTest = new UpdateEventRequest("E1", "name", null); + underTest = new UpdateEventRequest("E1", "name"); assertThat(underTest.getEvent()).isEqualTo("E1"); assertThat(underTest.getName()).isEqualTo("name"); - assertThat(underTest.getDescription()).isNull(); - } - - @Test - public void request_with_description_only() { - underTest = new UpdateEventRequest("E1", null , "description"); - - assertThat(underTest.getEvent()).isEqualTo("E1"); - assertThat(underTest.getName()).isNull(); - assertThat(underTest.getDescription()).isEqualTo("description"); } @Test public void request_with_all_parameters() { - underTest = new UpdateEventRequest("E1", "name", "description"); + underTest = new UpdateEventRequest("E1", "name"); assertThat(underTest.getEvent()).isEqualTo("E1"); assertThat(underTest.getName()).isEqualTo("name"); - assertThat(underTest.getDescription()).isEqualTo("description"); } @Test @@ -64,14 +53,22 @@ public class UpdateEventRequestTest { expectedException.expect(NullPointerException.class); expectedException.expectMessage("Event key is required"); - new UpdateEventRequest(null, "name", "description"); + new UpdateEventRequest(null, "name"); + } + + @Test + public void fail_if_name_not_provided() { + expectedException.expect(NullPointerException.class); + expectedException.expectMessage("Name is required"); + + new UpdateEventRequest("E1", null); } @Test - public void fail_if_name_and_description_not_provided() { + public void fail_if_name_blank() { expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Name or description is required"); + expectedException.expectMessage("A non empty name is required"); - new UpdateEventRequest("E1", null, null); + new UpdateEventRequest("E1", " "); } } -- 2.39.5