Search in sources :

Example 1 with USER

use of org.sonar.api.web.UserRole.USER in project sonarqube by SonarSource.

the class ListActionTest method status_on_branch.

@Test
public void status_on_branch() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn().addProjectPermission(USER, project);
    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.BRANCH));
    db.measures().insertLiveMeasure(branch, qualityGateStatus, m -> m.setData("OK"));
    ListWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWsResponse.class);
    assertThat(response.getBranchesList()).extracting(b -> b.getStatus().hasQualityGateStatus(), b -> b.getStatus().getQualityGateStatus()).containsExactlyInAnyOrder(tuple(false, ""), tuple(true, "OK"));
}
Also used : SCAN_EXECUTION(org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION) ComponentFinder(org.sonar.server.component.ComponentFinder) PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) AsyncIssueIndexing(org.sonar.server.issue.index.AsyncIssueIndexing) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) BranchType(org.sonarqube.ws.Common.BranchType) ProjectBranches(org.sonarqube.ws.ProjectBranches) EsTester(org.sonar.server.es.EsTester) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BUG(org.sonar.api.rules.RuleType.BUG) Branch(org.sonarqube.ws.ProjectBranches.Branch) PROJECT(org.sonar.api.resources.Qualifiers.PROJECT) DateUtils.dateToLong(org.sonar.api.utils.DateUtils.dateToLong) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) ComponentTesting(org.sonar.db.component.ComponentTesting) ResourceTypesRule(org.sonar.db.component.ResourceTypesRule) ResourceTypes(org.sonar.api.resources.ResourceTypes) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) USER(org.sonar.api.web.UserRole.USER) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) BRANCH(org.sonar.db.component.BranchType.BRANCH) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) ComponentDto(org.sonar.db.component.ComponentDto) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) ListWsResponse(org.sonarqube.ws.ProjectBranches.ListWsResponse) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) Mockito.mock(org.mockito.Mockito.mock) ListWsResponse(org.sonarqube.ws.ProjectBranches.ListWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 2 with USER

use of org.sonar.api.web.UserRole.USER in project sonarqube by SonarSource.

the class PermissionTemplateDaoTest method delete_user_permissions_by_user_uuid.

@Test
public void delete_user_permissions_by_user_uuid() {
    UserDto user = db.users().insertUser();
    UserDto anotherUser = db.users().insertUser();
    PermissionTemplateDto template = db.permissionTemplates().insertTemplate();
    String permission = "PERMISSION";
    db.permissionTemplates().addUserToTemplate(template.getUuid(), user.getUuid(), permission, template.getName(), user.getLogin());
    db.permissionTemplates().addUserToTemplate(template.getUuid(), anotherUser.getUuid(), permission, template.getName(), anotherUser.getLogin());
    underTest.deleteUserPermissionsByUserUuid(dbSession, user.getUuid(), user.getLogin());
    db.commit();
    assertThat(db.select("select template_uuid as \"templateUuid\", user_uuid as \"userUuid\", permission_reference as \"permission\" from perm_templates_users")).extracting((row) -> row.get("templateUuid"), (row) -> row.get("userUuid"), (row) -> row.get("permission")).containsOnly(tuple(template.getUuid(), anotherUser.getUuid(), permission));
}
Also used : ISSUE_ADMIN(org.sonar.api.web.UserRole.ISSUE_ADMIN) SCAN_EXECUTION(org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION) UserDto(org.sonar.db.user.UserDto) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CODEVIEWER(org.sonar.api.web.UserRole.CODEVIEWER) DbSession(org.sonar.db.DbSession) ArrayList(java.util.ArrayList) ADMIN(org.sonar.api.web.UserRole.ADMIN) Arrays.asList(java.util.Arrays.asList) UuidFactoryFast(org.sonar.core.util.UuidFactoryFast) Before(org.junit.Before) GroupDto(org.sonar.db.user.GroupDto) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) USER(org.sonar.api.web.UserRole.USER) UuidFactory(org.sonar.core.util.UuidFactory) Test(org.junit.Test) NoOpAuditPersister(org.sonar.db.audit.NoOpAuditPersister) Mockito.when(org.mockito.Mockito.when) List(java.util.List) Rule(org.junit.Rule) UserRole(org.sonar.api.web.UserRole) PermissionTemplateTesting.newPermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) Mockito.mock(org.mockito.Mockito.mock) PermissionTemplateTesting.newPermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto) UserDto(org.sonar.db.user.UserDto) Test(org.junit.Test)

Example 3 with USER

use of org.sonar.api.web.UserRole.USER in project sonarqube by SonarSource.

the class ListActionTest method response_contains_date_of_last_analysis.

@Test
public void response_contains_date_of_last_analysis() {
    Long lastAnalysisBranch = dateToLong(parseDateTime("2017-04-01T00:00:00+0100"));
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn().addProjectPermission(USER, project);
    ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.BRANCH));
    db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(branch2).setCreatedAt(lastAnalysisBranch));
    db.commit();
    indexIssues();
    permissionIndexerTester.allowOnlyAnyone(project);
    ListWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWsResponse.class);
    assertThat(response.getBranchesList()).extracting(ProjectBranches.Branch::getType, ProjectBranches.Branch::hasAnalysisDate, b -> "".equals(b.getAnalysisDate()) ? null : dateToLong(parseDateTime(b.getAnalysisDate()))).containsExactlyInAnyOrder(tuple(BranchType.BRANCH, false, null), tuple(BranchType.BRANCH, true, lastAnalysisBranch));
}
Also used : SCAN_EXECUTION(org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION) ComponentFinder(org.sonar.server.component.ComponentFinder) PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) AsyncIssueIndexing(org.sonar.server.issue.index.AsyncIssueIndexing) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) BranchType(org.sonarqube.ws.Common.BranchType) ProjectBranches(org.sonarqube.ws.ProjectBranches) EsTester(org.sonar.server.es.EsTester) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BUG(org.sonar.api.rules.RuleType.BUG) Branch(org.sonarqube.ws.ProjectBranches.Branch) PROJECT(org.sonar.api.resources.Qualifiers.PROJECT) DateUtils.dateToLong(org.sonar.api.utils.DateUtils.dateToLong) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) ComponentTesting(org.sonar.db.component.ComponentTesting) ResourceTypesRule(org.sonar.db.component.ResourceTypesRule) ResourceTypes(org.sonar.api.resources.ResourceTypes) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) USER(org.sonar.api.web.UserRole.USER) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) BRANCH(org.sonar.db.component.BranchType.BRANCH) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) ComponentDto(org.sonar.db.component.ComponentDto) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) ListWsResponse(org.sonarqube.ws.ProjectBranches.ListWsResponse) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) Mockito.mock(org.mockito.Mockito.mock) ListWsResponse(org.sonarqube.ws.ProjectBranches.ListWsResponse) ProjectBranches(org.sonarqube.ws.ProjectBranches) DateUtils.dateToLong(org.sonar.api.utils.DateUtils.dateToLong) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assertions.tuple (org.assertj.core.api.Assertions.tuple)3 Before (org.junit.Before)3 Rule (org.junit.Rule)3 Test (org.junit.Test)3 Mockito.mock (org.mockito.Mockito.mock)3 System2 (org.sonar.api.utils.System2)3 USER (org.sonar.api.web.UserRole.USER)3 SCAN_EXECUTION (org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION)3 DbTester (org.sonar.db.DbTester)3 String.format (java.lang.String.format)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 ALERT_STATUS_KEY (org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY)2 PROJECT (org.sonar.api.resources.Qualifiers.PROJECT)2 ResourceTypes (org.sonar.api.resources.ResourceTypes)2 BUG (org.sonar.api.rules.RuleType.BUG)2 WebService (org.sonar.api.server.ws.WebService)2 DateUtils.dateToLong (org.sonar.api.utils.DateUtils.dateToLong)2 DateUtils.parseDateTime (org.sonar.api.utils.DateUtils.parseDateTime)2 BRANCH (org.sonar.db.component.BranchType.BRANCH)2