com.google.api.client.googleapis.json.GoogleJsonError

Here are the examples of the java api class com.google.api.client.googleapis.json.GoogleJsonError taken from open source projects.

1. BigQueryTableInserterTest#errorWithReasonAndStatus()

Project: DataflowJavaSDK
File: BigQueryTableInserterTest.java
/** 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);
    // The actual JSON response is an error container.
    GoogleJsonErrorContainer container = new GoogleJsonErrorContainer();
    container.setError(error);
    return container;
}

2. BigQueryServicesImplTest#errorWithReasonAndStatus()

Project: DataflowJavaSDK
File: BigQueryServicesImplTest.java
/** 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);
    // The actual JSON response is an error container.
    GoogleJsonErrorContainer container = new GoogleJsonErrorContainer();
    container.setError(error);
    return container;
}

3. BigQueryTableInserterTest#errorWithReasonAndStatus()

Project: incubator-beam
File: BigQueryTableInserterTest.java
/** 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);
    // The actual JSON response is an error container.
    GoogleJsonErrorContainer container = new GoogleJsonErrorContainer();
    container.setError(error);
    return container;
}

4. BigQueryServicesImplTest#errorWithReasonAndStatus()

Project: incubator-beam
File: BigQueryServicesImplTest.java
/** 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);
    // The actual JSON response is an error container.
    GoogleJsonErrorContainer container = new GoogleJsonErrorContainer();
    container.setError(error);
    return container;
}

5. DnsBatchTest#testGetChangeRequestNotFound()

Project: gcloud-java
File: DnsBatchTest.java
@Test
public void testGetChangeRequestNotFound() {
    EasyMock.reset(batchMock);
    Capture<RpcBatch.Callback<Change>> callback = Capture.newInstance();
    Capture<Map<DnsRpc.Option, Object>> capturedOptions = Capture.newInstance();
    batchMock.addGetChangeRequest(EasyMock.eq(ZONE_NAME), EasyMock.eq(CHANGE_REQUEST_COMPLETE.generatedId()), EasyMock.capture(callback), EasyMock.capture(capturedOptions));
    EasyMock.replay(batchMock);
    DnsBatchResult<ChangeRequest> batchResult = dnsBatch.getChangeRequest(ZONE_NAME, CHANGE_REQUEST_COMPLETE.generatedId());
    assertEquals(0, capturedOptions.getValue().size());
    RpcBatch.Callback<Change> capturedCallback = callback.getValue();
    GoogleJsonError error = new GoogleJsonError();
    GoogleJsonError.ErrorInfo errorInfo = new GoogleJsonError.ErrorInfo();
    errorInfo.setReason("reason");
    errorInfo.setLocation("entity.parameters.changeId");
    error.setCode(404);
    error.setErrors(ImmutableList.of(errorInfo));
    capturedCallback.onFailure(error);
    assertNull(batchResult.get());
}

6. DnsBatchTest#testGetZoneNotFound()

Project: gcloud-java
File: DnsBatchTest.java
@Test
public void testGetZoneNotFound() {
    EasyMock.reset(batchMock);
    Capture<RpcBatch.Callback<ManagedZone>> callback = Capture.newInstance();
    Capture<Map<DnsRpc.Option, Object>> capturedOptions = Capture.newInstance();
    batchMock.addGetZone(EasyMock.eq(ZONE_NAME), EasyMock.capture(callback), EasyMock.capture(capturedOptions));
    EasyMock.replay(batchMock);
    DnsBatchResult<Zone> batchResult = dnsBatch.getZone(ZONE_NAME);
    assertEquals(0, capturedOptions.getValue().size());
    GoogleJsonError error = new GoogleJsonError();
    error.setCode(404);
    RpcBatch.Callback<ManagedZone> capturedCallback = callback.getValue();
    capturedCallback.onFailure(error);
    assertNull(batchResult.get());
}

7. StorageExceptionTest#testStorageException()

Project: gcloud-java
File: StorageExceptionTest.java
@Test
public void testStorageException() {
    StorageException exception = new StorageException(500, "message");
    assertEquals(500, exception.code());
    assertEquals("message", exception.getMessage());
    assertNull(exception.reason());
    assertTrue(exception.retryable());
    assertTrue(exception.idempotent());
    exception = new StorageException(502, "message");
    assertEquals(502, exception.code());
    assertEquals("message", exception.getMessage());
    assertNull(exception.reason());
    assertTrue(exception.retryable());
    assertTrue(exception.idempotent());
    exception = new StorageException(503, "message");
    assertEquals(503, exception.code());
    assertEquals("message", exception.getMessage());
    assertNull(exception.reason());
    assertTrue(exception.retryable());
    assertTrue(exception.idempotent());
    exception = new StorageException(504, "message");
    assertEquals(504, exception.code());
    assertEquals("message", exception.getMessage());
    assertNull(exception.reason());
    assertTrue(exception.retryable());
    assertTrue(exception.idempotent());
    exception = new StorageException(429, "message");
    assertEquals(429, exception.code());
    assertEquals("message", exception.getMessage());
    assertNull(exception.reason());
    assertTrue(exception.retryable());
    assertTrue(exception.idempotent());
    exception = new StorageException(408, "message");
    assertEquals(408, exception.code());
    assertEquals("message", exception.getMessage());
    assertNull(exception.reason());
    assertTrue(exception.retryable());
    assertTrue(exception.idempotent());
    exception = new StorageException(400, "message");
    assertEquals(400, exception.code());
    assertEquals("message", exception.getMessage());
    assertNull(exception.reason());
    assertFalse(exception.retryable());
    assertTrue(exception.idempotent());
    IOException cause = new SocketTimeoutException();
    exception = new StorageException(cause);
    assertNull(exception.reason());
    assertNull(exception.getMessage());
    assertTrue(exception.retryable());
    assertTrue(exception.idempotent());
    assertSame(cause, exception.getCause());
    GoogleJsonError error = new GoogleJsonError();
    error.setCode(503);
    error.setMessage("message");
    exception = new StorageException(error);
    assertEquals(503, exception.code());
    assertEquals("message", exception.getMessage());
    assertTrue(exception.retryable());
    assertTrue(exception.idempotent());
    exception = new StorageException(400, "message", cause);
    assertEquals(400, exception.code());
    assertEquals("message", exception.getMessage());
    assertNull(exception.reason());
    assertFalse(exception.retryable());
    assertTrue(exception.idempotent());
    assertSame(cause, exception.getCause());
}

8. DnsExceptionTest#testDnsException()

Project: gcloud-java
File: DnsExceptionTest.java
@Test
public void testDnsException() throws Exception {
    IOException cause = new SocketTimeoutException("socketTimeoutMessage");
    DnsException exception = new DnsException(500, "message", cause);
    assertEquals(500, exception.code());
    assertEquals("message", exception.getMessage());
    assertNull(exception.reason());
    assertTrue(exception.retryable());
    assertTrue(exception.idempotent());
    assertSame(cause, exception.getCause());
    exception = new DnsException(502, "message", cause);
    assertEquals(502, exception.code());
    assertEquals("message", exception.getMessage());
    assertNull(exception.reason());
    assertTrue(exception.retryable());
    assertTrue(exception.idempotent());
    assertSame(cause, exception.getCause());
    exception = new DnsException(503, "message", cause);
    assertEquals(503, exception.code());
    assertEquals("message", exception.getMessage());
    assertNull(exception.reason());
    assertTrue(exception.retryable());
    assertTrue(exception.idempotent());
    assertSame(cause, exception.getCause());
    exception = new DnsException(429, "message", cause);
    assertEquals(429, exception.code());
    assertEquals("message", exception.getMessage());
    assertNull(exception.reason());
    assertTrue(exception.retryable());
    assertTrue(exception.idempotent());
    assertSame(cause, exception.getCause());
    exception = new DnsException(404, "message", cause);
    assertEquals(404, exception.code());
    assertEquals("message", exception.getMessage());
    assertNull(exception.reason());
    assertFalse(exception.retryable());
    assertTrue(exception.idempotent());
    assertSame(cause, exception.getCause());
    exception = new DnsException(cause, true);
    assertEquals(DnsException.UNKNOWN_CODE, exception.code());
    assertNull(exception.reason());
    assertEquals("socketTimeoutMessage", exception.getMessage());
    assertEquals(cause, exception.getCause());
    assertTrue(exception.retryable());
    assertTrue(exception.idempotent());
    assertSame(cause, exception.getCause());
    GoogleJsonError error = new GoogleJsonError();
    error.setCode(503);
    error.setMessage("message");
    exception = new DnsException(error, true);
    assertEquals(503, exception.code());
    assertEquals("message", exception.getMessage());
    assertTrue(exception.retryable());
    assertTrue(exception.idempotent());
}

9. BaseServiceExceptionTest#testBaseServiceException()

Project: gcloud-java
File: BaseServiceExceptionTest.java
@Test
public void testBaseServiceException() {
    BaseServiceException serviceException = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT);
    assertEquals(CODE, serviceException.code());
    assertEquals(MESSAGE, serviceException.getMessage());
    assertEquals(REASON, serviceException.reason());
    assertFalse(serviceException.retryable());
    assertEquals(IDEMPOTENT, serviceException.idempotent());
    assertNull(serviceException.getCause());
    serviceException = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT);
    assertEquals(CODE, serviceException.code());
    assertEquals(MESSAGE, serviceException.getMessage());
    assertEquals(REASON, serviceException.reason());
    assertFalse(serviceException.retryable());
    assertEquals(IDEMPOTENT, serviceException.idempotent());
    assertNull(serviceException.getCause());
    Exception cause = new RuntimeException();
    serviceException = new BaseServiceException(CODE, MESSAGE, REASON, IDEMPOTENT, cause);
    assertEquals(CODE, serviceException.code());
    assertEquals(MESSAGE, serviceException.getMessage());
    assertEquals(REASON, serviceException.reason());
    assertFalse(serviceException.retryable());
    assertEquals(IDEMPOTENT, serviceException.idempotent());
    assertEquals(cause, serviceException.getCause());
    serviceException = new BaseServiceException(CODE, MESSAGE, REASON, false, cause);
    assertEquals(CODE, serviceException.code());
    assertEquals(MESSAGE, serviceException.getMessage());
    assertEquals(REASON, serviceException.reason());
    assertFalse(serviceException.retryable());
    assertFalse(serviceException.idempotent());
    assertEquals(cause, serviceException.getCause());
    IOException exception = new SocketTimeoutException();
    serviceException = new BaseServiceException(exception, true);
    assertTrue(serviceException.retryable());
    assertTrue(serviceException.idempotent());
    assertEquals(exception, serviceException.getCause());
    GoogleJsonError error = new GoogleJsonError();
    error.setCode(CODE);
    error.setMessage(MESSAGE);
    serviceException = new BaseServiceException(error, true);
    assertEquals(CODE, serviceException.code());
    assertEquals(MESSAGE, serviceException.getMessage());
    assertFalse(serviceException.retryable());
    assertTrue(serviceException.idempotent());
    serviceException = new CustomServiceException(CODE, MESSAGE, REASON, IDEMPOTENT);
    assertEquals(CODE, serviceException.code());
    assertEquals(MESSAGE, serviceException.getMessage());
    assertEquals(REASON, serviceException.reason());
    assertEquals(RETRYABLE, serviceException.retryable());
    assertEquals(IDEMPOTENT, serviceException.idempotent());
    serviceException = new CustomServiceException(CODE_NO_REASON, MESSAGE, null, IDEMPOTENT);
    assertEquals(CODE_NO_REASON, serviceException.code());
    assertEquals(MESSAGE, serviceException.getMessage());
    assertNull(serviceException.reason());
    assertEquals(RETRYABLE, serviceException.retryable());
    assertEquals(IDEMPOTENT, serviceException.idempotent());
    serviceException = new CustomServiceException(UNKNOWN_CODE, MESSAGE, REASON, IDEMPOTENT);
    assertEquals(UNKNOWN_CODE, serviceException.code());
    assertEquals(MESSAGE, serviceException.getMessage());
    assertEquals(REASON, serviceException.reason());
    assertEquals(RETRYABLE, serviceException.retryable());
    assertEquals(IDEMPOTENT, serviceException.idempotent());
}

10. DnsBatchTest#testCreateZone()

Project: gcloud-java
File: DnsBatchTest.java
@Test
public void testCreateZone() {
    EasyMock.reset(batchMock);
    Capture<RpcBatch.Callback<ManagedZone>> callback = Capture.newInstance();
    Capture<Map<DnsRpc.Option, Object>> capturedOptions = Capture.newInstance();
    Capture<ManagedZone> capturedZone = Capture.newInstance();
    batchMock.addCreateZone(EasyMock.capture(capturedZone), EasyMock.capture(callback), EasyMock.capture(capturedOptions));
    EasyMock.replay(batchMock);
    DnsBatchResult<Zone> batchResult = dnsBatch.createZone(ZONE_INFO);
    assertEquals(0, capturedOptions.getValue().size());
    assertEquals(ZONE_INFO.toPb(), capturedZone.getValue());
    assertNotNull(callback.getValue());
    try {
        batchResult.get();
        fail("No result available yet.");
    } catch (IllegalStateException ex) {
    }
    // testing error here, success is tested with options
    RpcBatch.Callback<ManagedZone> capturedCallback = callback.getValue();
    GoogleJsonError error = new GoogleJsonError();
    error.setCode(404);
    capturedCallback.onFailure(error);
    try {
        batchResult.get();
        fail("Should throw a DnsException on error.");
    } catch (DnsException ex) {
        assertTrue(ex.idempotent());
    }
}

11. DnsBatchTest#testApplyChangeRequest()

Project: gcloud-java
File: DnsBatchTest.java
@Test
public void testApplyChangeRequest() {
    EasyMock.reset(batchMock);
    Capture<RpcBatch.Callback<Change>> callback = Capture.newInstance();
    Capture<Map<DnsRpc.Option, Object>> capturedOptions = Capture.newInstance();
    batchMock.addApplyChangeRequest(EasyMock.eq(ZONE_NAME), EasyMock.eq(CHANGE_REQUEST_PARTIAL.toPb()), EasyMock.capture(callback), EasyMock.capture(capturedOptions));
    EasyMock.replay(batchMock);
    DnsBatchResult<ChangeRequest> batchResult = dnsBatch.applyChangeRequest(ZONE_INFO.name(), CHANGE_REQUEST_PARTIAL);
    assertEquals(0, capturedOptions.getValue().size());
    assertNotNull(callback.getValue());
    try {
        batchResult.get();
        fail("No result available yet.");
    } catch (IllegalStateException ex) {
    }
    // testing error here, success is tested with options
    RpcBatch.Callback<Change> capturedCallback = callback.getValue();
    GoogleJsonError error = new GoogleJsonError();
    error.setCode(404);
    capturedCallback.onFailure(error);
    try {
        batchResult.get();
        fail("Should throw a DnsException on error.");
    } catch (DnsException ex) {
        assertFalse(ex.idempotent());
    }
}