com.brightcove.test.upload.HLS.Encrypted.HLSEncryptionUseCaseIntegrationTest.java Source code

Java tutorial

Introduction

Here is the source code for com.brightcove.test.upload.HLS.Encrypted.HLSEncryptionUseCaseIntegrationTest.java

Source

/**
 * Copyright (C) 2012 Brightcove Inc. All Rights Reserved. No use, copying or distribution of this
 * work may be made except in accordance with a valid license agreement from Brightcove Inc. This
 * notice must be included on all copies, modifications and derivatives of this work.
 * 
 * Brightcove Inc MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. BRIGHTCOVE SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS
 * SOFTWARE OR ITS DERIVATIVES.
 * 
 * "Brightcove" is a registered trademark of Brightcove Inc.
 */
package com.brightcove.test.upload.HLS.Encrypted;

import static org.junit.Assert.assertNotNull;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.Vector;

import org.json.JSONException;
import org.junit.Before;
import org.junit.Test;

import com.brightcove.com.uploader.verifier.AppleStreamingCheck;
import com.brightcove.com.uploader.waiter.WaiterHelper;
import com.brightcove.common.logging.BrightcoveLog;
import com.brightcove.test.upload.HLS.HLSBaseClass;
import com.brightcove.uploader.config.Account;
import com.brightcove.uploader.config.Environment;
import com.brightcove.uploader.config.ParameterList;
import com.brightcove.uploader.exception.BadEnvironmentException;
import com.brightcove.uploader.exception.MediaAPIError;
import com.brightcove.uploader.upload.IngestFile;
import com.brightcove.uploader.upload.Options;

public class HLSEncryptionUseCaseIntegrationTest extends HLSBaseClass {
    private BrightcoveLog mLog = BrightcoveLog.getLogger(this.getClass());
    public Account mAccountInfo;
    public Environment mEnvironment;

    public static final String SOURCE_FILE_NAME = "10sec.mp4";
    IngestFile videoFile;
    Long videoId = 123L;
    String readToken;
    String writeToken;
    //This used to be 3, but we never got 3 in production. Should we get 3?
    int noOfRenditionVideoContains = 2;

    @Before
    public void setup() throws URISyntaxException, IOException, MediaAPIError, JSONException,
            BadEnvironmentException, InterruptedException {
        //Production tokens
        readToken = "84xzLDZQOh6SCuzTeFcgn146rwFaaWCL6EwIS_51Oh500zVWltNkSw..";
        writeToken = "QE7M90_ZbHqxI9CN_j8tzXWUB24VQId49NSiRjWd8WNa7gy0VvlmFA..";
        //Kong tokens
        //readToken = "Rgfvt_FGEVz0OxBdrAIDD7YrZ9sF4SJhWAiJcA1KN7V7sHOENFqivg..";
        //writeToken = "Rgfvt_FGEVweW2rnKr84xCJcEfBkFTJhTOAEXSu-rIuTpBvxYRMlig..";
        mAccountInfo = setAccountInfo("qa+appleSecurity@brightcove.com", "joejoe", "1136918641001", readToken,
                writeToken);
        mEnvironment = setEnvironmentsInfo("test.environment", "kong");
    }

    public void uploadMBRVideo() throws URISyntaxException, MalformedURLException, MediaAPIError, JSONException,
            BadEnvironmentException, InterruptedException {
        Options uploadOpts = new Options();
        uploadOpts.setMBR(true);
        videoFile = new IngestFile(getAbsoluteVideoFilePath(SOURCE_FILE_NAME), uploadOpts);
        videoId = uploadVideo(videoFile, mAccountInfo, mEnvironment);
        assertNotNull(videoId);
        ParameterList paramList = new ParameterList(mAccountInfo, "find_video_by_id", "video_id",
                videoId.toString(), "", "IOSRenditions");
        WaiterHelper renditionComplete = new WaiterHelper();
        renditionComplete.renditionWaiter(mAccountInfo, mEnvironment, paramList, noOfRenditionVideoContains,
                1200000L);

    }

    /**
     * Test does following checks 1. Verify the output when TTL Token on rendition is valid 2.
     * Verify the Rendition url has SSL support 3. Verify the output when TTL Token on rendition URL
     * are expired
     * @throws InterruptedException 
     * @throws BadEnvironmentException 
     * @throws JSONException 
     * @throws MediaAPIError 
     * @throws URISyntaxException 
     * @throws MalformedURLException 
     */

    @Test
    public void testSSLTTLOnRendition() throws MalformedURLException, URISyntaxException, MediaAPIError,
            JSONException, BadEnvironmentException, InterruptedException {
        uploadMBRVideo();
        AppleStreamingCheck appleCheck = new AppleStreamingCheck();
        Vector rendition = retriveRenditionURL(mAccountInfo, mEnvironment, videoId);
        if (!rendition.isEmpty()) {
            appleCheck.assertTTL(rendition);
            appleCheck.assertURLAreSSLSecured(rendition);
            //appleCheck.assertTTLExpiration(rendition);
        }
    }

    @Test
    public void testSSLTTLOnKeyFile() throws MalformedURLException, URISyntaxException, MediaAPIError,
            JSONException, BadEnvironmentException, InterruptedException {
        uploadMBRVideo();
        AppleStreamingCheck appleCheck = new AppleStreamingCheck();
        Vector keyFile = retriveKeyFilesURLS(mAccountInfo, mEnvironment, videoId);
        appleCheck.assertTTL(keyFile);
        appleCheck.assertURLAreSSLSecured(keyFile);
        //appleCheck.assertTTLExpiration(keyFile);
    }

}