Search in sources :

Example 21 with PropertyDto

use of org.sonar.db.property.PropertyDto 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)

Example 22 with PropertyDto

use of org.sonar.db.property.PropertyDto in project sonarqube by SonarSource.

the class QualityGatesTest method should_delete_qgate_if_non_default.

@Test
public void should_delete_qgate_if_non_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("666"));
    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) PropertyDto(org.sonar.db.property.PropertyDto) Test(org.junit.Test)

Example 23 with PropertyDto

use of org.sonar.db.property.PropertyDto 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 24 with PropertyDto

use of org.sonar.db.property.PropertyDto in project sonarqube by SonarSource.

the class SetActionTest method assertComponentSetting.

private void assertComponentSetting(String key, String value, long componentId) {
    PropertyDto result = dbClient.propertiesDao().selectProjectProperty(componentId, key);
    assertThat(result).extracting(PropertyDto::getKey, PropertyDto::getValue, PropertyDto::getResourceId).containsExactly(key, value, componentId);
}
Also used : PropertyTesting.newComponentPropertyDto(org.sonar.db.property.PropertyTesting.newComponentPropertyDto) PropertyTesting.newGlobalPropertyDto(org.sonar.db.property.PropertyTesting.newGlobalPropertyDto) PropertyDto(org.sonar.db.property.PropertyDto)

Example 25 with PropertyDto

use of org.sonar.db.property.PropertyDto 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)

Aggregations

PropertyDto (org.sonar.db.property.PropertyDto)57 Test (org.junit.Test)25 ComponentDto (org.sonar.db.component.ComponentDto)23 OrganizationDto (org.sonar.db.organization.OrganizationDto)13 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)13 DbSession (org.sonar.db.DbSession)8 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)6 MapSettings (org.sonar.api.config.MapSettings)3 Settings (org.sonar.api.config.Settings)3 PropertyTesting.newComponentPropertyDto (org.sonar.db.property.PropertyTesting.newComponentPropertyDto)2 PropertyTesting.newGlobalPropertyDto (org.sonar.db.property.PropertyTesting.newGlobalPropertyDto)2 UserDto (org.sonar.db.user.UserDto)2 Date (java.util.Date)1 Matchers.anyString (org.mockito.Matchers.anyString)1 PropertyDefinition (org.sonar.api.config.PropertyDefinition)1 FilePathWithHashDto (org.sonar.db.component.FilePathWithHashDto)1 SnapshotDto (org.sonar.db.component.SnapshotDto)1 PropertyQuery (org.sonar.db.property.PropertyQuery)1 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)1 TestResponse (org.sonar.server.ws.TestResponse)1