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 {
.setDescription("Name")
.setExampleValue("5.6")
.setRequired(true);
-
- action.createParam(PARAM_DESCRIPTION)
- .setDescription("Description")
- .setExampleValue("Version released");
}
@Override
.setAnalysis(request.mandatoryParam(PARAM_ANALYSIS))
.setName(request.mandatoryParam(PARAM_NAME))
.setCategory(request.mandatoryParamAsEnum(PARAM_CATEGORY, EventCategory.class))
- .setDescription(request.param(PARAM_DESCRIPTION))
.build();
}
.setComponentUuid(analysis.getComponentUuid())
.setCategory(request.getCategory().getLabel())
.setName(request.getName())
- .setDescription(request.getDescription())
.setCreatedAt(system.now())
.setDate(analysis.getCreatedAt());
}
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;
action.createParam(PARAM_NAME)
.setDescription("New name")
.setExampleValue("5.6");
-
- action.createParam(PARAM_DESCRIPTION)
- .setDescription("New description")
- .setExampleValue("Version released");
}
@Override
private static Function<EventDto, EventDto> updateNameAndDescription(UpdateEventRequest request) {
return event -> {
setNullable(request.getName(), event::setName);
- setNullable(request.getDescription(), event::setDescription);
return event;
};
}
private static Function<Request, UpdateEventRequest> toUpdateEventRequest() {
return request -> new UpdateEventRequest(
request.mandatoryParam(PARAM_EVENT),
- request.param(PARAM_NAME),
- request.param(PARAM_DESCRIPTION));
+ request.param(PARAM_NAME));
}
}
"key": "E1",
"category": "OTHER",
"name": "My Custom Event",
- "description": "event description"
}
}
"key": "E1",
"category": "OTHER",
"name": "My Custom Event",
- "description": "event description"
}
}
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 {
.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"));
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);
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());
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);
CreateEventRequest.Builder request = CreateEventRequest.builder()
.setAnalysis(analysis.getUuid())
.setCategory(VERSION)
- .setName("5.6.3")
- .setDescription("LTS version");
+ .setName("5.6.3");
call(request);
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
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);
.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) {
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;
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");
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");
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");
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");
@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
expectedException.expect(ForbiddenException.class);
- call("E1", "name", "description");
+ call("E1", "name");
}
@Test
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
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
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());
.setComponentUuid(analysis.getComponentUuid())
.setUuid(randomAlphanumeric(40))
.setName(randomAlphanumeric(400))
- .setDescription(randomAlphanumeric(400))
+ .setDescription(null)
.setCategory("Other")
.setComponentUuid(analysis.getComponentUuid())
.setCreatedAt(System.currentTimeMillis())
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() {
return name;
}
- @CheckForNull
- public String getDescription() {
- return description;
- }
-
public static Builder builder() {
return new Builder();
}
private String analysis;
private EventCategory category = EventCategory.OTHER;
private String name;
- private String description;
private Builder() {
// enforce static factory method
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);
}
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";
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() {
public String getName() {
return name;
}
-
- @CheckForNull
- public String getDescription() {
- return description;
- }
}
@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
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();
+ }
}
@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
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", " ");
}
}