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.

AzureDevOpsProjectCreatorFactoryTest.java 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 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.server.common.almsettings.azuredevops;
  21. import org.junit.jupiter.api.Test;
  22. import org.junit.jupiter.api.extension.ExtendWith;
  23. import org.mockito.InjectMocks;
  24. import org.mockito.Mock;
  25. import org.mockito.junit.jupiter.MockitoExtension;
  26. import org.sonar.alm.client.azure.AzureDevOpsHttpClient;
  27. import org.sonar.db.DbClient;
  28. import org.sonar.db.alm.setting.ALM;
  29. import org.sonar.db.alm.setting.AlmSettingDto;
  30. import org.sonar.server.common.almintegration.ProjectKeyGenerator;
  31. import org.sonar.server.common.almsettings.DevOpsProjectCreator;
  32. import org.sonar.server.common.almsettings.DevOpsProjectDescriptor;
  33. import org.sonar.server.common.project.ProjectCreator;
  34. import org.sonar.server.user.UserSession;
  35. import static org.assertj.core.api.Assertions.assertThat;
  36. import static org.mockito.Mockito.mock;
  37. import static org.mockito.Mockito.when;
  38. @ExtendWith(MockitoExtension.class)
  39. class AzureDevOpsProjectCreatorFactoryTest {
  40. @Mock()
  41. private DbClient dbClient;
  42. @Mock
  43. private UserSession userSession;
  44. @Mock
  45. private AzureDevOpsHttpClient azureDevOpsHttpClient;
  46. @Mock
  47. private ProjectCreator projectCreator;
  48. @Mock
  49. private ProjectKeyGenerator projectKeyGenerator;
  50. @InjectMocks
  51. private AzureDevOpsProjectCreatorFactory underTest;
  52. @Test
  53. void getDevOpsProjectCreator_whenAlmIsNotAzureDevOps_shouldReturnEmpty() {
  54. AlmSettingDto almSettingDto = mock(AlmSettingDto.class);
  55. when(almSettingDto.getAlm()).thenReturn(ALM.GITLAB);
  56. DevOpsProjectDescriptor devOpsProjectDescriptor = new DevOpsProjectDescriptor(ALM.GITLAB, null, null, "bitbucket_project");
  57. assertThat(underTest.getDevOpsProjectCreator(almSettingDto, devOpsProjectDescriptor)).isEmpty();
  58. }
  59. @Test
  60. void getDevOpsProjectCreator_whenAlmIsAzureDevOps_shouldReturnProjectCreator() {
  61. AlmSettingDto almSettingDto = mock(AlmSettingDto.class);
  62. when(almSettingDto.getAlm()).thenReturn(ALM.AZURE_DEVOPS);
  63. DevOpsProjectDescriptor devOpsProjectDescriptor = new DevOpsProjectDescriptor(ALM.AZURE_DEVOPS, null, "project-identifier", "bitbucket_project");
  64. DevOpsProjectCreator expectedProjectCreator = new AzureDevOpsProjectCreator(dbClient, almSettingDto, devOpsProjectDescriptor, userSession, azureDevOpsHttpClient,
  65. projectCreator, projectKeyGenerator);
  66. DevOpsProjectCreator devOpsProjectCreator = underTest.getDevOpsProjectCreator(almSettingDto, devOpsProjectDescriptor).orElseThrow();
  67. assertThat(devOpsProjectCreator).usingRecursiveComparison().isEqualTo(expectedProjectCreator);
  68. }
  69. }