Search in sources :

Example 41 with QualityGateDto

use of org.sonar.db.qualitygate.QualityGateDto in project sonarqube by SonarSource.

the class RegisterQualityGatesTest method register_default_gate.

@Test
public void register_default_gate() {
    MetricDto newReliability = dbClient.metricDao().insert(dbSession, newMetricDto().setKey(NEW_RELIABILITY_RATING_KEY).setValueType(INT.name()).setHidden(false));
    MetricDto newSecurity = dbClient.metricDao().insert(dbSession, newMetricDto().setKey(NEW_SECURITY_RATING_KEY).setValueType(INT.name()).setHidden(false));
    MetricDto newMaintainability = dbClient.metricDao().insert(dbSession, newMetricDto().setKey(NEW_MAINTAINABILITY_RATING_KEY).setValueType(PERCENT.name()).setHidden(false));
    MetricDto newCoverage = dbClient.metricDao().insert(dbSession, newMetricDto().setKey(NEW_COVERAGE_KEY).setValueType(PERCENT.name()).setHidden(false));
    dbSession.commit();
    task.start();
    assertThat(dbClient.loadedTemplateDao().countByTypeAndKey("QUALITY_GATE", "SonarQube way", dbSession)).isEqualTo(1);
    QualityGateDto qualityGateDto = dbClient.qualityGateDao().selectByName(dbSession, "SonarQube way");
    assertThat(qualityGateDto).isNotNull();
    assertThat(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getId())).extracting(QualityGateConditionDto::getMetricId, QualityGateConditionDto::getOperator, QualityGateConditionDto::getWarningThreshold, QualityGateConditionDto::getErrorThreshold, QualityGateConditionDto::getPeriod).containsOnly(tuple(newReliability.getId().longValue(), OPERATOR_GREATER_THAN, null, "1", 1), tuple(newSecurity.getId().longValue(), OPERATOR_GREATER_THAN, null, "1", 1), tuple(newMaintainability.getId().longValue(), OPERATOR_GREATER_THAN, null, "1", 1), tuple(newCoverage.getId().longValue(), OPERATOR_LESS_THAN, null, "80", 1));
    verify(qualityGates).setDefault(any(DbSession.class), anyLong());
    task.stop();
}
Also used : DbSession(org.sonar.db.DbSession) MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) MetricDto(org.sonar.db.metric.MetricDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 42 with QualityGateDto

use of org.sonar.db.qualitygate.QualityGateDto in project sonarqube by SonarSource.

the class QualityGateFinderTest method return_default_quality_gate_for_project.

@Test
public void return_default_quality_gate_for_project() {
    ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization()));
    QualityGateDto dbQualityGate = dbTester.qualityGates().createDefaultQualityGate("Sonar way");
    Optional<QualityGateFinder.QualityGateData> result = underTest.getQualityGate(dbSession, project.getId());
    assertThat(result).isPresent();
    assertThat(result.get().getQualityGate().getId()).isEqualTo(dbQualityGate.getId());
    assertThat(result.get().isDefault()).isTrue();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 43 with QualityGateDto

use of org.sonar.db.qualitygate.QualityGateDto in project sonarqube by SonarSource.

the class QualityGateFinderTest method fail_when_project_qgate_defined_in_properties_does_not_exists.

@Test
public void fail_when_project_qgate_defined_in_properties_does_not_exists() throws Exception {
    ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization()));
    QualityGateDto dbQualityGate = dbTester.qualityGates().insertQualityGate("My team QG");
    dbTester.qualityGates().associateProjectToQualityGate(project, dbQualityGate);
    dbTester.getDbClient().qualityGateDao().delete(dbQualityGate, dbSession);
    expectedException.expect(NotFoundException.class);
    underTest.getQualityGate(dbSession, project.getId());
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 44 with QualityGateDto

use of org.sonar.db.qualitygate.QualityGateDto in project sonarqube by SonarSource.

the class QualityGateUpdaterTest method create_quality_gate.

@Test
public void create_quality_gate() throws Exception {
    QualityGateDto result = underTest.create(dbSession, QGATE_NAME);
    assertThat(result).isNotNull();
    assertThat(result.getName()).isEqualTo(QGATE_NAME);
    assertThat(result.getCreatedAt()).isNotNull();
    QualityGateDto reloaded = dbClient.qualityGateDao().selectByName(dbSession, QGATE_NAME);
    assertThat(reloaded).isNotNull();
}
Also used : QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 45 with QualityGateDto

use of org.sonar.db.qualitygate.QualityGateDto in project sonarqube by SonarSource.

the class GetByProjectActionTest method fail_when_insufficient_permission.

@Test
public void fail_when_insufficient_permission() {
    ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()));
    userSession.logIn();
    QualityGateDto dbQualityGate = insertQualityGate("Sonar way");
    setDefaultQualityGate(dbQualityGate.getId());
    expectedException.expect(ForbiddenException.class);
    callByUuid(project.uuid());
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Aggregations

QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)51 Test (org.junit.Test)33 ComponentDto (org.sonar.db.component.ComponentDto)12 DbSession (org.sonar.db.DbSession)6 PropertyDto (org.sonar.db.property.PropertyDto)6 GetByProjectWsResponse (org.sonarqube.ws.WsQualityGates.GetByProjectWsResponse)6 QualityGateConditionDto (org.sonar.db.qualitygate.QualityGateConditionDto)5 JsonWriter (org.sonar.api.utils.text.JsonWriter)4 OrganizationDto (org.sonar.db.organization.OrganizationDto)2 WsQualityGates (org.sonarqube.ws.WsQualityGates)2 CreateWsResponse (org.sonarqube.ws.WsQualityGates.CreateWsResponse)2 Matchers.anyString (org.mockito.Matchers.anyString)1 SnapshotDto (org.sonar.db.component.SnapshotDto)1 MetricDto (org.sonar.db.metric.MetricDto)1 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)1 UserDto (org.sonar.db.user.UserDto)1