Search in sources :

Example 1 with AnalysisPropertyDto

use of org.sonar.db.component.AnalysisPropertyDto in project sonarqube by SonarSource.

the class PersistAnalysisPropertiesStepTest method persist_should_stores_sonarDotAnalysisDot_and_sonarDotPullRequestDot_properties.

@Test
public void persist_should_stores_sonarDotAnalysisDot_and_sonarDotPullRequestDot_properties() {
    when(batchReportReader.readContextProperties()).thenReturn(CloseableIterator.from(PROPERTIES.iterator()));
    when(analysisMetadataHolder.getUuid()).thenReturn(SNAPSHOT_UUID);
    when(analysisMetadataHolder.getScmRevision()).thenReturn(Optional.of(SCM_REV_ID));
    underTest.execute(new TestComputationStepContext());
    assertThat(dbTester.countRowsOfTable("analysis_properties")).isEqualTo(8);
    List<AnalysisPropertyDto> propertyDtos = dbTester.getDbClient().analysisPropertiesDao().selectByAnalysisUuid(dbTester.getSession(), SNAPSHOT_UUID);
    assertThat(propertyDtos).extracting(AnalysisPropertyDto::getAnalysisUuid, AnalysisPropertyDto::getKey, AnalysisPropertyDto::getValue).containsExactlyInAnyOrder(tuple(SNAPSHOT_UUID, "sonar.analysis.branch", SMALL_VALUE2), tuple(SNAPSHOT_UUID, "sonar.analysis.empty_string", ""), tuple(SNAPSHOT_UUID, "sonar.analysis.big_value", BIG_VALUE), tuple(SNAPSHOT_UUID, "sonar.analysis.", SMALL_VALUE3), tuple(SNAPSHOT_UUID, "sonar.pullrequest.branch", VALUE_PREFIX_FOR_PR_PROPERTIES + SMALL_VALUE2), tuple(SNAPSHOT_UUID, "sonar.pullrequest.empty_string", ""), tuple(SNAPSHOT_UUID, "sonar.pullrequest.big_value", VALUE_PREFIX_FOR_PR_PROPERTIES + BIG_VALUE), tuple(SNAPSHOT_UUID, "sonar.pullrequest.", VALUE_PREFIX_FOR_PR_PROPERTIES + SMALL_VALUE3));
}
Also used : AnalysisPropertyDto(org.sonar.db.component.AnalysisPropertyDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 2 with AnalysisPropertyDto

use of org.sonar.db.component.AnalysisPropertyDto in project sonarqube by SonarSource.

the class PersistAnalysisPropertiesStep method execute.

@Override
public void execute(ComputationStep.Context context) {
    List<AnalysisPropertyDto> analysisPropertyDtos = new ArrayList<>();
    try (CloseableIterator<ScannerReport.ContextProperty> it = reportReader.readContextProperties()) {
        it.forEachRemaining(contextProperty -> {
            String propertyKey = contextProperty.getKey();
            if (propertyKey.startsWith(SONAR_ANALYSIS) || propertyKey.startsWith(SONAR_PULL_REQUEST) || ANALYSIS_PROPERTIES_TO_PERSIST.contains(propertyKey)) {
                analysisPropertyDtos.add(new AnalysisPropertyDto().setUuid(uuidFactory.create()).setKey(propertyKey).setValue(contextProperty.getValue()).setAnalysisUuid(analysisMetadataHolder.getUuid()));
            }
        });
    }
    if (analysisPropertyDtos.isEmpty()) {
        return;
    }
    try (DbSession dbSession = dbClient.openSession(false)) {
        dbClient.analysisPropertiesDao().insert(dbSession, analysisPropertyDtos);
        dbSession.commit();
    }
}
Also used : AnalysisPropertyDto(org.sonar.db.component.AnalysisPropertyDto) DbSession(org.sonar.db.DbSession) ArrayList(java.util.ArrayList)

Example 3 with AnalysisPropertyDto

use of org.sonar.db.component.AnalysisPropertyDto 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)

Aggregations

AnalysisPropertyDto (org.sonar.db.component.AnalysisPropertyDto)3 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)1 DbSession (org.sonar.db.DbSession)1 BranchDto (org.sonar.db.component.BranchDto)1 ComponentDto (org.sonar.db.component.ComponentDto)1 ComponentTesting.newBranchDto (org.sonar.db.component.ComponentTesting.newBranchDto)1 SnapshotDto (org.sonar.db.component.SnapshotDto)1 EventComponentChangeDto (org.sonar.db.event.EventComponentChangeDto)1 EventDto (org.sonar.db.event.EventDto)1 NewCodePeriodDto (org.sonar.db.newcodeperiod.NewCodePeriodDto)1