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);
}
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();
}
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);
}
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();
}
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();
}
Aggregations