JAL-3937 enable AIA download of intermediate certificates when needed
[jalview.git] / test / jalview / io / EmblFlatFileTest.java
index 4ca826c..7775c8f 100644 (file)
@@ -3,9 +3,9 @@ package jalview.io;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertNull;
 import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.fail;
-import static org.testng.AssertJUnit.assertNull;
 
 import java.io.File;
 import java.io.IOException;
@@ -14,8 +14,10 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
 
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import jalview.bin.Cache;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.Mapping;
 import jalview.datamodel.Sequence.DBModList;
@@ -26,6 +28,12 @@ import jalview.util.MapList;
 
 public class EmblFlatFileTest
 {
+  @BeforeClass(alwaysRun = true)
+  public void setUp()
+  {
+    Cache.initLogger();
+  }
+
   /**
    * A fairly tough test, using J03321 (circular DNA), which has 8 CDS features,
    * one of them reverse strand
@@ -39,7 +47,6 @@ public class EmblFlatFileTest
     File dataFile = new File("test/jalview/io/J03321.embl.txt");
     FileParse fp = new FileParse(dataFile, DataSourceType.FILE);
     EmblFlatFile parser = new EmblFlatFile(fp, "EmblTest");
-    parser.parse();
     List<SequenceI> seqs = parser.getSeqs();
 
     assertEquals(seqs.size(), 1);
@@ -223,6 +230,22 @@ public class EmblFlatFileTest
     }
     assertEquals(uniprotCount, 8);
   }
+  /**
+   * A fairly tough test, using J03321 (circular DNA), which has 8 CDS features,
+   * one of them reverse strand
+   * 
+   * @throws MalformedURLException
+   * @throws IOException
+   */
+  @Test(groups = "Functional")
+  public void testParseToRNA() throws MalformedURLException, IOException
+  {
+    File dataFile = new File("test/jalview/io/J03321_rna.embl.txt");
+    FileParse fp = new FileParse(dataFile, DataSourceType.FILE);
+    EmblFlatFile parser = new EmblFlatFile(fp, "EmblTest");
+    List<SequenceI> seqs = parser.getSeqs();
+    assertTrue(seqs.get(0).getSequenceAsString().indexOf("u")>-1);
+  }
 
   @Test(groups = "Functional")
   public void testParse_codonStartNot1()
@@ -242,17 +265,19 @@ public class EmblFlatFileTest
   public void testParse_noUniprotXref() throws IOException
   {
     // MN908947 cut down to 40BP, one CDS, length 5 peptide for test purposes
+    // plus an additional (invented) test case:
+    // - multi-line /product qualifier including escaped quotes
     String data = "ID   MN908947; SV 3; linear; genomic RNA; STD; VRL; 20 BP.\n"
             + "DE   Severe acute respiratory syndrome coronavirus 2 isolate Wuhan-Hu-1,\n"
             + "FT   CDS             3..17\n"
             + "FT                   /protein_id=\"QHD43415.1\"\n"
-            + "FT                   /product=\"orf1ab polyprotein\"\n"
+            + "FT                   /product=\"orf1ab polyprotein\n"
+            + "FT                   \"\"foobar\"\" \"\n"
             + "FT                   /translation=\"MRKLD\n"
             + "SQ   Sequence 7496 BP; 2450 A; 1290 C; 1434 G; 2322 T; 0 other;\n"
             + "     ggatGcgtaa gttagacgaa attttgtctt tgcgcacaga        40\n";
     FileParse fp = new FileParse(data, DataSourceType.PASTE);
     EmblFlatFile parser = new EmblFlatFile(fp, "EmblTest");
-    parser.parse();
     List<SequenceI> seqs = parser.getSeqs();
     assertEquals(seqs.size(), 1);
     SequenceI seq = seqs.get(0);
@@ -284,7 +309,8 @@ public class EmblFlatFileTest
     mapping = dbref.getMap();
     SequenceI mapTo = mapping.getTo();
     assertEquals(mapTo.getName(), "QHD43415.1");
-    assertEquals(mapTo.getDescription(), "orf1ab polyprotein");
+    // the /product qualifier transfers to protein product description
+    assertEquals(mapTo.getDescription(), "orf1ab polyprotein \"foobar\"");
     assertEquals(mapTo.getSequenceAsString(), "MRKLD");
     map = mapping.getMap();
     assertEquals(map.getFromLowest(), 3);
@@ -323,4 +349,13 @@ public class EmblFlatFileTest
     truncated = EmblFlatFile.adjustForProteinLength(7, exons);
     assertSame(exons, truncated);
   }
+
+  @Test(groups = "Functional")
+  public void testRemoveQuotes()
+  {
+    assertNull(EmblFlatFile.removeQuotes(null));
+    assertEquals(EmblFlatFile.removeQuotes("No quotes here"), "No quotes here");
+    assertEquals(EmblFlatFile.removeQuotes("\"Enclosing quotes\""), "Enclosing quotes");
+    assertEquals(EmblFlatFile.removeQuotes("\"Escaped \"\"quotes\"\" example\""), "Escaped \"quotes\" example");
+  }
 }