3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertFalse;
5 import static org.testng.Assert.assertNotEquals;
6 import static org.testng.Assert.assertNull;
7 import static org.testng.Assert.assertSame;
8 import static org.testng.Assert.assertTrue;
10 import java.util.Iterator;
12 import org.testng.annotations.AfterMethod;
13 import org.testng.annotations.BeforeMethod;
14 import org.testng.annotations.Test;
16 public class FileFormatsTest
18 @AfterMethod(alwaysRun = true)
19 public void tearDown()
21 FileFormats.getInstance().reset();
24 @BeforeMethod(alwaysRun = true)
27 FileFormats.getInstance().reset();
30 @Test(groups = "Functional")
31 public void testIsIdentifiable()
33 FileFormats formats = FileFormats.getInstance();
34 assertTrue(formats.isIdentifiable(formats.forName(FileFormat.Fasta
36 assertTrue(formats.isIdentifiable(formats.forName(FileFormat.MMCif
38 assertTrue(formats.isIdentifiable(formats.forName(FileFormat.Jnet
40 assertFalse(formats.isIdentifiable(formats.forName(FileFormat.Jalview
42 assertFalse(formats.isIdentifiable(null));
45 * remove and re-add a format: it is still 'identifiable'
47 formats.deregisterFileFormat(FileFormat.Fasta.getName());
48 assertNull(formats.forName(FileFormat.Fasta.getName()));
49 formats.registerFileFormat(FileFormat.Fasta);
50 assertSame(FileFormat.Fasta,
51 formats.forName(FileFormat.Fasta.getName()));
52 assertTrue(formats.isIdentifiable(FileFormat.Fasta));
55 @Test(groups = "Functional")
56 public void testGetReadableFormats()
58 String expected = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, HTML, RNAML, JSON, PileUp, MSF, Clustal, PHYLIP, GFF or Jalview features, PDB, mmCIF, Jalview]";
59 FileFormats formats = FileFormats.getInstance();
60 assertEquals(formats.getReadableFormats().toString(), expected);
63 @Test(groups = "Functional")
64 public void testGetWritableFormats()
66 String expected = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP]";
67 FileFormats formats = FileFormats.getInstance();
68 assertEquals(formats.getWritableFormats(true).toString(), expected);
69 expected = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, Jalview]";
70 assertEquals(formats.getWritableFormats(false).toString(), expected);
73 @Test(groups = "Functional")
74 public void testDeregisterFileFormat()
76 String writable = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP]";
77 String readable = "[Fasta, PFAM, Stockholm, PIR, BLC, AMSA, HTML, RNAML, JSON, PileUp, MSF, Clustal, PHYLIP, GFF or Jalview features, PDB, mmCIF, Jalview]";
78 FileFormats formats = FileFormats.getInstance();
79 assertEquals(formats.getWritableFormats(true).toString(), writable);
80 assertEquals(formats.getReadableFormats().toString(), readable);
82 formats.deregisterFileFormat(FileFormat.Fasta.getName());
83 writable = "[PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP]";
84 readable = "[PFAM, Stockholm, PIR, BLC, AMSA, HTML, RNAML, JSON, PileUp, MSF, Clustal, PHYLIP, GFF or Jalview features, PDB, mmCIF, Jalview]";
85 assertEquals(formats.getWritableFormats(true).toString(), writable);
86 assertEquals(formats.getReadableFormats().toString(), readable);
89 * re-register the format: it gets added to the end of the list
91 formats.registerFileFormat(FileFormat.Fasta);
92 writable = "[PFAM, Stockholm, PIR, BLC, AMSA, JSON, PileUp, MSF, Clustal, PHYLIP, Fasta]";
93 readable = "[PFAM, Stockholm, PIR, BLC, AMSA, HTML, RNAML, JSON, PileUp, MSF, Clustal, PHYLIP, GFF or Jalview features, PDB, mmCIF, Jalview, Fasta]";
94 assertEquals(formats.getWritableFormats(true).toString(), writable);
95 assertEquals(formats.getReadableFormats().toString(), readable);
98 @Test(groups = "Functional")
99 public void testForName()
101 FileFormats formats = FileFormats.getInstance();
102 for (FileFormatI ff : FileFormat.values())
104 assertSame(ff, formats.forName(ff.getName()));
105 assertSame(ff, formats.forName(ff.getName().toUpperCase()));
106 assertSame(ff, formats.forName(ff.getName().toLowerCase()));
108 assertNull(formats.forName(null));
109 assertNull(formats.forName("rubbish"));
112 @Test(groups = "Functional")
113 public void testRegisterFileFormat()
115 FileFormats formats = FileFormats.getInstance();
116 assertSame(FileFormat.MMCif,
117 formats.forName(FileFormat.MMCif.getName()));
118 assertTrue(formats.isIdentifiable(FileFormat.MMCif));
121 * deregister mmCIF format
123 formats.deregisterFileFormat(FileFormat.MMCif.getName());
124 assertNull(formats.forName(FileFormat.MMCif.getName()));
127 * re-register mmCIF format
128 * it is reinstated (still 'identifiable')
130 formats.registerFileFormat(FileFormat.MMCif);
131 assertSame(FileFormat.MMCif,
132 formats.forName(FileFormat.MMCif.getName()));
133 assertTrue(formats.isIdentifiable(FileFormat.MMCif));
134 // repeating does nothing
135 formats.registerFileFormat(FileFormat.MMCif);
136 assertSame(FileFormat.MMCif,
137 formats.forName(FileFormat.MMCif.getName()));
140 @Test(groups = "Functional")
141 public void testGetFormats()
144 * verify the list of file formats registered matches the enum values
146 FileFormats instance = FileFormats.getInstance();
147 Iterator<FileFormatI> formats = instance.getFormats()
149 FileFormatI[] builtIn = FileFormat.values();
151 for (FileFormatI ff : builtIn)
153 assertSame(ff, formats.next());
155 assertFalse(formats.hasNext());
158 * remove the first format, check it is no longer in
159 * the list of formats
161 String firstFormatName = instance.getFormats().iterator().next()
163 instance.deregisterFileFormat(firstFormatName);
164 assertNotEquals(instance.getFormats().iterator().next().getName(),