diff options
author | Janos Gyerik <janos.gyerik@sonarsource.com> | 2017-10-20 10:23:38 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-10-20 18:23:38 +1000 |
commit | d41338e67fd95bfe18aa7bcf10e50b98898928c2 (patch) | |
tree | 8798fdca197834baea6454af4d9304ed4473b7df /sonar-scanner-engine/src/test/java/org | |
parent | 769b079d87d8c64fb0e5c4b0c074558f7a151d14 (diff) | |
download | sonarqube-d41338e67fd95bfe18aa7bcf10e50b98898928c2.tar.gz sonarqube-d41338e67fd95bfe18aa7bcf10e50b98898928c2.zip |
SONAR-9969 Change the validation logic of the new branch parameter (#2666)
* Fail-fast when branch name or target used without branch plugin
* Allow missing BranchParamsValidator, improve the check for missing
* Reuse branches doc link constant
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org')
2 files changed, 40 insertions, 4 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java index 0de22581f63..8a5dada204c 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java @@ -174,14 +174,16 @@ public class FileSystemMediumTest { File srcDir = new File(baseDir, "src"); assertThat(srcDir.mkdir()).isTrue(); + // Using sonar.branch.name when the branch plugin is not installed is an error. + // IllegalStateException is expected here, because this test is in a bit artificial, + // the fail-fast mechanism in the scanner should have prevented reaching this point. + thrown.expect(IllegalStateException.class); + tester.newTask() .properties(builder .put("sonar.sources", "src") .build()) .execute(); - - assertThat(logs.getAllAsString()).contains("Project key: com.foo.project"); - assertThat(logs.getAllAsString()).contains("Branch name: my-branch, type: long living"); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java index 1cb2a037206..9a3c0a86158 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java @@ -19,6 +19,7 @@ */ package org.sonar.scanner.scan; +import java.util.Optional; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -28,7 +29,11 @@ import org.sonar.api.batch.AnalysisMode; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.utils.MessageException; +import org.sonar.core.config.ScannerProperties; +import org.sonar.scanner.bootstrap.GlobalConfiguration; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -39,11 +44,14 @@ public class ProjectReactorValidatorTest { private AnalysisMode mode; private ProjectReactorValidator validator; + private GlobalConfiguration settings; @Before public void prepare() { mode = mock(AnalysisMode.class); - validator = new ProjectReactorValidator(mode); + settings = mock(GlobalConfiguration.class); + when(settings.get(anyString())).thenReturn(Optional.empty()); + validator = new ProjectReactorValidator(mode, settings); } @Test @@ -153,6 +161,32 @@ public class ProjectReactorValidatorTest { validator.validate(reactor); } + @Test + public void fail_when_branch_name_is_specified_but_branch_plugin_not_present() { + ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo"); + ProjectReactor reactor = new ProjectReactor(def); + + when(settings.get(eq(ScannerProperties.BRANCH_NAME))).thenReturn(Optional.of("feature1")); + + thrown.expect(MessageException.class); + thrown.expectMessage("the branch plugin is required but not installed"); + + validator.validate(reactor); + } + + @Test + public void fail_when_branch_target_is_specified_but_branch_plugin_not_present() { + ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo"); + ProjectReactor reactor = new ProjectReactor(def); + + when(settings.get(eq(ScannerProperties.BRANCH_TARGET))).thenReturn(Optional.of("feature1")); + + thrown.expect(MessageException.class); + thrown.expectMessage("the branch plugin is required but not installed"); + + validator.validate(reactor); + } + private ProjectReactor createProjectReactor(String projectKey) { ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, projectKey); ProjectReactor reactor = new ProjectReactor(def); |