本文整理汇总了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");
}
}
示例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");
}
}
示例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");
}
}
示例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, "");
}
示例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);
}
示例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;
}
示例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);
}