Package org.jclouds.http.options

Examples of org.jclouds.http.options.GetOptions


            ImmutableList.of(dateService.rfc822DateFormat(date)));
   }

   public void testCreateGetOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
      Date date = new Date();
      GetOptions options = GetOptions.Builder.ifModifiedSince(date);
      Invokable<?, ?> method = method(TestRequest.class, "get", String.class, HttpRequestOptions.class);
      GeneratedHttpRequest request = processor.apply(Invocation.create(method,
            ImmutableList.<Object> of("1", options)));
      assertEquals(request.getEndpoint().getHost(), "localhost");
      assertEquals(request.getEndpoint().getPath(), "/1");


    * @param key
    *           blob key
    */
   @Override
   public Blob getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) {
      GetOptions azureOptions = blob2ObjectGetOptions.apply(options);
      return azureBlob2Blob.apply(sync.getBlob(container, key, azureOptions));

   }

      Date ifUnmodifiedSince = new Date(999999l);

      org.jclouds.blobstore.options.GetOptions in = new org.jclouds.blobstore.options.GetOptions();
      in.ifUnmodifiedSince(ifUnmodifiedSince);
      GetOptions expected = new GetOptions();
      expected.ifUnmodifiedSince(ifUnmodifiedSince);

      assertEquals(fn.apply(in), expected);
   }

      Date ifModifiedSince = new Date(999999l);

      org.jclouds.blobstore.options.GetOptions in = new org.jclouds.blobstore.options.GetOptions();
      in.ifModifiedSince(ifModifiedSince);
      GetOptions expected = new GetOptions();
      expected.ifModifiedSince(ifModifiedSince);

      assertEquals(fn.apply(in), expected);
   }

      String ifUnmatch = "foo";

      org.jclouds.blobstore.options.GetOptions in = new org.jclouds.blobstore.options.GetOptions();
      in.ifETagDoesntMatch(ifUnmatch);
      GetOptions expected = new GetOptions();
      expected.ifETagDoesntMatch(ifUnmatch);

      assertEquals(fn.apply(in), expected);
   }

      String ifMatch = "foo";

      org.jclouds.blobstore.options.GetOptions in = new org.jclouds.blobstore.options.GetOptions();
      in.ifETagMatches(ifMatch);
     
      GetOptions expected = new GetOptions();
      expected.ifETagMatches(ifMatch);

      assertEquals(fn.apply(in), expected);
   }

   public void testRanges(){
      org.jclouds.blobstore.options.GetOptions in = new org.jclouds.blobstore.options.GetOptions();
      in.range(0,1024);
      in.startAt(2048);
     
      GetOptions expected = new GetOptions();
      expected.range(0,1024);
      expected.startAt(2048);

      assertEquals(fn.apply(in), expected);

   }

   @Test
   public void testRangesTail(){
      org.jclouds.blobstore.options.GetOptions in = new org.jclouds.blobstore.options.GetOptions();
      in.tail(1024);

      GetOptions expected = new GetOptions();
      expected.tail(1024);

      assertEquals(fn.apply(in), expected);

   }

   @Test
   public void testRangesStart(){
      org.jclouds.blobstore.options.GetOptions in = new org.jclouds.blobstore.options.GetOptions();
      in.startAt(1024);

      GetOptions expected = new GetOptions();
      expected.startAt(1024);

      assertEquals(fn.apply(in), expected);

   }

   @Override
   public GetOptions apply(org.jclouds.blobstore.options.GetOptions from) {
      checkNotNull(from, "options");
      if (from == org.jclouds.blobstore.options.GetOptions.NONE)
         return GetOptions.NONE;
      GetOptions httpOptions = new GetOptions();
      if (from.getIfMatch() != null) {
         httpOptions.ifETagMatches(from.getIfMatch());
      }
      if (from.getIfModifiedSince() != null) {
         httpOptions.ifModifiedSince(from.getIfModifiedSince());
      }
      if (from.getIfNoneMatch() != null) {
         httpOptions.ifETagDoesntMatch(from.getIfNoneMatch());
      }
      if (from.getIfUnmodifiedSince() != null) {
         httpOptions.ifUnmodifiedSince(from.getIfUnmodifiedSince());
      }
      for (String range : from.getRanges()) {
         String[] firstLast = range.split("\\-", 2);
         if (!firstLast[0].isEmpty() && !firstLast[1].isEmpty())
            httpOptions.range(Long.parseLong(firstLast[0]), Long.parseLong(firstLast[1]));
         else if (firstLast[0].isEmpty() && !firstLast[1].isEmpty())
            httpOptions.tail(Long.parseLong(firstLast[1]));
         else
            httpOptions.startAt(Long.parseLong(firstLast[0]));
      }
      return httpOptions;
   }

TOP

Related Classes of org.jclouds.http.options.GetOptions

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.