Search in sources :

Example 36 with QualityGateDto

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

the class QualityGatesTest method should_get_qgate_by_id.

@Test
public void should_get_qgate_by_id() {
    long id = QUALITY_GATE_ID;
    final String name = "Golden";
    QualityGateDto existing = new QualityGateDto().setId(id).setName(name);
    when(dao.selectById(dbSession, id)).thenReturn(existing);
    assertThat(underTest.get(id)).isEqualTo(existing);
    verify(dao).selectById(dbSession, id);
}
Also used : QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 37 with QualityGateDto

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

the class QualityGatesTest method should_allow_rename_with_same_name.

@Test
public void should_allow_rename_with_same_name() {
    long id = QUALITY_GATE_ID;
    String name = "SG-1";
    QualityGateDto existing = new QualityGateDto().setId(id).setName(name);
    when(dao.selectById(dbSession, id)).thenReturn(existing);
    QualityGateDto sg1 = underTest.rename(id, name);
    assertThat(sg1.getName()).isEqualTo(name);
    verify(dao).selectById(dbSession, id);
    verify(dao).selectByName(dbSession, name);
    verify(dao).update(sg1, dbSession);
}
Also used : QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 38 with QualityGateDto

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

the class QualityGatesTest method should_copy_qgate.

@Test
public void should_copy_qgate() {
    String name = "Atlantis";
    long sourceId = QUALITY_GATE_ID;
    final long destId = 43L;
    long metric1Id = 1L;
    long metric2Id = 2L;
    QualityGateConditionDto cond1 = new QualityGateConditionDto().setMetricId(metric1Id);
    QualityGateConditionDto cond2 = new QualityGateConditionDto().setMetricId(metric2Id);
    Collection<QualityGateConditionDto> conditions = ImmutableList.of(cond1, cond2);
    when(dao.selectById(dbSession, sourceId)).thenReturn(new QualityGateDto().setId(sourceId).setName("SG-1"));
    Mockito.doAnswer(invocation -> {
        ((QualityGateDto) invocation.getArguments()[1]).setId(destId);
        return null;
    }).when(dao).insert(eq(dbSession), any(QualityGateDto.class));
    when(conditionDao.selectForQualityGate(eq(dbSession), anyLong())).thenReturn(conditions);
    QualityGateDto atlantis = underTest.copy(sourceId, name);
    assertThat(atlantis.getName()).isEqualTo(name);
    verify(dao).selectByName(dbSession, name);
    verify(dao).insert(dbSession, atlantis);
    verify(conditionDao).selectForQualityGate(eq(dbSession), anyLong());
    verify(conditionDao, times(conditions.size())).insert(any(QualityGateConditionDto.class), eq(dbSession));
}
Also used : QualityGateConditionDto(org.sonar.db.qualitygate.QualityGateConditionDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 39 with QualityGateDto

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

the class QualityGatesTest method should_delete_qgate_even_if_default.

@Test
public void should_delete_qgate_even_if_default() {
    long idToDelete = QUALITY_GATE_ID;
    String name = "To Delete";
    QualityGateDto toDelete = new QualityGateDto().setId(idToDelete).setName(name);
    when(dao.selectById(dbSession, idToDelete)).thenReturn(toDelete);
    when(propertiesDao.selectGlobalProperty("sonar.qualitygate")).thenReturn(new PropertyDto().setValue("42"));
    when(dbClient.openSession(false)).thenReturn(dbSession);
    underTest.delete(idToDelete);
    verify(dao).selectById(dbSession, idToDelete);
    verify(propertiesDao).deleteGlobalProperty("sonar.qualitygate", dbSession);
    verify(propertiesDao).deleteProjectProperties("sonar.qualitygate", "42", dbSession);
    verify(dao).delete(toDelete, dbSession);
}
Also used : QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) PropertyDto(org.sonar.db.property.PropertyDto) Test(org.junit.Test)

Example 40 with QualityGateDto

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

the class QualityGatesTest method should_rename_qgate.

@Test
public void should_rename_qgate() {
    long id = QUALITY_GATE_ID;
    String name = "SG-1";
    QualityGateDto existing = new QualityGateDto().setId(id).setName("Golden");
    when(dao.selectById(dbSession, id)).thenReturn(existing);
    QualityGateDto sg1 = underTest.rename(id, name);
    assertThat(sg1.getName()).isEqualTo(name);
    verify(dao).selectById(dbSession, id);
    verify(dao).selectByName(dbSession, name);
    verify(dao).update(sg1, dbSession);
}
Also used : 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