Search in sources :

Example 6 with CeTaskSubmit

use of org.sonar.ce.queue.CeTaskSubmit 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().insertProject(db.getDefaultOrganization());
    userSession.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
    mockSuccessfulPrepareSubmitCall();
    underTest.submit(defaultOrganizationKey, project.getKey(), null, project.name(), IOUtils.toInputStream("{binary}"));
    verifyReportIsPersisted(TASK_UUID);
    verifyZeroInteractions(permissionTemplateService);
    verifyZeroInteractions(favoriteUpdater);
    verify(queue).submit(argThat(new TypeSafeMatcher<CeTaskSubmit>() {

        @Override
        protected boolean matchesSafely(CeTaskSubmit submit) {
            return submit.getType().equals(CeTaskTypes.REPORT) && submit.getComponentUuid().equals(project.uuid()) && submit.getUuid().equals(TASK_UUID);
        }

        @Override
        public void describeTo(Description description) {
        }
    }));
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ComponentDto(org.sonar.db.component.ComponentDto) CeTaskSubmit(org.sonar.ce.queue.CeTaskSubmit) Test(org.junit.Test)

Example 7 with CeTaskSubmit

use of org.sonar.ce.queue.CeTaskSubmit in project sonarqube by SonarSource.

the class ReportSubmitterTest method provision_project_if_does_not_exist.

@Test
public void provision_project_if_does_not_exist() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    userSession.addProjectUuidPermissions(SCAN_EXECUTION, PROJECT_UUID).addPermission(PROVISION_PROJECTS, organization);
    mockSuccessfulPrepareSubmitCall();
    ComponentDto createdProject = newProjectDto(organization, PROJECT_UUID).setKey(PROJECT_KEY);
    when(componentUpdater.create(any(DbSession.class), any(NewComponent.class), eq(null))).thenReturn(createdProject);
    when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(DbSession.class), eq(organization.getUuid()), anyInt(), anyString(), eq(PROJECT_KEY), eq(Qualifiers.PROJECT))).thenReturn(true);
    when(permissionTemplateService.hasDefaultTemplateWithPermissionOnProjectCreator(any(DbSession.class), eq(organization.getUuid()), any(ComponentDto.class))).thenReturn(true);
    underTest.submit(organization.getKey(), PROJECT_KEY, null, PROJECT_NAME, IOUtils.toInputStream("{binary}"));
    verifyReportIsPersisted(TASK_UUID);
    verify(queue).submit(argThat(new TypeSafeMatcher<CeTaskSubmit>() {

        @Override
        protected boolean matchesSafely(CeTaskSubmit submit) {
            return submit.getType().equals(CeTaskTypes.REPORT) && submit.getComponentUuid().equals(PROJECT_UUID) && submit.getUuid().equals(TASK_UUID);
        }

        @Override
        public void describeTo(Description description) {
        }
    }));
}
Also used : DbSession(org.sonar.db.DbSession) NewComponent(org.sonar.server.component.NewComponent) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ComponentDto(org.sonar.db.component.ComponentDto) CeTaskSubmit(org.sonar.ce.queue.CeTaskSubmit) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 CeTaskSubmit (org.sonar.ce.queue.CeTaskSubmit)7 CeTask (org.sonar.ce.queue.CeTask)5 ComponentDto (org.sonar.db.component.ComponentDto)4 Description (org.hamcrest.Description)2 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)2 DbSession (org.sonar.db.DbSession)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 NewComponent (org.sonar.server.component.NewComponent)1