org.sonarqube.ws.client.WsConnector.call()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(96)

本文整理了Java中org.sonarqube.ws.client.WsConnector.call()方法的一些代码示例,展示了WsConnector.call()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WsConnector.call()方法的具体详情如下:
包路径:org.sonarqube.ws.client.WsConnector
类名称:WsConnector
方法名:call

WsConnector.call介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

protected WsResponse call(WsRequest request) {
 return wsConnector.call(request).failIfNotSuccessful();
}

代码示例来源:origin: SonarSource/sonarqube

public void test() {
 GetRequest get = new GetRequest(path("issue")).setParam("key", "ABC");
 when(wsConnector.call(get)).thenReturn(newProtobufFakeResponse());
 Testing.Fake message = call(get, Testing.Fake.parser());
 assertThat(message.getLabel()).isEqualTo("ok");
 assertThat(get.getPath()).isEqualTo("api/issues/issue");
 // media type automatically set to protobuf
 assertThat(get.getMediaType()).isEqualTo(MediaTypes.PROTOBUF);
}

代码示例来源:origin: SonarSource/sonarqube

/**
 * 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) {
 Preconditions.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;
}

代码示例来源:origin: SonarSource/sonarqube

public void test() throws IOException {
 GetRequest get = new GetRequest(path("issue")).setMediaType(MediaTypes.JSON);
 when(wsConnector.call(get)).thenReturn(new MockWsResponse().setContent("ok"));
 WsResponse response = call(get);
 assertThat(response.content()).isEqualTo("ok");
}

代码示例来源:origin: SonarSource/sonarqube

public void test() {
  GetRequest get = new GetRequest(path("issue")).setParam("key", "ABC");
  when(wsConnector.call(get)).thenReturn(MockWsResponse.createJson("{}").setRequestUrl("http://local/api/issues/issue?key=ABC"));
  try {
   call(get, Testing.Fake.parser());
   fail();
  } catch (IllegalStateException e) {
   assertThat(e).hasMessage("Fail to parse protobuf response of http://local/api/issues/issue?key=ABC");
  }
 }
}.test();

代码示例来源:origin: SonarSource/sonarqube

@Test
public void log_and_profile_request_if_debug_level() {
 WsRequest request = newRequest();
 WsResponse response = newResponse().setRequestUrl("https://local/api/issues/search");
 when(wsClient.wsConnector().call(request)).thenReturn(response);
 logTester.setLevel(LoggerLevel.DEBUG);
 ScannerWsClient underTest = new ScannerWsClient(wsClient, false, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())));
 WsResponse result = underTest.call(request);
 // do not fail the execution -> interceptor returns the response
 assertThat(result).isSameAs(response);
 // check logs
 List<String> debugLogs = logTester.logs(LoggerLevel.DEBUG);
 assertThat(debugLogs).hasSize(1);
 assertThat(debugLogs.get(0)).contains("GET 200 https://local/api/issues/search | time=");
}

代码示例来源:origin: SonarSource/sonarqube

public void test() {
 GetRequest get = new GetRequest(path("issue")).setParam("key", "ABC");
 when(wsConnector.call(get)).thenReturn(new MockWsResponse().setCode(403).setRequestUrl("https://local/foo").setContent("error"));
 try {
  call(get, Testing.Fake.parser());
  fail();
 } catch (HttpException e) {
  assertThat(e.code()).isEqualTo(403);
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void fail_if_requires_credentials() {
 expectedException.expect(MessageException.class);
 expectedException
  .expectMessage("Not authorized. Analyzing this project requires to be authenticated. Please provide the values of the properties sonar.login and sonar.password.");
 WsRequest request = newRequest();
 WsResponse response = newResponse().setCode(401);
 when(wsClient.wsConnector().call(request)).thenReturn(response);
 new ScannerWsClient(wsClient, false, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void fail_if_credentials_are_not_valid() {
 expectedException.expect(MessageException.class);
 expectedException.expectMessage("Not authorized. Please check the properties sonar.login and sonar.password.");
 WsRequest request = newRequest();
 WsResponse response = newResponse().setCode(401);
 when(wsClient.wsConnector().call(request)).thenReturn(response);
 new ScannerWsClient(wsClient, /* credentials are configured */true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void fail_if_requires_permission() {
 expectedException.expect(MessageException.class);
 expectedException.expectMessage("You're not authorized to run analysis. Please contact the project administrator.");
 WsRequest request = newRequest();
 WsResponse response = newResponse()
  .setCode(403);
 when(wsClient.wsConnector().call(request)).thenReturn(response);
 new ScannerWsClient(wsClient, true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void fail_if_bad_request() {
 expectedException.expect(MessageException.class);
 expectedException.expectMessage("Boo! bad request! bad!");
 WsRequest request = newRequest();
 WsResponse response = newResponse()
  .setCode(400)
  .setContent("{\"errors\":[{\"msg\":\"Boo! bad request! bad!\"}]}");
 when(wsClient.wsConnector().call(request)).thenReturn(response);
 new ScannerWsClient(wsClient, true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request);
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-ws

protected WsResponse call(WsRequest request) {
 return wsConnector.call(request).failIfNotSuccessful();
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch

/**
 * @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 HttpException if the response code is not in range [200..300)
 */
public WsResponse call(WsRequest request) {
 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;
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-scanner-engine

/**
 * 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) {
 Preconditions.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;
}

代码示例来源:origin: gabrie-allaigre/sonar-gitlab-plugin

private Rules.ShowResponse showRule(String ruleKey) {
  GetRequest getRequest = new GetRequest("api/rules/show").setParam("key", ruleKey).setMediaType(MediaTypes.PROTOBUF);
  WsResponse wsResponse = wsClient.wsConnector().call(getRequest);
  if (wsResponse.code() != 200) {
    throw new HttpException(wsClient.wsConnector().baseUrl() + toString(getRequest), wsResponse.code(), wsResponse.content());
  }
  try {
    return Rules.ShowResponse.parseFrom(wsResponse.contentStream());
  } catch (IOException e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}

代码示例来源:origin: SonarQubeCommunity/sonar-build-breaker

WsResponse wsResponse = wsClient.wsConnector().call(ceTaskRequest);

相关文章