JAL-1759 merge from develop
[jalview.git] / test / jalview / ws / jabaws / MinJabawsClientTests.java
1 package jalview.ws.jabaws;
2
3 import static org.testng.AssertJUnit.assertEquals;
4
5 import java.util.ArrayList;
6 import java.util.List;
7
8 import org.testng.Assert;
9 import org.testng.annotations.Test;
10
11 import compbio.data.msa.MsaWS;
12 import compbio.data.msa.RegistryWS;
13 import compbio.data.sequence.FastaSequence;
14 import compbio.metadata.JobStatus;
15 import compbio.ws.client.Jws2Client;
16 import compbio.ws.client.Services;
17
18 public class MinJabawsClientTests
19 {
20
21         /**
22          * simple test for the benefit of JAL-1338
23          * @throws Exception
24          */
25         @SuppressWarnings("rawtypes")
26   @Test(groups =
27   { "Network" })
28         public void msaTest() throws Exception {
29                 String url;
30                 RegistryWS registry = Jws2Client
31                                 .connectToRegistry(url = "http://www.compbio.dundee.ac.uk/jabaws");
32                 if (registry != null) {
33
34                         MsaWS msaservice = null;
35                         for (Services service : registry.getSupportedServices()) {
36                                 if (service.equals(Services.ClustalOWS)) {
37                                         msaservice = (MsaWS) Jws2Client.connect(url, service);
38                                         if (msaservice != null) {
39                                                 break;
40                                         }
41                                 }
42                         }
43                         if (msaservice == null) {
44                                 Assert.fail("couldn't find a clustalO service on the public registry");
45                         }
46                         FastaSequence fsq = new FastaSequence("seqA",
47                                         "SESESESESESESESSESESSESESESESESESESESESEEEEEESSESESESESSSSESESESESESESE");
48                         List<FastaSequence> iseqs = new ArrayList<FastaSequence>();
49                         for (int i = 0; i < 9; i++) {
50                                 iseqs.add(new FastaSequence(fsq.getId() + i, fsq.getSequence()
51                                                 + fsq.getSequence().substring(i + 3, i + 3 + i)));
52                         }
53
54                         String jobid = msaservice.align(iseqs);
55       if (jobid != null)
56       {
57         JobStatus js = null;
58         do
59         {
60           try
61           {
62             Thread.sleep(500);
63           } catch (InterruptedException q)
64           {
65           }
66           ;
67           js = msaservice.getJobStatus(jobid);
68         } while (!js.equals(JobStatus.FAILED)
69                 && !js.equals(JobStatus.CANCELLED)
70                 && !js.equals(JobStatus.FINISHED));
71         assertEquals("Trial alignment failed. State was " + js.name(), js,
72                 JobStatus.FINISHED);
73         assertEquals(
74                 "Mismatch in number of input and result sequences - assume alignment service wasn't interacted with correctly",
75                 msaservice.getResult(jobid).getSequences().size(),
76                 iseqs.size());
77         for (FastaSequence t : msaservice.getResult(jobid).getSequences())
78         {
79           System.out.println(">" + t.getId());
80           System.out.println(t.getFormattedFasta());
81         }
82         // .forEach(new Consumer<FastaSequence>() {
83         // @Override
84         // public void accept(FastaSequence t) {
85         // System.out.println(">"+t.getId());
86         // System.out.println(t.getFormattedFasta());
87         // }
88         // });
89                         }
90
91                 }
92         }
93 }