/** * {@inheritDoc} */ @Override public void setPayload(String data) { setPayload(newPayload(checkNotNull(data, "data"))); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; BlobImpl other = (BlobImpl) obj; if (metadata == null) { if (other.metadata != null) return false; } else if (!metadata.equals(other.metadata)) return false; return true; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((metadata == null) ? 0 : metadata.hashCode()); return result; }
@Override public PayloadEnclosingImpl apply(HttpResponse response) { PayloadEnclosingImpl impl = new PayloadEnclosingImpl(); impl.setPayload(response.getPayload()); return impl; } }
public void multipartUpload() throws Exception { server.enqueue(jsonResponse("/object_get.json")); PayloadEnclosing p = new PayloadEnclosingImpl(); String testPayload = "this is a test payload for upload!"; p.setPayload(testPayload.getBytes()); ObjectTemplate template = new ObjectTemplate().name("file_name").size((long) testPayload.length()).crc32c("crc32c").contentType(MediaType.ANY_TEXT_TYPE); assertEquals(objectApi().multipartUpload("bucket_name", template, p.getPayload()), new ParseGoogleCloudStorageObject().expected()); RecordedRequest request = assertSent(server, "POST", "/upload/storage/v1/b/bucket_name/o?uploadType=multipart", null); assertTrue(new String(request.getBody(), UTF_8).contains(testPayload)); assertTrue(new String(request.getBody(), UTF_8).contains(testPayload)); //TODO: this should be a more robust assertion about the formatting of the payload }
@Test(groups = "live") public void testPutBlobWithMd5() throws IOException, InterruptedException { String containerName = getContainerName(); String blobName = "md5test"; try { long contentLength = 32 * 1024L; ByteSource byteSource = TestUtils.randomByteSource().slice(0, contentLength); ByteSourcePayload payload = Payloads.newByteSourcePayload(byteSource); PayloadEnclosingImpl payloadImpl = new PayloadEnclosingImpl(payload); BlobStore blobStore = view.getBlobStore(); // This would trigger server side validation of md5 HashCode hcMd5 = byteSource.hash(Hashing.md5()); Blob blob = blobStore.blobBuilder(blobName).payload(payloadImpl.getPayload()).contentType("image/jpeg") .contentLength(contentLength).contentLanguage("en").contentDisposition("attachment") .contentMD5(hcMd5).userMetadata(ImmutableMap.of("Adrian", "powderpuff")).build(); blobStore.putBlob(containerName, blob); checkMD5(containerName, blobName, hcMd5.asBytes()); } finally { returnContainer(containerName); } } }
@Override public PayloadEnclosingImpl apply(HttpResponse response) { PayloadEnclosingImpl impl = new PayloadEnclosingImpl(); impl.setPayload(response.getPayload()); return impl; } }
public void testPutPayloadEnclosing() throws SecurityException, NoSuchMethodException, IOException { Invokable<?, ?> method = method(TestTransformers.class, "put", PayloadEnclosing.class); GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList.<Object> of(new PayloadEnclosingImpl(newStringPayload("whoops"))))); assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "whoops", "application/unknown", false); }
/** * {@inheritDoc} */ @Override public void setPayload(File data) { setPayload(newPayload(checkNotNull(data, "data"))); }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((metadata == null) ? 0 : metadata.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; AzureBlobImpl other = (AzureBlobImpl) obj; if (properties == null) { if (other.properties != null) return false; } else if (!properties.equals(other.properties)) return false; return true; }
@Override public PayloadEnclosingImpl apply(HttpResponse response) { PayloadEnclosingImpl impl = new PayloadEnclosingImpl(); impl.setPayload(response.getPayload()); return impl; } }
public void testPutPayloadEnclosing() throws Exception { Invokable<?, ?> method = method(TestTransformers.class, "put", PayloadEnclosing.class); GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList.<Object> of(new PayloadEnclosingImpl(newStringPayload("whoops"))))); assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "whoops", "application/unknown", false); }
/** * {@inheritDoc} */ @Override public void setPayload(String data) { setPayload(newPayload(checkNotNull(data, "data"))); }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((properties == null) ? 0 : properties.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; BlobImpl other = (BlobImpl) obj; if (metadata == null) { if (other.metadata != null) return false; } else if (!metadata.equals(other.metadata)) return false; return true; }
public void testPutPayloadEnclosingGenerateMD5() throws SecurityException, NoSuchMethodException, IOException { Invokable<?, ?> method = method(TestTransformers.class, "put", PayloadEnclosing.class); PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(newStringPayload("whoops")); calculateMD5(payloadEnclosing); GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList.<Object> of(payloadEnclosing))); assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1"); assertNonPayloadHeadersEqual(request, ""); assertPayloadEquals(request, "whoops", "application/unknown", true); }
/** * {@inheritDoc} */ @Override public void setPayload(File data) { setPayload(newPayload(checkNotNull(data, "data"))); }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((metadata == null) ? 0 : metadata.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; BlobImpl other = (BlobImpl) obj; if (metadata == null) { if (other.metadata != null) return false; } else if (!metadata.equals(other.metadata)) return false; return true; }