X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fio%2FFileIOTester.java;h=04d01b045cb4993ce8c88d7d6e04128e945ee4a4;hb=f60987555392a60449a37fe08a0f53003c26937b;hp=f741e743454a3f6c35ec7f8afe3268942008127d;hpb=17e77c3f2949a0729322b4a8d907f3f34b6a9914;p=jalview.git diff --git a/test/jalview/io/FileIOTester.java b/test/jalview/io/FileIOTester.java index f741e74..04d01b0 100644 --- a/test/jalview/io/FileIOTester.java +++ b/test/jalview/io/FileIOTester.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9) - * Copyright (C) 2015 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -20,14 +20,23 @@ */ package jalview.io; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import java.io.BufferedInputStream; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import org.testng.AssertJUnit; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import jalview.bin.Cache; +import jalview.gui.JvOptionPane; + /** * @author jimp * @@ -35,18 +44,26 @@ import org.testng.annotations.Test; public class FileIOTester { + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + /** * @throws java.lang.Exception */ @BeforeClass(alwaysRun = true) public static void setUpBeforeClass() throws Exception { + Cache.initLogger(); } /** * @throws java.lang.Exception */ - @AfterClass + @AfterClass(alwaysRun = true) public static void tearDownAfterClass() throws Exception { } @@ -65,66 +82,90 @@ public class FileIOTester final static File STARS_FA_FILE2 = new File( "test/jalview/io/test_fasta_stars2.fa"); - private void assertValidFormat(String fmt, String src, FileParse fp) + private void assertValidFormat(FileFormatI fmt, String src, FileParse fp) + throws FileFormatException { AssertJUnit.assertTrue("Couldn't resolve " + src + " as a valid file", fp.isValid()); - String type = new IdentifyFile().Identify(fp); - AssertJUnit.assertTrue("Data from '" + src + "' Expected to be '" + fmt - + "' identified as '" + type + "'", type.equalsIgnoreCase(fmt)); + FileFormatI type = new IdentifyFile().identify(fp); + AssertJUnit.assertSame("Data from '" + src + "' Expected to be '" + fmt + + "' identified as '" + type + "'", type, fmt); } @Test(groups = { "Functional" }) public void testStarsInFasta1() throws IOException { String uri; - FileParse fp = new FileParse(uri = STARS_FA_FILE1.getAbsoluteFile() - .toString(), AppletFormatAdapter.FILE); - assertValidFormat("FASTA", uri, fp); + FileParse fp = new FileParse( + uri = STARS_FA_FILE1.getAbsoluteFile().toString(), + DataSourceType.FILE); + assertValidFormat(FileFormat.Fasta, uri, fp); } @Test(groups = { "Functional" }) public void testStarsInFasta2() throws IOException { String uri; - FileParse fp = new FileParse(uri = STARS_FA_FILE2.getAbsoluteFile() - .toString(), AppletFormatAdapter.FILE); - assertValidFormat("FASTA", uri, fp); + FileParse fp = new FileParse( + uri = STARS_FA_FILE2.getAbsoluteFile().toString(), + DataSourceType.FILE); + assertValidFormat(FileFormat.Fasta, uri, fp); } @Test(groups = { "Functional" }) public void testGzipIo() throws IOException { String uri; - FileParse fp = new FileParse(uri = ALIGN_FILE.getAbsoluteFile().toURI() - .toString(), AppletFormatAdapter.URL); - assertValidFormat("FASTA", uri, fp); + FileParse fp = new FileParse( + uri = ALIGN_FILE.getAbsoluteFile().toURI().toString(), + DataSourceType.URL); + assertValidFormat(FileFormat.Fasta, uri, fp); } @Test(groups = { "Functional" }) public void testGziplocalFileIO() throws IOException { String filepath; - FileParse fp = new FileParse(filepath = ALIGN_FILE.getAbsoluteFile() - .toString(), AppletFormatAdapter.FILE); - assertValidFormat("FASTA", filepath, fp); + FileParse fp = new FileParse( + filepath = ALIGN_FILE.getAbsoluteFile().toString(), + DataSourceType.FILE); + assertValidFormat(FileFormat.Fasta, filepath, fp); + } + + @Test(groups = { "Functional" }) + public void testIsGzipInputStream() throws IOException + { + InputStream is = new FileInputStream(ALIGN_FILE); + + /* + * first try fails - FileInputStream does not support mark/reset + */ + assertFalse(FileParse.isGzipStream(is)); + + /* + * wrap in a BufferedInputStream and try again + */ + is = new BufferedInputStream(is, 16); + assertTrue(FileParse.isGzipStream(is)); } @Test(groups = { "Functional" }) public void testNonGzipURLIO() throws IOException { String uri; - FileParse fp = new FileParse(uri = NOTGZALIGN_FILE.getAbsoluteFile() - .toURI().toString(), AppletFormatAdapter.URL); - assertValidFormat("FASTA", uri, fp); + FileParse fp = new FileParse( + uri = NOTGZALIGN_FILE.getAbsoluteFile().toURI().toString(), + DataSourceType.URL); + assertValidFormat(FileFormat.Fasta, uri, fp); } @Test(groups = { "Functional" }) public void testNonGziplocalFileIO() throws IOException { String filepath; - FileParse fp = new FileParse(filepath = NOTGZALIGN_FILE - .getAbsoluteFile().toString(), AppletFormatAdapter.FILE); - assertValidFormat("FASTA", filepath, fp); + FileParse fp = new FileParse( + filepath = NOTGZALIGN_FILE.getAbsoluteFile().toString(), + DataSourceType.FILE); + assertValidFormat(FileFormat.Fasta, filepath, fp); } }