private void compareFirstValueWith(AnalysisPropertyDto analysisPropertyDto) { AnalysisPropertyDto dtoFromDatabase = underTest.selectBySnapshotUuid(dbSession, analysisPropertyDto.getSnapshotUuid()).get(0); assertThat(dtoFromDatabase).isEqualTo(analysisPropertyDto); } }
@Test public void selectByAnalysisUuid_should_return_correct_values() { String snapshotUuid = randomAlphanumeric(40); List<AnalysisPropertyDto> propertyDtos = Arrays.asList( newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid), newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid), newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid), newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid), newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid), newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid), newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid), newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid)); underTest.insert(dbSession, propertyDtos); assertThat(dbTester.countRowsOfTable(dbSession, "ANALYSIS_PROPERTIES")).isEqualTo(propertyDtos.size()); List<AnalysisPropertyDto> result = underTest.selectBySnapshotUuid(dbSession, snapshotUuid); assertThat(result).containsExactlyInAnyOrder(propertyDtos.toArray(new AnalysisPropertyDto[0])); }
@Test public void persist_should_only_store_scmRevisionId_if_there_is_no_context_properties() { when(analysisMetadataHolder.getScmRevisionId()).thenReturn(Optional.of(SCM_REV_ID)); when(batchReportReader.readContextProperties()).thenReturn(CloseableIterator.emptyCloseableIterator()); when(analysisMetadataHolder.getUuid()).thenReturn(SNAPSHOT_UUID); underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("analysis_properties")).isEqualTo(1); List<AnalysisPropertyDto> propertyDtos = dbTester.getDbClient() .analysisPropertiesDao().selectBySnapshotUuid(dbTester.getSession(), SNAPSHOT_UUID); assertThat(propertyDtos) .extracting(AnalysisPropertyDto::getSnapshotUuid, AnalysisPropertyDto::getKey, AnalysisPropertyDto::getValue) .containsExactlyInAnyOrder(tuple(SNAPSHOT_UUID, "sonar.analysis.scm_revision_id", SCM_REV_ID)); }
private WebhookPayload buildWebHookPayload(DbSession dbSession, QGChangeEvent event, @Nullable EvaluatedQualityGate evaluatedQualityGate) { ComponentDto project = event.getProject(); BranchDto branch = event.getBranch(); SnapshotDto analysis = event.getAnalysis(); Map<String, String> analysisProperties = dbClient.analysisPropertiesDao().selectBySnapshotUuid(dbSession, analysis.getUuid()) .stream() .collect(Collectors.toMap(AnalysisPropertyDto::getKey, AnalysisPropertyDto::getValue)); String projectUuid = StringUtils.defaultString(project.getMainBranchProjectUuid(), project.projectUuid()); ProjectAnalysis projectAnalysis = new ProjectAnalysis( new Project(projectUuid, project.getKey(), project.name()), null, new Analysis(analysis.getUuid(), analysis.getCreatedAt()), new Branch(branch.isMain(), branch.getKey(), Type.valueOf(branch.getBranchType().name())), evaluatedQualityGate, null, analysisProperties); return webhookPayloadFactory.create(projectAnalysis); }
@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.getScmRevisionId()).thenReturn(Optional.of(SCM_REV_ID)); underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("analysis_properties")).isEqualTo(9); List<AnalysisPropertyDto> propertyDtos = dbTester.getDbClient() .analysisPropertiesDao().selectBySnapshotUuid(dbTester.getSession(), SNAPSHOT_UUID); assertThat(propertyDtos) .extracting(AnalysisPropertyDto::getSnapshotUuid, 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.analysis.scm_revision_id", SCM_REV_ID), 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)); }
@Test public void persist_should_not_stores_sonarDotAnalysisDotscm_revision_id_properties_when_its_not_available_in_report_metada() { when(batchReportReader.readContextProperties()).thenReturn(CloseableIterator.from(PROPERTIES.iterator())); when(analysisMetadataHolder.getUuid()).thenReturn(SNAPSHOT_UUID); when(analysisMetadataHolder.getScmRevisionId()).thenReturn(Optional.empty()); underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("analysis_properties")).isEqualTo(8); List<AnalysisPropertyDto> propertyDtos = dbTester.getDbClient() .analysisPropertiesDao().selectBySnapshotUuid(dbTester.getSession(), SNAPSHOT_UUID); assertThat(propertyDtos) .extracting(AnalysisPropertyDto::getSnapshotUuid, 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)); }
private WebhookPayload buildWebHookPayload(DbSession dbSession, QGChangeEvent event, @Nullable EvaluatedQualityGate evaluatedQualityGate) { ComponentDto project = event.getProject(); BranchDto branch = event.getBranch(); SnapshotDto analysis = event.getAnalysis(); Map<String, String> analysisProperties = dbClient.analysisPropertiesDao().selectBySnapshotUuid(dbSession, analysis.getUuid()) .stream() .collect(Collectors.toMap(AnalysisPropertyDto::getKey, AnalysisPropertyDto::getValue)); String projectUuid = StringUtils.defaultString(project.getMainBranchProjectUuid(), project.projectUuid()); ProjectAnalysis projectAnalysis = new ProjectAnalysis( new Project(projectUuid, project.getKey(), project.name()), null, new Analysis(analysis.getUuid(), analysis.getCreatedAt()), new Branch(branch.isMain(), branch.getKey(), Type.valueOf(branch.getBranchType().name())), evaluatedQualityGate, null, analysisProperties); return webhookPayloadFactory.create(projectAnalysis); }