当前位置: 首页>>代码示例>>Java>>正文


Java ErrorInfo.setReason方法代码示例

本文整理汇总了Java中com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo.setReason方法的典型用法代码示例。如果您正苦于以下问题:Java ErrorInfo.setReason方法的具体用法?Java ErrorInfo.setReason怎么用?Java ErrorInfo.setReason使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo的用法示例。


在下文中一共展示了ErrorInfo.setReason方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create_adminApiNotEnabled

import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入方法依赖的package包/类
@Test
public void create_adminApiNotEnabled() throws IOException {
  ErrorInfo error = new ErrorInfo();
  error.setReason(SslSocketFactory.ADMIN_API_NOT_ENABLED_REASON);
  GoogleJsonError details = new GoogleJsonError();
  details.setErrors(ImmutableList.of(error));
  when(adminApiInstancesGet.execute())
      .thenThrow(
          new GoogleJsonResponseException(
              new HttpResponseException.Builder(403, "Forbidden", new HttpHeaders()),
              details));

  SslSocketFactory sslSocketFactory =
      new SslSocketFactory(new Clock(), clientKeyPair, credential, adminApi, 3307);
  try {
    sslSocketFactory.create(INSTANCE_CONNECTION_STRING);
    fail("Expected RuntimeException");
  } catch (RuntimeException e) {
    // TODO(berezv): should we throw something more specific than RuntimeException?
    assertThat(e.getMessage()).contains("Cloud SQL API is not enabled");
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-sql-jdbc-socket-factory,代码行数:23,代码来源:SslSocketFactoryTest.java

示例2: create_notAuthorizedToGetInstance

import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入方法依赖的package包/类
@Test
public void create_notAuthorizedToGetInstance() throws IOException {
  ErrorInfo error = new ErrorInfo();
  error.setReason(SslSocketFactory.INSTANCE_NOT_AUTHORIZED_REASON);
  GoogleJsonError details = new GoogleJsonError();
  details.setErrors(ImmutableList.of(error));
  when(adminApiInstancesGet.execute())
      .thenThrow(
          new GoogleJsonResponseException(
              new HttpResponseException.Builder(403, "Forbidden", new HttpHeaders()),
              details));

  SslSocketFactory sslSocketFactory =
      new SslSocketFactory(new Clock(), clientKeyPair, credential, adminApi, 3307);
  try {
    sslSocketFactory.create(INSTANCE_CONNECTION_STRING);
    fail("Expected RuntimeException");
  } catch (RuntimeException e) {
    // TODO(berezv): should we throw something more specific than RuntimeException?
    assertThat(e.getMessage()).contains("not authorized");
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-sql-jdbc-socket-factory,代码行数:23,代码来源:SslSocketFactoryTest.java

示例3: create_notAuthorizedToCreateEphemeralCertificate

import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入方法依赖的package包/类
@Test
public void create_notAuthorizedToCreateEphemeralCertificate() throws IOException {
  ErrorInfo error = new ErrorInfo();
  error.setReason(SslSocketFactory.INSTANCE_NOT_AUTHORIZED_REASON);
  GoogleJsonError details = new GoogleJsonError();
  details.setErrors(ImmutableList.of(error));
  when(adminApiSslCertsCreateEphemeral.execute())
      .thenThrow(
          new GoogleJsonResponseException(
              new HttpResponseException.Builder(403, "Forbidden", new HttpHeaders()),
              details));

  SslSocketFactory sslSocketFactory =
      new SslSocketFactory(new Clock(), clientKeyPair, credential, adminApi, 3307);
  try {
    sslSocketFactory.create(INSTANCE_CONNECTION_STRING);
    fail();
  } catch (RuntimeException e) {
    // TODO(berezv): should we throw something more specific than RuntimeException?
    assertThat(e.getMessage()).contains("Unable to obtain ephemeral certificate");
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-sql-jdbc-socket-factory,代码行数:23,代码来源:SslSocketFactoryTest.java

示例4: setUp

import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
  accessDenied = googleJsonResponseException(
      HttpStatusCodes.STATUS_CODE_FORBIDDEN, "Forbidden", "Forbidden");
  statusOk = googleJsonResponseException(
      HttpStatusCodes.STATUS_CODE_OK, "A reason", "ok");
  notFound = googleJsonResponseException(
      HttpStatusCodes.STATUS_CODE_NOT_FOUND, "Not found", "Not found");
  badRange = googleJsonResponseException(
      ApiErrorExtractor.STATUS_CODE_RANGE_NOT_SATISFIABLE, "Bad range", "Bad range");
  alreadyExists = googleJsonResponseException(
      409, "409", "409");
  resourceNotReady = googleJsonResponseException(
      400, ApiErrorExtractor.RESOURCE_NOT_READY_REASON_CODE, "Resource not ready");

  // This works because googleJsonResponseException takes final ErrorInfo
  ErrorInfo errorInfo = new ErrorInfo();
  errorInfo.setReason(ApiErrorExtractor.RATE_LIMITED_REASON_CODE);
  notRateLimited = googleJsonResponseException(POSSIBLE_RATE_LIMIT, errorInfo, "");
  errorInfo.setDomain(ApiErrorExtractor.USAGE_LIMITS_DOMAIN);
  rateLimited = googleJsonResponseException(POSSIBLE_RATE_LIMIT, errorInfo, "");
  errorInfo.setDomain(ApiErrorExtractor.GLOBAL_DOMAIN);
  bigqueryRateLimited = googleJsonResponseException(POSSIBLE_RATE_LIMIT, errorInfo, "");
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:25,代码来源:ApiErrorExtractorTest.java

示例5: googleJsonResponseException

import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入方法依赖的package包/类
/**
 * Builds a fake GoogleJsonResponseException for testing API error handling.
 */
private static GoogleJsonResponseException googleJsonResponseException(
    final int status, final String reason, final String message) throws IOException {
  final JsonFactory jsonFactory = new JacksonFactory();
  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      ErrorInfo errorInfo = new ErrorInfo();
      errorInfo.setReason(reason);
      errorInfo.setMessage(message);
      errorInfo.setFactory(jsonFactory);
      GenericJson error = new GenericJson();
      error.set("code", status);
      error.set("errors", Arrays.asList(errorInfo));
      error.setFactory(jsonFactory);
      GenericJson errorResponse = new GenericJson();
      errorResponse.set("error", error);
      errorResponse.setFactory(jsonFactory);
      return new MockLowLevelHttpRequest().setResponse(
          new MockLowLevelHttpResponse().setContent(errorResponse.toPrettyString())
          .setContentType(Json.MEDIA_TYPE).setStatusCode(status));
      }
  };
  HttpRequest request =
      transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
  request.setThrowExceptionOnExecuteError(false);
  HttpResponse response = request.execute();
  return GoogleJsonResponseException.from(jsonFactory, response);
}
 
开发者ID:apache,项目名称:beam,代码行数:32,代码来源:GcsUtilTest.java

示例6: errorWithReasonAndStatus

import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入方法依赖的package包/类
/** A helper that generates the error JSON payload that Google APIs produce. */
private static GoogleJsonErrorContainer errorWithReasonAndStatus(String reason, int status) {
  ErrorInfo info = new ErrorInfo();
  info.setReason(reason);
  info.setDomain("global");
  // GoogleJsonError contains one or more ErrorInfo objects; our utiities read the first one.
  GoogleJsonError error = new GoogleJsonError();
  error.setErrors(ImmutableList.of(info));
  error.setCode(status);
  error.setMessage(reason);
  // The actual JSON response is an error container.
  GoogleJsonErrorContainer container = new GoogleJsonErrorContainer();
  container.setError(error);
  return container;
}
 
开发者ID:apache,项目名称:beam,代码行数:16,代码来源:BigQueryServicesImplTest.java

示例7: googleJsonResponseException

import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; //导入方法依赖的package包/类
/**
 * Builds a fake GoogleJsonResponseException for testing API error handling.
 */
private static GoogleJsonResponseException googleJsonResponseException(
    int httpStatus, String reason, String message, String httpStatusString) throws IOException {
  ErrorInfo errorInfo = new ErrorInfo();
  errorInfo.setReason(reason);
  errorInfo.setMessage(message);
  return googleJsonResponseException(httpStatus, errorInfo, httpStatusString);
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:11,代码来源:ApiErrorExtractorTest.java


注:本文中的com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo.setReason方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。