Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcazacu committed Aug 27, 2018
1 parent a1eecd5 commit f147727
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 16 deletions.
52 changes: 42 additions & 10 deletions src/main/java/com/netflix/imflibrary/utils/FileLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

package com.netflix.imflibrary.utils;

import sun.misc.IOUtils;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -30,7 +27,7 @@
import java.nio.file.StandardCopyOption;

/**
* This interface is the supertype for classes representing an file locator
* This interface is the supertype for classes representing an file locator across different storage facilities.
*/
public interface FileLocator
{
Expand Down Expand Up @@ -60,6 +57,9 @@ public static FileLocator fromLocation(URI location) {
return new LocalFileLocator(location);
}

/**
* Copies all bytes from a file denoted by a file locator to a target file
*/
public static Path copy(FileLocator fileLocator, Path outputFilePath) throws IOException {
InputStream inputStream = fileLocator.getInputStream();

Expand All @@ -74,29 +74,61 @@ public static Path copy(FileLocator fileLocator, Path outputFilePath) throws IOE
}

/**
* Tests whether the file denoted by this abstract pathname is a
* directory.
* @return <code>true</code> if and only if the file denoted by this
* abstract pathname exists <em>and</em> is a directory;
* <code>false</code> otherwise
*/
* Tests whether the file locator represents a directory.
*/
public boolean isDirectory() throws IOException;

/**
* Return the absolute pathname string denoting the same file or
* directory as this abstract pathname
*/
public String getAbsolutePath() throws IOException;

/**
* Returns an array of abstract pathnames denoting the files in the
* directory denoted by this abstract pathname.
*/
public FileLocator[] listFiles(FilenameFilter filenameFilter) throws IOException;

/**
* Constructs a <tt>file:</tt> URI that represents this abstract pathname.
*/
public URI toURI() throws IOException;

/**
* Tests whether the file or directory denoted by this abstract pathname
* exists.
*/
public boolean exists() throws IOException;

/**
* Returns the name of the file or directory denoted by this abstract
* pathname. This is just the last name in the pathname's name
* sequence. If the pathname's name sequence is empty, then the empty
* string is returned.
*/
public String getName() throws IOException;

/**
* Converts this abstract pathname into a pathname string. The resulting
* string uses the {@link #separator default name-separator character} to
* separate the names in the name sequence.
*/
public String getPath() throws IOException;

/**
* Returns the length of the file denoted by this abstract pathname.
* The return value is unspecified if this pathname denotes a directory.
*/
public long length() throws IOException;

/**
*
*/
public InputStream getInputStream() throws IOException;

/**
*
*/
public ResourceByteRangeProvider getResourceByteRangeProvider();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.netflix.imflibrary.IMFErrorLogger;
import com.netflix.imflibrary.IMFErrorLoggerImpl;
import com.netflix.imflibrary.KLVPacket;
import com.netflix.imflibrary.utils.FileLocator;
import org.smpte_ra.schemas.st2067_2_2013.CompositionPlaylistType;
import com.netflix.imflibrary.st0377.HeaderPartition;
import com.netflix.imflibrary.st0377.header.InterchangeObject;
Expand Down Expand Up @@ -64,7 +65,10 @@ public void RegXMLLibTest() throws IOException, ParserConfigurationException, Tr
/*AudioEssence*/
File inputFile = TestHelper.findResourceByPath("TearsOfSteel_4k_Test_Master_Audio_002.mxf");
File workingDirectory = Files.createTempDirectory(null).toFile();
IMFTrackFileCPLBuilder imfTrackFileCPLBuilder = new IMFTrackFileCPLBuilder(workingDirectory, inputFile);
IMFTrackFileCPLBuilder imfTrackFileCPLBuilder = new IMFTrackFileCPLBuilder(
workingDirectory,
FileLocator.fromLocation(inputFile.toURI())
);
IMFTrackFileReader imfTrackFileReader = new IMFTrackFileReader(workingDirectory, new FileByteRangeProvider(inputFile));
IMFErrorLogger imfErrorLogger = new IMFErrorLoggerImpl();
List<InterchangeObject.InterchangeObjectBO> essenceDescriptors = imfTrackFileReader.getEssenceDescriptors(imfErrorLogger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.netflix.imflibrary.IMFErrorLogger;
import com.netflix.imflibrary.IMFErrorLoggerImpl;
import com.netflix.imflibrary.utils.FileLocator;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand All @@ -34,7 +35,10 @@ public void IMFTrackFileCPLBuilderTest() throws IOException
{
File inputFile = TestHelper.findResourceByPath("TearsOfSteel_4k_Test_Master_Audio_002.mxf");
File workingDirectory = Files.createTempDirectory(null).toFile();
IMFTrackFileCPLBuilder imfTrackFileCPLBuilder = new IMFTrackFileCPLBuilder(workingDirectory, inputFile);
IMFTrackFileCPLBuilder imfTrackFileCPLBuilder = new IMFTrackFileCPLBuilder(
workingDirectory,
FileLocator.fromLocation(inputFile.toURI())
);
IMFErrorLogger imfErrorLogger = new IMFErrorLoggerImpl();
Assert.assertTrue(imfTrackFileCPLBuilder.getCompositionPlaylist(imfErrorLogger).length() > 0);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.netflix.imflibrary.app;

import com.netflix.imflibrary.utils.ErrorLogger;
import com.netflix.imflibrary.utils.FileLocator;
import org.testng.Assert;
import org.testng.annotations.Test;
import testUtils.TestHelper;
Expand All @@ -19,7 +20,9 @@ public class IMPAnalyzerTest
public void IMPAnalyzerTest() throws IOException
{
File inputFile = TestHelper.findResourceByPath("TestIMP/MERIDIAN_Netflix_Photon_161006/");
Map<String, List<ErrorLogger.ErrorObject>> errorMap = analyzePackage(inputFile);
Map<String, List<ErrorLogger.ErrorObject>> errorMap = analyzePackage(
FileLocator.fromLocation(inputFile.toURI())
);
Assert.assertEquals(errorMap.size(), 7);
errorMap.entrySet().stream().forEach( e ->
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.netflix.imflibrary.st0429_8;

import com.netflix.imflibrary.IMFErrorLoggerImpl;
import com.netflix.imflibrary.utils.FileLocator;
import org.testng.Assert;
import org.testng.annotations.Test;
import testUtils.TestHelper;
Expand All @@ -15,7 +16,7 @@ public class PackingListTest
public void testPackingList() throws Exception
{
File inputFile = TestHelper.findResourceByPath("test_mapped_file_set/PKL_51edd4be-4506-494d-a58e-516553055c33.xml");
PackingList packingList = new PackingList(inputFile);
PackingList packingList = new PackingList(FileLocator.fromLocation(inputFile.toURI()));
Assert.assertEquals(packingList.getUUID(), UUID.fromString("51edd4be-4506-494d-a58e-516553055c33"));
Assert.assertEquals(packingList.getAssets().size(), 3);
Assert.assertTrue(packingList.toString().length() > 0);
Expand All @@ -32,7 +33,7 @@ public void testPackingList() throws Exception
public void testPackingList2016() throws Exception
{
File inputFile = TestHelper.findResourceByPath("PKL_2067_2_2016.xml");
PackingList packingList = new PackingList(inputFile);
PackingList packingList = new PackingList(FileLocator.fromLocation(inputFile.toURI()));
Assert.assertEquals(packingList.getUUID(), UUID.fromString("7281a71b-0dcb-4ed7-93a4-97b7929e2a7c"));
Assert.assertEquals(packingList.getAssets().size(), 2);
Assert.assertTrue(packingList.toString().length() > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.netflix.imflibrary.InteroperableMasterPackage;
import com.netflix.imflibrary.st0429_9.BasicMapProfileV2FileSet;
import com.netflix.imflibrary.st0429_9.BasicMapProfileV2MappedFileSet;
import com.netflix.imflibrary.utils.FileLocator;
import org.testng.Assert;
import org.testng.annotations.Test;
import testUtils.TestHelper;
Expand All @@ -17,7 +18,9 @@ public class IMPDeliveryTest
public void testIMPDelivery() throws Exception
{
File inputFile = TestHelper.findResourceByPath("test_mapped_file_set");
BasicMapProfileV2MappedFileSet basicMapProfileV2MappedFileSet = new BasicMapProfileV2MappedFileSet(inputFile);
BasicMapProfileV2MappedFileSet basicMapProfileV2MappedFileSet = new BasicMapProfileV2MappedFileSet(
FileLocator.fromLocation(inputFile.toURI())
);
BasicMapProfileV2FileSet basicMapProfileV2FileSet = new BasicMapProfileV2FileSet(basicMapProfileV2MappedFileSet);
IMPDelivery impDelivery = new IMPDelivery(basicMapProfileV2FileSet);
Assert.assertTrue(impDelivery.toString().length() > 0);
Expand Down

0 comments on commit f147727

Please sign in to comment.