Java tutorial
/** * Copyright (C) 2011 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.NonEncrypted; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.util.Iterator; import java.util.Vector; import org.json.JSONException; import org.junit.After; import org.junit.Before; import org.junit.Test; import com.brightcove.com.uploader.verifier.AppleStreamingCheck; import com.brightcove.com.uploader.verifier.ExistenceCheck; import com.brightcove.com.uploader.waiter.WaiterHelper; import com.brightcove.common.logging.BrightcoveLog; import com.brightcove.test.upload.MediaAPIParentClass; 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; /** * SystemTest * To test and verify the video upload via Apple Streaming Account * @author ppasad * */ public class MediaAPIUploadViaAppleStreamingIntegrationTest extends HLSBaseClass { public Account mAccountInfo; public Environment mEnvironment; public static final String SOURCE_FILE_NAME = "10sec.mp4"; IngestFile videoFile; static Long videoId; String readToken; int noOfIOSRenditionVideoContain = 5; String writeToken; private BrightcoveLog mLog = BrightcoveLog.getLogger(this.getClass()); @Before public void setup() throws URISyntaxException, IOException { readToken = "wizjqhZuzhS5HCilz5wB6BJy130C8qAVhPWTQDr0BTJIQgkJKX2XKA.."; writeToken = "wizjqhZuzhRY0kL6zw-0jHZxeWj1jzOo9FMN5zwSGTi2bOpEAq6RbQ.."; mAccountInfo = setAccountInfo("qa+apple@brightcove.com", "joejoe", "702974241001", "wizjqhZuzhS5HCilz5wB6BJy130C8qAVhPWTQDr0BTJIQgkJKX2XKA..", "wizjqhZuzhRY0kL6zw-0jHZxeWj1jzOo9FMN5zwSGTi2bOpEAq6RbQ.."); mEnvironment = setEnvironmentsInfo("test.environment", "kong"); } /** * Test video upload with single rendition on Apple Streaming account. * @throws MediaAPIError * @throws URISyntaxException * @throws JSONException * @throws BadEnvironmentException * @throws MalformedURLException */ @Test public void testUploadOnAppleStreamingAccountWithSingleRendition() throws MediaAPIError, URISyntaxException, JSONException, BadEnvironmentException, MalformedURLException { Options uploadOpts = new Options(); uploadOpts.setMBR(false); videoFile = new IngestFile(getAbsoluteVideoFilePath(SOURCE_FILE_NAME), uploadOpts); videoId = uploadVideo(videoFile, mAccountInfo, mEnvironment); assertNotNull(videoId); // Verify Video Exist ExistenceCheck existenceCheck = new ExistenceCheck(mEnvironment); existenceCheck.assertVideoExists(videoId, mAccountInfo); //Verify the flv url is correct String url = retrivePropertyValueFromJSONResponse(mAccountInfo, mEnvironment, videoId, "", "FLVURL"); assertEquals(true, url.startsWith("http")); assertEquals(true, url.contains(".m3u8")); //Verify the URL's in Rentition Files AppleStreamingCheck appleCheck = new AppleStreamingCheck(); appleCheck.assertRenditionFileURLCheckForAppleStreaming(url); } /** * Test video upload with Multi rendition on Apple Streaming account. * @throws MediaAPIError * @throws URISyntaxException * @throws JSONException * @throws BadEnvironmentException * @throws MalformedURLException */ @Test public void testUploadOnAppleStreamingAccountWithMultiRendition() throws MediaAPIError, URISyntaxException, JSONException, BadEnvironmentException, MalformedURLException { Options uploadOpts = new Options(); uploadOpts.setMBR(true); videoFile = new IngestFile(getAbsoluteVideoFilePath(SOURCE_FILE_NAME), uploadOpts); videoId = uploadVideo(videoFile, mAccountInfo, mEnvironment); assertNotNull("Exceed the maxWait time to upload the video on publisherid : " + mAccountInfo.getId(), videoId); ParameterList paramList = new ParameterList(mAccountInfo, "find_video_by_id", "video_id", videoId.toString(), "", "IOSRenditions"); WaiterHelper renditionComplete = new WaiterHelper(); renditionComplete.renditionWaiter(mAccountInfo, mEnvironment, paramList, noOfIOSRenditionVideoContain, 1200000L); // Verify Video Exist ExistenceCheck existenceCheck = new ExistenceCheck(mEnvironment); existenceCheck.assertVideoExists(videoId, mAccountInfo); //Verify the rendition url's String url = retriveMasterOrRenditionURL(mAccountInfo, mEnvironment, videoId); assertTrue("URL : " + url + " from rendition file doesn't match startWith(http://) condition", url.startsWith("http://")); assertTrue("URL : " + url + " from rendition file doesn't match contains(.m3u8) condition", url.contains("master.m3u8")); /** * Need to verify the apple rendition URL is displayed correctly. */ //url=url.replace("c.brightcove.com", mEnvironment.getServer("c.brightcove.com")); Vector renditionUrl = retriveRenditionURL(mAccountInfo, mEnvironment, videoId); Iterator iRendition = renditionUrl.iterator(); while (iRendition.hasNext()) { AppleStreamingCheck appleCheck = new AppleStreamingCheck(); appleCheck.assertRenditionFileURLCheckForAppleStreaming(iRendition.next().toString()); } } @After public void teardown() { videoFile = null; } }