選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DefaultGlobalSettingsLoaderTest.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.scanner.repository.settings;
  21. import java.io.IOException;
  22. import java.io.PipedInputStream;
  23. import java.io.PipedOutputStream;
  24. import java.util.Map;
  25. import org.junit.Test;
  26. import org.mockito.ArgumentCaptor;
  27. import org.sonar.scanner.bootstrap.DefaultScannerWsClient;
  28. import org.sonarqube.ws.Settings;
  29. import org.sonarqube.ws.client.GetRequest;
  30. import org.sonarqube.ws.client.WsResponse;
  31. import static org.assertj.core.api.Assertions.assertThat;
  32. import static org.mockito.ArgumentMatchers.any;
  33. import static org.mockito.Mockito.mock;
  34. import static org.mockito.Mockito.times;
  35. import static org.mockito.Mockito.verify;
  36. import static org.mockito.Mockito.when;
  37. public class DefaultGlobalSettingsLoaderTest {
  38. private DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class);
  39. private DefaultGlobalSettingsLoader underTest = new DefaultGlobalSettingsLoader(wsClient);
  40. @Test
  41. public void loadGlobalSettings() throws IOException {
  42. WsResponse response = mock(WsResponse.class);
  43. PipedOutputStream out = new PipedOutputStream();
  44. PipedInputStream in = new PipedInputStream(out);
  45. Settings.ValuesWsResponse.newBuilder()
  46. .addSettings(Settings.Setting.newBuilder()
  47. .setKey("abc").setValue("def")
  48. .build())
  49. .addSettings(Settings.Setting.newBuilder()
  50. .setKey("123").setValue("456")
  51. .build())
  52. .build()
  53. .writeTo(out);
  54. out.close();
  55. when(response.contentStream()).thenReturn(in);
  56. when(wsClient.call(any())).thenReturn(response);
  57. Map<String, String> result = underTest.loadGlobalSettings();
  58. ArgumentCaptor<GetRequest> argumentCaptor = ArgumentCaptor.forClass(GetRequest.class);
  59. verify(wsClient, times(1)).call(argumentCaptor.capture());
  60. assertThat(argumentCaptor.getValue().getPath()).isEqualTo("api/settings/values.protobuf");
  61. assertThat(result).isNotNull();
  62. assertThat(result).hasSize(2);
  63. assertThat(result.get("abc")).isEqualTo("def");
  64. assertThat(result.get("123")).isEqualTo("456");
  65. }
  66. }