Search in sources :

Example 11 with GoogleJsonError

use of com.google.api.client.googleapis.json.GoogleJsonError in project google-cloud-java by GoogleCloudPlatform.

the class StorageImplTest method testDeleteAllIterable.

@Test
public void testDeleteAllIterable() {
    BlobId blobId1 = BlobId.of(BUCKET_NAME1, BLOB_NAME1);
    BlobId blobId2 = BlobId.of(BUCKET_NAME1, BLOB_NAME2);
    RpcBatch batchMock = EasyMock.createMock(RpcBatch.class);
    Capture<RpcBatch.Callback<Void>> callback1 = Capture.newInstance();
    Capture<RpcBatch.Callback<Void>> callback2 = Capture.newInstance();
    batchMock.addDelete(EasyMock.eq(blobId1.toPb()), EasyMock.capture(callback1), EasyMock.eq(ImmutableMap.<StorageRpc.Option, Object>of()));
    batchMock.addDelete(EasyMock.eq(blobId2.toPb()), EasyMock.capture(callback2), EasyMock.eq(ImmutableMap.<StorageRpc.Option, Object>of()));
    EasyMock.expect(storageRpcMock.createBatch()).andReturn(batchMock);
    batchMock.submit();
    EasyMock.replay(storageRpcMock, batchMock);
    initializeService();
    List<Boolean> result = storage.delete(blobId1, blobId2);
    callback1.getValue().onSuccess(null);
    callback2.getValue().onFailure(new GoogleJsonError());
    assertEquals(2, result.size());
    assertTrue(result.get(0));
    assertFalse(result.get(1));
    EasyMock.verify(batchMock);
}
Also used : BlobWriteOption(com.google.cloud.storage.Storage.BlobWriteOption) BucketSourceOption(com.google.cloud.storage.Storage.BucketSourceOption) BlobSourceOption(com.google.cloud.storage.Storage.BlobSourceOption) BlobTargetOption(com.google.cloud.storage.Storage.BlobTargetOption) StorageObject(com.google.api.services.storage.model.StorageObject) GoogleJsonError(com.google.api.client.googleapis.json.GoogleJsonError) RpcBatch(com.google.cloud.storage.spi.v1.RpcBatch) Test(org.junit.Test)

Example 12 with GoogleJsonError

use of com.google.api.client.googleapis.json.GoogleJsonError in project google-cloud-java by GoogleCloudPlatform.

the class StorageImplTest method testUpdateAllArray.

@Test
public void testUpdateAllArray() {
    RpcBatch batchMock = EasyMock.createMock(RpcBatch.class);
    Capture<RpcBatch.Callback<StorageObject>> callback1 = Capture.newInstance();
    Capture<RpcBatch.Callback<StorageObject>> callback2 = Capture.newInstance();
    batchMock.addPatch(EasyMock.eq(BLOB_INFO1.toPb()), EasyMock.capture(callback1), EasyMock.eq(ImmutableMap.<StorageRpc.Option, Object>of()));
    batchMock.addPatch(EasyMock.eq(BLOB_INFO2.toPb()), EasyMock.capture(callback2), EasyMock.eq(ImmutableMap.<StorageRpc.Option, Object>of()));
    EasyMock.expect(storageRpcMock.createBatch()).andReturn(batchMock);
    batchMock.submit();
    EasyMock.replay(storageRpcMock, batchMock);
    initializeService();
    List<Blob> resultBlobs = storage.update(BLOB_INFO1, BLOB_INFO2);
    callback1.getValue().onSuccess(BLOB_INFO1.toPb());
    callback2.getValue().onFailure(new GoogleJsonError());
    assertEquals(2, resultBlobs.size());
    assertEquals(new Blob(storage, new BlobInfo.BuilderImpl(BLOB_INFO1)), resultBlobs.get(0));
    assertNull(resultBlobs.get(1));
    EasyMock.verify(batchMock);
}
Also used : BlobWriteOption(com.google.cloud.storage.Storage.BlobWriteOption) BucketSourceOption(com.google.cloud.storage.Storage.BucketSourceOption) BlobSourceOption(com.google.cloud.storage.Storage.BlobSourceOption) BlobTargetOption(com.google.cloud.storage.Storage.BlobTargetOption) StorageObject(com.google.api.services.storage.model.StorageObject) GoogleJsonError(com.google.api.client.googleapis.json.GoogleJsonError) RpcBatch(com.google.cloud.storage.spi.v1.RpcBatch) Test(org.junit.Test)

Example 13 with GoogleJsonError

use of com.google.api.client.googleapis.json.GoogleJsonError in project google-cloud-java by GoogleCloudPlatform.

the class DnsBatchTest method testCreateZone.

@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) {
    // expected
    }
    // 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) {
    // expected
    }
}
Also used : ManagedZone(com.google.api.services.dns.model.ManagedZone) RpcBatch(com.google.cloud.dns.spi.v1.RpcBatch) DnsRpc(com.google.cloud.dns.spi.v1.DnsRpc) ManagedZone(com.google.api.services.dns.model.ManagedZone) GoogleJsonError(com.google.api.client.googleapis.json.GoogleJsonError) Map(java.util.Map) Test(org.junit.Test)

Example 14 with GoogleJsonError

use of com.google.api.client.googleapis.json.GoogleJsonError in project google-cloud-java by GoogleCloudPlatform.

the class DnsBatchTest method testApplyChangeRequest.

@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.getName(), CHANGE_REQUEST_PARTIAL);
    assertEquals(0, capturedOptions.getValue().size());
    assertNotNull(callback.getValue());
    try {
        batchResult.get();
        fail("No result available yet.");
    } catch (IllegalStateException ex) {
    // expected
    }
    // 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) {
    // expected
    }
}
Also used : Change(com.google.api.services.dns.model.Change) RpcBatch(com.google.cloud.dns.spi.v1.RpcBatch) DnsRpc(com.google.cloud.dns.spi.v1.DnsRpc) GoogleJsonError(com.google.api.client.googleapis.json.GoogleJsonError) Map(java.util.Map) Test(org.junit.Test)

Example 15 with GoogleJsonError

use of com.google.api.client.googleapis.json.GoogleJsonError in project google-cloud-java by GoogleCloudPlatform.

the class DnsExceptionTest method testDnsException.

@Test
public void testDnsException() throws Exception {
    IOException cause = new SocketTimeoutException("socketTimeoutMessage");
    DnsException exception = new DnsException(500, "message", cause);
    assertEquals(500, exception.getCode());
    assertEquals("message", exception.getMessage());
    assertNull(exception.getReason());
    assertTrue(exception.isRetryable());
    assertSame(cause, exception.getCause());
    exception = new DnsException(502, "message", cause);
    assertEquals(502, exception.getCode());
    assertEquals("message", exception.getMessage());
    assertNull(exception.getReason());
    assertTrue(exception.isRetryable());
    assertSame(cause, exception.getCause());
    exception = new DnsException(503, "message", cause);
    assertEquals(503, exception.getCode());
    assertEquals("message", exception.getMessage());
    assertNull(exception.getReason());
    assertTrue(exception.isRetryable());
    assertSame(cause, exception.getCause());
    exception = new DnsException(429, "message", cause);
    assertEquals(429, exception.getCode());
    assertEquals("message", exception.getMessage());
    assertNull(exception.getReason());
    assertTrue(exception.isRetryable());
    assertSame(cause, exception.getCause());
    exception = new DnsException(404, "message", cause);
    assertEquals(404, exception.getCode());
    assertEquals("message", exception.getMessage());
    assertNull(exception.getReason());
    assertFalse(exception.isRetryable());
    assertSame(cause, exception.getCause());
    exception = new DnsException(cause, true);
    assertEquals(DnsException.UNKNOWN_CODE, exception.getCode());
    assertNull(exception.getReason());
    assertEquals("socketTimeoutMessage", exception.getMessage());
    assertEquals(cause, exception.getCause());
    assertTrue(exception.isRetryable());
    assertSame(cause, exception.getCause());
    GoogleJsonError error = new GoogleJsonError();
    error.setCode(503);
    error.setMessage("message");
    exception = new DnsException(error, true);
    assertEquals(503, exception.getCode());
    assertEquals("message", exception.getMessage());
    assertTrue(exception.isRetryable());
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) GoogleJsonError(com.google.api.client.googleapis.json.GoogleJsonError) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

GoogleJsonError (com.google.api.client.googleapis.json.GoogleJsonError)20 Test (org.junit.Test)13 StorageObject (com.google.api.services.storage.model.StorageObject)8 IOException (java.io.IOException)8 BlobSourceOption (com.google.cloud.storage.Storage.BlobSourceOption)6 BlobTargetOption (com.google.cloud.storage.Storage.BlobTargetOption)6 BlobWriteOption (com.google.cloud.storage.Storage.BlobWriteOption)6 BucketSourceOption (com.google.cloud.storage.Storage.BucketSourceOption)6 RpcBatch (com.google.cloud.storage.spi.v1.RpcBatch)6 HttpHeaders (com.google.api.client.http.HttpHeaders)5 DnsRpc (com.google.cloud.dns.spi.v1.DnsRpc)4 RpcBatch (com.google.cloud.dns.spi.v1.RpcBatch)4 Map (java.util.Map)4 HttpResponseException (com.google.api.client.http.HttpResponseException)3 Objects (com.google.api.services.storage.model.Objects)3 SocketTimeoutException (java.net.SocketTimeoutException)3 GenericUrl (com.google.api.client.http.GenericUrl)2 HttpRequest (com.google.api.client.http.HttpRequest)2 HttpResponse (com.google.api.client.http.HttpResponse)2 LowLevelHttpResponse (com.google.api.client.http.LowLevelHttpResponse)2