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

GithubPermissionsServiceTest.java 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 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.sonarqube.ws.client.github.provisioning.permissions;
  21. import org.junit.Test;
  22. import org.junit.runner.RunWith;
  23. import org.mockito.ArgumentCaptor;
  24. import org.mockito.InjectMocks;
  25. import org.mockito.Mock;
  26. import org.mockito.junit.MockitoJUnitRunner;
  27. import org.sonarqube.ws.client.PostRequest;
  28. import org.sonarqube.ws.client.WsConnector;
  29. import org.sonarqube.ws.client.WsRequest;
  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.verify;
  35. import static org.mockito.Mockito.when;
  36. @RunWith(MockitoJUnitRunner.class)
  37. public class GithubPermissionsServiceTest {
  38. @Mock
  39. private WsConnector wsConnector;
  40. @InjectMocks
  41. private GithubPermissionsService githubPermissionsService;
  42. @Test
  43. public void addPermissionMapping_whenRequestIsSuccessful_returns() {
  44. AddGithubPermissionMappingRequest addGithubPermissionMappingRequest = new AddGithubPermissionMappingRequest("admin",
  45. new SonarqubePermissions(true, true, true, true, true, true));
  46. WsResponse response = mock(WsResponse.class);
  47. when(response.failIfNotSuccessful()).thenReturn(response);
  48. when(wsConnector.call(any(PostRequest.class))).thenReturn(response);
  49. githubPermissionsService.addPermissionMapping(addGithubPermissionMappingRequest);
  50. ArgumentCaptor<WsRequest> wsRequestArgumentCaptor = ArgumentCaptor.forClass(WsRequest.class);
  51. verify(wsConnector).call(wsRequestArgumentCaptor.capture());
  52. WsRequest request = wsRequestArgumentCaptor.getValue();
  53. assertThat(request.getMethod()).isEqualTo(WsRequest.Method.POST);
  54. assertThat(request.getPath()).isEqualTo("api/v2/dop-translation/github-permission-mappings");
  55. }
  56. }