public void insert(DbSession session, List<AnalysisPropertyDto> analysisPropertyDto) { analysisPropertyDto.forEach(a -> insert(session, a)); }
private AnalysisPropertyDto insertAnalysisPropertyDto(int valueLength) { AnalysisPropertyDto analysisPropertyDto = newAnalysisPropertyDto(valueLength, randomAlphanumeric(40)); underTest.insert(dbSession, analysisPropertyDto); return 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])); }
private void insertPropertiesFor(String snapshotUuid, Map<String, String> properties) { List<AnalysisPropertyDto> analysisProperties = properties.entrySet().stream() .map(entry -> new AnalysisPropertyDto() .setUuid(UuidFactoryFast.getInstance().create()) .setSnapshotUuid(snapshotUuid) .setKey(entry.getKey()) .setValue(entry.getValue())) .collect(toArrayList(properties.size())); dbTester.getDbClient().analysisPropertiesDao().insert(dbTester.getSession(), analysisProperties); dbTester.getSession().commit(); }
@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)) { analysisPropertyDtos.add(new AnalysisPropertyDto() .setUuid(uuidFactory.create()) .setKey(propertyKey) .setValue(contextProperty.getValue()) .setSnapshotUuid(analysisMetadataHolder.getUuid())); } }); } analysisMetadataHolder.getScmRevisionId().ifPresent(scmRevisionId -> analysisPropertyDtos.add(new AnalysisPropertyDto() .setUuid(uuidFactory.create()) .setKey(SCM_REVISION_ID) .setValue(scmRevisionId) .setSnapshotUuid(analysisMetadataHolder.getUuid()))); if (analysisPropertyDtos.isEmpty()) { return; } try (DbSession dbSession = dbClient.openSession(false)) { dbClient.analysisPropertiesDao().insert(dbSession, analysisPropertyDtos); dbSession.commit(); } }
@Test public void insert_a_list() { List<AnalysisPropertyDto> propertyDtos = Arrays.asList( newAnalysisPropertyDto(random.nextInt(8000), randomAlphanumeric(40)), newAnalysisPropertyDto(random.nextInt(8000), randomAlphanumeric(40)), newAnalysisPropertyDto(random.nextInt(8000), randomAlphanumeric(40)), newAnalysisPropertyDto(random.nextInt(8000), randomAlphanumeric(40)), newAnalysisPropertyDto(random.nextInt(8000), randomAlphanumeric(40)), newAnalysisPropertyDto(random.nextInt(8000), randomAlphanumeric(40)), newAnalysisPropertyDto(random.nextInt(8000), randomAlphanumeric(40)), newAnalysisPropertyDto(random.nextInt(8000), randomAlphanumeric(40))); underTest.insert(dbSession, propertyDtos); assertThat(dbTester.countRowsOfTable(dbSession, "ANALYSIS_PROPERTIES")).isEqualTo(propertyDtos.size()); }
@Test public void insert_with_null_uuid_throws_NPE() { AnalysisPropertyDto analysisPropertyDto = new AnalysisPropertyDto() .setSnapshotUuid(randomAlphanumeric(10)) .setKey(randomAlphanumeric(10)) .setValue(randomAlphanumeric(10)); expectedException.expect(NullPointerException.class); expectedException.expectMessage("uuid cannot be null"); underTest.insert(dbSession, analysisPropertyDto); }
@Test public void insert_with_null_snapshot_uuid_throws_NPE() { AnalysisPropertyDto analysisPropertyDto = new AnalysisPropertyDto() .setUuid(randomAlphanumeric(10)) .setKey(randomAlphanumeric(10)) .setValue(randomAlphanumeric(10)); expectedException.expect(NullPointerException.class); expectedException.expectMessage("snapshot uuid cannot be null"); underTest.insert(dbSession, analysisPropertyDto); }
@Test public void insert_with_null_key_throws_NPE() { AnalysisPropertyDto analysisPropertyDto = new AnalysisPropertyDto() .setSnapshotUuid(randomAlphanumeric(10)) .setUuid(randomAlphanumeric(10)) .setValue(randomAlphanumeric(10)); expectedException.expect(NullPointerException.class); expectedException.expectMessage("key cannot be null"); underTest.insert(dbSession, analysisPropertyDto); }
@Test public void insert_with_null_value_throws_NPE() { AnalysisPropertyDto analysisPropertyDto = new AnalysisPropertyDto() .setSnapshotUuid(randomAlphanumeric(10)) .setUuid(randomAlphanumeric(10)) .setKey(randomAlphanumeric(10)); expectedException.expect(NullPointerException.class); expectedException.expectMessage("value cannot be null"); underTest.insert(dbSession, analysisPropertyDto); }
@Override public void execute() { final List<AnalysisPropertyDto> analysisPropertyDtos = new ArrayList<>(); reportReader.readContextProperties().forEachRemaining( contextProperty -> { String propertyKey = contextProperty.getKey(); if (propertyKey.startsWith(SONAR_ANALYSIS) || propertyKey.startsWith(SONAR_PULL_REQUEST)) { analysisPropertyDtos.add(new AnalysisPropertyDto() .setUuid(uuidFactory.create()) .setKey(propertyKey) .setValue(contextProperty.getValue()) .setSnapshotUuid(analysisMetadataHolder.getUuid())); } }); if (analysisPropertyDtos.isEmpty()) { return; } try (DbSession dbSession = dbClient.openSession(false)) { dbClient.analysisPropertiesDao().insert(dbSession, analysisPropertyDtos); dbSession.commit(); } }