formatting
authorJim Procter <jprocter@compbio.dundee.ac.uk>
Wed, 25 Sep 2013 15:34:55 +0000 (16:34 +0100)
committerJim Procter <jprocter@compbio.dundee.ac.uk>
Wed, 25 Sep 2013 15:34:55 +0000 (16:34 +0100)
test/jalview/ws/jabaws/RNAStructExportImport.java

index 4e407af..a2c361b 100644 (file)
@@ -2,28 +2,38 @@ package jalview.ws.jabaws;
 
 import static org.junit.Assert.*;
 
+import java.awt.Component;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Vector;
 
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+
 import jalview.api.AlignCalcManagerI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
+import jalview.gui.Jalview2XML;
 import jalview.io.AnnotationFile;
 import jalview.io.FormatAdapter;
 import jalview.io.StockholmFileTest;
 import jalview.ws.jws2.AADisorderClient;
 import jalview.ws.jws2.Jws2Discoverer;
 import jalview.ws.jws2.RNAalifoldClient;
+import jalview.ws.jws2.SequenceAnnotationWSClient;
+import jalview.ws.jws2.dm.JabaOption;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.params.AutoCalcSetting;
 
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-public class RNAStructExportImport 
+import compbio.metadata.WrongParameterException;
+
+public class RNAStructExportImport
 {
   public static String testseqs = "examples/unfolded_RF00031.aln";
 
@@ -150,4 +160,77 @@ public class RNAStructExportImport
             + "\nCouldn't complete Annotation file roundtrip input/output/input test.");
   }
 
+  @Test
+  public void testRnaalifoldSettingsRecovery()
+  {
+    List<compbio.metadata.Argument> opts = new ArrayList<compbio.metadata.Argument>();
+    for (compbio.metadata.Argument rg : (List<compbio.metadata.Argument>) rnaalifoldws
+            .getRunnerConfig().getArguments())
+    {
+      if (rg.getDescription().contains("emperature"))
+      {
+        try
+        {
+          rg.setValue("292");
+        } catch (WrongParameterException q)
+        {
+          fail("Couldn't set the temperature parameter "
+                  + q.getStackTrace());
+        }
+        opts.add(rg);
+      }
+      if (rg.getDescription().contains("max"))
+      {
+        opts.add(rg);
+      }
+    }
+    alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, opts);
+    
+    af.getViewport().getCalcManager().startWorker(alifoldClient);
+    
+    do
+    {
+      try
+      {
+        Thread.sleep(50);
+      } catch (InterruptedException x)
+      {
+      }
+      ;
+    } while (af.getViewport().getCalcManager().isWorking());
+    AutoCalcSetting oldacs = af.getViewport().getCalcIdSettingsFor(alifoldClient.getCalcId());
+    String oldsettings = oldacs.getWsParamFile();
+    // write out parameters
+    jalview.gui.AlignFrame nalf=null;
+    assertTrue("Couldn't write out the Jar file",new Jalview2XML(false).SaveAlignment(af, "testRnalifold_param.jar","trial parameter writeout"));
+    assertTrue("Couldn't read back the Jar file",(nalf = new Jalview2XML(false).LoadJalviewAlign("testRnalifold_param.jar"))!=null);
+    if (nalf!=null)
+    {
+      AutoCalcSetting acs = af.getViewport().getCalcIdSettingsFor(alifoldClient.getCalcId());
+      assertTrue("Calc ID settings not recovered from viewport stash", acs.equals(oldacs));
+      assertTrue("Serialised Calc ID settings not identical to those recovered from viewport stash", acs.getWsParamFile().equals(oldsettings));
+      JMenu nmenu=new JMenu();
+      new SequenceAnnotationWSClient().attachWSMenuEntry(nmenu, rnaalifoldws, af);
+      assertTrue("Couldn't get menu entry for service",nmenu.getItemCount()>0);
+      for (Component itm: nmenu.getMenuComponents())
+      {
+        if (itm instanceof JMenuItem)
+        {
+          JMenuItem i = (JMenuItem) itm;
+          if (i.getText().equals(rnaalifoldws.getAlignAnalysisUI().getAAconToggle()))
+                  {
+            i.doClick();
+            break;
+                  }
+        }
+      }
+      while (af.getViewport().isCalcInProgress())
+      {
+        try { Thread.sleep(200);
+        } catch (Exception x) {};
+      }
+      AutoCalcSetting acs2 = af.getViewport().getCalcIdSettingsFor(alifoldClient.getCalcId());
+      assertTrue("Calc ID settings after recalculation has not been recovered.", acs2.getWsParamFile().equals(oldsettings));
+    }
+  }
 }