From 7ce2e1f63202ad3707219707ff4264fe7b47e40d Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 3 Oct 2019 17:53:46 +0100 Subject: [PATCH] JAL-3070 test jabaws and slivka AACon service functionality --- .../jalview/ws/jabaws/AAConAnnotAndSettingsIO.java | 118 ++++++++++---------- 1 file changed, 58 insertions(+), 60 deletions(-) diff --git a/test/jalview/ws/jabaws/AAConAnnotAndSettingsIO.java b/test/jalview/ws/jabaws/AAConAnnotAndSettingsIO.java index fae8b21..02d0d82 100644 --- a/test/jalview/ws/jabaws/AAConAnnotAndSettingsIO.java +++ b/test/jalview/ws/jabaws/AAConAnnotAndSettingsIO.java @@ -28,21 +28,17 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.gui.AlignFrame; import jalview.gui.JvOptionPane; -import jalview.io.AnnotationFile; -import jalview.io.DataSourceType; -import jalview.io.FileFormat; -import jalview.io.FormatAdapter; -import jalview.io.StockholmFileTest; import jalview.ws.api.ServiceWithParameters; import jalview.ws.jws2.Jws2Discoverer; import jalview.ws.jws2.SeqAnnotationServiceCalcWorker; +import jalview.ws.slivkaws.SlivkaWSDiscoverer; import java.util.ArrayList; import java.util.List; -import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /* @@ -50,7 +46,7 @@ import org.testng.annotations.Test; * if there is no network. */ @Test(singleThreaded = true) -public class DisorderAnnotExportImport +public class AAConAnnotAndSettingsIO { @BeforeClass(alwaysRun = true) @@ -64,7 +60,7 @@ public class DisorderAnnotExportImport public static Jws2Discoverer disc; - public static List aacon; + public static List aacon; jalview.ws.jws2.SeqAnnotationServiceCalcWorker aaconClient; @@ -83,19 +79,25 @@ public class DisorderAnnotExportImport Thread.sleep(100); } + aacon = new ArrayList<>(); for (ServiceWithParameters svc : disc.getServices()) { if (svc.getNameURI().toLowerCase().contains("aacon")) { - aacon.add(svc); + aacon.add(new ServiceWithParameters[] { svc }); + } + } + + for (ServiceWithParameters svc : SlivkaWSDiscoverer.getServices()) + { + if (svc.getNameURI().toLowerCase().contains("aacon")) + { + aacon.add(new ServiceWithParameters[] { svc }); } } assertTrue("Couldn't discover any AACon services to use to test.", aacon.size() > 0); - jalview.io.FileLoader fl = new jalview.io.FileLoader(false); - af = fl.LoadFileWaitTillLoaded(testseqs, jalview.io.DataSourceType.FILE); - assertNotNull("Couldn't load test data ('" + testseqs + "')", af); } @AfterClass(alwaysRun = true) @@ -109,21 +111,58 @@ public class DisorderAnnotExportImport } } + @DataProvider(name = "aacons") + public Object[][] getAaconArray() + { + + Object[][] rtn = new Object[aacon.size()][1]; + int i = 0; + for (ServiceWithParameters[] aa : aacon) + { + rtn[i++] = aa; + } + return rtn; + } /** * Run AACon on an alignment with defaults and verify Just Shenkin annotation * appears */ - @Test(groups = { "External", "Network" }) - public void testAAConAnnotAndRecovery() + @Test(groups = { "External", "Network" }, dataProvider = "aacons") + public void testAAConAnnotAndRecovery(ServiceWithParameters service) { - testAAConClient(af, aacon.get(0)); + jalview.io.FileLoader fl = new jalview.io.FileLoader(false); + AlignFrame _af = fl.LoadFileWaitTillLoaded(testseqs, + jalview.io.DataSourceType.FILE); + assertNotNull("Couldn't load test data ('" + testseqs + "')", _af); + af = _af; + try + { + testAAConClient(_af, service); + } finally + { + af = null; + _af.setVisible(false); + _af.dispose(); + _af = null; + + } } + /** + * triggers the given aacon worker on the alignment, waits for 5s and gives up + * or verifies SHENKIN annotation is produced. + * + * @param af + * - test data in an alignment frame + * @param aacon + * - the service to test + */ static void testAAConClient(AlignFrame af, ServiceWithParameters aacon) { SeqAnnotationServiceCalcWorker aaconClient = new SeqAnnotationServiceCalcWorker( aacon, af, null, null); + long current = System.currentTimeMillis(), limit = 5; af.getViewport().getCalcManager().startWorker(aaconClient); do { @@ -134,6 +173,10 @@ public class DisorderAnnotExportImport { } ; + assertTrue( + "Waited " + limit + "s for " + aacon.getHostURL() + + " - giving up.", + (System.currentTimeMillis() - current) < limit * 1000); } while (af.getViewport().getCalcManager().isWorking()); AlignmentI orig_alig = af.getViewport().getAlignment(); boolean foundShenkin = false; @@ -150,49 +193,4 @@ public class DisorderAnnotExportImport } assertTrue("Failed to locate 'SHENKIN' annotation row.", foundShenkin); } - - static void checkAnnotationFileIO(String testname, AlignmentI al) - { - try - { - String aligfileout = FileFormat.Pfam.getWriter(al).print( - al.getSequencesArray(), true); - String anfileout = new AnnotationFile() - .printAnnotationsForAlignment(al); - assertTrue( - "Test " - + testname - + "\nAlignment annotation file was not regenerated. Null string", - anfileout != null); - assertTrue( - "Test " - + testname - + "\nAlignment annotation file was not regenerated. Empty string", - anfileout.length() > "JALVIEW_ANNOTATION".length()); - - System.out.println("Output annotation file:\n" + anfileout - + "\n<