Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / test / jalview / gui / AlignViewportTest.java
index b3c6b2a..db41f3e 100644 (file)
@@ -27,6 +27,7 @@ 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;
 
@@ -54,6 +55,7 @@ import jalview.schemes.ColourSchemeI;
 import jalview.schemes.PIDColourScheme;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.MapList;
+import jalview.viewmodel.AlignmentViewport;
 import jalview.viewmodel.ViewportRanges;
 
 public class AlignViewportTest
@@ -68,7 +70,7 @@ public class AlignViewportTest
 
   AlignmentI al;
 
-  AlignViewport testee;
+  AlignmentViewport testee;
 
   @BeforeClass(alwaysRun = true)
   public static void setUpBeforeClass() throws Exception
@@ -81,7 +83,7 @@ public class AlignViewportTest
      * remove any sequence mappings left lying around by other tests
      */
     StructureSelectionManager ssm = StructureSelectionManager
-            .getStructureSelectionManager(Desktop.instance);
+            .getStructureSelectionManager(Desktop.getInstance());
     ssm.resetAll();
   }
 
@@ -107,18 +109,16 @@ public class AlignViewportTest
     /*
      * alignment with reference to mappings
      */
-    AlignFrame af1 = new FileLoader()
-            .LoadFileWaitTillLoaded(">Seq1\nCAGT\n", DataSourceType.PASTE);
+    AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
+            ">Seq1\nCAGT\n", DataSourceType.PASTE);
 
     SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
     AlignedCodonFrame acf1 = new AlignedCodonFrame();
-    acf1.addMap(s1, s1,
-            new MapList(new int[]
-            { 1, 4 }, new int[] { 1, 4 }, 1, 1));
+    acf1.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 1, 4 },
+            1, 1));
     AlignedCodonFrame acf2 = new AlignedCodonFrame();
-    acf2.addMap(s1, s1,
-            new MapList(new int[]
-            { 1, 4 }, new int[] { 4, 1 }, 1, 1));
+    acf2.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 4, 1 },
+            1, 1));
 
     List<AlignedCodonFrame> mappings = new ArrayList<>();
     mappings.add(acf1);
@@ -131,7 +131,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));
@@ -153,33 +153,30 @@ 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(">Seq1\nRSVQ\n", DataSourceType.PASTE);
-    AlignFrame af2 = new FileLoader()
-            .LoadFileWaitTillLoaded(">Seq2\nDGEL\n", DataSourceType.PASTE);
+    AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
+            ">Seq1\nRSVQ\n", DataSourceType.PASTE);
+    AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
+            ">Seq2\nDGEL\n", DataSourceType.PASTE);
     SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA");
     SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA");
     SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
     SequenceI s2 = af2.getViewport().getAlignment().getSequenceAt(0);
     // need to be distinct
     AlignedCodonFrame acf1 = new AlignedCodonFrame();
-    acf1.addMap(cs1, s1,
-            new MapList(new int[]
-            { 1, 4 }, new int[] { 1, 12 }, 1, 3));
+    acf1.addMap(cs1, s1, new MapList(new int[] { 1, 4 },
+            new int[] { 1, 12 }, 1, 3));
     AlignedCodonFrame acf2 = new AlignedCodonFrame();
-    acf2.addMap(cs2, s2,
-            new MapList(new int[]
-            { 1, 4 }, new int[] { 1, 12 }, 1, 3));
+    acf2.addMap(cs2, s2, new MapList(new int[] { 1, 4 },
+            new int[] { 1, 12 }, 1, 3));
     AlignedCodonFrame acf3 = new AlignedCodonFrame();
-    acf3.addMap(cs2, cs2,
-            new MapList(new int[]
-            { 1, 12 }, new int[] { 1, 12 }, 1, 1));
+    acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
+        12 }, 1, 1));
 
     List<AlignedCodonFrame> mappings1 = new ArrayList<>();
     mappings1.add(acf1);
@@ -219,33 +216,30 @@ 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(">Seq1\nRSVQ\n", DataSourceType.PASTE);
-    AlignFrame af2 = new FileLoader()
-            .LoadFileWaitTillLoaded(">Seq2\nDGEL\n", DataSourceType.PASTE);
+    AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
+            ">Seq1\nRSVQ\n", DataSourceType.PASTE);
+    AlignFrame af2 = new FileLoader().LoadFileWaitTillLoaded(
+            ">Seq2\nDGEL\n", DataSourceType.PASTE);
     SequenceI cs1 = new Sequence("cseq1", "CCCGGGTTTAAA");
     SequenceI cs2 = new Sequence("cseq2", "CTTGAGTCTAGA");
     SequenceI s1 = af1.getViewport().getAlignment().getSequenceAt(0);
     SequenceI s2 = af2.getViewport().getAlignment().getSequenceAt(0);
     // need to be distinct
     AlignedCodonFrame acf1 = new AlignedCodonFrame();
-    acf1.addMap(cs1, s1,
-            new MapList(new int[]
-            { 1, 4 }, new int[] { 1, 12 }, 1, 3));
+    acf1.addMap(cs1, s1, new MapList(new int[] { 1, 4 },
+            new int[] { 1, 12 }, 1, 3));
     AlignedCodonFrame acf2 = new AlignedCodonFrame();
-    acf2.addMap(cs2, s2,
-            new MapList(new int[]
-            { 1, 4 }, new int[] { 1, 12 }, 1, 3));
+    acf2.addMap(cs2, s2, new MapList(new int[] { 1, 4 },
+            new int[] { 1, 12 }, 1, 3));
     AlignedCodonFrame acf3 = new AlignedCodonFrame();
-    acf3.addMap(cs2, cs2,
-            new MapList(new int[]
-            { 1, 12 }, new int[] { 1, 12 }, 1, 1));
+    acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
+        12 }, 1, 1));
 
     List<AlignedCodonFrame> mappings1 = new ArrayList<>();
     mappings1.add(acf1);
@@ -286,18 +280,18 @@ 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" }, timeOut = 2000)
+  @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);
@@ -328,7 +322,9 @@ public class AlignViewportTest
   {
     synchronized (this)
     {
-      do
+      System.out.print("waiting...");
+      int n = 3;
+      while (--n >= 0 || viewport.getCalcManager().isWorking())
       {
         try
         {
@@ -336,7 +332,8 @@ public class AlignViewportTest
         } catch (InterruptedException e)
         {
         }
-      } while (viewport.getCalcManager().isWorking());
+      }
+           System.out.println("...done");
     }
   }
 
@@ -346,15 +343,16 @@ public class AlignViewportTest
     /*
      * 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();
     AlignViewport viewport = af.getViewport();
     viewport.setGlobalColourScheme(cs);
-    assertFalse(viewport.getResidueShading().conservationApplied());
+    assertFalse(viewport.getResidueShading()
+            .conservationApplied());
 
     /*
      * JAL-3201 groups have their own ColourSchemeI instances
@@ -415,7 +413,7 @@ public class AlignViewportTest
   {
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
             "examples/uniref50.fa", DataSourceType.FILE);
-    AlignViewport av = af.getViewport();
+    AlignViewportI av = af.getViewport();
     SequenceGroup sg1 = new SequenceGroup();
     SequenceGroup sg2 = new SequenceGroup();
     SequenceGroup sg3 = new SequenceGroup();
@@ -434,20 +432,17 @@ public class AlignViewportTest
     av.setSelectionGroup(sg3);
     assertTrue(sg3.isDefined()); // unchanged
   }
-
   /**
-   * Verify that setting/clearing SHOW_OCCUPANCY preference adds or omits
-   * occupancy row from viewport
+   * Verify that setting/clearing SHOW_OCCUPANCY preference adds or omits occupancy row from viewport
    */
   @Test(groups = { "Functional" })
   public void testShowOrDontShowOccupancy()
   {
     // disable occupancy
-    jalview.bin.Cache.setProperty("SHOW_OCCUPANCY",
-            Boolean.FALSE.toString());
+    jalview.bin.Cache.setProperty("SHOW_OCCUPANCY", Boolean.FALSE.toString());
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
             "examples/uniref50.fa", DataSourceType.FILE);
-    AlignViewport av = af.getViewport();
+    AlignViewportI av = af.getViewport();
     Assert.assertNull(av.getAlignmentGapAnnotation(),
             "Preference did not disable occupancy row.");
     int c = 0;
@@ -457,12 +452,11 @@ public class AlignViewportTest
       c++;
     }
     Assert.assertEquals(c, 0, "Expected zero occupancy rows.");
-
+    
     // enable occupancy
-    jalview.bin.Cache.setProperty("SHOW_OCCUPANCY",
-            Boolean.TRUE.toString());
-    af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa",
-            DataSourceType.FILE);
+    jalview.bin.Cache.setProperty("SHOW_OCCUPANCY", Boolean.TRUE.toString());
+    af = new FileLoader().LoadFileWaitTillLoaded(
+            "examples/uniref50.fa", DataSourceType.FILE);
     av = af.getViewport();
     Assert.assertNotNull(av.getAlignmentGapAnnotation(),
             "Preference did not enable occupancy row.");