Search in sources :

Example 1 with ComponentDto

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

the class SettingsFinderTest method return_component_setting_even_if_no_definition.

@Test
public void return_component_setting_even_if_no_definition() throws Exception {
    ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()));
    insertProperties(newComponentPropertyDto(project).setKey("property").setValue("one"));
    Multimap<String, Setting> settings = underTest.loadComponentSettings(dbSession, newHashSet("property"), project);
    assertThat(settings.values()).hasSize(1);
    assertSetting(settings.get(project.uuid()).iterator().next(), "property", "one", project.getId(), false);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 2 with ComponentDto

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

the class SettingsFinderTest method return_component_settings.

@Test
public void return_component_settings() throws Exception {
    ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()));
    addDefinitions(PropertyDefinition.builder("property").defaultValue("default").build());
    insertProperties(newComponentPropertyDto(project).setKey("property").setValue("one"));
    Multimap<String, Setting> result = underTest.loadComponentSettings(dbSession, newHashSet("property"), project);
    assertThat(result.values()).hasSize(1);
    List<Setting> settings = new ArrayList<>(result.get(project.uuid()));
    assertThat(settings).hasSize(1);
    assertSetting(settings.get(0), "property", "one", project.getId(), true);
    assertThat(underTest.loadComponentSettings(dbSession, newHashSet("unknown"), project)).isEmpty();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with ComponentDto

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

the class SettingsFinderTest method return_module_settings.

@Test
public void return_module_settings() throws Exception {
    ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()));
    ComponentDto module = componentDb.insertComponent(newModuleDto(project));
    ComponentDto subModule = componentDb.insertComponent(newModuleDto(module));
    ComponentDto anotherProject = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()));
    insertProperties(newComponentPropertyDto(project).setKey("property").setValue("one"), newComponentPropertyDto(module).setKey("property").setValue("two"), newComponentPropertyDto(subModule).setKey("property2").setValue("three"), newComponentPropertyDto(anotherProject).setKey("property").setValue("another one"));
    Multimap<String, Setting> result = underTest.loadComponentSettings(dbSession, newHashSet("property", "property2"), subModule);
    assertThat(result).hasSize(3);
    assertThat(result.keySet()).containsExactly(project.uuid(), module.uuid(), subModule.uuid());
    assertSetting(result.get(subModule.uuid()).iterator().next(), "property2", "three", subModule.getId(), false);
    assertSetting(result.get(module.uuid()).iterator().next(), "property", "two", module.getId(), false);
    assertSetting(result.get(project.uuid()).iterator().next(), "property", "one", project.getId(), false);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 4 with ComponentDto

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

the class ServerUserSessionTest method hasComponentPermission_keeps_cache_of_permissions_of_logged_in_user.

@Test
public void hasComponentPermission_keeps_cache_of_permissions_of_logged_in_user() {
    ComponentDto project = db.components().insertProject();
    db.users().insertProjectPermissionOnUser(userDto, UserRole.USER, project);
    UserSession session = newUserSession(userDto);
    // feed the cache
    assertThat(session.hasComponentPermission(UserRole.USER, project)).isTrue();
    // change permissions without updating the cache
    db.users().deletePermissionFromUser(project, userDto, UserRole.USER);
    db.users().insertProjectPermissionOnUser(userDto, UserRole.ADMIN, project);
    assertThat(session.hasComponentPermission(UserRole.USER, project)).isTrue();
    assertThat(session.hasComponentPermission(UserRole.ADMIN, project)).isFalse();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 5 with ComponentDto

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

the class ServerUserSessionTest method test_hasPermission_on_organization_for_logged_in_user.

@Test
public void test_hasPermission_on_organization_for_logged_in_user() {
    OrganizationDto org = db.organizations().insert();
    ComponentDto project = db.components().insertProject(org);
    db.users().insertPermissionOnUser(org, userDto, PROVISION_PROJECTS);
    db.users().insertProjectPermissionOnUser(userDto, UserRole.ADMIN, project);
    UserSession session = newUserSession(userDto);
    assertThat(session.hasPermission(PROVISION_PROJECTS, org.getUuid())).isTrue();
    assertThat(session.hasPermission(ADMINISTER, org.getUuid())).isFalse();
    assertThat(session.hasPermission(PROVISION_PROJECTS, "another-org")).isFalse();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Aggregations

ComponentDto (org.sonar.db.component.ComponentDto)2680 Test (org.junit.Test)2343 UserDto (org.sonar.db.user.UserDto)353 IssueDto (org.sonar.db.issue.IssueDto)332 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)329 SnapshotDto (org.sonar.db.component.SnapshotDto)244 DbSession (org.sonar.db.DbSession)192 MetricDto (org.sonar.db.metric.MetricDto)192 NotFoundException (org.sonar.server.exceptions.NotFoundException)159 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)137 Rule (org.junit.Rule)137 DbTester (org.sonar.db.DbTester)137 Date (java.util.Date)134 GroupDto (org.sonar.db.user.GroupDto)132 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)127 TestRequest (org.sonar.server.ws.TestRequest)124 System2 (org.sonar.api.utils.System2)121 List (java.util.List)110 OrganizationDto (org.sonar.db.organization.OrganizationDto)107 UserSessionRule (org.sonar.server.tester.UserSessionRule)101