getApi().disableCDN(containerNameWithCDN);
getApi().disableCDN(containerNameWithoutCDN);
} catch (Exception e) {
}
ContainerCDNMetadata cdnMetadata = null;
// Enable CDN with PUT for one container
final URI cdnUri = getApi().enableCDN(containerNameWithCDN);
assertNotNull(cdnUri);
// Confirm CDN is enabled via HEAD request and has default TTL
cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN);
assertTrue(cdnMetadata.isCDNEnabled());
assertEquals(cdnMetadata.getCDNUri(), cdnUri);
// Test static website metadata
getApi().setCDNStaticWebsiteIndex(containerNameWithCDN, "index.html");
getApi().setCDNStaticWebsiteError(containerNameWithCDN, "error.html");
ContainerMetadata containerMetadata = getApi().getContainerMetadata(containerNameWithCDN);
assertEquals(containerMetadata.getMetadata().get("web-index"), "index.html");
assertEquals(containerMetadata.getMetadata().get("web-error"), "error.html");
cdnMetadata = getApi().getCDNMetadata(containerNameWithoutCDN);
assert cdnMetadata == null || !cdnMetadata.isCDNEnabled() : containerNameWithoutCDN
+ " should not have metadata";
assert getApi().getCDNMetadata("DoesNotExist") == null;
// List CDN metadata for containers, and ensure all CDN info is
// available for enabled
// container
Set<ContainerCDNMetadata> cdnMetadataList = getApi().listCDNContainers();
assertTrue(cdnMetadataList.size() >= 1);
cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN);
final boolean cdnEnabled = cdnMetadata.isCDNEnabled();
final boolean logRetention = cdnMetadata.isLogRetention();
final long initialTTL = cdnMetadata.getTTL();
final URI cdnSslUri = cdnMetadata.getCDNSslUri();
final URI cdnStreamingUri = cdnMetadata.getCDNStreamingUri();
final URI cdnIosUri = cdnMetadata.getCDNIosUri();
assertTrue(cdnMetadataList.contains(new ContainerCDNMetadata(
containerNameWithCDN, cdnEnabled, logRetention, initialTTL, cdnUri, cdnSslUri, cdnStreamingUri, cdnIosUri)));
// Test listing with options
cdnMetadataList = getApi().listCDNContainers(ListCdnContainerOptions.Builder.enabledOnly());
assertTrue(Iterables.all(cdnMetadataList, new Predicate<ContainerCDNMetadata>() {
public boolean apply(ContainerCDNMetadata cdnMetadata) {
return cdnMetadata.isCDNEnabled();
}
}));
cdnMetadataList = getApi().listCDNContainers(
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 and Log Retention
long ttl = 4000;
getApi().enableCDN(containerNameWithCDN, ttl, true);
cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN);
assertTrue(cdnMetadata.isCDNEnabled());
assertEquals(cdnMetadata.getTTL(), ttl);
// Check POST by updating TTL settings
ttl = minimumTTL;
getApi().updateCDN(containerNameWithCDN, minimumTTL, false);
cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN);
assertTrue(cdnMetadata.isCDNEnabled());
assertEquals(cdnMetadata.getTTL(), minimumTTL);
// Confirm that minimum allowed value for TTL is 3600, lower values are
// ignored.
getApi().updateCDN(containerNameWithCDN, 3599L, false);
cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN);
assertEquals(cdnMetadata.getTTL(), 3599L);
// Test purging an object from a CDN container
SwiftObject swiftObject = newSwiftObject("hello", "hello.txt");
getApi().putObject(containerNameWithCDN, swiftObject);
assertTrue(getApi().purgeCDNObject(containerNameWithCDN, swiftObject.getInfo().getName()));
// Disable CDN with POST
assertTrue(getApi().disableCDN(containerNameWithCDN));
cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN);
assertEquals(cdnMetadata.isCDNEnabled(), false);
} finally {
recycleContainer(containerNameWithCDN);
recycleContainer(containerNameWithoutCDN);
}
}