use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class DefaultGlobalSettingsLoaderTest method loadGlobalSettings.
@Test
public void loadGlobalSettings() throws IOException {
WsResponse response = mock(WsResponse.class);
PipedOutputStream out = new PipedOutputStream();
PipedInputStream in = new PipedInputStream(out);
Settings.ValuesWsResponse.newBuilder().addSettings(Settings.Setting.newBuilder().setKey("abc").setValue("def").build()).addSettings(Settings.Setting.newBuilder().setKey("123").setValue("456").build()).build().writeTo(out);
out.close();
when(response.contentStream()).thenReturn(in);
when(wsClient.call(any())).thenReturn(response);
Map<String, String> result = underTest.loadGlobalSettings();
ArgumentCaptor<GetRequest> argumentCaptor = ArgumentCaptor.forClass(GetRequest.class);
verify(wsClient, times(1)).call(argumentCaptor.capture());
assertThat(argumentCaptor.getValue().getPath()).isEqualTo("api/settings/values.protobuf");
assertThat(result).isNotNull().hasSize(2).containsEntry("abc", "def").containsEntry("123", "456");
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class ReportPublisherTest method send_pull_request_characteristic.
@Test
public void send_pull_request_characteristic() throws Exception {
String branchName = "feature";
String pullRequestId = "pr-123";
when(branchConfiguration.branchName()).thenReturn(branchName);
when(branchConfiguration.branchType()).thenReturn(PULL_REQUEST);
when(branchConfiguration.pullRequestKey()).thenReturn(pullRequestId);
WsResponse response = mock(WsResponse.class);
PipedOutputStream out = new PipedOutputStream();
PipedInputStream in = new PipedInputStream(out);
Ce.SubmitResponse.newBuilder().build().writeTo(out);
out.close();
when(response.failIfNotSuccessful()).thenReturn(response);
when(response.contentStream()).thenReturn(in);
when(wsClient.call(any(WsRequest.class))).thenReturn(response);
underTest.upload(reportTempFolder.newFile());
ArgumentCaptor<WsRequest> capture = ArgumentCaptor.forClass(WsRequest.class);
verify(wsClient).call(capture.capture());
WsRequest wsRequest = capture.getValue();
assertThat(wsRequest.getParameters().getKeys()).hasSize(2);
assertThat(wsRequest.getParameters().getValues("projectKey")).containsExactly("org.sonarsource.sonarqube:sonarqube");
assertThat(wsRequest.getParameters().getValues("characteristic")).containsExactlyInAnyOrder("pullRequest=" + pullRequestId);
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class DefaultScannerWsClient method call.
/**
* If an exception is not thrown, the response needs to be closed by either calling close() directly, or closing the
* body content's stream/reader.
*
* @throws IllegalStateException if the request could not be executed due to a connectivity problem or timeout. Because networks can
* fail during an exchange, it is possible that the remote server accepted the request before the failure
* @throws MessageException if there was a problem with authentication or if a error message was parsed from the response.
* @throws HttpException if the response code is not in range [200..300). Consider using {@link #createErrorMessage(HttpException)} to create more relevant messages for the users.
*/
public WsResponse call(WsRequest request) {
checkState(!globalMode.isMediumTest(), "No WS call should be made in medium test mode");
Profiler profiler = Profiler.createIfDebug(LOG).start();
WsResponse response = target.wsConnector().call(request);
profiler.stopDebug(format("%s %d %s", request.getMethod(), response.code(), response.requestUrl()));
failIfUnauthorized(response);
return response;
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class WsTestUtil method mockStream.
public static void mockStream(DefaultScannerWsClient mock, String path, InputStream is) {
WsResponse response = mock(WsResponse.class);
when(response.contentStream()).thenReturn(is);
when(mock.call(argThat(new RequestMatcher(path)))).thenReturn(response);
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class WsTestUtil method mockStream.
public static void mockStream(DefaultScannerWsClient mock, InputStream is) {
WsResponse response = mock(WsResponse.class);
when(response.contentStream()).thenReturn(is);
when(mock.call(any(WsRequest.class))).thenReturn(response);
}
Aggregations