Merge branch 'releases/Release_2_11_4_Branch'
[jalview.git] / test / jalview / io / IdentifyFileTest.java
index cf7f58f..1d0785e 100644 (file)
@@ -24,13 +24,15 @@ import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.assertTrue;
 
-import jalview.gui.JvOptionPane;
+import java.io.FileNotFoundException;
 
 import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
+import jalview.gui.JvOptionPane;
+
 public class IdentifyFileTest
 {
 
@@ -43,7 +45,7 @@ public class IdentifyFileTest
 
   @Test(groups = { "Functional" }, dataProvider = "identifyFiles")
   public void testIdentify(String data, FileFormatI expectedFileType)
-          throws FileFormatException
+          throws FileFormatException, FileNotFoundException
   {
     DataSourceType protocol = DataSourceType.FILE;
     IdentifyFile ider = new IdentifyFile();
@@ -58,7 +60,8 @@ public class IdentifyFileTest
    * @throws FileFormatException
    */
   @Test(groups = "Functional")
-  public void testIdentify_featureFile() throws FileFormatException
+  public void testIdentify_featureFile()
+          throws FileFormatException, FileNotFoundException
   {
     IdentifyFile ider = new IdentifyFile();
 
@@ -102,6 +105,8 @@ public class IdentifyFileTest
         { "examples/testdata/test.html", FileFormat.Html },
         { "examples/testdata/test.pileup", FileFormat.Pileup },
         { "examples/testdata/test.blc", FileFormat.BLC },
+        { "test/jalview/io/J03321.embl.txt", FileFormat.Embl },
+        { "test/jalview/io/J03321.gb", FileFormat.GenBank },
         { "examples/exampleFeatures.txt", FileFormat.Features },
         { "examples/testdata/simpleGff3.gff", FileFormat.Features },
         { "examples/testdata/test.jvp", FileFormat.Jalview },
@@ -133,4 +138,60 @@ public class IdentifyFileTest
     // non-numeric start column:
     assertFalse(id.looksLikeFeatureData("Helix\tSeq1\t-1\t2456\t.\tss"));
   }
+
+  @Test(groups = "Network", dataProvider = "urlTargetsAndExceptions")
+  public void testExceptions(String url,
+          Class<? extends Exception> expectedExceptionClass,
+          FileFormatI expectedFormat)
+  {
+    Class<? extends Exception> actualExceptionClass = null;
+    FileFormatI actualFormat = null;
+    try
+    {
+      actualFormat = new IdentifyFile().identify(url, DataSourceType.URL);
+    } catch (FileFormatException | FileNotFoundException e)
+    {
+      Assert.assertNull(expectedFormat,
+              "Exception occurred when expecting an identifiable format.");
+      Assert.assertNotNull(expectedExceptionClass,
+              "An unexpected exception occurred: '" + e.getMessage() + "'");
+      Assert.assertEquals(e.getClass(), expectedExceptionClass,
+              "Got the wrong kind of exception.");
+      actualExceptionClass = e.getClass();
+    }
+
+    if (expectedExceptionClass != null)
+    {
+      Assert.assertEquals(actualExceptionClass, expectedExceptionClass,
+              "Expected an exception but got the wrong one.");
+    }
+
+  }
+
+  @DataProvider(name = "urlTargetsAndExceptions")
+  public Object[][] urlTargetsAndExceptions()
+  {
+    /*
+    String targetUrl,
+    String finalUrl,
+    String foundInFirstLine,
+    */
+    return new Object[][] {
+        //
+        /*
+        { "http://jalview.org/examples/uniref50.fa", null,
+            FileFormat.Fasta },
+        { "https://www.jalview.org/examples/NOFILE.fa",
+            FileNotFoundException.class, null },
+        { "https://NOSERVER.jalview.org/", FileNotFoundException.class,
+            null },
+         */
+        { "https://www.jalview.org/schools/Jalview_Schools_Workbook_200.jpg",
+            FileFormatException.class, null },
+        /*
+         */
+        //
+    };
+  }
+
 }