From 8f681b73c9248f18c3109b3c194012283be38526 Mon Sep 17 00:00:00 2001 From: kiramt Date: Wed, 7 Dec 2016 14:26:01 +0000 Subject: [PATCH] JAL-2316 Unit test for download client --- test/jalview/ws/UrlDownloadClientTest.java | 85 ++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 test/jalview/ws/UrlDownloadClientTest.java diff --git a/test/jalview/ws/UrlDownloadClientTest.java b/test/jalview/ws/UrlDownloadClientTest.java new file mode 100644 index 0000000..90470f5 --- /dev/null +++ b/test/jalview/ws/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; + +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); + } +} -- 1.7.10.2