Search in sources :

Example 11 with ComponentDto

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

the class ViewIndexerTest method addProjectWithIssue.

private ComponentDto addProjectWithIssue(RuleDto rule, OrganizationDto org) {
    ComponentDto project = ComponentTesting.newProjectDto(org);
    ComponentDto file = ComponentTesting.newFileDto(project, null);
    dbTester.components().insertComponents(project, file);
    dbTester.users().insertProjectPermissionOnAnyone(UserRole.USER, project);
    IssueDto issue = IssueTesting.newDto(rule, file, project);
    dbClient.issueDao().insert(dbSession, issue);
    dbSession.commit();
    return project;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto)

Example 12 with ComponentDto

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

the class PropertiesDaoTest method selectEnabledDescendantModuleProperties_supports_all_values.

@Test
@UseDataProvider("allValuesForSelect")
public void selectEnabledDescendantModuleProperties_supports_all_values(String dbValue, String expected) throws SQLException {
    String projectUuid = "A";
    ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid);
    dbClient.componentDao().insert(session, project);
    long projectId = project.getId();
    insertProperty("project.one", dbValue, projectId, null);
    List<PropertyDto> dtos = underTest.selectEnabledDescendantModuleProperties(projectUuid, dbTester.getSession());
    assertThat(dtos).hasSize(1);
    assertThatDto(dtos.iterator().next()).hasKey("project.one").hasResourceId(projectId).hasNoUserId().hasValue(expected);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) PropertyTesting.newUserPropertyDto(org.sonar.db.property.PropertyTesting.newUserPropertyDto) PropertyTesting.newComponentPropertyDto(org.sonar.db.property.PropertyTesting.newComponentPropertyDto) PropertyTesting.newGlobalPropertyDto(org.sonar.db.property.PropertyTesting.newGlobalPropertyDto) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 13 with ComponentDto

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

the class PropertiesDaoTest method select_component_properties_by_ids.

@Test
public void select_component_properties_by_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.selectPropertiesByComponentIds(session, newHashSet(project.getId()))).extracting("key", "resourceId").containsOnly(tuple(key, project.getId()));
    assertThat(underTest.selectPropertiesByComponentIds(session, newHashSet(project.getId(), project2.getId()))).extracting("key", "resourceId").containsOnly(tuple(key, project.getId()), tuple(key, project2.getId()), tuple(anotherKey, project2.getId()));
    assertThat(underTest.selectPropertiesByComponentIds(session, newHashSet(123456789L))).isEmpty();
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 14 with ComponentDto

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

the class AuthorizationDaoTest method selectOrganizationPermissions_for_logged_in_user.

/**
   * Union of the permissions granted to:
   * - the user
   * - the groups which user is member
   * - anyone
   */
@Test
public void selectOrganizationPermissions_for_logged_in_user() {
    ComponentDto project = db.components().insertProject(org);
    db.users().insertMember(group1, user);
    db.users().insertPermissionOnUser(org, user, "perm1");
    db.users().insertProjectPermissionOnUser(user, "perm42", project);
    db.users().insertPermissionOnGroup(group1, "perm2");
    db.users().insertPermissionOnAnyone(org, "perm3");
    // ignored permissions, user is not member of this group
    db.users().insertPermissionOnGroup(group2, "ignored");
    Set<String> permissions = underTest.selectOrganizationPermissions(dbSession, org.getUuid(), user.getId());
    assertThat(permissions).containsOnly("perm1", "perm2", "perm3");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 15 with ComponentDto

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

the class AuthorizationDaoTest method selectProjectPermissionsOfAnonymous_returns_empty_set_when_project_does_not_exist.

@Test
public void selectProjectPermissionsOfAnonymous_returns_empty_set_when_project_does_not_exist() {
    ComponentDto project = db.components().insertProject(org);
    db.users().insertProjectPermissionOnAnyone(UserRole.CODEVIEWER, project);
    assertThat(underTest.selectProjectPermissionsOfAnonymous(dbSession, "does_not_exist")).isEmpty();
}
Also used : 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