From f14772761fa44d16bdd3478fa4aedb8e0bde63eb Mon Sep 17 00:00:00 2001 From: Alex Cazacu Date: Fri, 24 Aug 2018 11:53:50 +0300 Subject: [PATCH] fix tests --- .../netflix/imflibrary/utils/FileLocator.java | 52 +++++++++++++++---- ...IMFTrackFileCPLBuilderFunctionalTests.java | 6 ++- .../app/IMFTrackFileCPLBuilderTests.java | 6 ++- .../imflibrary/app/IMPAnalyzerTest.java | 5 +- .../imflibrary/st0429_8/PackingListTest.java | 5 +- .../imflibrary/st2067_2/IMPDeliveryTest.java | 5 +- 6 files changed, 63 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/netflix/imflibrary/utils/FileLocator.java b/src/main/java/com/netflix/imflibrary/utils/FileLocator.java index 7bbe06e9..32407467 100644 --- a/src/main/java/com/netflix/imflibrary/utils/FileLocator.java +++ b/src/main/java/com/netflix/imflibrary/utils/FileLocator.java @@ -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; @@ -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 { @@ -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(); @@ -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 true if and only if the file denoted by this - * abstract pathname exists and is a directory; - * false 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 file: 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(); } diff --git a/src/test/java/com/netflix/imflibrary/app/IMFTrackFileCPLBuilderFunctionalTests.java b/src/test/java/com/netflix/imflibrary/app/IMFTrackFileCPLBuilderFunctionalTests.java index ec6b4e1f..5722d6b2 100644 --- a/src/test/java/com/netflix/imflibrary/app/IMFTrackFileCPLBuilderFunctionalTests.java +++ b/src/test/java/com/netflix/imflibrary/app/IMFTrackFileCPLBuilderFunctionalTests.java @@ -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; @@ -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 essenceDescriptors = imfTrackFileReader.getEssenceDescriptors(imfErrorLogger); diff --git a/src/test/java/com/netflix/imflibrary/app/IMFTrackFileCPLBuilderTests.java b/src/test/java/com/netflix/imflibrary/app/IMFTrackFileCPLBuilderTests.java index 151a54f9..73ddb37b 100644 --- a/src/test/java/com/netflix/imflibrary/app/IMFTrackFileCPLBuilderTests.java +++ b/src/test/java/com/netflix/imflibrary/app/IMFTrackFileCPLBuilderTests.java @@ -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; @@ -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); } diff --git a/src/test/java/com/netflix/imflibrary/app/IMPAnalyzerTest.java b/src/test/java/com/netflix/imflibrary/app/IMPAnalyzerTest.java index 495b1728..4cf0a26f 100644 --- a/src/test/java/com/netflix/imflibrary/app/IMPAnalyzerTest.java +++ b/src/test/java/com/netflix/imflibrary/app/IMPAnalyzerTest.java @@ -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; @@ -19,7 +20,9 @@ public class IMPAnalyzerTest public void IMPAnalyzerTest() throws IOException { File inputFile = TestHelper.findResourceByPath("TestIMP/MERIDIAN_Netflix_Photon_161006/"); - Map> errorMap = analyzePackage(inputFile); + Map> errorMap = analyzePackage( + FileLocator.fromLocation(inputFile.toURI()) + ); Assert.assertEquals(errorMap.size(), 7); errorMap.entrySet().stream().forEach( e -> { diff --git a/src/test/java/com/netflix/imflibrary/st0429_8/PackingListTest.java b/src/test/java/com/netflix/imflibrary/st0429_8/PackingListTest.java index d2b35d50..d17a9350 100644 --- a/src/test/java/com/netflix/imflibrary/st0429_8/PackingListTest.java +++ b/src/test/java/com/netflix/imflibrary/st0429_8/PackingListTest.java @@ -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; @@ -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); @@ -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); diff --git a/src/test/java/com/netflix/imflibrary/st2067_2/IMPDeliveryTest.java b/src/test/java/com/netflix/imflibrary/st2067_2/IMPDeliveryTest.java index 0dc38244..fb465450 100644 --- a/src/test/java/com/netflix/imflibrary/st2067_2/IMPDeliveryTest.java +++ b/src/test/java/com/netflix/imflibrary/st2067_2/IMPDeliveryTest.java @@ -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; @@ -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);