use of org.sonar.db.event.EventDto in project sonarqube by SonarSource.
the class CreateEventAction method insertDbEvent.
private EventDto insertDbEvent(DbSession dbSession, CreateEventRequest request, SnapshotDto analysis) {
EventDto dbEvent = dbClient.eventDao().insert(dbSession, toDbEvent(request, analysis));
if (VERSION.equals(request.getCategory())) {
analysis.setVersion(request.getName());
dbClient.snapshotDao().update(dbSession, analysis);
}
dbSession.commit();
return dbEvent;
}
use of org.sonar.db.event.EventDto in project sonarqube by SonarSource.
the class CreateEventAction method doHandle.
private CreateEventResponse doHandle(CreateEventRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
SnapshotDto analysis = getAnalysis(dbSession, request);
checkExistingDbEvents(dbSession, request, analysis);
EventDto dbEvent = insertDbEvent(dbSession, request, analysis);
return toCreateEventResponse(dbEvent);
}
}
use of org.sonar.db.event.EventDto 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());
}
use of org.sonar.db.event.EventDto in project sonarqube by SonarSource.
the class UpdateEventActionTest method ws_response_with_updated_name.
@Test
public void ws_response_with_updated_name() {
SnapshotDto analysis = createAnalysisAndLogInAsProjectAdministrator("5.6");
EventDto originalEvent = db.events().insertEvent(newEvent(analysis).setUuid("E1").setName("Original Name"));
ProjectAnalyses.Event result = call("E1", "name").getEvent();
assertThat(result.getName()).isEqualTo("name");
assertThat(result.hasDescription()).isFalse();
assertThat(result.getCategory()).isEqualTo(OTHER.name());
assertThat(result.getAnalysis()).isEqualTo(originalEvent.getAnalysisUuid());
assertThat(result.getKey()).isEqualTo("E1");
}
use of org.sonar.db.event.EventDto in project sonarqube by SonarSource.
the class SearchActionTest method return_events.
@Test
public void return_events() {
OrganizationDto organizationDto = db.organizations().insert();
ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto).setKey("P1"));
userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1"));
SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(newProjectDto(organizationDto)).setUuid("A42"));
EventDto e1 = db.events().insertEvent(newEvent(a1).setUuid("E1").setName("N1").setCategory(EventCategory.QUALITY_GATE.getLabel()).setDescription("D1"));
EventDto e2 = db.events().insertEvent(newEvent(a1).setUuid("E2").setName("N2").setCategory(VERSION.getLabel()).setDescription("D2"));
db.events().insertEvent(newEvent(a42));
List<Analysis> result = call("P1").getAnalysesList();
assertThat(result).hasSize(1);
List<Event> events = result.get(0).getEventsList();
assertThat(events).hasSize(2);
assertThat(events).extracting(Event::getKey, wsToDbCategory(), Event::getName, Event::getDescription).containsOnly(tuple(e1.getUuid(), e1.getCategory(), e1.getName(), e1.getDescription()), tuple(e2.getUuid(), e2.getCategory(), e2.getName(), e2.getDescription()));
}
Aggregations