Search in sources :

Example 1 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class AnalysisMetadataHolderImplTest method set_and_get_project.

@Test
public void set_and_get_project() {
    AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider);
    Project project = Project.from(newPrivateProjectDto());
    underTest.setProject(project);
    assertThat(underTest.getProject()).isSameAs(project);
}
Also used : Project(org.sonar.server.project.Project) Test(org.junit.Test)

Example 2 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class TargetBranchComponentUuidsTest method setup.

@Before
public void setup() {
    underTest = new TargetBranchComponentUuids(analysisMetadataHolder, db.getDbClient());
    Project project = mock(Project.class);
    analysisMetadataHolder.setProject(project);
    analysisMetadataHolder.setBranch(branch);
    ComponentDto projectDto = db.components().insertPublicProject();
    when(project.getUuid()).thenReturn(projectDto.uuid());
    branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey(BRANCH_KEY));
    ComponentDto pr1branch = db.components().insertProjectBranch(projectDto, b -> b.setKey(PR_KEY).setBranchType(BranchType.PULL_REQUEST).setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setTarget(BRANCH_KEY).build()).setMergeBranchUuid(projectDto.getMainBranchProjectUuid()));
    branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File");
    pr1File = ComponentTesting.newFileDto(pr1branch, null, "file").setUuid("file1");
    db.components().insertComponents(branch1File, pr1File);
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) DbTester(org.sonar.db.DbTester) BranchType(org.sonar.db.component.BranchType) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DbProjectBranches(org.sonar.db.protobuf.DbProjectBranches) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) AnalysisMetadataHolderRule(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule) ComponentTesting(org.sonar.db.component.ComponentTesting) Before(org.junit.Before) Project(org.sonar.server.project.Project) Mockito.mock(org.mockito.Mockito.mock) Project(org.sonar.server.project.Project) ComponentDto(org.sonar.db.component.ComponentDto) Before(org.junit.Before)

Example 3 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class PostMeasuresComputationChecksStepTest method context_contains_project_uuid_from_analysis_metada_holder.

@Test
public void context_contains_project_uuid_from_analysis_metada_holder() {
    Project project = Project.from(newPrivateProjectDto());
    analysisMetadataHolder.setProject(project);
    PostMeasuresComputationCheck check = mock(PostMeasuresComputationCheck.class);
    newStep(check).execute(new TestComputationStepContext());
    ArgumentCaptor<Context> contextArgumentCaptor = ArgumentCaptor.forClass(Context.class);
    verify(check).onCheck(contextArgumentCaptor.capture());
    assertThat(contextArgumentCaptor.getValue().getProjectUuid()).isEqualTo(project.getUuid());
}
Also used : TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Context(org.sonar.ce.task.projectanalysis.measure.PostMeasuresComputationCheck.Context) Project(org.sonar.server.project.Project) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 4 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class SendIssueNotificationsStepTest method do_not_send_notifications_if_no_subscribers.

@Test
public void do_not_send_notifications_if_no_subscribers() {
    analysisMetadataHolder.setProject(new Project(PROJECT.getUuid(), PROJECT.getKey(), PROJECT.getName(), null, emptyList()));
    when(notificationService.hasProjectSubscribersForTypes(PROJECT.getUuid(), NOTIF_TYPES)).thenReturn(false);
    TestComputationStepContext context = new TestComputationStepContext();
    underTest.execute(context);
    verify(notificationService, never()).deliver(any(Notification.class));
    verify(notificationService, never()).deliverEmails(anyCollection());
    verifyStatistics(context, 0, 0, 0);
}
Also used : Project(org.sonar.server.project.Project) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) NewIssuesNotification(org.sonar.server.issue.notification.NewIssuesNotification) MyNewIssuesNotification(org.sonar.server.issue.notification.MyNewIssuesNotification) Notification(org.sonar.api.notifications.Notification) IssuesChangesNotification(org.sonar.server.issue.notification.IssuesChangesNotification) Test(org.junit.Test)

Example 5 with Project

use of org.sonar.server.project.Project in project sonarqube by SonarSource.

the class LoadReportAnalysisMetadataHolderStepTest method setUp.

@Before
public void setUp() {
    CeTask defaultOrgCeTask = createCeTask(PROJECT_KEY);
    underTest = createStep(defaultOrgCeTask);
    project = db.components().insertPublicProject(p -> p.setDbKey(PROJECT_KEY));
}
Also used : Plugin(org.sonar.api.Plugin) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) BranchLoader(org.sonar.ce.task.projectanalysis.component.BranchLoader) HashMap(java.util.HashMap) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) PluginInfo(org.sonar.core.platform.PluginInfo) ScannerPlugin(org.sonar.ce.task.projectanalysis.analysis.ScannerPlugin) ComputationStep(org.sonar.ce.task.step.ComputationStep) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CeTask(org.sonar.ce.task.CeTask) Map(java.util.Map) MessageException(org.sonar.api.utils.MessageException) Assertions(org.assertj.core.api.Assertions) BatchReportReaderRule(org.sonar.ce.task.projectanalysis.batch.BatchReportReaderRule) Before(org.junit.Before) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Collection(java.util.Collection) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) PluginRepository(org.sonar.core.platform.PluginRepository) MutableAnalysisMetadataHolderRule(org.sonar.ce.task.projectanalysis.analysis.MutableAnalysisMetadataHolderRule) DbClient(org.sonar.db.DbClient) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Optional(java.util.Optional) Arrays.stream(java.util.Arrays.stream) Project(org.sonar.server.project.Project) Mockito.mock(org.mockito.Mockito.mock) CeTask(org.sonar.ce.task.CeTask) Before(org.junit.Before)

Aggregations

Project (org.sonar.server.project.Project)26 Test (org.junit.Test)21 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)14 ComponentDto (org.sonar.db.component.ComponentDto)14 Before (org.junit.Before)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 Rule (org.junit.Rule)11 Mockito.mock (org.mockito.Mockito.mock)11 Mockito.when (org.mockito.Mockito.when)11 DbTester (org.sonar.db.DbTester)11 AnalysisMetadataHolderRule (org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule)10 Branch (org.sonar.ce.task.projectanalysis.analysis.Branch)10 BranchType (org.sonar.db.component.BranchType)10 Date (java.util.Date)9 Notification (org.sonar.api.notifications.Notification)8 UserDto (org.sonar.db.user.UserDto)8 IssuesChangesNotification (org.sonar.server.issue.notification.IssuesChangesNotification)8 MyNewIssuesNotification (org.sonar.server.issue.notification.MyNewIssuesNotification)8 NewIssuesNotification (org.sonar.server.issue.notification.NewIssuesNotification)8 System2 (org.sonar.api.utils.System2)6