Search in sources :

Example 21 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class NotificationFactoryTest method newNonMainBranch.

private static Branch newNonMainBranch(BranchType branchType, String branchName) {
    Branch nonMainBranch = mock(Branch.class);
    when(nonMainBranch.isMain()).thenReturn(false);
    when(nonMainBranch.getType()).thenReturn(branchType);
    when(nonMainBranch.getName()).thenReturn(branchName);
    return nonMainBranch;
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch)

Example 22 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class NotificationFactoryTest method noBranchNameBranches.

@DataProvider
public static Object[][] noBranchNameBranches() {
    Branch mainBranch = mock(Branch.class);
    when(mainBranch.isMain()).thenReturn(true);
    when(mainBranch.getType()).thenReturn(BranchType.BRANCH);
    Branch pr = mock(Branch.class);
    when(pr.isMain()).thenReturn(false);
    when(pr.getType()).thenReturn(BranchType.PULL_REQUEST);
    return new Object[][] { { mainBranch }, { pr } };
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 23 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class PostProjectAnalysisTasksExecutorTest method branch_comes_from_AnalysisMetadataHolder_when_set.

@Test
public void branch_comes_from_AnalysisMetadataHolder_when_set() {
    analysisMetadataHolder.setBranch(new Branch() {

        @Override
        public BranchType getType() {
            return BranchType.BRANCH;
        }

        @Override
        public boolean isMain() {
            return false;
        }

        @Override
        public String getReferenceBranchUuid() {
            throw new UnsupportedOperationException();
        }

        @Override
        public String getName() {
            return "feature/foo";
        }

        @Override
        public boolean supportsCrossProjectCpd() {
            throw new UnsupportedOperationException();
        }

        @Override
        public String getPullRequestKey() {
            throw new UnsupportedOperationException();
        }

        @Override
        public String getTargetBranchName() {
            throw new UnsupportedOperationException();
        }

        @Override
        public String generateKey(String projectKey, @Nullable String fileOrDirPath) {
            throw new UnsupportedOperationException();
        }
    });
    underTest.finished(true);
    verify(postProjectAnalysisTask).finished(taskContextCaptor.capture());
    org.sonar.api.ce.posttask.Branch branch = taskContextCaptor.getValue().getProjectAnalysis().getBranch().get();
    assertThat(branch.isMain()).isFalse();
    assertThat(branch.getName()).hasValue("feature/foo");
    assertThat(branch.getType()).isEqualTo(BranchImpl.Type.BRANCH);
}
Also used : BranchType(org.sonar.db.component.BranchType) Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) Test(org.junit.Test)

Example 24 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class BranchLoaderTest method regular_analysis_of_project_is_enabled_if_delegate_is_absent.

@Test
public void regular_analysis_of_project_is_enabled_if_delegate_is_absent() {
    ScannerReport.Metadata metadata = ScannerReport.Metadata.newBuilder().build();
    new BranchLoader(metadataHolder).load(metadata);
    assertThat(metadataHolder.getBranch()).isNotNull();
    Branch branch = metadataHolder.getBranch();
    assertThat(branch.isMain()).isTrue();
    assertThat(branch.getName()).isEqualTo(BranchDto.DEFAULT_MAIN_BRANCH_NAME);
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) Test(org.junit.Test)

Example 25 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class BuildComponentTreeStepTest method setAnalysisMetadataHolder.

private void setAnalysisMetadataHolder(boolean isPr) {
    Branch branch = isPr ? new PrBranch() : new DefaultBranchImpl();
    analysisMetadataHolder.setRootComponentRef(ROOT_REF).setAnalysisDate(ANALYSIS_DATE).setBranch(branch).setProject(Project.from(newPrivateProjectDto().setDbKey(REPORT_PROJECT_KEY).setName(REPORT_PROJECT_KEY)));
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) DefaultBranchImpl(org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl)

Aggregations

Branch (org.sonar.ce.task.projectanalysis.analysis.Branch)40 Test (org.junit.Test)21 DefaultIssue (org.sonar.core.issue.DefaultIssue)7 ComponentDto (org.sonar.db.component.ComponentDto)7 Before (org.junit.Before)5 BranchType (org.sonar.db.component.BranchType)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Rule (org.junit.Rule)4 Mockito.mock (org.mockito.Mockito.mock)4 Mockito.when (org.mockito.Mockito.when)4 AnalysisMetadataHolderRule (org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule)4 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)4 DbTester (org.sonar.db.DbTester)4 Project (org.sonar.server.project.Project)4 Date (java.util.Date)3 FieldDiffs (org.sonar.core.issue.FieldDiffs)3 ComponentTesting (org.sonar.db.component.ComponentTesting)3 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)3 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)3 RuleKey (org.sonar.api.rule.RuleKey)2