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;
31 import java.util.Locale;
33 import org.testng.annotations.AfterMethod;
34 import org.testng.annotations.BeforeMethod;
35 import org.testng.annotations.Test;
37 public class FileFormatsTest
39 @AfterMethod(alwaysRun = true)
40 public void tearDown()
42 FileFormats.getInstance().reset();
45 @BeforeMethod(alwaysRun = true)
48 FileFormats.getInstance().reset();
51 @Test(groups = "Functional")
52 public void testIsIdentifiable()
54 FileFormats formats = FileFormats.getInstance();
55 assertTrue(formats.isIdentifiable(formats.forName(FileFormat.Fasta
57 assertTrue(formats.isIdentifiable(formats.forName(FileFormat.MMCif
59 assertTrue(formats.isIdentifiable(formats.forName(FileFormat.Jnet
61 assertTrue(formats.isIdentifiable(formats.forName(FileFormat.Jalview
63 assertFalse(formats.isIdentifiable(null));
66 * remove and re-add a format: it is still 'identifiable'
68 formats.deregisterFileFormat(FileFormat.Fasta.getName());
69 assertNull(formats.forName(FileFormat.Fasta.getName()));
70 formats.registerFileFormat(FileFormat.Fasta);
71 assertSame(FileFormat.Fasta,
72 formats.forName(FileFormat.Fasta.getName()));
73 assertTrue(formats.isIdentifiable(FileFormat.Fasta));
76 @Test(groups = "Functional")
77 public void testGetReadableFormats()
79 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, HMMER3, BSML]";
80 FileFormats formats = FileFormats.getInstance();
81 assertEquals(formats.getReadableFormats().toString(), expected);
84 @Test(groups = "Functional")
85 public void testGetWritableFormats()
87 String expected = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, HMMER3]";
88 FileFormats formats = FileFormats.getInstance();
89 assertEquals(formats.getWritableFormats(true).toString(), expected);
90 expected = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, Jalview, HMMER3]";
91 assertEquals(formats.getWritableFormats(false).toString(), expected);
94 @Test(groups = "Functional")
95 public void testDeregisterFileFormat()
97 String writable = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, HMMER3]";
98 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]";
99 FileFormats formats = FileFormats.getInstance();
100 System.out.println(formats.getReadableFormats().toString());
101 assertEquals(formats.getWritableFormats(true).toString(), writable);
102 assertEquals(formats.getReadableFormats().toString(), readable);
104 formats.deregisterFileFormat(FileFormat.Fasta.getName());
105 writable = "[PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, HMMER3]";
106 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]";
107 assertEquals(formats.getWritableFormats(true).toString(), writable);
108 assertEquals(formats.getReadableFormats().toString(), readable);
111 * re-register the format: it gets added to the end of the list
113 formats.registerFileFormat(FileFormat.Fasta);
114 writable = "[PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, HMMER3, Fasta]";
115 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]";
116 assertEquals(formats.getWritableFormats(true).toString(), writable);
117 assertEquals(formats.getReadableFormats().toString(), readable);
120 @Test(groups = "Functional")
121 public void testForName()
123 FileFormats formats = FileFormats.getInstance();
124 for (FileFormatI ff : FileFormat.values())
126 assertSame(ff, formats.forName(ff.getName()));
128 formats.forName(ff.getName().toUpperCase(Locale.ROOT)));
130 formats.forName(ff.getName().toLowerCase(Locale.ROOT)));
132 assertNull(formats.forName(null));
133 assertNull(formats.forName("rubbish"));
136 @Test(groups = "Functional")
137 public void testRegisterFileFormat()
139 FileFormats formats = FileFormats.getInstance();
140 assertSame(FileFormat.MMCif,
141 formats.forName(FileFormat.MMCif.getName()));
142 assertTrue(formats.isIdentifiable(FileFormat.MMCif));
145 * deregister mmCIF format
147 formats.deregisterFileFormat(FileFormat.MMCif.getName());
148 assertNull(formats.forName(FileFormat.MMCif.getName()));
151 * re-register mmCIF format
152 * it is reinstated (still 'identifiable')
154 formats.registerFileFormat(FileFormat.MMCif);
155 assertSame(FileFormat.MMCif,
156 formats.forName(FileFormat.MMCif.getName()));
157 assertTrue(formats.isIdentifiable(FileFormat.MMCif));
158 // repeating does nothing
159 formats.registerFileFormat(FileFormat.MMCif);
160 assertSame(FileFormat.MMCif,
161 formats.forName(FileFormat.MMCif.getName()));
164 @Test(groups = "Functional")
165 public void testGetFormats()
168 * verify the list of file formats registered matches the enum values
170 FileFormats instance = FileFormats.getInstance();
171 Iterator<FileFormatI> formats = instance.getFormats()
173 FileFormatI[] builtIn = FileFormat.values();
175 for (FileFormatI ff : builtIn)
177 assertSame(ff, formats.next());
179 assertFalse(formats.hasNext());
182 * remove the first format, check it is no longer in
183 * the list of formats
185 String firstFormatName = instance.getFormats().iterator().next()
187 instance.deregisterFileFormat(firstFormatName);
188 assertNotEquals(instance.getFormats().iterator().next().getName(),