Search in sources :

Example 26 with QualityGateDto

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

the class QualityGatesTest method should_get_qgate_by_name.

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

Example 27 with QualityGateDto

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

the class QualityGatesTest method should_return_default_qgate_if_set.

@Test
public void should_return_default_qgate_if_set() {
    String defaultName = "Sonar way";
    long defaultId = QUALITY_GATE_ID;
    when(propertiesDao.selectGlobalProperty("sonar.qualitygate")).thenReturn(new PropertyDto().setValue(Long.toString(defaultId)));
    QualityGateDto defaultQgate = new QualityGateDto().setId(defaultId).setName(defaultName);
    when(dao.selectById(dbSession, defaultId)).thenReturn(defaultQgate);
    assertThat(underTest.getDefault()).isEqualTo(defaultQgate);
}
Also used : PropertyDto(org.sonar.db.property.PropertyDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 28 with QualityGateDto

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

the class QualityGatesTest method should_delete_qgate.

@Test
public void should_delete_qgate() {
    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(dbClient.openSession(false)).thenReturn(dbSession);
    underTest.delete(idToDelete);
    verify(dao).selectById(dbSession, idToDelete);
    verify(propertiesDao).deleteProjectProperties("sonar.qualitygate", "42", dbSession);
    verify(dao).delete(toDelete, dbSession);
}
Also used : QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 29 with QualityGateDto

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

the class ComponentActionTest method test_example_response.

@Test
public void test_example_response() throws Exception {
    init(createPages());
    OrganizationDto organizationDto = dbTester.organizations().insertForKey("my-org-1");
    ComponentDto project = newProjectDto(organizationDto, "ABCD").setKey("org.codehaus.sonar:sonar").setName("Sonarqube").setDescription("Open source platform for continuous inspection of code quality");
    componentDbTester.insertComponent(project);
    SnapshotDto analysis = newAnalysis(project).setCreatedAt(DateUtils.parseDateTime("2016-12-06T11:44:00+0200").getTime()).setVersion("6.3").setLast(true);
    componentDbTester.insertSnapshot(analysis);
    when(resourceTypes.get(project.qualifier())).thenReturn(DefaultResourceTypes.get().getRootType());
    UserDto user = dbTester.users().insertUser("obiwan");
    propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(user.getId()));
    addQualityProfiles(project, analysis, createQProfile("qp1", "Sonar Way Java", "java"), createQProfile("qp2", "Sonar Way Xoo", "xoo"));
    QualityGateDto qualityGateDto = dbTester.qualityGates().insertQualityGate("Sonar way");
    dbTester.qualityGates().associateProjectToQualityGate(project, qualityGateDto);
    userSession.logIn(user).addProjectUuidPermissions(UserRole.USER, project.uuid()).addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
    String result = execute(project.key());
    assertJson(result).ignoreFields("snapshotDate", "key", "qualityGate.key").isSimilarTo(ws.getDef().responseExampleAsString());
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) Matchers.anyString(org.mockito.Matchers.anyString) OrganizationDto(org.sonar.db.organization.OrganizationDto) PropertyDto(org.sonar.db.property.PropertyDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 30 with QualityGateDto

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

the class CreateAction method handle.

@Override
public void handle(Request request, Response response) {
    userSession.checkPermission(OrganizationPermission.ADMINISTER_QUALITY_GATES, defaultOrganizationProvider.get().getUuid());
    try (DbSession dbSession = dbClient.openSession(false)) {
        QualityGateDto newQualityGate = qualityGateUpdater.create(dbSession, request.mandatoryParam(PARAM_NAME));
        CreateWsResponse.Builder createWsResponse = CreateWsResponse.newBuilder().setId(newQualityGate.getId()).setName(newQualityGate.getName());
        writeProtobuf(createWsResponse.build(), request, response);
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) CreateWsResponse(org.sonarqube.ws.WsQualityGates.CreateWsResponse)

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