JAL-3444 missed commit of removal of object creation test.
[jalview.git] / test / jalview / gui / AlignViewportTest.java
index 5ed0cac..3ba93bc 100644 (file)
@@ -23,6 +23,7 @@ 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;
 
@@ -33,8 +34,6 @@ import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
-import jalview.datamodel.PDBEntry;
-import jalview.datamodel.PDBEntry.Type;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.Sequence;
@@ -42,6 +41,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;
@@ -79,9 +79,7 @@ public class AlignViewportTest
     /*
      * remove any sequence mappings left lying around by other tests
      */
-    StructureSelectionManager ssm = StructureSelectionManager
-            .getStructureSelectionManager(Desktop.instance);
-    ssm.resetAll();
+    Desktop.getStructureSelectionManager().resetAll();
   }
 
   @BeforeMethod(alwaysRun = true)
@@ -127,9 +125,8 @@ public class AlignViewportTest
      * Verify that creating the alignment for the new View has registered the
      * mappings
      */
-    StructureSelectionManager ssm = StructureSelectionManager
-            .getStructureSelectionManager(Desktop.instance);
-    List<AlignedCodonFrame> sequenceMappings = ssm.getSequenceMappings();
+    List<AlignedCodonFrame> sequenceMappings = Desktop.getInstance()
+            .getStructureSelectionManager().getSequenceMappings();
     assertEquals(2, sequenceMappings.size());
     assertTrue(sequenceMappings.contains(acf1));
     assertTrue(sequenceMappings.contains(acf2));
@@ -150,10 +147,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);
+    StructureSelectionManager ssm = Desktop.getInstance()
+            .getStructureSelectionManager();
     ssm.resetAll();
 
     AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
@@ -213,10 +210,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);
+    StructureSelectionManager ssm = Desktop.getInstance()
+            .getStructureSelectionManager();
     ssm.resetAll();
 
     AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
@@ -277,22 +274,52 @@ 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) // BH removed 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(Preferences.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();
+    synchronized (this)
+    {
+      System.out.println("AVT consv: "
+              + viewport.getAlignmentConservationAnnotation());
+      try
+      {
+        wait(250); // BH increased from 50 -- was getting Quality in column 1
+                   // is null
+      } catch (InterruptedException e)
+      {
+      }
+      System.out.println("AVT consv: "
+              + viewport.getAlignmentConservationAnnotation());
+      while (viewport.getAlignmentConservationAnnotation() != null)
+      {
+        try
+        {
+          wait(250); // BH increased from 50 -- was getting Quality in column 1
+                     // is null
+        } catch (InterruptedException e)
+        {
+        }
+      }
+    }
+    af.paintImmediately(af.getBounds());
+    AlignmentAnnotation[] anns = viewport.getAlignment()
             .getAlignmentAnnotation();
     assertNotNull("No annotations found", anns);
     assertEquals("More than one annotation found", 1, anns.length);
@@ -310,15 +337,40 @@ 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();
-    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" })
@@ -406,7 +458,6 @@ public class AlignViewportTest
     {
       c++;
     }
-    ;
     Assert.assertEquals(c, 1, "Expected to find one occupancy row.");
   }
 
@@ -423,8 +474,21 @@ 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);
+    synchronized (this)
+    {
+    try
+    {
+        wait(50);
+    } catch (InterruptedException e)
+    {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+    }
+    }
+    // af.paintImmediately(af.getBounds());
     AlignViewport testme = af.getViewport();
     SequenceI cons = testme.getConsensusSeq();
+    System.out.println("AVT " + cons.getSequenceAsString());
     assertEquals("A-C", cons.getSequenceAsString());
   }