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 java.util.Locale;
25 import static org.testng.Assert.assertEquals;
26 import static org.testng.Assert.assertFalse;
27 import static org.testng.Assert.assertNotEquals;
28 import static org.testng.Assert.assertNull;
29 import static org.testng.Assert.assertSame;
30 import static org.testng.Assert.assertTrue;
32 import java.util.Iterator;
34 import org.testng.annotations.AfterMethod;
35 import org.testng.annotations.BeforeMethod;
36 import org.testng.annotations.Test;
38 public class FileFormatsTest
40 @AfterMethod(alwaysRun = true)
41 public void tearDown()
43 FileFormats.getInstance().reset();
46 @BeforeMethod(alwaysRun = true)
49 FileFormats.getInstance().reset();
52 @Test(groups = "Functional")
53 public void testIsIdentifiable()
55 FileFormats formats = FileFormats.getInstance();
57 .isIdentifiable(formats.forName(FileFormat.Fasta.getName())));
59 .isIdentifiable(formats.forName(FileFormat.MMCif.getName())));
61 .isIdentifiable(formats.forName(FileFormat.Jnet.getName())));
63 .isIdentifiable(formats.forName(FileFormat.Jalview.getName())));
65 assertFalse(formats.isIdentifiable(null));
68 * remove and re-add a format: it is still 'identifiable'
70 formats.deregisterFileFormat(FileFormat.Fasta.getName());
71 assertNull(formats.forName(FileFormat.Fasta.getName()));
72 formats.registerFileFormat(FileFormat.Fasta);
73 assertSame(FileFormat.Fasta,
74 formats.forName(FileFormat.Fasta.getName()));
75 assertTrue(formats.isIdentifiable(FileFormat.Fasta));
78 @Test(groups = "Functional")
79 public void testGetReadableFormats()
81 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]";
82 FileFormats formats = FileFormats.getInstance();
83 assertEquals(formats.getReadableFormats().toString(), expected);
86 @Test(groups = "Functional")
87 public void testGetWritableFormats()
89 String expected = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP]";
90 FileFormats formats = FileFormats.getInstance();
91 assertEquals(formats.getWritableFormats(true).toString(), expected);
92 expected = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, Jalview]";
93 assertEquals(formats.getWritableFormats(false).toString(), expected);
96 @Test(groups = "Functional")
97 public void testDeregisterFileFormat()
99 String writable = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP]";
100 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]";
101 FileFormats formats = FileFormats.getInstance();
102 assertEquals(formats.getWritableFormats(true).toString(), writable);
103 assertEquals(formats.getReadableFormats().toString(), readable);
105 formats.deregisterFileFormat(FileFormat.Fasta.getName());
106 writable = "[PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP]";
107 readable = "[PFAM, Stockholm, PIR, BLC, AMSA, HTML, RNAML, JSON, PileUp, MSF, Clustal, PHYLIP, GenBank Flatfile, ENA Flatfile, GFF or Jalview features, PDB, mmCIF, Jalview]";
108 assertEquals(formats.getWritableFormats(true).toString(), writable);
109 assertEquals(formats.getReadableFormats().toString(), readable);
112 * re-register the format: it gets added to the end of the list
114 formats.registerFileFormat(FileFormat.Fasta);
115 writable = "[PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, Fasta]";
116 readable = "[PFAM, Stockholm, PIR, BLC, AMSA, HTML, RNAML, JSON, PileUp, MSF, Clustal, PHYLIP, GenBank Flatfile, ENA Flatfile, GFF or Jalview features, PDB, mmCIF, Jalview, Fasta]";
117 assertEquals(formats.getWritableFormats(true).toString(), writable);
118 assertEquals(formats.getReadableFormats().toString(), readable);
121 @Test(groups = "Functional")
122 public void testForName()
124 FileFormats formats = FileFormats.getInstance();
125 for (FileFormatI ff : FileFormat.values())
127 assertSame(ff, formats.forName(ff.getName()));
129 formats.forName(ff.getName().toUpperCase(Locale.ROOT)));
131 formats.forName(ff.getName().toLowerCase(Locale.ROOT)));
133 assertNull(formats.forName(null));
134 assertNull(formats.forName("rubbish"));
137 @Test(groups = "Functional")
138 public void testRegisterFileFormat()
140 FileFormats formats = FileFormats.getInstance();
141 assertSame(FileFormat.MMCif,
142 formats.forName(FileFormat.MMCif.getName()));
143 assertTrue(formats.isIdentifiable(FileFormat.MMCif));
146 * deregister mmCIF format
148 formats.deregisterFileFormat(FileFormat.MMCif.getName());
149 assertNull(formats.forName(FileFormat.MMCif.getName()));
152 * re-register mmCIF format
153 * it is reinstated (still 'identifiable')
155 formats.registerFileFormat(FileFormat.MMCif);
156 assertSame(FileFormat.MMCif,
157 formats.forName(FileFormat.MMCif.getName()));
158 assertTrue(formats.isIdentifiable(FileFormat.MMCif));
159 // repeating does nothing
160 formats.registerFileFormat(FileFormat.MMCif);
161 assertSame(FileFormat.MMCif,
162 formats.forName(FileFormat.MMCif.getName()));
165 @Test(groups = "Functional")
166 public void testGetFormats()
169 * verify the list of file formats registered matches the enum values
171 FileFormats instance = FileFormats.getInstance();
172 Iterator<FileFormatI> formats = instance.getFormats().iterator();
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(),