Search in sources :

Example 21 with QualityGateDto

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

the class GetByProjectActionTest method insertQualityGate.

private QualityGateDto insertQualityGate(String name) {
    QualityGateDto qualityGate = dbClient.qualityGateDao().insert(dbSession, new QualityGateDto().setName(name));
    db.commit();
    return qualityGate;
}
Also used : QualityGateDto(org.sonar.db.qualitygate.QualityGateDto)

Example 22 with QualityGateDto

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

the class GetByProjectActionTest method get_with_project_admin_permission.

@Test
public void get_with_project_admin_permission() {
    ComponentDto project = componentDb.insertProject();
    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
    QualityGateDto dbQualityGate = insertQualityGate("Sonar way");
    setDefaultQualityGate(dbQualityGate.getId());
    GetByProjectWsResponse result = callByUuid(project.uuid());
    assertThat(result.getQualityGate().getName()).isEqualTo(dbQualityGate.getName());
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) GetByProjectWsResponse(org.sonarqube.ws.WsQualityGates.GetByProjectWsResponse) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 23 with QualityGateDto

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

the class QualityGateFinderTest method fail_when_default_qgate_defined_in_properties_does_not_exists.

@Test
public void fail_when_default_qgate_defined_in_properties_does_not_exists() throws Exception {
    ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.organizations().insert()));
    QualityGateDto dbQualityGate = dbTester.qualityGates().createDefaultQualityGate("Sonar way");
    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 24 with QualityGateDto

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

the class QualityGateFinderTest method return_project_quality_gate_over_default.

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

Example 25 with QualityGateDto

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

the class QualityGatesTest method should_select_default_qgate.

@Test
public void should_select_default_qgate() {
    long defaultId = QUALITY_GATE_ID;
    String defaultName = "Default Name";
    when(dao.selectById(dbSession, defaultId)).thenReturn(new QualityGateDto().setId(defaultId).setName(defaultName));
    underTest.setDefault(defaultId);
    verify(dao).selectById(dbSession, defaultId);
    ArgumentCaptor<PropertyDto> propertyCaptor = ArgumentCaptor.forClass(PropertyDto.class);
    verify(propertiesDao).saveProperty(any(DbSession.class), propertyCaptor.capture());
    assertThat(propertyCaptor.getValue().getKey()).isEqualTo("sonar.qualitygate");
    assertThat(propertyCaptor.getValue().getValue()).isEqualTo("42");
}
Also used : DbSession(org.sonar.db.DbSession) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) PropertyDto(org.sonar.db.property.PropertyDto) 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