JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / test / jalview / ext / jmol / PDBFileWithJmolTest.java
index ef14287..fa3922b 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
+ * Copyright (C) 2015 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  */
 package jalview.ext.jmol;
 
-import static org.junit.Assert.*;
-
-import java.util.Vector;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
 
+import jalview.bin.Cache;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
@@ -31,7 +31,12 @@ import jalview.gui.AlignFrame;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.FileLoader;
 
-import org.junit.Test;
+import java.util.Vector;
+
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import MCview.PDBfile;
 
 /**
  * @author jimp
@@ -39,26 +44,43 @@ import org.junit.Test;
  */
 public class PDBFileWithJmolTest
 {
-  String[] testFile = new String[]
-  { "./examples/1GAQ.txt" }; // , "./examples/DNMT1_MOUSE.pdb" };
+  String[] testFile = new String[] { "./examples/1GAQ.txt",
+      "./test/jalview/ext/jmol/1QCF.pdb" }; // ,
 
-  @Test
-   public void testAlignmentLoader() throws Exception
-   {
-    for (String f:testFile) {
+  // "./examples/DNMT1_MOUSE.pdb"
+  // };
+
+  @BeforeMethod(alwaysRun = true)
+  public void setUp()
+  {
+    Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
+            Boolean.TRUE.toString());
+    Cache.applicationProperties.setProperty("ADD_SS_ANN",
+            Boolean.TRUE.toString());
+  }
+
+  @Test(groups = { "Functional" })
+  public void testAlignmentLoader() throws Exception
+  {
+    for (String f : testFile)
+    {
       FileLoader fl = new jalview.io.FileLoader(false);
-      AlignFrame af = fl.LoadFileWaitTillLoaded(f, AppletFormatAdapter.FILE);
+      AlignFrame af = fl
+              .LoadFileWaitTillLoaded(f, AppletFormatAdapter.FILE);
       validateSecStrRows(af.getViewport().getAlignment());
     }
-   }
-  @Test
+  }
+
+  @Test(groups = { "Functional" })
   public void testFileParser() throws Exception
   {
     for (String pdbStr : testFile)
     {
+      PDBfile mctest = new PDBfile(false, false, false, pdbStr,
+              AppletFormatAdapter.FILE);
       PDBFileWithJmol jtest = new PDBFileWithJmol(pdbStr,
               jalview.io.AppletFormatAdapter.FILE);
-      Vector<SequenceI> seqs = jtest.getSeqs();
+      Vector<SequenceI> seqs = jtest.getSeqs(), mcseqs = mctest.getSeqs();
 
       assertTrue(
               "No sequences extracted from testfile\n"
@@ -67,8 +89,11 @@ public class PDBFileWithJmolTest
                       && seqs.size() > 0);
       for (SequenceI sq : seqs)
       {
-        AlignmentI al = new Alignment(new SequenceI[]
-        { sq });
+        assertEquals("JMol didn't process " + pdbStr
+                + " to the same sequence as MCView",
+                sq.getSequenceAsString(), mcseqs.remove(0)
+                        .getSequenceAsString());
+        AlignmentI al = new Alignment(new SequenceI[] { sq });
         validateSecStrRows(al);
       }
     }
@@ -76,26 +101,36 @@ public class PDBFileWithJmolTest
 
   private void validateSecStrRows(AlignmentI al)
   {
-
     if (!al.isNucleotide())
     {
       for (SequenceI asq : al.getSequences())
       {
         SequenceI sq = asq;
-        while (sq.getDatasetSequence()!=null && sq.getAnnotation()==null)
+        boolean hasDs = false;
+        while (sq.getDatasetSequence() != null
+                && sq.getAnnotation() == null)
         {
-          sq = asq.getDatasetSequence();
+          sq = sq.getDatasetSequence();
+          hasDs = true;
+        }
+        checkFirstAAIsAssoc(sq);
+        if (hasDs)
+        {
+          // also verify if alignment sequence has annotation on it
+          // that is correctly mapped
+          checkFirstAAIsAssoc(asq);
         }
-        assertTrue(
-                "No secondary structure assigned for protein sequence.",
-                sq.getAnnotation() != null
-                        && sq.getAnnotation().length >= 1
-                        && sq.getAnnotation()[0].hasIcons);
-        assertTrue(
-                "Secondary structure not associated for sequence "
-                        + sq.getName(),
-                sq.getAnnotation()[0].sequenceRef == sq);
       }
     }
   }
+
+  private void checkFirstAAIsAssoc(SequenceI sq)
+  {
+    assertTrue("No secondary structure assigned for protein sequence.",
+            sq.getAnnotation() != null && sq.getAnnotation().length >= 1
+                    && sq.getAnnotation()[0].hasIcons);
+    assertTrue(
+            "Secondary structure not associated for sequence "
+                    + sq.getName(), sq.getAnnotation()[0].sequenceRef == sq);
+  }
 }