import java.io.StringReader;
import java.util.List;
+import javax.xml.parsers.ParserConfigurationException;
+
import org.junit.Test;
+import org.xml.sax.SAXException;
+
+import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
+import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
+import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
+import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
public class TCoffeeScoreFileTest {
- final static File SCORE_FILE = new File("./test/jalview/io/tcoffee.score_ascii");
+ final static File SCORE_FILE = new File("test/jalview/io/tcoffee.score_ascii");
+ final static File ALIGN_FILE = new File("test/jalview/io/tcoffee.fasta_aln");
@Test
- public void testReadHeader() throws FileNotFoundException {
+ public void testReadHeader() throws IOException, FileNotFoundException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses {
- Header header = TCoffeeScoreFile.readHeader( new BufferedReader(new FileReader(SCORE_FILE)) );
+ TCoffeeScoreFile scoreFile = new TCoffeeScoreFile(SCORE_FILE.getPath(),AppletFormatAdapter.FILE);
+ assertTrue(scoreFile.getWarningMessage(),scoreFile.isValid());
+ Header header = scoreFile.header;
assertNotNull(header);
assertEquals( "T-COFFEE, Version_9.02.r1228 (2012-02-16 18:15:12 - Revision 1228 - Build 336)", header.head );
assertEquals( 90, header.score );
@Test
- public void testWrongFile() {
- TCoffeeScoreFile result = TCoffeeScoreFile.load(new File("./test/jalview/io/tcoffee.fasta_aln"));
- assertNull(result);
+ public void testWrongFile() throws ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses {
+ try {
+ TCoffeeScoreFile result = new TCoffeeScoreFile(ALIGN_FILE.getPath(), FormatAdapter.FILE);
+ assertFalse(result.isValid());
+ } catch (IOException x)
+ {
+ assertTrue("File not found exception thrown",x instanceof FileNotFoundException);
+ }
}
@Test
- public void testHeightAndWidth() {
- TCoffeeScoreFile result = TCoffeeScoreFile.load(new File("./test/jalview/io/tcoffee.score_ascii"));
- assertNotNull(result);
+ public void testHeightAndWidth() throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses {
+ TCoffeeScoreFile result = new TCoffeeScoreFile(SCORE_FILE.getPath(), FormatAdapter.FILE);
+ assertTrue(result.isValid());
assertEquals( 8, result.getHeight() );
assertEquals( 83, result.getWidth() );
}
"cons 999999999999999999999999999851000110321100001134\n" +
"\n" +
"\n";
-
- Block block = TCoffeeScoreFile.readBlock(new BufferedReader(new StringReader(BLOCK)), 0);
- assertNotNull(block);
+ FileParse source=new FileParse(BLOCK, FormatAdapter.PASTE);
+ Block block = TCoffeeScoreFile.readBlock(source, 0);
+
+ assertNotNull(block);
assertEquals( "999999999999999999999999998762112222543211112134", block.getScoresFor("1PHT") );
assertEquals( "99999999999999999999999999987-------4322----2234", block.getScoresFor("1BB9") );
assertEquals( "99999999999999999999999999987-------5321----2246", block.getScoresFor("1UHC") );
}
@Test
- public void testParse() throws FileNotFoundException {
+ public void testParse() throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses {
- TCoffeeScoreFile parser = TCoffeeScoreFile.load(new BufferedReader(new FileReader(SCORE_FILE)) );
+ TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(), FormatAdapter.FILE);
assertEquals( "999999999999999999999999998762112222543211112134----------5666642367889999999999889", parser.getScoresFor("1PHT") );
assertEquals( "99999999999999999999999999987-------4322----22341111111111676653-355679999999999889", parser.getScoresFor("1BB9") );
@Test
- public void testGetAsList() throws FileNotFoundException {
+ public void testGetAsList() throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses {
- TCoffeeScoreFile parser = TCoffeeScoreFile.load(new BufferedReader(new FileReader(SCORE_FILE)) );
-
+ TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),FormatAdapter.FILE);
+ assertTrue(parser.getWarningMessage(),parser.isValid());
List<String> scores = parser.getScoresList();
assertEquals( "999999999999999999999999998762112222543211112134----------5666642367889999999999889", scores.get(0) );
assertEquals( "99999999999999999999999999987-------4322----22341111111111676653-355679999999999889", scores.get(1) );
@Test
- public void testGetAsArray() throws FileNotFoundException {
+ public void testGetAsArray() throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses {
- TCoffeeScoreFile parser = TCoffeeScoreFile.load(new BufferedReader(new FileReader(SCORE_FILE)) );
-
+ TCoffeeScoreFile parser = new TCoffeeScoreFile(SCORE_FILE.getPath(),FormatAdapter.FILE);
+ assertTrue(parser.getWarningMessage(),parser.isValid());
byte[][] scores = parser.getScoresArray();
assertEquals( 9, scores[0][0] );