Search in sources :

Example 1 with CreateEventResponse

use of org.sonarqube.ws.ProjectAnalyses.CreateEventResponse in project sonarqube by SonarSource.

the class CreateEventActionTest method create_event_in_db.

@Test
public void create_event_in_db() {
    ComponentDto project = newProjectDto(db.organizations().insert());
    SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
    CreateEventRequest.Builder request = CreateEventRequest.builder().setAnalysis(analysis.getUuid()).setCategory(VERSION).setName("5.6.3");
    when(system.now()).thenReturn(123_456_789L);
    logInAsProjectAdministrator(project);
    CreateEventResponse result = call(request);
    List<EventDto> dbEvents = dbClient.eventDao().selectByComponentUuid(dbSession, analysis.getComponentUuid());
    assertThat(dbEvents).hasSize(1);
    EventDto dbEvent = dbEvents.get(0);
    assertThat(dbEvent.getName()).isEqualTo("5.6.3");
    assertThat(dbEvent.getCategory()).isEqualTo(VERSION.getLabel());
    assertThat(dbEvent.getDescription()).isNull();
    assertThat(dbEvent.getAnalysisUuid()).isEqualTo(analysis.getUuid());
    assertThat(dbEvent.getComponentUuid()).isEqualTo(analysis.getComponentUuid());
    assertThat(dbEvent.getUuid()).isEqualTo(result.getEvent().getKey());
    assertThat(dbEvent.getCreatedAt()).isEqualTo(123_456_789L);
    assertThat(dbEvent.getDate()).isEqualTo(analysis.getCreatedAt());
}
Also used : CreateEventRequest(org.sonarqube.ws.client.projectanalysis.CreateEventRequest) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) CreateEventResponse(org.sonarqube.ws.ProjectAnalyses.CreateEventResponse) Test(org.junit.Test)

Example 2 with CreateEventResponse

use of org.sonarqube.ws.ProjectAnalyses.CreateEventResponse in project sonarqube by SonarSource.

the class CreateEventAction method handle.

@Override
public void handle(Request httpRequest, Response httpResponse) throws Exception {
    CreateEventRequest request = toAddEventRequest(httpRequest);
    CreateEventResponse response = doHandle(request);
    writeProtobuf(response, httpRequest, httpResponse);
}
Also used : CreateEventRequest(org.sonarqube.ws.client.projectanalysis.CreateEventRequest) CreateEventResponse(org.sonarqube.ws.ProjectAnalyses.CreateEventResponse)

Example 3 with CreateEventResponse

use of org.sonarqube.ws.ProjectAnalyses.CreateEventResponse in project sonarqube by SonarSource.

the class CreateEventActionTest method create_event_without_description.

@Test
public void create_event_without_description() {
    ComponentDto project = newProjectDto(db.getDefaultOrganization());
    SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
    CreateEventRequest.Builder request = CreateEventRequest.builder().setAnalysis(analysis.getUuid()).setCategory(OTHER).setName("Project Import");
    logInAsProjectAdministrator(project);
    CreateEventResponse result = call(request);
    ProjectAnalyses.Event event = result.getEvent();
    assertThat(event.getKey()).isNotEmpty();
    assertThat(event.hasDescription()).isFalse();
}
Also used : CreateEventRequest(org.sonarqube.ws.client.projectanalysis.CreateEventRequest) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) ProjectAnalyses(org.sonarqube.ws.ProjectAnalyses) CreateEventResponse(org.sonarqube.ws.ProjectAnalyses.CreateEventResponse) Test(org.junit.Test)

Example 4 with CreateEventResponse

use of org.sonarqube.ws.ProjectAnalyses.CreateEventResponse in project sonarqube by SonarSource.

the class CreateEventActionTest method create_other_event_with_ws_response.

@Test
public void create_other_event_with_ws_response() {
    ComponentDto project = newProjectDto(db.organizations().insert());
    SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
    CreateEventRequest.Builder request = CreateEventRequest.builder().setAnalysis(analysis.getUuid()).setName("Project Import");
    logInAsProjectAdministrator(project);
    CreateEventResponse result = call(request);
    SnapshotDto newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get();
    assertThat(analysis.getVersion()).isEqualTo(newAnalysis.getVersion());
    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());
}
Also used : CreateEventRequest(org.sonarqube.ws.client.projectanalysis.CreateEventRequest) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) ProjectAnalyses(org.sonarqube.ws.ProjectAnalyses) CreateEventResponse(org.sonarqube.ws.ProjectAnalyses.CreateEventResponse) Test(org.junit.Test)

Example 5 with CreateEventResponse

use of org.sonarqube.ws.ProjectAnalyses.CreateEventResponse in project sonarqube by SonarSource.

the class CreateEventActionTest method create_event_as_project_admin.

@Test
public void create_event_as_project_admin() {
    ComponentDto project = newProjectDto(db.getDefaultOrganization(), "P1");
    SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
    CreateEventRequest.Builder request = CreateEventRequest.builder().setAnalysis(analysis.getUuid()).setCategory(VERSION).setName("5.6.3");
    logInAsProjectAdministrator(project);
    CreateEventResponse result = call(request);
    assertThat(result.getEvent().getKey()).isNotEmpty();
}
Also used : CreateEventRequest(org.sonarqube.ws.client.projectanalysis.CreateEventRequest) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) CreateEventResponse(org.sonarqube.ws.ProjectAnalyses.CreateEventResponse) Test(org.junit.Test)

Aggregations

CreateEventResponse (org.sonarqube.ws.ProjectAnalyses.CreateEventResponse)5 CreateEventRequest (org.sonarqube.ws.client.projectanalysis.CreateEventRequest)5 Test (org.junit.Test)4 ComponentDto (org.sonar.db.component.ComponentDto)4 SnapshotDto (org.sonar.db.component.SnapshotDto)4 ProjectAnalyses (org.sonarqube.ws.ProjectAnalyses)2 EventDto (org.sonar.db.event.EventDto)1