Search in sources :

Example 1 with PermissionTemplateService

use of org.sonar.server.permission.PermissionTemplateService in project sonarqube by SonarSource.

the class ReportSubmitterTest method submit_a_report_on_existing_project.

@Test
public void submit_a_report_on_existing_project() {
    ComponentDto project = db.components().insertPrivateProject();
    UserDto user = db.users().insertUser();
    userSession.logIn(user).addProjectPermission(SCAN_EXECUTION, project);
    mockSuccessfulPrepareSubmitCall();
    underTest.submit(project.getDbKey(), project.name(), emptyMap(), IOUtils.toInputStream("{binary}", StandardCharsets.UTF_8));
    verifyReportIsPersisted(TASK_UUID);
    verifyNoInteractions(permissionTemplateService);
    verify(queue).submit(argThat(submit -> submit.getType().equals(CeTaskTypes.REPORT) && submit.getComponent().filter(cpt -> cpt.getUuid().equals(project.uuid()) && cpt.getMainComponentUuid().equals(project.uuid())).isPresent() && submit.getSubmitterUuid().equals(user.getUuid()) && submit.getUuid().equals(TASK_UUID)));
}
Also used : CeTaskTypes(org.sonar.db.ce.CeTaskTypes) IntStream.rangeClosed(java.util.stream.IntStream.rangeClosed) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) GlobalPermission(org.sonar.db.permission.GlobalPermission) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) DbSession(org.sonar.db.DbSession) BadRequestException(org.sonar.server.exceptions.BadRequestException) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) SCAN(org.sonar.db.permission.GlobalPermission.SCAN) Map(java.util.Map) Visibility(org.sonar.server.project.Visibility) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) StandardCharsets(java.nio.charset.StandardCharsets) String.format(java.lang.String.format) PermissionTemplateService(org.sonar.server.permission.PermissionTemplateService) IOUtils(org.apache.commons.io.IOUtils) ComponentDto(org.sonar.db.component.ComponentDto) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) MoreCollectors.uniqueIndex(org.sonar.core.util.stream.MoreCollectors.uniqueIndex) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SCAN_EXECUTION(org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION) FavoriteUpdater(org.sonar.server.favorite.FavoriteUpdater) UserDto(org.sonar.db.user.UserDto) I18n(org.sonar.core.i18n.I18n) PROVISION_PROJECTS(org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS) ProjectDefaultVisibility(org.sonar.server.project.ProjectDefaultVisibility) TestProjectIndexers(org.sonar.server.es.TestProjectIndexers) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Before(org.junit.Before) ComponentUpdater(org.sonar.server.component.ComponentUpdater) UserSessionRule(org.sonar.server.tester.UserSessionRule) Collections.emptyMap(java.util.Collections.emptyMap) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) CeQueueImpl(org.sonar.ce.queue.CeQueueImpl) SequenceUuidFactory(org.sonar.core.util.SequenceUuidFactory) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) CeTaskSubmit(org.sonar.ce.queue.CeTaskSubmit) InputStream(java.io.InputStream) CeQueue(org.sonar.ce.queue.CeQueue) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)1 String.format (java.lang.String.format)1 StandardCharsets (java.nio.charset.StandardCharsets)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Map (java.util.Map)1 Random (java.util.Random)1 IntStream (java.util.stream.IntStream)1 IntStream.rangeClosed (java.util.stream.IntStream.rangeClosed)1 IOUtils (org.apache.commons.io.IOUtils)1 RandomStringUtils.randomAlphabetic (org.apache.commons.lang.RandomStringUtils.randomAlphabetic)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)1 Mockito.mock (org.mockito.Mockito.mock)1