You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

QualityProfileProviderTest.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 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;
  21. import java.util.ArrayList;
  22. import java.util.Date;
  23. import java.util.List;
  24. import org.junit.Before;
  25. import org.junit.Rule;
  26. import org.junit.Test;
  27. import org.sonar.api.utils.DateUtils;
  28. import org.sonar.api.utils.log.LogTester;
  29. import org.sonar.scanner.bootstrap.ProcessedScannerProperties;
  30. import org.sonar.scanner.rule.QualityProfiles;
  31. import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile;
  32. import static org.assertj.core.api.Assertions.assertThat;
  33. import static org.mockito.ArgumentMatchers.eq;
  34. import static org.mockito.Mockito.mock;
  35. import static org.mockito.Mockito.verify;
  36. import static org.mockito.Mockito.verifyNoMoreInteractions;
  37. import static org.mockito.Mockito.when;
  38. public class QualityProfileProviderTest {
  39. @Rule
  40. public LogTester logTester = new LogTester();
  41. private QualityProfilesProvider qualityProfileProvider;
  42. private QualityProfileLoader loader = mock(QualityProfileLoader.class);
  43. private ProcessedScannerProperties props = mock(ProcessedScannerProperties.class);
  44. private List<QualityProfile> response;
  45. @Before
  46. public void setUp() {
  47. qualityProfileProvider = new QualityProfilesProvider();
  48. when(props.getProjectKey()).thenReturn("project");
  49. response = new ArrayList<>(1);
  50. response.add(QualityProfile.newBuilder().setKey("profile").setName("profile").setLanguage("lang").setRulesUpdatedAt(DateUtils.formatDateTime(new Date())).build());
  51. }
  52. @Test
  53. public void testProvide() {
  54. when(loader.load("project")).thenReturn(response);
  55. QualityProfiles qps = qualityProfileProvider.provide(loader, props);
  56. assertResponse(qps);
  57. verify(loader).load("project");
  58. verifyNoMoreInteractions(loader);
  59. }
  60. @Test
  61. public void testProfileProp() {
  62. when(loader.load(eq("project"))).thenReturn(response);
  63. QualityProfiles qps = qualityProfileProvider.provide(loader, props);
  64. assertResponse(qps);
  65. verify(loader).load(eq("project"));
  66. verifyNoMoreInteractions(loader);
  67. }
  68. private void assertResponse(QualityProfiles qps) {
  69. assertThat(qps.findAll()).extracting("key").containsExactly("profile");
  70. }
  71. }