JAL-3690 Remove references to old AlignCalcManager.
[jalview.git] / test / jalview / gui / AlignViewportTest.java
index 6ab2622..f675f68 100644 (file)
@@ -23,10 +23,19 @@ package jalview.gui;
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertNotSame;
 import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.assertTrue;
 
 import jalview.api.AlignViewportI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
 import jalview.datamodel.AlignedCodonFrame;
@@ -41,6 +50,7 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
+import jalview.schemes.ClustalxColourScheme;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.PIDColourScheme;
 import jalview.structure.StructureSelectionManager;
@@ -48,14 +58,6 @@ import jalview.util.MapList;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.viewmodel.ViewportRanges;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
 public class AlignViewportTest
 {
 
@@ -73,14 +75,16 @@ public class AlignViewportTest
   @BeforeClass(alwaysRun = true)
   public static void setUpBeforeClass() throws Exception
   {
-    Jalview.main(new String[] { "-nonews", "-props",
+    Jalview.main(new String[] {
+        //"-jabaws", "none", 
+        "-nonews", "-props",
         "test/jalview/testProps.jvprops" });
 
     /*
      * remove any sequence mappings left lying around by other tests
      */
     StructureSelectionManager ssm = StructureSelectionManager
-            .getStructureSelectionManager(Desktop.instance);
+            .getStructureSelectionManager(Desktop.getInstance());
     ssm.resetAll();
   }
 
@@ -128,7 +132,7 @@ public class AlignViewportTest
      * mappings
      */
     StructureSelectionManager ssm = StructureSelectionManager
-            .getStructureSelectionManager(Desktop.instance);
+            .getStructureSelectionManager(Desktop.getInstance());
     List<AlignedCodonFrame> sequenceMappings = ssm.getSequenceMappings();
     assertEquals(2, sequenceMappings.size());
     assertTrue(sequenceMappings.contains(acf1));
@@ -150,10 +154,10 @@ public class AlignViewportTest
   @Test(groups = { "Functional" })
   public void testDeregisterMapping_withNoReference()
   {
-    Desktop d = Desktop.instance;
+    Desktop d = Desktop.getInstance();
     assertNotNull(d);
     StructureSelectionManager ssm = StructureSelectionManager
-            .getStructureSelectionManager(Desktop.instance);
+            .getStructureSelectionManager(Desktop.getInstance());
     ssm.resetAll();
 
     AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
@@ -213,10 +217,10 @@ public class AlignViewportTest
   @Test(groups = { "Functional" })
   public void testDeregisterMapping_withReference()
   {
-    Desktop d = Desktop.instance;
+    Desktop d = Desktop.getInstance();
     assertNotNull(d);
     StructureSelectionManager ssm = StructureSelectionManager
-            .getStructureSelectionManager(Desktop.instance);
+            .getStructureSelectionManager(Desktop.getInstance());
     ssm.resetAll();
 
     AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
@@ -277,22 +281,28 @@ public class AlignViewportTest
    * Test for JAL-1306 - conservation thread should run even when only Quality
    * (and not Conservation) is enabled in Preferences
    */
-  @Test(groups = { "Functional" })
+  @Test(groups = { "Functional" }, timeOut=2000)
   public void testUpdateConservation_qualityOnly()
   {
-    Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
+    Cache.setPropertyNoSave("SHOW_ANNOTATIONS",
             Boolean.TRUE.toString());
-    Cache.applicationProperties.setProperty("SHOW_QUALITY",
+    Cache.setPropertyNoSave("SHOW_QUALITY",
             Boolean.TRUE.toString());
-    Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
+    Cache.setPropertyNoSave("SHOW_CONSERVATION",
             Boolean.FALSE.toString());
-    Cache.applicationProperties.setProperty("SHOW_OCCUPANCY",
+    Cache.setPropertyNoSave("SHOW_OCCUPANCY",
             Boolean.FALSE.toString());
-    Cache.applicationProperties.setProperty("SHOW_IDENTITY",
+    Cache.setPropertyNoSave("SHOW_IDENTITY",
             Boolean.FALSE.toString());
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
             "examples/uniref50.fa", DataSourceType.FILE);
-    AlignmentAnnotation[] anns = af.viewport.getAlignment()
+
+    /*
+     * wait for Conservation thread to complete
+     */
+    AlignViewport viewport = af.getViewport();
+    waitForCalculations(viewport);
+    AlignmentAnnotation[] anns = viewport.getAlignment()
             .getAlignmentAnnotation();
     assertNotNull("No annotations found", anns);
     assertEquals("More than one annotation found", 1, anns.length);
@@ -304,21 +314,70 @@ public class AlignViewportTest
     assertTrue("No quality value in column 1", annotations[0].value > 10f);
   }
 
+  /**
+   * Wait for consensus etc calculation threads to complete
+   * 
+   * @param viewport
+   */
+  protected void waitForCalculations(AlignViewport viewport)
+  {
+    synchronized (this)
+    {
+      System.out.print("waiting...");
+      int n = 3;
+      while (--n >= 0 || viewport.getCalcManager().isWorking())
+      {
+        try
+        {
+          wait(50);
+        } catch (InterruptedException e)
+        {
+        }
+      }
+           System.out.println("...done");
+    }
+  }
+
   @Test(groups = { "Functional" })
   public void testSetGlobalColourScheme()
   {
     /*
      * test for JAL-2283: don't inadvertently turn on colour by conservation
      */
-    Cache.applicationProperties.setProperty("DEFAULT_COLOUR_PROT", "None");
-    Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
+    Cache.setPropertyNoSave("DEFAULT_COLOUR_PROT", "None");
+    Cache.setPropertyNoSave("SHOW_CONSERVATION",
             Boolean.TRUE.toString());
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
             "examples/uniref50.fa", DataSourceType.FILE);
     ColourSchemeI cs = new PIDColourScheme();
-    af.getViewport().setGlobalColourScheme(cs);
-    assertFalse(af.getViewport().getResidueShading()
+    AlignViewport viewport = af.getViewport();
+    viewport.setGlobalColourScheme(cs);
+    assertFalse(viewport.getResidueShading()
             .conservationApplied());
+
+    /*
+     * JAL-3201 groups have their own ColourSchemeI instances
+     */
+    AlignmentI aln = viewport.getAlignment();
+    SequenceGroup sg1 = new SequenceGroup();
+    sg1.addSequence(aln.getSequenceAt(0), false);
+    sg1.addSequence(aln.getSequenceAt(2), false);
+    SequenceGroup sg2 = new SequenceGroup();
+    sg2.addSequence(aln.getSequenceAt(1), false);
+    sg2.addSequence(aln.getSequenceAt(3), false);
+    aln.addGroup(sg1);
+    aln.addGroup(sg2);
+    viewport.setColourAppliesToAllGroups(true);
+    viewport.setGlobalColourScheme(new ClustalxColourScheme());
+    ColourSchemeI cs0 = viewport.getGlobalColourScheme();
+    ColourSchemeI cs1 = sg1.getColourScheme();
+    ColourSchemeI cs2 = sg2.getColourScheme();
+    assertTrue(cs0 instanceof ClustalxColourScheme);
+    assertTrue(cs1 instanceof ClustalxColourScheme);
+    assertTrue(cs2 instanceof ClustalxColourScheme);
+    assertNotSame(cs0, cs1);
+    assertNotSame(cs0, cs2);
+    assertNotSame(cs1, cs2);
   }
 
   @Test(groups = { "Functional" })
@@ -385,7 +444,8 @@ public class AlignViewportTest
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
             "examples/uniref50.fa", DataSourceType.FILE);
     AlignViewportI av = af.getViewport();
-    Assert.assertNull(av.getOccupancyAnnotation(), "Preference did not disable occupancy row.");
+    Assert.assertNull(av.getAlignmentGapAnnotation(),
+            "Preference did not disable occupancy row.");
     int c = 0;
     for (AlignmentAnnotation aa : av.getAlignment().findAnnotations(null,
             null, "Occupancy"))
@@ -399,10 +459,11 @@ public class AlignViewportTest
     af = new FileLoader().LoadFileWaitTillLoaded(
             "examples/uniref50.fa", DataSourceType.FILE);
     av = af.getViewport();
-    Assert.assertNotNull(av.getOccupancyAnnotation(), "Preference did not enable occupancy row.");
+    Assert.assertNotNull(av.getAlignmentGapAnnotation(),
+            "Preference did not enable occupancy row.");
     c = 0;
     for (AlignmentAnnotation aa : av.getAlignment().findAnnotations(null,
-            null, av.getOccupancyAnnotation().label))
+            null, av.getAlignmentGapAnnotation().label))
     {
       c++;
     }
@@ -423,9 +484,13 @@ public class AlignViewportTest
     String fasta = ">s1\nA-C\n>s2\nA-C\n>s3\nA-D\n>s4\n--D\n";
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(fasta,
             DataSourceType.PASTE);
-    AlignmentViewport testme = af.getViewport();
+    AlignViewport testme = af.getViewport();
+    waitForCalculations(testme);
     SequenceI cons = testme.getConsensusSeq();
-    assertEquals("A-C", cons.getSequenceAsString());
+    String s = cons.getSequenceAsString();
+    System.out.println("s is " + s);
+    
+    assertEquals("A-C", s);
   }
 
   @Test(groups = { "Functional" })