Search in sources :

Example 31 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerIteratorTest method does_not_return_non_active_projects.

@Test
public void does_not_return_non_active_projects() throws Exception {
    // Disabled project
    dbTester.components().insertProjectAndSnapshot(newProjectDto(dbTester.getDefaultOrganization()).setEnabled(false));
    // Disabled project with analysis
    ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization()).setEnabled(false));
    dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
    // A view
    dbTester.components().insertProjectAndSnapshot(newView(dbTester.getDefaultOrganization()));
    // A developer
    dbTester.components().insertProjectAndSnapshot(newDeveloper(dbTester.getDefaultOrganization(), "dev"));
    dbSession.commit();
    assertResultSetIsEmpty();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 32 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerIteratorTest method return_language_distribution_measure.

@Test
public void return_language_distribution_measure() throws Exception {
    MetricDto metric = insertMetric("ncloc_language_distribution", DATA);
    ComponentDto project = newProjectDto(dbTester.getDefaultOrganization());
    SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
    insertMeasure(project, analysis, metric, "<null>=2;java=6;xoo=18");
    Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
    assertThat(docsById.get(project.uuid()).getMeasures().getLanguages()).containsOnly("<null>", "java", "xoo");
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ProjectMeasures(org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 33 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class PropertiesDaoTest method shouldFindUsersForNotification.

@Test
public void shouldFindUsersForNotification() throws SQLException {
    ComponentDto project1 = insertProject("uuid_45");
    ComponentDto project2 = insertProject("uuid_56");
    int userId1 = insertUser("user1");
    int userId2 = insertUser("user2");
    int userId3 = insertUser("user3");
    insertProperty("notification.NewViolations.Email", "true", project1.getId(), userId2);
    insertProperty("notification.NewViolations.Twitter", "true", null, userId3);
    insertProperty("notification.NewViolations.Twitter", "true", project2.getId(), userId1);
    insertProperty("notification.NewViolations.Twitter", "true", project2.getId(), userId3);
    assertThat(underTest.selectUsersForNotification("NewViolations", "Email", null)).isEmpty();
    assertThat(underTest.selectUsersForNotification("NewViolations", "Email", "uuid_78")).isEmpty();
    assertThat(underTest.selectUsersForNotification("NewViolations", "Email", "uuid_45")).hasSize(1).containsOnly("user2");
    assertThat(underTest.selectUsersForNotification("NewViolations", "Twitter", null)).hasSize(1).containsOnly("user3");
    assertThat(underTest.selectUsersForNotification("NewViolations", "Twitter", "uuid_78")).isEmpty();
    assertThat(underTest.selectUsersForNotification("NewViolations", "Twitter", "uuid_56")).hasSize(2).containsOnly("user1", "user3");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 34 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class PropertiesDaoTest method select_properties_by_keys_and_component_ids.

@Test
public void select_properties_by_keys_and_component_ids() throws Exception {
    ComponentDto project = dbTester.components().insertProject();
    ComponentDto project2 = dbTester.components().insertProject();
    UserDto user = UserTesting.newUserDto();
    dbClient.userDao().insert(session, user);
    String key = "key";
    String anotherKey = "anotherKey";
    insertProperties(newGlobalPropertyDto().setKey(key), newComponentPropertyDto(project).setKey(key), newComponentPropertyDto(project2).setKey(key), newComponentPropertyDto(project2).setKey(anotherKey), newUserPropertyDto(user).setKey(key));
    assertThat(underTest.selectPropertiesByKeysAndComponentIds(session, newHashSet(key), newHashSet(project.getId()))).extracting("key", "resourceId").containsOnly(tuple(key, project.getId()));
    assertThat(underTest.selectPropertiesByKeysAndComponentIds(session, newHashSet(key), newHashSet(project.getId(), project2.getId()))).extracting("key", "resourceId").containsOnly(tuple(key, project.getId()), tuple(key, project2.getId()));
    assertThat(underTest.selectPropertiesByKeysAndComponentIds(session, newHashSet(key, anotherKey), newHashSet(project.getId(), project2.getId()))).extracting("key", "resourceId").containsOnly(tuple(key, project.getId()), tuple(key, project2.getId()), tuple(anotherKey, project2.getId()));
    assertThat(underTest.selectPropertiesByKeysAndComponentIds(session, newHashSet("unknown"), newHashSet(project.getId()))).isEmpty();
    assertThat(underTest.selectPropertiesByKeysAndComponentIds(session, newHashSet("key"), newHashSet(123456789L))).isEmpty();
    assertThat(underTest.selectPropertiesByKeysAndComponentIds(session, newHashSet("unknown"), newHashSet(123456789L))).isEmpty();
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 35 with ComponentDto

use of org.sonar.db.component.ComponentDto in project sonarqube by SonarSource.

the class EventDaoTest method select_by_analysis_uuid.

@Test
public void select_by_analysis_uuid() {
    ComponentDto project = newProjectDto(dbTester.getDefaultOrganization());
    SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
    SnapshotDto otherAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
    dbTester.commit();
    dbTester.events().insertEvent(newEvent(analysis).setUuid("A1"));
    dbTester.events().insertEvent(newEvent(otherAnalysis).setUuid("O1"));
    dbTester.events().insertEvent(newEvent(analysis).setUuid("A2"));
    dbTester.events().insertEvent(newEvent(otherAnalysis).setUuid("O2"));
    dbTester.events().insertEvent(newEvent(analysis).setUuid("A3"));
    dbTester.events().insertEvent(newEvent(otherAnalysis).setUuid("O3"));
    List<EventDto> result = underTest.selectByAnalysisUuid(dbSession, analysis.getUuid());
    assertThat(result).hasSize(3);
    assertThat(result).extracting(EventDto::getUuid).containsOnly("A1", "A2", "A3");
}
Also used : SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

ComponentDto (org.sonar.db.component.ComponentDto)836 Test (org.junit.Test)661 OrganizationDto (org.sonar.db.organization.OrganizationDto)151 SnapshotDto (org.sonar.db.component.SnapshotDto)94 DbSession (org.sonar.db.DbSession)70 SearchOptions (org.sonar.server.es.SearchOptions)62 MetricDto (org.sonar.db.metric.MetricDto)49 IssueDto (org.sonar.db.issue.IssueDto)48 RuleDto (org.sonar.db.rule.RuleDto)47 GroupDto (org.sonar.db.user.GroupDto)39 UserDto (org.sonar.db.user.UserDto)38 WsTester (org.sonar.server.ws.WsTester)33 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)25 PropertyDto (org.sonar.db.property.PropertyDto)23 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)21 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)18 Date (java.util.Date)16 ComponentLinkDto (org.sonar.db.component.ComponentLinkDto)14 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)14 ComponentTreeWsResponse (org.sonarqube.ws.WsMeasures.ComponentTreeWsResponse)13