getApi().getCDNExtension().get().disable(containerNameWithCDN);
getApi().getCDNExtension().get().disable(containerNameWithoutCDN);
} catch (Exception e) {
e.printStackTrace();
}
CDNContainer cdnMetadata = null;
// Enable CDN with PUT for one container
final URI cdnUri = getApi().getCDNExtension().get().enable(containerNameWithCDN);
assertNotNull(cdnUri);
// Confirm CDN is enabled via HEAD request and has default TTL
cdnMetadata = getApi().getCDNExtension().get().get(containerNameWithCDN);
assertTrue(cdnMetadata.isCDNEnabled());
assertEquals(cdnMetadata.getCDNUri(), cdnUri);
cdnMetadata = getApi().getCDNExtension().get().get(containerNameWithoutCDN);
assert cdnMetadata == null || !cdnMetadata.isCDNEnabled() : containerNameWithoutCDN
+ " should not have metadata";
assert getApi().getCDNExtension().get().get("DoesNotExist") == null;
// List CDN metadata for containers, and ensure all CDN info is
// available for enabled
// container
FluentIterable<CDNContainer> cdnMetadataList = getApi().getCDNExtension().get().list();
assertTrue(cdnMetadataList.size() >= 1);
final long initialTTL = cdnMetadata.getTTL();
assertTrue(cdnMetadataList.contains(CDNContainer.builder().name(containerNameWithCDN)
.CDNEnabled(true).ttl(initialTTL).CDNUri(cdnUri).build()));
/*
* Test listing with options FIXFIX cdnMetadataList =
* getApi().list(ListCDNContainerOptions.Builder.enabledOnly());
* assertTrue(Iterables.all(cdnMetadataList, new Predicate<CDNContainer>() { public
* boolean apply(CDNContainer cdnMetadata) { return cdnMetadata.isCDNEnabled(); }
* }));
*/
cdnMetadataList = getApi().getCDNExtension().get().list(
ListCDNContainerOptions.Builder.afterMarker(
containerNameWithCDN.substring(0, containerNameWithCDN.length() - 1)).maxResults(1));
assertEquals(cdnMetadataList.size(), 1);
// Enable CDN with PUT for the same container, this time with a custom
// TTL
long ttl = 4000;
getApi().getCDNExtension().get().enable(containerNameWithCDN, ttl);
cdnMetadata = getApi().getCDNExtension().get().get(containerNameWithCDN);
assertTrue(cdnMetadata.isCDNEnabled());
assertEquals(cdnMetadata.getTTL(), ttl);
// Check POST by updating TTL settings
ttl = minimumTTL;
getApi().getCDNExtension().get().update(containerNameWithCDN, minimumTTL);
cdnMetadata = getApi().getCDNExtension().get().get(containerNameWithCDN);
assertTrue(cdnMetadata.isCDNEnabled());
assertEquals(cdnMetadata.getTTL(), minimumTTL);
// Confirm that minimum allowed value for TTL is 3600, lower values are
// ignored.
getApi().getCDNExtension().get().update(containerNameWithCDN, 3599L);
cdnMetadata = getApi().getCDNExtension().get().get(containerNameWithCDN);
assertEquals(cdnMetadata.getTTL(), 3599L);
// Disable CDN with POST
assertTrue(getApi().getCDNExtension().get().disable(containerNameWithCDN));
cdnMetadata = getApi().getCDNExtension().get().get(containerNameWithCDN);
assertEquals(cdnMetadata.isCDNEnabled(), false);
} catch (Exception e) {
e.printStackTrace();
} finally {
recycleContainer(containerNameWithCDN);
recycleContainer(containerNameWithoutCDN);