Search in sources :

Example 1 with EventPurgeData

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()));
}
Also used : SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) Analysis(org.sonarqube.ws.ProjectAnalyses.Analysis) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) EventTesting.newEvent(org.sonar.db.event.EventTesting.newEvent) Event(org.sonarqube.ws.ProjectAnalyses.Event) EventComponentChangeDto(org.sonar.db.event.EventComponentChangeDto) EventPurgeData(org.sonar.db.event.EventPurgeData) Test(org.junit.Test)

Example 2 with EventPurgeData

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());
}
Also used : SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) Analysis(org.sonarqube.ws.ProjectAnalyses.Analysis) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) EventTesting.newEvent(org.sonar.db.event.EventTesting.newEvent) Event(org.sonarqube.ws.ProjectAnalyses.Event) EventComponentChangeDto(org.sonar.db.event.EventComponentChangeDto) EventPurgeData(org.sonar.db.event.EventPurgeData) Test(org.junit.Test)

Example 3 with EventPurgeData

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");
}
Also used : SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) Analysis(org.sonarqube.ws.ProjectAnalyses.Analysis) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) EventTesting.newEvent(org.sonar.db.event.EventTesting.newEvent) Event(org.sonarqube.ws.ProjectAnalyses.Event) EventComponentChangeDto(org.sonar.db.event.EventComponentChangeDto) EventPurgeData(org.sonar.db.event.EventPurgeData) Test(org.junit.Test)

Example 4 with EventPurgeData

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();
}
Also used : EventComponentChangeDto(org.sonar.db.event.EventComponentChangeDto) EventPurgeData(org.sonar.db.event.EventPurgeData)

Example 5 with EventPurgeData

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()));
}
Also used : SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) Analysis(org.sonarqube.ws.ProjectAnalyses.Analysis) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) EventTesting.newEvent(org.sonar.db.event.EventTesting.newEvent) Event(org.sonarqube.ws.ProjectAnalyses.Event) EventComponentChangeDto(org.sonar.db.event.EventComponentChangeDto) EventPurgeData(org.sonar.db.event.EventPurgeData) Test(org.junit.Test)

Aggregations

EventComponentChangeDto (org.sonar.db.event.EventComponentChangeDto)5 EventPurgeData (org.sonar.db.event.EventPurgeData)5 Test (org.junit.Test)4 ComponentDto (org.sonar.db.component.ComponentDto)4 SnapshotDto (org.sonar.db.component.SnapshotDto)4 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)4 EventDto (org.sonar.db.event.EventDto)4 EventTesting.newEvent (org.sonar.db.event.EventTesting.newEvent)4 Analysis (org.sonarqube.ws.ProjectAnalyses.Analysis)4 Event (org.sonarqube.ws.ProjectAnalyses.Event)4