aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java/org/sonar/scanner
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2020-03-04 18:06:32 +0100
committersonartech <sonartech@sonarsource.com>2020-03-12 20:04:29 +0000
commitec384a1e6926c801dc5167807f26b1f2ef6baf84 (patch)
treeffa22fe9324d16006a61ef8739cf277d99092e76 /sonar-scanner-engine/src/test/java/org/sonar/scanner
parent0433161433a5f234790fae5eba2cf438cbde5d36 (diff)
downloadsonarqube-ec384a1e6926c801dc5167807f26b1f2ef6baf84.tar.gz
sonarqube-ec384a1e6926c801dc5167807f26b1f2ef6baf84.zip
SONAR-13160 Fix display of Portfolio Admin page when project contains UTF-8 characters
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scanner')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java39
1 files changed, 35 insertions, 4 deletions
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 91993c340c5..f74dd8df5bd 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
@@ -34,11 +34,15 @@ import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.utils.MessageException;
+import org.sonar.api.utils.log.LogAndArguments;
+import org.sonar.api.utils.log.LogTester;
+import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.core.config.ScannerProperties;
import org.sonar.scanner.ProjectInfo;
import org.sonar.scanner.bootstrap.GlobalConfiguration;
import static org.apache.commons.lang.RandomStringUtils.randomAscii;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@@ -50,6 +54,9 @@ public class ProjectReactorValidatorTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
+ @Rule
+ public LogTester logTester = new LogTester();
+
private GlobalConfiguration settings = mock(GlobalConfiguration.class);
private ProjectInfo projectInfo = mock(ProjectInfo.class);
private ProjectReactorValidator underTest = new ProjectReactorValidator(settings);
@@ -86,12 +93,36 @@ public class ProjectReactorValidatorTest {
}
@Test
- public void fail_with_invalid_key() {
- ProjectReactor reactor = createProjectReactor(" ");
+ public void log_warning_when_invalid_key() {
+ ProjectReactor reactor = createProjectReactor("foo$bar");
+
+ underTest.validate(reactor);
+
+ assertThat(logTester.getLogs(LoggerLevel.WARN))
+ .extracting(LogAndArguments::getFormattedMsg)
+ .containsOnly("\"foo$bar\" is not a valid project or module key. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.");
+ }
+
+ @Test
+ public void log_warning_when_only_digits() {
+ ProjectReactor reactor = createProjectReactor("12345");
+
+ underTest.validate(reactor);
+
+ assertThat(logTester.getLogs(LoggerLevel.WARN))
+ .extracting(LogAndArguments::getFormattedMsg)
+ .containsOnly("\"12345\" is not a valid project or module key. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.");
+ }
+
+ @Test
+ public void log_warning_when_backslash_in_key() {
+ ProjectReactor reactor = createProjectReactor("foo\\bar");
- thrown.expect(MessageException.class);
- thrown.expectMessage("\" \" is not a valid project or module key");
underTest.validate(reactor);
+
+ assertThat(logTester.getLogs(LoggerLevel.WARN))
+ .extracting(LogAndArguments::getFormattedMsg)
+ .containsOnly("\"foo\\bar\" is not a valid project or module key. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.");
}
@Test