public CloudFilesObject get(String path, long start) { final SwiftObject swiftObject; if (start == 0) { swiftObject = objectApi.get(path); } else { swiftObject = objectApi.get(path, new GetOptions().startAt(start)); } Payload payload = swiftObject.getPayload(); return new CloudFilesObject(payload, this.region, this.container, path); }
@Test public void testStartAt() { GetOptions options = new GetOptions(); options.startAt(100); assertEquals(options.getRange(), "bytes=100-"); }
@Test public void testIfModifiedSince() { GetOptions options = new GetOptions(); options.ifModifiedSince(now); assertEquals(options.getIfModifiedSince(), nowExpected); }
@Test public void testRangeZeroToFiveAnd10through100() { GetOptions options = new GetOptions(); options.range(0, 5).range(10, 100); assertEquals(options.getRange(), "bytes=0-5,10-100"); }
@Test public void testTail() { GetOptions options = new GetOptions(); options.tail(100); assertEquals(options.getRange(), "bytes=-100"); }
/** * Only return the object if it hasn't changed since this time. * <p /> * Not compatible with {@link #ifETagDoesntMatch(String)} or {@link #ifModifiedSince(Date)} */ public GetOptions ifUnmodifiedSince(Date ifUnmodifiedSince) { checkArgument(getIfNoneMatch() == null, "ifETagDoesntMatch() is not compatible with ifUnmodifiedSince()"); checkArgument(getIfModifiedSince() == null, "ifModifiedSince() is not compatible with ifUnmodifiedSince()"); this.headers.put(IF_UNMODIFIED_SINCE, dateService.rfc822DateFormat(checkNotNull(ifUnmodifiedSince, "ifUnmodifiedSince"))); return this; }
/** * Only return the object if it has changed since this time. * <p /> * Not compatible with {@link #ifETagMatches(String)} or {@link #ifUnmodifiedSince(Date)} */ public GetOptions ifModifiedSince(Date ifModifiedSince) { checkArgument(getIfMatch() == null, "ifETagMatches() is not compatible with ifModifiedSince()"); checkArgument(getIfUnmodifiedSince() == null, "ifUnmodifiedSince() is not compatible with ifModifiedSince()"); this.headers.put(IF_MODIFIED_SINCE, dateService.rfc822DateFormat(checkNotNull(ifModifiedSince, "ifModifiedSince"))); return this; }
@Test public void testIfUnmodifiedSince() { 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); }
@Test public void testIfMatch() { 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); }
@Test public void testIfModifiedSinceStatic() { GetOptions options = ifModifiedSince(now); assertEquals(options.getIfModifiedSince(), nowExpected); }
@Test public void testNullIfETagMatches() { GetOptions options = new GetOptions(); assertNull(options.getIfMatch()); }
@Test public void testNullIfModifiedSince() { GetOptions options = new GetOptions(); assertNull(options.getIfModifiedSince()); }
@Test public void testNullRange() { GetOptions options = new GetOptions(); assertNull(options.getRange()); }
@Test public void testIfETagMatches() { GetOptions options = new GetOptions(); options.ifETagMatches(etag); matchesHex(options.getIfMatch()); }
@Test public void testIfETagDoesntMatch() { GetOptions options = new GetOptions(); options.ifETagDoesntMatch(etag); matchesHex(options.getIfNoneMatch()); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testTailFail() { GetOptions options = new GetOptions(); options.tail(0); }
@Test public void testIfUnmodifiedSince() { GetOptions options = new GetOptions(); options.ifUnmodifiedSince(now); isNowExpected(options); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testStartAtFail() { GetOptions options = new GetOptions(); options.startAt(-1); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testIfModifiedAfterETagMatches() { ifETagMatches(etag).ifModifiedSince(now); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testETagDoesntMatchAfterETagMatches() { ifETagMatches(etag).ifETagDoesntMatch(etag); }