blobStore.getContext().utils().date() .iso8601DateFormat(creationDate).trim());
blobStore.getContext().utils().date() .iso8601DateFormat(new Date()));
@Override public Utils utils() { return context.utils(); }
@Override public Utils utils() { return delegate().utils(); }
@Override public Utils utils() { return delegate().utils(); }
private LoadingCache<Credentials, Access> getAuthCache(BlobStoreContext context) { return context.utils().injector().getInstance(CachePeeker.class).authenticationResponseCache; }
@Test(groups = "live") public void testSetGetContainerMetadata() throws InterruptedException { CommonSwiftClient swift = view.utils().injector().getInstance(CommonSwiftClient.class); String containerName = getContainerName(); assertTrue(swift.createContainer(containerName)); ImmutableMap<String, String> metadata = ImmutableMap.<String, String> of( "key1", "value1", "key2", "value2"); assertTrue(swift.setContainerMetadata(containerName, metadata)); ContainerMetadata containerMetadata = swift.getContainerMetadata(containerName); assertEquals(containerMetadata.getMetadata().get("key1"), "value1"); assertEquals(containerMetadata.getMetadata().get("key2"), "value2"); }
public void testGetAndSetTemporaryUrlKey() { TemporaryUrlKeyApi client = view.utils().injector().getInstance(TemporaryUrlKeyApi.class); String currentSecretKey = client.getTemporaryUrlKey(); assertNotNull(currentSecretKey); try { String testKey = UUID.randomUUID().toString(); client.setTemporaryUrlKey(testKey); assertEquals(client.getTemporaryUrlKey(), testKey); } finally { client.setTemporaryUrlKey(currentSecretKey); } } }
@Test public void testSignGetUrl() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signGetBlob(container, name); assertEquals(request.getFilters().size(), 0); assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), text); } finally { returnContainer(container); } }
@Test public void testSignPutUrl() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { HttpRequest request = view.getSigner().signPutBlob(container, blob); assertEquals(request.getFilters().size(), 0); Strings2.toString(view.utils().http().invoke(request).getPayload()); assertConsistencyAwareContainerSize(container, 1); } finally { returnContainer(container); } }
@Test public void testSignGetUrlOptions() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signGetBlob(container, name, range(0, 1)); assertEquals(request.getFilters().size(), 0); assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), "fo"); } finally { returnContainer(container); } }
@Test public void testSignPutUrl() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("image/png").build(); String container = getContainerName(); try { HttpRequest request = view.getSigner().signPutBlob(container, blob); assertEquals(request.getFilters().size(), 0); Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()); blob = view.getBlobStore().getBlob(container, name); assertThat(blob.getMetadata().getContentMetadata().getContentType()).isEqualTo("image/png"); } finally { returnContainer(container); } }
@Test public void testSignGetUrl() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signGetBlob(container, name); assertEquals(request.getFilters().size(), 0); assertEquals(Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()), text); } finally { returnContainer(container); } }
@Test public void testSignPutUrlWithTime() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { HttpRequest request = view.getSigner().signPutBlob(container, blob, getSignedUrlTimeout()); assertEquals(request.getFilters().size(), 0); // Strip Expect: 100-continue to make actual responses visible, since // Java 7+ will throw a ProtocolException instead of setting the response code: // http://www.docjar.com/html/api/sun/net/www/protocol/http/HttpURLConnection.java.html#1021 request = request.toBuilder().removeHeader(EXPECT).build(); Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()); } finally { returnContainer(container); } }
@Test @Parameters( { "jclouds.blobstore.httpstream.url", "jclouds.blobstore.httpstream.md5" }) public void testCopyUrl(@Optional String httpStreamUrl, @Optional String httpStreamMD5) throws Exception { httpStreamUrl = checkNotNull(httpStreamUrl != null ? httpStreamUrl : sysHttpStreamUrl, "httpStreamUrl"); httpStreamMD5 = checkNotNull(httpStreamMD5 != null ? httpStreamMD5 : sysHttpStreamMD5, "httpStreamMd5"); HttpResponse response = view.utils().http().invoke(HttpRequest.builder().method("GET").endpoint(httpStreamUrl).build()); long length = response.getPayload().getContentMetadata().getContentLength(); String name = "hello"; byte[] md5 = base16().lowerCase().decode(httpStreamMD5); Blob blob = view.getBlobStore().blobBuilder(name).payload(response.getPayload()).contentLength(length) .contentMD5(md5).build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); checkMD5(container, name, md5); } finally { returnContainer(container); } }
@Test public void testSignGetUrlOptions() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signGetBlob(container, name, range(0, 1)); assertEquals(request.getFilters().size(), 0); assertEquals(Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()), "fo"); } finally { returnContainer(container); } }
@Test @Parameters( { "jclouds.blobstore.httpstream.url", "jclouds.blobstore.httpstream.md5" }) public void testCopyUrl(@Optional String httpStreamUrl, @Optional String httpStreamMD5) throws Exception { httpStreamUrl = checkNotNull(httpStreamUrl != null ? httpStreamUrl : sysHttpStreamUrl, "httpStreamUrl"); httpStreamMD5 = checkNotNull(httpStreamMD5 != null ? httpStreamMD5 : sysHttpStreamMD5, "httpStreamMd5"); HttpResponse response = view.utils().http().invoke(HttpRequest.builder().method("GET").endpoint(httpStreamUrl).build()); long length = response.getPayload().getContentMetadata().getContentLength(); String name = "hello"; byte[] md5 = base16().lowerCase().decode(httpStreamMD5); Blob blob = view.getBlobStore().blobBuilder(name).payload(response.getPayload()).contentLength(length) .contentMD5(md5).build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); checkMD5(container, name, md5); } finally { returnContainer(container); } }
@Test public void testSignGetUrlWithTime() throws InterruptedException, IOException { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signGetBlob(container, name, getSignedUrlTimeout()); assertEquals(request.getFilters().size(), 0); assertEquals(Strings2.toStringAndClose(view.utils().http().invoke(request).getPayload().openStream()), text); } finally { returnContainer(container); } }
@Test public void testSignRemoveUrl() throws Exception { String name = "hello"; String text = "fooooooooooooooooooooooo"; Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); String container = getContainerName(); try { view.getBlobStore().putBlob(container, blob); assertConsistencyAwareContainerSize(container, 1); HttpRequest request = view.getSigner().signRemoveBlob(container, name); assertEquals(request.getFilters().size(), 0); view.utils().http().invoke(request); assert !view.getBlobStore().blobExists(container, name); } finally { returnContainer(container); } } }
private void runCreateContainerInLocation(String payload, Location nonDefault) throws InterruptedException, IOException { String blobName = "hello"; BlobStore blobStore = view.getBlobStore(); final String containerName = getScratchContainerName(); try { Logger.getAnonymousLogger().info( String.format("creating public container %s in location %s", containerName, nonDefault.getId())); blobStore.createContainerInLocation(nonDefault, containerName, publicRead()); assertConsistencyAwareContainerExists(containerName); assertConsistencyAwareContainerInLocation(containerName, nonDefault); blobStore.putBlob(containerName, blobStore.blobBuilder(blobName).payload(payload).build()); assertConsistencyAwareContainerSize(containerName, 1); BlobMetadata metadata = view.getBlobStore().blobMetadata(containerName, blobName); assertEquals(Strings2.toStringAndClose(view.utils().http().get(metadata.getPublicUri())), payload); assertConsistencyAwareBlobInLocation(containerName, blobName, nonDefault); } finally { // this container is now public, so we can't reuse it directly recycleContainer(containerName); } }