assertEquals("default-origin-id", origin.getId());
assertEquals(originBucket, origin.getDomainName());
assertNull(origin.getOriginAccessIdentity());
assertEquals(originBucket.split("\\.")[0], origin.getOriginAsBucketName());
// Check cache behaviors
CacheBehavior defaultCacheBehavior = config.getDefaultCacheBehavior();
assertNull(defaultCacheBehavior.getPathPattern());
assertEquals(origin.getId(), defaultCacheBehavior.getTargetOriginId());
assertEquals(false, defaultCacheBehavior.isForwardQueryString());
assertEquals(Long.valueOf(0), defaultCacheBehavior.getMinTTL());
assertEquals(0, defaultCacheBehavior.getTrustedSignerAwsAccountNumbers().length);
assertEquals(ViewerProtocolPolicy.ALLOW_ALL, defaultCacheBehavior.getViewerProtocolPolicy());
// Check legacy distribution info (pre 2012-05-05 API version)
assertEquals(comment, distribution.getComment());
assertEquals(Arrays.asList(cnames), Arrays.asList(distribution.getCNAMEs()));
assertEquals(false, distribution.isEnabled());
assertTrue(distribution.getOrigin() instanceof S3Origin);
origin = (S3Origin) distribution.getOrigin();
// Update distribution to enable it, add a CNAME, update comment, enable logging,
// set default root object, set default cache behavior, add additional cache behavior
cnames = new String[] {callerId + originBucket, callerId + "2" + originBucket};
comment = "Updated comment";
LoggingStatus logging = new LoggingStatus("log-bucket.s3.amazonaws.com", "log-prefix/");
DistributionConfig testDistributionConfig = new DistributionConfig(
distribution.getConfig().getOrigins(),
distribution.getConfig().getCallerReference(),
cnames,
comment,
true, // Enabled
logging,
"index.html", // defaultRootObject
// defaultCacheBehavior
new CacheBehavior(
distribution.getConfig().getOrigins()[0].getId(),
false, // isForwardQueryString
new String[] {"self"}, // trustedSignerAwsAccountNumbers
ViewerProtocolPolicy.HTTPS_ONLY,
3600l // minTTL
),
// Additional cache behavior
new CacheBehavior[] {
new CacheBehavior(
"/https-only-path", // pathPattern
distribution.getConfig().getOrigins()[0].getId(),
true, // isForwardQueryString
null, // trustedSignerAwsAccountNumbers
ViewerProtocolPolicy.ALLOW_ALL,
1800l // minTTL
)}
);
config = getService().updateDistributionConfig(
distribution.getId(), testDistributionConfig);
// Check distribution config info
assertEquals(testDistributionConfig.getCallerReference(), config.getCallerReference());
assertEquals(testDistributionConfig.getComment(), config.getComment());
assertEquals(testDistributionConfig.isEnabled(), config.isEnabled());
List testConfigCNAMEs = Arrays.asList(testDistributionConfig.getCNAMEs());
List configCNAMEs = Arrays.asList(config.getCNAMEs());
// Collections.sort() returns null, bah!
Collections.sort(testConfigCNAMEs);
Collections.sort(configCNAMEs);
assertEquals(testConfigCNAMEs, configCNAMEs);
assertEquals(1, config.getOrigins().length);
assertEquals(S3Origin.class, config.getOrigins()[0].getClass());
origin = (S3Origin) config.getOrigins()[0];
assertEquals("default-origin-id", origin.getId());
assertEquals(this.originBucket, origin.getDomainName());
assertNull(origin.getOriginAccessIdentity());
assertEquals(this.originBucket.split("\\.")[0], origin.getOriginAsBucketName());
// Check cache behaviors
defaultCacheBehavior = config.getDefaultCacheBehavior();
assertNull(defaultCacheBehavior.getPathPattern());
assertEquals(origin.getId(), defaultCacheBehavior.getTargetOriginId());
assertEquals(false, defaultCacheBehavior.isForwardQueryString());
assertEquals(Long.valueOf(3600), defaultCacheBehavior.getMinTTL());
assertEquals(1, defaultCacheBehavior.getTrustedSignerAwsAccountNumbers().length);
assertEquals("self", defaultCacheBehavior.getTrustedSignerAwsAccountNumbers()[0]);
assertEquals(ViewerProtocolPolicy.HTTPS_ONLY, defaultCacheBehavior.getViewerProtocolPolicy());
assertEquals(1, config.getCacheBehaviors().length);
CacheBehavior cacheBehavior = config.getCacheBehaviors()[0];
assertEquals("/https-only-path", cacheBehavior.getPathPattern());
assertEquals(origin.getId(), cacheBehavior.getTargetOriginId());
assertTrue(cacheBehavior.isForwardQueryString());
assertEquals(Long.valueOf(1800), cacheBehavior.getMinTTL());
assertEquals(0, cacheBehavior.getTrustedSignerAwsAccountNumbers().length);
assertEquals(ViewerProtocolPolicy.ALLOW_ALL, cacheBehavior.getViewerProtocolPolicy());
// TODO Get distribution details
// TODO Disable distribution in preparation for deletion