Merge branch 'develop' into menard
[jalview.git] / test / jalview / io / TCoffeeScoreFileTest.java
index 7257e14..2c09148 100644 (file)
@@ -1,3 +1,20 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
+ * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ */
 package jalview.io;
 
 import static org.junit.Assert.*;
@@ -12,16 +29,27 @@ import java.io.IOException;
 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 );
@@ -38,15 +66,20 @@ public class TCoffeeScoreFileTest {
        
        
        @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() );
        }       
@@ -68,9 +101,10 @@ public class TCoffeeScoreFileTest {
                                "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") );
@@ -83,9 +117,9 @@ public class TCoffeeScoreFileTest {
        }
 
        @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") );
@@ -100,10 +134,10 @@ public class TCoffeeScoreFileTest {
 
        
        @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) );
@@ -119,10 +153,10 @@ public class TCoffeeScoreFileTest {
        
        
        @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] );