private void assertNoTags(String projectKey) { assertThat(dbClient.componentDao().selectOrFailByKey(dbSession, projectKey).getTags()).isEmpty(); } }
@Override public QualityGate loadQualityGate(DbSession dbSession, OrganizationDto organization, ComponentDto project, BranchDto branch) { if (branch.getBranchType() == BranchType.SHORT || branch.getBranchType() == BranchType.PULL_REQUEST) { return ShortLivingBranchQualityGate.GATE; } ComponentDto mainProject = project.getMainBranchProjectUuid() == null ? project : dbClient.componentDao().selectOrFailByKey(dbSession, project.getKey()); QualityGateDto gateDto = qGateFinder.getQualityGate(dbSession, organization, mainProject) .orElseThrow(() -> new IllegalStateException(format("Quality Gate not found for project %s", mainProject.getKey()))) .getQualityGate(); Collection<QualityGateConditionDto> conditionDtos = dbClient.gateConditionDao().selectForQualityGate(dbSession, gateDto.getId()); Set<Integer> metricIds = conditionDtos.stream().map(c -> (int) c.getMetricId()) .collect(toHashSet(conditionDtos.size())); Map<Integer, MetricDto> metricsById = dbClient.metricDao().selectByIds(dbSession, metricIds).stream() .collect(uniqueIndex(MetricDto::getId)); Set<Condition> conditions = conditionDtos.stream().map(conditionDto -> { String metricKey = metricsById.get((int) conditionDto.getMetricId()).getKey(); Condition.Operator operator = Condition.Operator.fromDbValue(conditionDto.getOperator()); return new Condition(metricKey, operator, conditionDto.getErrorThreshold()); }).collect(toHashSet(conditionDtos.size())); return new QualityGate(String.valueOf(gateDto.getId()), gateDto.getName(), conditions); }
private void assertTags(String projectKey, String... tags) { assertThat(dbClient.componentDao().selectOrFailByKey(dbSession, projectKey).getTags()).containsExactlyInAnyOrder(tags); }
@Test public void get_by_key_on_a_root_project() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto result = underTest.selectOrFailByKey(dbSession, project.getDbKey()); assertThat(result.getDbKey()).isEqualTo(project.getDbKey()); assertThat(result.uuid()).isEqualTo(project.uuid()); assertThat(result.getUuidPath()).isEqualTo(project.getUuidPath()); assertThat(result.getRootUuid()).isEqualTo(project.uuid()); assertThat(result.projectUuid()).isEqualTo(project.uuid()); }
@Test public void get_by_key_on_disabled_component() { ComponentDto project = db.components().insertPrivateProject(p -> p.setEnabled(false)); ComponentDto result = underTest.selectOrFailByKey(dbSession, project.getDbKey()); assertThat(result.isEnabled()).isFalse(); }
@Test public void selectOrFailByKey_fails_when_component_not_found() { db.components().insertPrivateProject(); expectedException.expect(RowNotFoundException.class); underTest.selectOrFailByKey(dbSession, "unknown"); }
@Test public void update_tags() { ComponentDto project = db.components().insertPrivateProject(p -> p.setTags(emptyList())); underTest.updateTags(dbSession, project.setTags(newArrayList("finance", "toto", "tutu"))); dbSession.commit(); assertThat(underTest.selectOrFailByKey(dbSession, project.getDbKey()).getTags()).containsOnly("finance", "toto", "tutu"); }
assertThat(loaded.isPrivate()).isEqualTo(project.isPrivate()); assertThat(loaded.getCreatedAt()).isNotNull(); assertThat(db.getDbClient().componentDao().selectOrFailByKey(db.getSession(), DEFAULT_PROJECT_KEY)).isNotNull();
@Override public QualityGate loadQualityGate(DbSession dbSession, OrganizationDto organization, ComponentDto project, BranchDto branch) { if (branch.getBranchType() == BranchType.SHORT || branch.getBranchType() == BranchType.PULL_REQUEST) { return ShortLivingBranchQualityGate.GATE; } ComponentDto mainProject = project.getMainBranchProjectUuid() == null ? project : dbClient.componentDao().selectOrFailByKey(dbSession, project.getKey()); QualityGateDto gateDto = qGateFinder.getQualityGate(dbSession, organization, mainProject).getQualityGate(); Collection<QualityGateConditionDto> conditionDtos = dbClient.gateConditionDao().selectForQualityGate(dbSession, gateDto.getId()); Set<Integer> metricIds = conditionDtos.stream().map(c -> (int) c.getMetricId()) .collect(toHashSet(conditionDtos.size())); Map<Integer, MetricDto> metricsById = dbClient.metricDao().selectByIds(dbSession, metricIds).stream() .collect(uniqueIndex(MetricDto::getId)); Set<Condition> conditions = conditionDtos.stream().map(conditionDto -> { String metricKey = metricsById.get((int) conditionDto.getMetricId()).getKey(); Condition.Operator operator = Condition.Operator.fromDbValue(conditionDto.getOperator()); boolean onLeak = Objects.equals(conditionDto.getPeriod(), 1); return new Condition(metricKey, operator, conditionDto.getErrorThreshold(), conditionDto.getWarningThreshold(), onLeak); }).collect(toHashSet(conditionDtos.size())); return new QualityGate(String.valueOf(gateDto.getId()), gateDto.getName(), conditions); }