use of org.sonar.db.event.EventPurgeData in project sonarqube by SonarSource.
the class SearchActionTest method incorrect_eventcomponentchange_two_identical_changes_added_on_same_project.
@Test
public void incorrect_eventcomponentchange_two_identical_changes_added_on_same_project() {
ComponentDto application = db.components().insertPublicApplication();
userSession.registerApplication(toProjectDto(application, 1L));
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
EventComponentChangeDto changeDto1 = generateEventComponentChange(event, ADDED, "My project", "app1", "master", uuidFactoryFast.create());
EventComponentChangeDto changeDto2 = generateEventComponentChange(event, ADDED, "My project", "app1", "master", uuidFactoryFast.create());
EventPurgeData eventPurgeData = new EventPurgeData(application.uuid(), firstAnalysis.getUuid());
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto1, eventPurgeData);
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto2, eventPurgeData);
db.getSession().commit();
List<Analysis> result = call(application.getDbKey()).getAnalysesList();
assertThat(result).hasSize(1);
List<Event> events = result.get(0).getEventsList();
assertThat(events).extracting(Event::getName, Event::getCategory, Event::getKey).containsExactly(tuple("", DEFINITION_CHANGE.name(), "E11"));
assertThat(events.get(0).getDefinitionChange().getProjectsList()).isEmpty();
assertThat(logTester.getLogs(LoggerLevel.ERROR)).extracting(LogAndArguments::getFormattedMsg).containsExactly(format("Incorrect changes : [uuid=%s change=ADDED, branch=master] and [uuid=%s, change=ADDED, branch=master]", changeDto1.getUuid(), changeDto2.getUuid()));
}
use of org.sonar.db.event.EventPurgeData in project sonarqube by SonarSource.
the class SearchActionTest method incorrect_eventcomponentchange_incorrect_category.
@Test
public void incorrect_eventcomponentchange_incorrect_category() {
ComponentDto application = db.components().insertPublicApplication();
userSession.registerApplication(toProjectDto(application, 1L));
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
EventComponentChangeDto changeDto1 = generateEventComponentChange(event, FAILED_QUALITY_GATE, "My project", "app1", "master", uuidFactoryFast.create());
EventPurgeData eventPurgeData = new EventPurgeData(application.uuid(), firstAnalysis.getUuid());
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto1, eventPurgeData);
db.getSession().commit();
List<Analysis> result = call(application.getDbKey()).getAnalysesList();
assertThat(result).hasSize(1);
List<Event> events = result.get(0).getEventsList();
assertThat(events).extracting(Event::getName, Event::getCategory, Event::getKey).containsExactly(tuple("", DEFINITION_CHANGE.name(), "E11"));
assertThat(events.get(0).getDefinitionChange().getProjectsList()).isEmpty();
assertThat(logTester.getLogs(LoggerLevel.ERROR)).extracting(LogAndArguments::getFormattedMsg).containsExactly("Unknown change FAILED_QUALITY_GATE for eventComponentChange uuid: " + changeDto1.getUuid());
}
use of org.sonar.db.event.EventPurgeData in project sonarqube by SonarSource.
the class SearchActionTest method incorrect_quality_gate_information.
@Test
public void incorrect_quality_gate_information() {
ComponentDto application = db.components().insertPublicApplication();
userSession.registerApplication(toProjectDto(application, 1L));
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(CATEGORY_ALERT).setData(// Error in Data
"UNPARSEABLE JSON"));
EventComponentChangeDto changeDto1 = generateEventComponentChange(event, FAILED_QUALITY_GATE, "My project", "app1", "master", uuidFactoryFast.create());
EventPurgeData eventPurgeData = new EventPurgeData(application.uuid(), firstAnalysis.getUuid());
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto1, eventPurgeData);
db.getSession().commit();
List<Analysis> result = call(application.getDbKey()).getAnalysesList();
assertThat(result).hasSize(1);
List<Event> events = result.get(0).getEventsList();
assertThat(events).extracting(Event::getName, Event::getCategory, Event::getKey).containsExactly(tuple("", QUALITY_GATE.name(), "E11"));
// Verify that the values are not populated
assertThat(events.get(0).getQualityGate().hasStatus()).isFalse();
assertThat(events.get(0).getQualityGate().hasStillFailing()).isFalse();
assertThat(logTester.getLogs(LoggerLevel.ERROR)).extracting(LogAndArguments::getFormattedMsg).containsExactly("Unable to retrieve data from event uuid=E11");
}
use of org.sonar.db.event.EventPurgeData in project sonarqube by SonarSource.
the class SearchActionTest method insertEventComponentChanges.
private void insertEventComponentChanges(ComponentDto component, SnapshotDto analysis, EventComponentChangeDto... changes) {
EventPurgeData eventPurgeData = new EventPurgeData(component.uuid(), analysis.getUuid());
for (EventComponentChangeDto change : changes) {
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), change, eventPurgeData);
}
db.getSession().commit();
}
use of org.sonar.db.event.EventPurgeData in project sonarqube by SonarSource.
the class SearchActionTest method incorrect_eventcomponentchange_three_component_changes_on_same_project.
@Test
public void incorrect_eventcomponentchange_three_component_changes_on_same_project() {
ComponentDto application = db.components().insertPublicApplication();
userSession.registerApplication(toProjectDto(application, 1L));
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(application).setCreatedAt(1_000_000L));
EventDto event = db.events().insertEvent(newEvent(firstAnalysis).setName("").setUuid("E11").setCategory(DEFINITION_CHANGE.getLabel()));
EventComponentChangeDto changeDto1 = generateEventComponentChange(event, ADDED, "My project", "app1", "master", uuidFactoryFast.create());
EventComponentChangeDto changeDto2 = generateEventComponentChange(event, REMOVED, "Another project", "app1", "", uuidFactoryFast.create());
EventComponentChangeDto changeDto3 = generateEventComponentChange(event, REMOVED, "Another project", "app1", "", uuidFactoryFast.create());
EventPurgeData eventPurgeData = new EventPurgeData(application.uuid(), firstAnalysis.getUuid());
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto1, eventPurgeData);
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto2, eventPurgeData);
db.getDbClient().eventComponentChangeDao().insert(db.getSession(), changeDto3, eventPurgeData);
db.getSession().commit();
List<Analysis> result = call(application.getDbKey()).getAnalysesList();
assertThat(result).hasSize(1);
List<Event> events = result.get(0).getEventsList();
assertThat(events).extracting(Event::getName, Event::getCategory, Event::getKey).containsExactly(tuple("", DEFINITION_CHANGE.name(), "E11"));
assertThat(events.get(0).getDefinitionChange().getProjectsList()).isEmpty();
assertThat(logTester.getLogs(LoggerLevel.ERROR)).extracting(LogAndArguments::getFormattedMsg).containsExactly(format("Too many changes on same project (3) for eventComponentChange uuids : %s,%s,%s", changeDto1.getUuid(), changeDto2.getUuid(), changeDto3.getUuid()));
}
Aggregations