diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2017-01-30 10:41:40 +0100 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2017-01-30 14:02:31 +0100 |
commit | 2072b8cf07b2c18c53a7a436df50920294a1f50a (patch) | |
tree | 4785d6658d67df4059b7d025fa2ba4a32031332d /sonar-scanner-engine/src/test | |
parent | 9c5a262cb54c49a38e76684778454ae9e32b358d (diff) | |
download | sonarqube-2072b8cf07b2c18c53a7a436df50920294a1f50a.tar.gz sonarqube-2072b8cf07b2c18c53a7a436df50920294a1f50a.zip |
SONAR-8386 Fetch all usernames in a single request in preview mode
Diffstat (limited to 'sonar-scanner-engine/src/test')
3 files changed, 25 insertions, 2 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueCallbackTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueCallbackTest.java index 6bde07dd80a..326e534af3a 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueCallbackTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/DefaultIssueCallbackTest.java @@ -37,6 +37,7 @@ import org.sonar.scanner.repository.user.UserRepositoryLoader; import org.junit.Before; import com.google.common.collect.ImmutableList; +import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -69,7 +70,8 @@ public class DefaultIssueCallbackTest { ScannerInput.User.Builder userBuilder = ScannerInput.User.newBuilder(); userBuilder.setLogin("user"); userBuilder.setName("name"); - when(userRepository.load("user")).thenReturn(userBuilder.build()); + when(userRepository.map(Collections.singleton("user"))) + .thenReturn(Collections.singletonMap("user", userBuilder.build())); Rule r = mock(Rule.class); when(r.name()).thenReturn("rule name"); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/user/UserRepositoryLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/user/UserRepositoryLoaderTest.java index 40c944ee8d8..11db8fc231a 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/user/UserRepositoryLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/user/UserRepositoryLoaderTest.java @@ -22,6 +22,7 @@ package org.sonar.scanner.repository.user; import org.assertj.core.util.Lists; import org.sonar.scanner.bootstrap.ScannerWsClient; import org.sonar.scanner.protocol.input.ScannerInput; +import org.sonar.scanner.protocol.input.ScannerInput.User; import org.sonar.scanner.repository.user.UserRepositoryLoader; import org.sonar.scanner.WsTestUtil; import org.junit.Before; @@ -68,6 +69,26 @@ public class UserRepositoryLoaderTest { } @Test + public void testLoadListWithSingleUser() throws IOException { + Map<String, String> userMap = ImmutableMap.of("fmallet", "Freddy Mallet"); + InputStream is = createUsersMock(userMap); + WsTestUtil.mockStream(wsClient, "/batch/users?logins=fmallet", is); + assertThat(userRepo.load(Arrays.asList("fmallet"))).extracting("login", "name").containsOnly(tuple("fmallet", "Freddy Mallet")); + } + + @Test + public void testMapUsers() throws IOException { + Map<String, String> userMap = ImmutableMap.of("fmallet", "Freddy Mallet"); + InputStream is = createUsersMock(userMap); + WsTestUtil.mockStream(wsClient, "/batch/users?logins=fmallet,sbrandhof", is); + Map<String, User> map = userRepo.map(Arrays.asList("fmallet", "sbrandhof")); + + // one user doesn't exist + assertThat(map).hasSize(1); + assertThat(map.values().iterator().next().getLogin()).isEqualTo("fmallet"); + } + + @Test public void testLoadSingleUser() throws IOException { InputStream is = createUsersMock(ImmutableMap.of("fmallet", "Freddy Mallet")); WsTestUtil.mockStream(wsClient, "/batch/users?logins=fmallet", is); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java index e464770bb66..c86b5ada7e7 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/report/JSONReportTest.java @@ -123,7 +123,7 @@ public class JSONReportTest { issue.setNew(false); when(issueCache.all()).thenReturn(Collections.singleton(issue)); ScannerInput.User user = ScannerInput.User.newBuilder().setLogin("simon").setName("Simon").build(); - when(userRepository.load("simon")).thenReturn(user); + when(userRepository.load(Collections.singleton("simon"))).thenReturn(Collections.singleton(user)); StringWriter writer = new StringWriter(); jsonReport.writeJson(writer); |