FilesArchiverFactory { public static FilesArchiver createFromURI(String uri) throws IOException { try { URI outputURI = new URI(uri); String scheme = outputURI.getScheme(); logger.info("Got scheme " + scheme + " for URI " + uri); if (scheme == null || scheme.equalsIgnoreCase(EMPTY_STRING)) { return makeDirectoryArchiver(new File(uri)); } if (scheme.equalsIgnoreCase(FILE_SCHEME)) { return makeDirectoryArchiver(new File(outputURI)); } if (scheme.equalsIgnoreCase(HDFS_SCHEME)) { return makeHdfsArchiver(uri); } if (scheme.equalsIgnoreCase(S3_SCHEME)) { return makeS3Archiver(outputURI); } throw new IllegalArgumentException("Unsupported scheme " + scheme); } catch (URISyntaxException e) { throw new IllegalArgumentException( "Unable to parse the URI " + uri, e); } }  static FilesArchiver createFromURI(String uri);  }
@Test public void testNoScheme() throws IOException { String filePath = "testfolder"; File file = new File(filePath); file.delete(); FilesArchiver archiver = FilesArchiverFactory.createFromURI(filePath); assertEquals("No scheme should create a DirectoryArchiver", archiver.getClass(), DirectoryArchiver.class); file.delete(); }
@Test public void testNoTarScheme() throws IOException { String tarFilePath = "testfolder.tar"; File tarFile = new File(tarFilePath); tarFile.delete(); FilesArchiver archiver = FilesArchiverFactory.createFromURI( tarFilePath); assertEquals("No scheme with tar extension should create a TarArchiver", archiver.getClass(), TarArchiver.class); tarFile.delete(); }
@Test public void testFileScheme() throws IOException { FilesArchiver archiver = FilesArchiverFactory.createFromURI( "file: assertEquals("file: archiver.getClass(), DirectoryArchiver.class); }
@Test public void testFileTarScheme() throws IOException, URISyntaxException { String tarFilePath = "file: File tarFile = new File(new URI(tarFilePath)); tarFile.delete(); FilesArchiver archiver = FilesArchiverFactory.createFromURI( tarFilePath); assertEquals("file: + "TarArchiver", archiver.getClass(), TarArchiver.class); tarFile.delete(); }
@Test @Ignore public void testHdfsScheme() throws IOException { FilesArchiver archiver = FilesArchiverFactory.createFromURI( "hdfs: assertEquals("hdfs: archiver.getClass(), HdfsArchiver.class); }
@Test @Ignore public void testHdfsTarScheme() throws IOException { FilesArchiver archiver = FilesArchiverFactory.createFromURI( "hdfs: assertEquals("hdfs: + "TarOnHdfsArchiver", archiver.getClass(), TarOnHdfsArchiver.class); }
@Test @Ignore public void testS3Scheme() throws IOException { FilesArchiver archiver = FilesArchiverFactory.createFromURI( "s3: assertEquals("s3: archiver.getClass(), S3Archiver.class); }