use of com.google.cloud.BaseServiceException in project google-cloud-java by GoogleCloudPlatform.
the class ComputeExceptionTest method testTranslateAndThrow.
@Test
public void testTranslateAndThrow() throws Exception {
Exception cause = new ComputeException(500, "message");
RetryHelperException exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
ComputeException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(500, ex.getCode());
assertEquals("message", ex.getMessage());
assertTrue(ex.isRetryable());
} finally {
verify(exceptionMock);
}
cause = new IllegalArgumentException("message");
exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getMessage()).andReturn("message").times(1);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
ComputeException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(ComputeException.UNKNOWN_CODE, ex.getCode());
assertEquals("message", ex.getMessage());
assertFalse(ex.isRetryable());
assertSame(cause, ex.getCause());
} finally {
verify(exceptionMock);
}
}
use of com.google.cloud.BaseServiceException in project google-cloud-java by GoogleCloudPlatform.
the class ResourceManagerExceptionTest method testTranslateAndThrow.
@Test
public void testTranslateAndThrow() throws Exception {
Exception cause = new ResourceManagerException(503, "message");
RetryHelperException exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
ResourceManagerException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(503, ex.getCode());
assertEquals("message", ex.getMessage());
assertTrue(ex.isRetryable());
} finally {
verify(exceptionMock);
}
cause = new IllegalArgumentException("message");
exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getMessage()).andReturn("message").times(1);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
ResourceManagerException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(ResourceManagerException.UNKNOWN_CODE, ex.getCode());
assertEquals("message", ex.getMessage());
assertFalse(ex.isRetryable());
assertSame(cause, ex.getCause());
} finally {
verify(exceptionMock);
}
}
use of com.google.cloud.BaseServiceException in project google-cloud-java by GoogleCloudPlatform.
the class DatastoreExceptionTest method testTranslateAndThrow.
@Test
public void testTranslateAndThrow() throws Exception {
Exception cause = new DatastoreException(14, "message", "UNAVAILABLE");
RetryHelper.RetryHelperException exceptionMock = createMock(RetryHelper.RetryHelperException.class);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
DatastoreException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(14, ex.getCode());
assertEquals("message", ex.getMessage());
assertTrue(ex.isRetryable());
} finally {
verify(exceptionMock);
}
cause = new IllegalArgumentException("message");
exceptionMock = createMock(RetryHelper.RetryHelperException.class);
expect(exceptionMock.getMessage()).andReturn("message").times(1);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
DatastoreException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(DatastoreException.UNKNOWN_CODE, ex.getCode());
assertEquals("message", ex.getMessage());
assertFalse(ex.isRetryable());
assertSame(cause, ex.getCause());
} finally {
verify(exceptionMock);
}
}
use of com.google.cloud.BaseServiceException in project google-cloud-java by GoogleCloudPlatform.
the class DnsExceptionTest method testTranslateAndThrow.
@Test
public void testTranslateAndThrow() throws Exception {
IOException timeoutException = new SocketTimeoutException("message");
Exception cause = new DnsException(timeoutException, true);
RetryHelperException exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
DnsException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(DnsException.UNKNOWN_CODE, ex.getCode());
assertNull(ex.getReason());
assertEquals("message", ex.getMessage());
assertEquals(timeoutException, ex.getCause());
assertTrue(ex.isRetryable());
} finally {
verify(exceptionMock);
}
cause = new IllegalArgumentException("message");
exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getMessage()).andReturn("message").times(1);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
DnsException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(DnsException.UNKNOWN_CODE, ex.getCode());
assertEquals("message", ex.getMessage());
assertFalse(ex.isRetryable());
assertSame(cause, ex.getCause());
} finally {
verify(exceptionMock);
}
}
use of com.google.cloud.BaseServiceException in project google-cloud-java by GoogleCloudPlatform.
the class StorageExceptionTest method testTranslateAndThrow.
@Test
public void testTranslateAndThrow() throws Exception {
Exception cause = new StorageException(503, "message");
RetryHelperException exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
StorageException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(503, ex.getCode());
assertEquals("message", ex.getMessage());
assertTrue(ex.isRetryable());
} finally {
verify(exceptionMock);
}
cause = new IllegalArgumentException("message");
exceptionMock = createMock(RetryHelperException.class);
expect(exceptionMock.getMessage()).andReturn("message").times(1);
expect(exceptionMock.getCause()).andReturn(cause).times(2);
replay(exceptionMock);
try {
StorageException.translateAndThrow(exceptionMock);
} catch (BaseServiceException ex) {
assertEquals(StorageException.UNKNOWN_CODE, ex.getCode());
assertEquals("message", ex.getMessage());
assertFalse(ex.isRetryable());
assertSame(cause, ex.getCause());
} finally {
verify(exceptionMock);
}
}
Aggregations