X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fws%2Futils%2FUrlDownloadClientTest.java;fp=test%2Fjalview%2Fws%2Futils%2FUrlDownloadClientTest.java;h=2bd8dd0ae5a45489682c1fde6b9384e48145378c;hb=9f70ff4b6d193b340031997634c9e3602486bc8e;hp=0000000000000000000000000000000000000000;hpb=76844c43faeeeba369deaf42f1998ca0fb33d956;p=jalview.git diff --git a/test/jalview/ws/utils/UrlDownloadClientTest.java b/test/jalview/ws/utils/UrlDownloadClientTest.java new file mode 100644 index 0000000..2bd8dd0 --- /dev/null +++ b/test/jalview/ws/utils/UrlDownloadClientTest.java @@ -0,0 +1,85 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.ws.utils; + +import java.io.File; +import java.io.IOException; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class UrlDownloadClientTest { + + /** + * Test that url is successfully loaded into download file + */ + @Test(groups = { "Network" }, enabled = true) + public void UrlDownloadTest() + { + UrlDownloadClient client = new UrlDownloadClient(); + String urlstring = "http://identifiers.org/rest/collections/"; + String outfile = "testfile.tmp"; + + try + { + client.download(urlstring, outfile); + } catch (IOException e) + { + Assert.fail("Exception was thrown from UrlDownloadClient download: " + + e.getMessage()); + File f = new File(outfile); + if (f.exists()) + { + f.delete(); + } + } + + // download file exists + File f = new File(outfile); + Assert.assertTrue(f.exists()); + + // download file has a believable size + // identifiers.org file typically at least 250K + Assert.assertTrue(f.length() > 250000); + + if (f.exists()) + { + f.delete(); + } + + } + + /** + * Test that garbage in results in IOException + */ + @Test( + groups = { "Network" }, + enabled = true, + expectedExceptions = { IOException.class }) + public void DownloadGarbageUrlTest() throws IOException + { + UrlDownloadClient client = new UrlDownloadClient(); + String urlstring = "identifiers.org/rest/collections/"; + String outfile = "testfile.tmp"; + + client.download(urlstring, outfile); + } +}