X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Furls%2FUrlProviderTest.java;fp=test%2Fjalview%2Furls%2FUrlProviderTest.java;h=1b77d4afb2acec59ae6806e9d310542d8920e57e;hb=3459a8a691cb22508d7067f240b7254e588e77d3;hp=460ebe92f19658a31a20732db391980d1e934e84;hpb=5b27f1062b2203c4c31702e205f4c78e1992063e;p=jalview.git diff --git a/test/jalview/urls/UrlProviderTest.java b/test/jalview/urls/UrlProviderTest.java index 460ebe9..1b77d4a 100644 --- a/test/jalview/urls/UrlProviderTest.java +++ b/test/jalview/urls/UrlProviderTest.java @@ -1,3 +1,23 @@ +/* + * 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.urls; import jalview.urls.api.UrlProviderI; @@ -14,18 +34,18 @@ import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +public class UrlProviderTest +{ -public class UrlProviderTest { - // Test identifiers.org download file private static final String testIdOrgString = "{\"Local\": [{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\"," - + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\"," - + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\"," - + "\"pattern\":\"^([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?$\"," - + "\"definition\":\"The UniProt Knowledgebase (UniProtKB)\",\"prefix\":\"uniprot\",\"url\":\"http://identifiers.org/uniprot\"}," - + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\"," - + "\"url\":\"http://identifiers.org/interpro\"}," - + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\"" + + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\"," + + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\"," + + "\"pattern\":\"^([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?$\"," + + "\"definition\":\"The UniProt Knowledgebase (UniProtKB)\",\"prefix\":\"uniprot\",\"url\":\"http://identifiers.org/uniprot\"}," + + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\"," + + "\"url\":\"http://identifiers.org/interpro\"}," + + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\"" + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]}"; private UrlProviderI prov; @@ -33,23 +53,23 @@ public class UrlProviderTest { @BeforeMethod(alwaysRun = true) public void setup() { - // make a dummy identifiers.org download file - File temp = null; - - try - { - temp = File.createTempFile("tempfile", ".tmp"); - temp.deleteOnExit(); - BufferedWriter bw = new BufferedWriter(new FileWriter(temp)); - bw.write(testIdOrgString); - bw.close(); - } catch (IOException e) - { - System.out.println("Error initialising UrlProviderTest test: " - + e.getMessage()); - } - - IdOrgSettings.setDownloadLocation(temp.getPath()); + // make a dummy identifiers.org download file + File temp = null; + + try + { + temp = File.createTempFile("tempfile", ".tmp"); + temp.deleteOnExit(); + BufferedWriter bw = new BufferedWriter(new FileWriter(temp)); + bw.write(testIdOrgString); + bw.close(); + } catch (IOException e) + { + System.out.println( + "Error initialising UrlProviderTest test: " + e.getMessage()); + } + + IdOrgSettings.setDownloadLocation(temp.getPath()); String defaultUrlString = "No default"; String cachedUrlList = "MIR:00000005|MIR:00000011|Test1|http://blah.blah/$SEQUENCE_ID$|" @@ -59,7 +79,7 @@ public class UrlProviderTest { DesktopUrlProviderFactory factory = new DesktopUrlProviderFactory( defaultUrlString, cachedUrlList, userUrlList); prov = factory.createUrlProvider(); - } + } @Test(groups = { "Functional" }) public void testInitUrlProvider() @@ -83,18 +103,18 @@ public class UrlProviderTest { // 6 links in menu (cachedUrlList) + new default Assert.assertEquals(menulinks.size(), 6); - Assert.assertTrue(menulinks - .contains("Test1|http://blah.blah/$SEQUENCE_ID$")); - Assert.assertTrue(menulinks - .contains("Test2|http://test2/$DB_ACCESSION$")); - Assert.assertTrue(menulinks - .contains("Test3|http://test3/$SEQUENCE_ID$")); - Assert.assertTrue(menulinks - .contains("UniProt Knowledgebase|http://identifiers.org/uniprot/$DB_ACCESSION$|uniprot")); - Assert.assertTrue(menulinks - .contains("InterPro|http://identifiers.org/interpro/$DB_ACCESSION$|interpro")); - Assert.assertTrue(menulinks.contains(UrlConstants.DEFAULT_LABEL - + UrlConstants.SEP + emblUrl)); + Assert.assertTrue( + menulinks.contains("Test1|http://blah.blah/$SEQUENCE_ID$")); + Assert.assertTrue( + menulinks.contains("Test2|http://test2/$DB_ACCESSION$")); + Assert.assertTrue( + menulinks.contains("Test3|http://test3/$SEQUENCE_ID$")); + Assert.assertTrue(menulinks.contains( + "UniProt Knowledgebase|http://identifiers.org/uniprot/$DB_ACCESSION$|uniprot")); + Assert.assertTrue(menulinks.contains( + "InterPro|http://identifiers.org/interpro/$DB_ACCESSION$|interpro")); + Assert.assertTrue(menulinks.contains( + UrlConstants.DEFAULT_LABEL + UrlConstants.SEP + emblUrl)); } @Test(groups = { "Functional" }) @@ -110,8 +130,10 @@ public class UrlProviderTest { } @Test( - groups = { "Functional" }, - expectedExceptions = { IllegalArgumentException.class }) + groups = + { "Functional" }, + expectedExceptions = + { IllegalArgumentException.class }) public void testSetDefaultUrlWrongly() { // don't allow default to be a non-key