2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertFalse;
25 import static org.testng.Assert.assertNotEquals;
26 import static org.testng.Assert.assertNull;
27 import static org.testng.Assert.assertSame;
28 import static org.testng.Assert.assertTrue;
30 import java.util.Iterator;
32 import org.testng.annotations.AfterMethod;
33 import org.testng.annotations.BeforeMethod;
34 import org.testng.annotations.Test;
36 public class FileFormatsTest
38 @AfterMethod(alwaysRun = true)
39 public void tearDown()
41 FileFormats.getInstance().reset();
44 @BeforeMethod(alwaysRun = true)
47 FileFormats.getInstance().reset();
50 @Test(groups = "Functional")
51 public void testIsIdentifiable()
53 FileFormats formats = FileFormats.getInstance();
54 assertTrue(formats.isIdentifiable(formats.forName(FileFormat.Fasta
56 assertTrue(formats.isIdentifiable(formats.forName(FileFormat.MMCif
58 assertTrue(formats.isIdentifiable(formats.forName(FileFormat.Jnet
60 assertTrue(formats.isIdentifiable(formats.forName(FileFormat.Jalview
62 assertFalse(formats.isIdentifiable(null));
65 * remove and re-add a format: it is still 'identifiable'
67 formats.deregisterFileFormat(FileFormat.Fasta.getName());
68 assertNull(formats.forName(FileFormat.Fasta.getName()));
69 formats.registerFileFormat(FileFormat.Fasta);
70 assertSame(FileFormat.Fasta,
71 formats.forName(FileFormat.Fasta.getName()));
72 assertTrue(formats.isIdentifiable(FileFormat.Fasta));
75 @Test(groups = "Functional")
76 public void testGetReadableFormats()
78 String expected = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, HTML, RNAML, JSON, PileUp, MSF, Clustal, PHYLIP, GenBank Flatfile, ENA Flatfile, GFF or Jalview features, PDB, mmCIF, Jalview]";
79 FileFormats formats = FileFormats.getInstance();
80 assertEquals(formats.getReadableFormats().toString(), expected);
83 @Test(groups = "Functional")
84 public void testGetWritableFormats()
86 String expected = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, HMMER3]";
87 FileFormats formats = FileFormats.getInstance();
88 assertEquals(formats.getWritableFormats(true).toString(), expected);
89 expected = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, Jalview, HMMER3]";
90 assertEquals(formats.getWritableFormats(false).toString(), expected);
93 @Test(groups = "Functional")
94 public void testDeregisterFileFormat()
96 String writable = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, HMMER3]";
97 String readable = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, HTML, RNAML, JSON, PileUp, MSF, Clustal, PHYLIP, GenBank Flatfile, ENA Flatfile, GFF or Jalview features, PDB, mmCIF, Jalview, HMMER3, BSML]";
98 FileFormats formats = FileFormats.getInstance();
99 System.out.println(formats.getReadableFormats().toString());
100 assertEquals(formats.getWritableFormats(true).toString(), writable);
101 assertEquals(formats.getReadableFormats().toString(), readable);
103 formats.deregisterFileFormat(FileFormat.Fasta.getName());
104 writable = "[PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, HMMER3]";
105 readable = "[PFAM, Stockholm, PIR, BLC, AMSA, HTML, RNAML, JSON, PileUp, MSF, Clustal, PHYLIP, GenBank Flatfile, ENA Flatfile, GFF or Jalview features, PDB, mmCIF, Jalview, HMMER3, BSML]";
106 assertEquals(formats.getWritableFormats(true).toString(), writable);
107 assertEquals(formats.getReadableFormats().toString(), readable);
110 * re-register the format: it gets added to the end of the list
112 formats.registerFileFormat(FileFormat.Fasta);
113 writable = "[PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, HMMER3, Fasta]";
114 readable = "[PFAM, Stockholm, PIR, BLC, AMSA, HTML, RNAML, JSON, PileUp, MSF, Clustal, PHYLIP, GenBank Flatfile, ENA Flatfile, GFF or Jalview features, PDB, mmCIF, Jalview, HMMER3, BSML, Fasta]";
115 assertEquals(formats.getWritableFormats(true).toString(), writable);
116 assertEquals(formats.getReadableFormats().toString(), readable);
119 @Test(groups = "Functional")
120 public void testForName()
122 FileFormats formats = FileFormats.getInstance();
123 for (FileFormatI ff : FileFormat.values())
125 assertSame(ff, formats.forName(ff.getName()));
127 formats.forName(ff.getName().toUpperCase(Locale.ROOT)));
129 formats.forName(ff.getName().toLowerCase(Locale.ROOT)));
131 assertNull(formats.forName(null));
132 assertNull(formats.forName("rubbish"));
135 @Test(groups = "Functional")
136 public void testRegisterFileFormat()
138 FileFormats formats = FileFormats.getInstance();
139 assertSame(FileFormat.MMCif,
140 formats.forName(FileFormat.MMCif.getName()));
141 assertTrue(formats.isIdentifiable(FileFormat.MMCif));
144 * deregister mmCIF format
146 formats.deregisterFileFormat(FileFormat.MMCif.getName());
147 assertNull(formats.forName(FileFormat.MMCif.getName()));
150 * re-register mmCIF format
151 * it is reinstated (still 'identifiable')
153 formats.registerFileFormat(FileFormat.MMCif);
154 assertSame(FileFormat.MMCif,
155 formats.forName(FileFormat.MMCif.getName()));
156 assertTrue(formats.isIdentifiable(FileFormat.MMCif));
157 // repeating does nothing
158 formats.registerFileFormat(FileFormat.MMCif);
159 assertSame(FileFormat.MMCif,
160 formats.forName(FileFormat.MMCif.getName()));
163 @Test(groups = "Functional")
164 public void testGetFormats()
167 * verify the list of file formats registered matches the enum values
169 FileFormats instance = FileFormats.getInstance();
170 Iterator<FileFormatI> formats = instance.getFormats()
172 FileFormatI[] builtIn = FileFormat.values();
174 for (FileFormatI ff : builtIn)
176 assertSame(ff, formats.next());
178 assertFalse(formats.hasNext());
181 * remove the first format, check it is no longer in
182 * the list of formats
184 String firstFormatName = instance.getFormats().iterator().next()
186 instance.deregisterFileFormat(firstFormatName);
187 assertNotEquals(instance.getFormats().iterator().next().getName(),