From 0a7dccf924dddc0bae404b5bd29f32225c2ff909 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Tue, 14 May 2024 21:09:38 +0100 Subject: [PATCH] JAL-1054 JAL-4414 Tests for the HttpUtils redirect wrapper methods. Tests for the different exceptions from IdentityFile.identify(). --- test/jalview/io/IdentifyFileTest.java | 56 +++++++++++++++++++++++++++++++++ test/jalview/util/HttpUtilsTest.java | 9 +++--- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/test/jalview/io/IdentifyFileTest.java b/test/jalview/io/IdentifyFileTest.java index 6ee3f0e..1d0785e 100644 --- a/test/jalview/io/IdentifyFileTest.java +++ b/test/jalview/io/IdentifyFileTest.java @@ -138,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 expectedExceptionClass, + FileFormatI expectedFormat) + { + Class 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 }, + /* + */ + // + }; + } + } diff --git a/test/jalview/util/HttpUtilsTest.java b/test/jalview/util/HttpUtilsTest.java index 34e838a..fbd8149 100644 --- a/test/jalview/util/HttpUtilsTest.java +++ b/test/jalview/util/HttpUtilsTest.java @@ -69,9 +69,10 @@ public class HttpUtilsTest public Object[][] urlTargetsAndDestinations() { /* - String targetUrl, - String finalUrl, - String foundInFirstLine, + String targetUrl, // the URL you ask for + String finalUrl, // the URL you end up at + String foundInFirstLine, // some text found in the first line + String foundInDocument, // some text found in the document (and won't be in an error page) */ return new Object[][] { // @@ -81,7 +82,7 @@ public class HttpUtilsTest "Jalview is a" }, { "http://www.jalview.org/", "https://www.jalview.org/", "