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; import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.Set; import javax.xml.parsers.ParserConfigurationException; import org.json.JSONException; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.xml.sax.SAXException; import com.brightcove.com.uploader.helper.FileFinder; import com.brightcove.com.uploader.helper.LoginHelper; import com.brightcove.com.uploader.helper.MediaManagerHelper; import com.brightcove.com.uploader.verifier.UploadData.UploadType; import com.brightcove.com.uploader.verifier.ValidatableMannheimUpload; import com.brightcove.common.logging.BrightcoveLog; import com.brightcove.uploader.config.Account; import com.brightcove.uploader.exception.BadEnvironmentException; import com.brightcove.uploader.exception.MediaAPIError; import com.brightcove.uploader.input.Batch; import com.brightcove.uploader.input.MediaManager; import com.brightcove.uploader.upload.IngestFile; import com.brightcove.uploader.upload.Options; import com.brightcove.uploader.upload.TitleMetaData; public class MThreeIntegrationTest extends MediaAPIIntegrationParent { private BrightcoveLog mLog = BrightcoveLog.getLogger(this.getClass()); private final Batch mBatch = new Batch(); private MediaManager mMediaManager; private enum IngestPoint { BATCH, API, MM } @After public void teardown() { } @Test public void testUploadMBR() throws MediaAPIError, URISyntaxException, JSONException, BadEnvironmentException, IOException, ParserConfigurationException, SAXException, InterruptedException, CloneNotSupportedException { mEnvironment.setSignInServer("signin.brightcove.com"); mEnvironment.setMediaUploadServer("console.brightcove."); for (Account a : accountsToTest()) { if (mEnvironment.getName().equalsIgnoreCase("kong") || mEnvironment.getName().equalsIgnoreCase("staging")) { a.setFtpLogin("qa"); a.setFtpPassword("Password!"); } for (Options uploadOpts : optionsToTest()) { for (String file : filesToTest()) { for (IngestPoint u : IngestPoint.values()) { if (file.endsWith("flv")) { uploadOpts.setIsVideoFileTypeFLV(true); if (uploadOpts.isMBR()) { continue; } } else { uploadOpts.setIsVideoFileTypeFLV(false); } IngestFile videoFile = new IngestFile(file, (Options) uploadOpts.clone()); videoFile.setRefId(u.name() + videoFile.getRefId()); videoFile.setDisplayName(u.name() + " upload to : " + a.getId()); TitleMetaData tm = new TitleMetaData(); tm.setActive(true); tm.setShortDescription("short Description"); tm.setTags(new ArrayList<String>(Arrays.asList("Tagliatelle", "Gnocci", "Sacchetti"))); videoFile.setMetaData(tm); upload(a, videoFile, u); } } } } dumpJson(); } private ArrayList<String> filesToTest() throws URISyntaxException { ArrayList<String> files = new ArrayList<String>(); files.add(FileFinder.findFileInClasspath("fishtank.mp4").getAbsolutePath()); files.add(FileFinder.findFileInClasspath("hunley_preview.flv").getAbsolutePath()); return files; } private Set<Options> optionsToTest() { HashSet<Options> opts = new HashSet<Options>(); Options uploadOpts = new Options(); uploadOpts.setMBR(true); opts.add(uploadOpts); uploadOpts = new Options(); uploadOpts.setMBR(true); uploadOpts.setPreserveSource(true); opts.add(uploadOpts); uploadOpts = new Options(); uploadOpts.setMBR(false); opts.add(uploadOpts); uploadOpts = new Options(); uploadOpts.setMBR(true); uploadOpts.setTargetCodec("FLV"); opts.add(uploadOpts); uploadOpts = new Options(); uploadOpts.setTargetCodec("FLV"); uploadOpts.setMBR(false); opts.add(uploadOpts); return opts; } private Set<Account> accountsToTest() { return mAccountHelper.getAllAccounts(); } public void upload(Account a, IngestFile videoFile, IngestPoint ut) throws BadEnvironmentException, MediaAPIError, JSONException, URISyntaxException, IOException, ParserConfigurationException, SAXException { ValidatableMannheimUpload upload = new ValidatableMannheimUpload("notMann", a, videoFile); upload.setUploadDate(mStartTime); Long videoId = null; switch (ut) { case BATCH: mBatch.createVideo(videoFile, a, mEnvironment); upload.setUploadMethod(UploadType.BATCH); break; case API: videoId = mMediaApi.createVideo(videoFile, a, mEnvironment, false); upload.setUploadMethod(UploadType.API); break; case MM: mMediaManager = new MediaManager(new LoginHelper(), new MediaManagerHelper()); videoId = mMediaManager.createVideo(videoFile, a, mEnvironment, false); upload.setUploadMethod(UploadType.MGR); break; } if (videoId != null) { upload.setVideoID(videoId); } jobsToValidate.add(upload); } }