Package org.jclouds.openstack.swift.domain

Examples of org.jclouds.openstack.swift.domain.SwiftObject$Factory


      String destinationContainer = getContainerName();
      String destinationObject = "copy.txt";
      String destinationPath = "/" + destinationContainer + "/" + destinationObject;
      String badDestination = "baddestination";
      String data = "Hello World";
      SwiftObject sourceSwiftObject = newSwiftObject(data, sourceObject);
     
      getApi().putObject(sourceContainer, sourceSwiftObject);

      // test that not giving a destination name *doesn't* copy source name to the destination container with
      // the source name but copy still returns success :(
      assertTrue(getApi().copyObject(sourceContainer, sourceObject, destinationContainer, ""));
      assertFalse(getApi().objectExists(destinationContainer, sourceObject));
     
      // test copy works
      assertTrue(getApi().copyObject(sourceContainer, sourceObject, destinationContainer, destinationObject));     
      assertTrue(getApi().objectExists(destinationContainer, destinationObject));
     
      SwiftObject destinationSwiftObject = getApi().getObject(destinationContainer, destinationObject);
      assertEquals(Strings2.toStringAndClose(destinationSwiftObject.getPayload().openStream()), data);
     
      // test exception thrown on bad destination container
      try {
         assertFalse(getApi().copyObject(sourceContainer, sourceObject, badDestination, destinationObject));
         fail("Expected CopyObjectException");
View Full Code Here


       String contentType = getBlob.getPayload().getContentMetadata().getContentType();
       assert contentType.startsWith("text/plain") || "application/x-www-form-urlencoded".equals(contentType) : contentType;
   }

   protected SwiftObject newSwiftObject(String data, String key) throws IOException {
      SwiftObject object = getApi().newSwiftObject();
      object.getInfo().setName(key);
      object.setPayload(data);
      object.getPayload().getContentMetadata().setContentMD5(Hashing.md5().hashString(data, Charsets.UTF_8).asBytes());
      object.getInfo().setContentType("text/plain");
      object.getInfo().getMetadata().put("Metadata", "metadata-value");
      return object;
   }
View Full Code Here

@Test(groups = "unit", testName = "BindSwiftObjectMetadataToRequestTest")
public class BindSwiftObjectMetadataToRequestTest extends CommonSwiftClientTest {

   @Test
   public void testPassWithMinimumDetailsAndPayload5GB() {
      SwiftObject object = injector.getInstance(SwiftObject.Factory.class).create(null);
      Payload payload = Payloads.newStringPayload("");
      payload.getContentMetadata().setContentLength(5 * 1024 * 1024 * 1024l);
      object.setPayload(payload);
      object.getInfo().setName("foo");

      HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http://localhost").build();
      BindSwiftObjectMetadataToRequest binder = injector.getInstance(BindSwiftObjectMetadataToRequest.class);

      assertEquals(binder.bindToRequest(request, object), HttpRequest.builder().method("PUT").endpoint(
View Full Code Here

               URI.create("http://localhost")).build());
   }

   @Test
   public void testExtendedPropertiesBind() {
      SwiftObject object = injector.getInstance(SwiftObject.Factory.class).create(null);
      Payload payload = Payloads.newStringPayload("");
      payload.getContentMetadata().setContentLength(5 * 1024 * 1024 * 1024l);
      long expiresMillis = 1000;
      payload.getContentMetadata().setExpires(new Date(expiresMillis));
      object.setPayload(payload);
      object.getInfo().setName("foo");
      object.getInfo().getMetadata().putAll(ImmutableMap.of("foo", "bar"));

      HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http://localhost").build();
      BindSwiftObjectMetadataToRequest binder = injector.getInstance(BindSwiftObjectMetadataToRequest.class);

      assertEquals(binder.bindToRequest(request, object), HttpRequest.builder().method("PUT")
View Full Code Here

                     MILLISECONDS.toSeconds(expiresMillis)))
               .endpoint("http://localhost").addHeader("X-Object-Meta-foo", "bar").build());
   }

   public void testNoContentLengthIsChunked() {
      SwiftObject object = injector.getInstance(SwiftObject.Factory.class).create(null);
      Payload payload = Payloads.newStringPayload("");
      payload.getContentMetadata().setContentLength(null);
      object.setPayload(payload);
      object.getInfo().setName("foo");

      HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http://localhost").build();
      BindSwiftObjectMetadataToRequest binder = injector.getInstance(BindSwiftObjectMetadataToRequest.class);

      assertEquals(binder.bindToRequest(request, object), HttpRequest.builder().method("PUT")
View Full Code Here

               .endpoint("http://localhost").addHeader("Transfer-Encoding", "chunked").build());
   }

   @Test(expectedExceptions = IllegalArgumentException.class)
   public void testNoNameIsBad() {
      SwiftObject object = injector.getInstance(SwiftObject.Factory.class).create(null);
      Payload payload = Payloads.newStringPayload("");
      payload.getContentMetadata().setContentLength(5368709120000l);
      object.setPayload(payload);

      HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http://localhost").build();
      BindSwiftObjectMetadataToRequest binder = injector.getInstance(BindSwiftObjectMetadataToRequest.class);
      binder.bindToRequest(request, object);
   }
View Full Code Here

      binder.bindToRequest(request, object);
   }

   @Test(expectedExceptions = IllegalArgumentException.class)
   public void testOver5GBIsBad() {
      SwiftObject object = injector.getInstance(SwiftObject.Factory.class).create(null);
      Payload payload = Payloads.newStringPayload("");
      payload.getContentMetadata().setContentLength(5 * 1024 * 1024 * 1024l + 1);
      object.setPayload(payload);
      object.getInfo().setName("foo");

      HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http://localhost").build();
      BindSwiftObjectMetadataToRequest binder = injector.getInstance(BindSwiftObjectMetadataToRequest.class);
      binder.bindToRequest(request, object);
   }
View Full Code Here

TOP

Related Classes of org.jclouds.openstack.swift.domain.SwiftObject$Factory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.