Example usage for com.amazonaws.services.cloudfront.model DistributionSummary setDefaultCacheBehavior

List of usage examples for com.amazonaws.services.cloudfront.model DistributionSummary setDefaultCacheBehavior

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudfront.model DistributionSummary setDefaultCacheBehavior.

Prototype


public void setDefaultCacheBehavior(DefaultCacheBehavior defaultCacheBehavior) 

Source Link

Document

A complex type that describes the default cache behavior if you don't specify a CacheBehavior element or if files don't match any of the values of PathPattern in CacheBehavior elements.

Usage

From source file:org.duracloud.s3task.streaminghls.HlsTaskRunnerTestBase.java

License:Apache License

/**
 * Used when expecting a valid distribution as a result of the
 * listDistributions call.//from  w  w w  .  j av  a  2s  .c  o m
 *
 * @param secure            defines if the returned distribution is secure or open
 * @param listCallsExpected the number of times the call to list distributions will
 *                          be called in order to retrieve the entire list
 */
protected void cfClientExpectValidDistribution(AmazonCloudFrontClient cfClient, boolean secure,
        int listCallsExpected) {
    Origin s3Origin = new Origin().withDomainName(bucketName + S3_ORIGIN_SUFFIX);
    DistributionSummary distSummary = new DistributionSummary().withId("id").withStatus("status")
            .withDomainName(domainName).withEnabled(true).withOrigins(new Origins().withItems(s3Origin));
    TrustedSigners trustedSigners = new TrustedSigners().withQuantity(0);
    if (secure) {
        trustedSigners = new TrustedSigners().withQuantity(1).withItems("trusted-signer-item");
    }

    DefaultCacheBehavior defaultCacheBehavior = new DefaultCacheBehavior();
    defaultCacheBehavior.setTrustedSigners(trustedSigners);
    distSummary.setDefaultCacheBehavior(defaultCacheBehavior);

    for (int i = 0; i < listCallsExpected; i++) {
        boolean truncated = false;
        if ((listCallsExpected - i) > 1) {
            truncated = true;
        }

        List<DistributionSummary> distSummaries = new ArrayList();
        distSummaries.add(distSummary);
        ListDistributionsResult distSummaryResult = new ListDistributionsResult()
                .withDistributionList(new DistributionList().withItems(distSummaries).withIsTruncated(truncated)
                        .withNextMarker("marker"));
        EasyMock.expect(cfClient.listDistributions(EasyMock.isA(ListDistributionsRequest.class)))
                .andReturn(distSummaryResult);
    }
}