Java tutorial
/** * 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.upload.ExpressTrial; import static org.junit.Assert.assertNotNull; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.util.HashMap; import java.util.Map; import javax.xml.parsers.ParserConfigurationException; import org.apache.commons.httpclient.HttpException; import org.json.JSONException; import org.junit.BeforeClass; import org.junit.Test; import org.xml.sax.SAXException; import com.brightcove.com.uploader.helper.EnvironmentRegistry; 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.ExistenceCheck; import com.brightcove.common.logging.BrightcoveLog; import com.brightcove.fiona.accounts.AccountWithVideo; import com.brightcove.fiona.accounts.ExpressTrialAccount; import com.brightcove.fiona.accounts.Video; import com.brightcove.test.upload.helpers.IntegrationTestHelper; import com.brightcove.uploader.config.Account; import com.brightcove.uploader.config.Environment; import com.brightcove.uploader.exception.BadEnvironmentException; import com.brightcove.uploader.exception.MediaAPIError; import com.brightcove.uploader.input.MediaManager; import com.brightcove.uploader.upload.IngestFile; import com.brightcove.uploader.upload.Options; public class ExpressTrialUploadViaMediaModuleTest { private static Account mAccount; private static Environment mEnvironment; private static IngestFile mVideoFile; private static ExistenceCheck mExistenceCheck; private static MediaManager mMediaManager; private static ExpressTrialAccount account; private BrightcoveLog mLog = BrightcoveLog.getLogger(this.getClass()); @BeforeClass public static void setup() throws URISyntaxException, IOException { account = ExpressTrialAccount.createAccountFromJSONFile("account.json"); mAccount = new Account(account.getExpressTrial().getLoginData().getEmail(), account.getExpressTrial().getLoginData().getPassword(), Long.parseLong(account.getExpressTrial().getPubid())); Map<String, String> settings = new HashMap<String, String>(); settings.put("drmEnabled", "true"); mAccount.setSettings(settings); IntegrationTestHelper.loadEnvironments(); String envName = System.getProperty("test.environment", "kong"); mEnvironment = EnvironmentRegistry.getEnvironment(envName); mEnvironment.setSignInServer("signin.brightcove.com"); mEnvironment.setMediaUploadServer("console.brightcove."); // TODO: Move this to a profile or props file Options uploadOpts = new Options(); uploadOpts.setMBR(true); File f = FileFinder.findFileInClasspath("10sec.mp4"); mVideoFile = new IngestFile(f.getAbsolutePath(), uploadOpts); mVideoFile.setDisplayName("Fiona test video."); mMediaManager = new MediaManager(new LoginHelper(), new MediaManagerHelper()); mExistenceCheck = new ExistenceCheck(); mExistenceCheck.setmEnvironment(mEnvironment); } @Test public void uploadMBR() throws MediaAPIError, URISyntaxException, JSONException, BadEnvironmentException, HttpException, IOException, ParserConfigurationException, SAXException { // upload a file Long videoId = mMediaManager.createVideo(mVideoFile, mAccount, mEnvironment, false); mLog.debug("videoId: " + videoId); assertNotNull(videoId); AccountWithVideo awv = new AccountWithVideo(account, new Video(videoId.toString())); awv.writeArtifact("account_with_video.json"); } }