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 static org.junit.Assert.assertTrue; import java.io.File; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collection; import org.json.JSONException; import org.junit.After; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; 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.upload.IngestFile; import com.brightcove.uploader.upload.Options; @RunWith(value = Parameterized.class) public class MediaAPIcreateVideoParameterizedIntegrationTest extends MediaAPIIntegrationParent { private final String mRenamedFilename; private File mRenamedFile; private boolean mRevertNeeded; private BrightcoveLog mLog = BrightcoveLog.getLogger(this.getClass()); @Parameters public static Collection<Object[]> data() { ArrayList<Object[]> filenames = new ArrayList<Object[]>(); filenames.add(new String[] { "10sec\"copy\".mp4" }); filenames.add(new String[] { "10sec\"co\'py\".mp4" }); filenames.add(new String[] { "10sec\'copy.mp4" }); return filenames; } public MediaAPIcreateVideoParameterizedIntegrationTest(String pRenamedFilename) throws URISyntaxException { mRenamedFilename = pRenamedFilename; } @Before public void dosomesetup() throws URISyntaxException { int retryCounter = 0; int maxRetries = 10; Options uploadOpts = new Options(); mRenamedFile = new File( MediaAPIIntegrationParent.getRenamableSourceFile().getParent() + File.separator + mRenamedFilename); /* TODO: wrap MediaAPIIntegrationParent.renamableCopyOfSourceFile in a monitor that * also has a mRevertNeeded, and sync on that monitor instead? */ synchronized (MediaAPIIntegrationParent.class) { while ((mRevertNeeded || (!MediaAPIIntegrationParent.getRenamableSourceFile().isFile())) && (retryCounter < maxRetries)) { try { Thread.sleep(3000); } catch (InterruptedException e) { // do nothing. } retryCounter++; } assertTrue("Could not rename file to " + mRenamedFilename, MediaAPIIntegrationParent.getRenamableSourceFile().renameTo(mRenamedFile)); mRevertNeeded = true; } uploadOpts.setMBR(true); mVideoFile = new IngestFile(mRenamedFile.getAbsolutePath(), uploadOpts); } @After public void teardown() { /* TODO: wrap MediaAPIIntegrationParent.renamableCopyOfSourceFile in a monitor that * also has a mRevertNeeded, and sync on that monitor instead? */ synchronized (MediaAPIIntegrationParent.class) { if (mRevertNeeded) { assertTrue("Could not revert filename back to " + RENAMABLE_SOURCE_FILE_NAME, mRenamedFile.renameTo(MediaAPIIntegrationParent.getRenamableSourceFile())); mRevertNeeded = false; } } mVideoFile = null; } @Ignore("Until BC-24245 gets fixed") @Test public void createVideo_funnyFilenames() throws Throwable, MediaAPIError, URISyntaxException, JSONException, BadEnvironmentException { try { for (Account a : mAccountHelper.getAllAccounts()) { uploadViaAPIandCheckExists(a, mVideoFile); } } catch (AssertionError ae) { AssertionError parameterizedAssertionError = new AssertionError( "Caught AssertionError for parameterized case: mRenamedFilename = " + mRenamedFilename); parameterizedAssertionError.initCause((AssertionError) ae); throw parameterizedAssertionError; } catch (Throwable t) { throw new Throwable("Caught throwable for parameterized case: mRenamedFilename = " + mRenamedFilename, t); } } }