Search in sources :

Example 6 with EventComponentChangeDto

use of org.sonar.db.event.EventComponentChangeDto in project sonarqube by SonarSource.

the class SearchActionTest method json_example.

@Test
public void json_example() {
    ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setDbKey(KEY_PROJECT_EXAMPLE_001));
    userSession.addProjectPermission(UserRole.USER, project);
    SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(parseDateTime("2016-12-11T17:12:45+0100").getTime()).setProjectVersion("1.2").setBuildString("1.2.0.322").setRevision("bfe36592eb7f9f2708b5d358b5b5f33ed535c8cf"));
    SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(parseDateTime("2016-12-12T17:12:45+0100").getTime()).setProjectVersion("1.2.1").setBuildString("1.2.1.423").setRevision("be6c75b85da526349c44e3978374c95e0b80a96d"));
    SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(project).setUuid("P1").setCreatedAt(parseDateTime("2015-11-11T10:00:00+0100").getTime()).setProjectVersion("1.2").setBuildString("1.2.0.321"));
    db.getDbClient().analysisPropertiesDao().insert(db.getSession(), new AnalysisPropertyDto().setUuid("P1-prop-uuid").setAnalysisUuid(a3.getUuid()).setKey(CorePropertyDefinitions.SONAR_ANALYSIS_DETECTEDCI).setValue("Jenkins").setCreatedAt(1L));
    BranchDto branchDto = newBranchDto(project, BRANCH);
    db.getDbClient().branchDao().insert(db.getSession(), branchDto);
    db.newCodePeriods().insert(new NewCodePeriodDto().setProjectUuid(project.uuid()).setBranchUuid(branchDto.getUuid()).setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue(a1.getUuid()));
    db.commit();
    db.events().insertEvent(newEvent(a1).setUuid("AXt91FkXy_c4CIP4ds6A").setName("Failed").setCategory(QUALITY_GATE.getLabel()).setDescription("Coverage on New Code < 85, Reliability Rating > 4, Maintainability Rating on New Code > 1, Reliability Rating on New Code > 1, Security Rating on New Code > 1, Duplicated Lines (%) on New Code > 3"));
    db.events().insertEvent(newEvent(a1).setUuid("AXx_QFJ6Wa8wkfuJ6r5P").setName("6.3").setCategory(VERSION.getLabel()));
    db.events().insertEvent(newEvent(a2).setUuid("E21").setName("Quality Profile changed to Sonar Way").setCategory(EventCategory.QUALITY_PROFILE.getLabel()));
    db.events().insertEvent(newEvent(a2).setUuid("E22").setName("6.3").setCategory(OTHER.getLabel()));
    EventDto eventDto = db.events().insertEvent(newEvent(a3).setUuid("E31").setName("Quality Gate is Red").setData("{stillFailing: true, status: \"ERROR\"}").setCategory(CATEGORY_ALERT).setDescription(""));
    EventComponentChangeDto changeDto1 = generateEventComponentChange(eventDto, FAILED_QUALITY_GATE, "My project", "app1", "master", project.uuid());
    EventComponentChangeDto changeDto2 = generateEventComponentChange(eventDto, FAILED_QUALITY_GATE, "Another project", "app2", "master", uuidFactoryFast.create());
    insertEventComponentChanges(project, a3, changeDto1, changeDto2);
    String result = ws.newRequest().setParam(PARAM_PROJECT, KEY_PROJECT_EXAMPLE_001).execute().getInput();
    assertJson(result).isSimilarTo(getClass().getResource("search-example.json"));
}
Also used : AnalysisPropertyDto(org.sonar.db.component.AnalysisPropertyDto) BranchDto(org.sonar.db.component.BranchDto) ComponentTesting.newBranchDto(org.sonar.db.component.ComponentTesting.newBranchDto) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) EventComponentChangeDto(org.sonar.db.event.EventComponentChangeDto) Test(org.junit.Test)

Example 7 with EventComponentChangeDto

use of org.sonar.db.event.EventComponentChangeDto 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 8 with EventComponentChangeDto

use of org.sonar.db.event.EventComponentChangeDto 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 9 with EventComponentChangeDto

use of org.sonar.db.event.EventComponentChangeDto in project sonarqube by SonarSource.

the class SearchActionTest method application_definition_change_with_branch.

@Test
@UseDataProvider("changedBranches")
public void application_definition_change_with_branch(@Nullable String oldBranch, @Nullable String newBranch) {
    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, REMOVED, "My project", "app1", oldBranch, uuidFactoryFast.create());
    EventComponentChangeDto changeDto2 = generateEventComponentChange(event, ADDED, "My project", "app1", newBranch, changeDto1.getComponentUuid());
    insertEventComponentChanges(application, firstAnalysis, changeDto1, changeDto2);
    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()).extracting(Project::getChangeType, Project::getKey, Project::getName, Project::getNewBranch, Project::getOldBranch).containsExactly(tuple("BRANCH_CHANGED", "app1", "My project", newBranch == null ? "" : newBranch, oldBranch == null ? "" : oldBranch));
}
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) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 10 with EventComponentChangeDto

use of org.sonar.db.event.EventComponentChangeDto 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)10 SnapshotDto (org.sonar.db.component.SnapshotDto)8 EventDto (org.sonar.db.event.EventDto)8 Test (org.junit.Test)7 ComponentDto (org.sonar.db.component.ComponentDto)7 Analysis (org.sonarqube.ws.ProjectAnalyses.Analysis)7 Event (org.sonarqube.ws.ProjectAnalyses.Event)7 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)6 EventTesting.newEvent (org.sonar.db.event.EventTesting.newEvent)6 EventPurgeData (org.sonar.db.event.EventPurgeData)5 Gson (com.google.gson.Gson)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 ListMultimap (com.google.common.collect.ListMultimap)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 String.format (java.lang.String.format)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Optional (java.util.Optional)1 Optional.ofNullable (java.util.Optional.ofNullable)1