0a50e473a8ab0d84e697dcfc0ca505757ae01001
[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
27         public void msaTest() throws Exception {
28                 String url;
29                 RegistryWS registry = Jws2Client
30                                 .connectToRegistry(url = "http://www.compbio.dundee.ac.uk/jabaws");
31                 if (registry != null) {
32
33                         MsaWS msaservice = null;
34                         for (Services service : registry.getSupportedServices()) {
35                                 if (service.equals(Services.ClustalOWS)) {
36                                         msaservice = (MsaWS) Jws2Client.connect(url, service);
37                                         if (msaservice != null) {
38                                                 break;
39                                         }
40                                 }
41                         }
42                         if (msaservice == null) {
43                                 Assert.fail("couldn't find a clustalO service on the public registry");
44                         }
45                         FastaSequence fsq = new FastaSequence("seqA",
46                                         "SESESESESESESESSESESSESESESESESESESESESEEEEEESSESESESESSSSESESESESESESE");
47                         List<FastaSequence> iseqs = new ArrayList<FastaSequence>();
48                         for (int i = 0; i < 9; i++) {
49                                 iseqs.add(new FastaSequence(fsq.getId() + i, fsq.getSequence()
50                                                 + fsq.getSequence().substring(i + 3, i + 3 + i)));
51                         }
52
53                         String jobid = msaservice.align(iseqs);
54       if (jobid != null)
55       {
56         JobStatus js = null;
57         do
58         {
59           try
60           {
61             Thread.sleep(500);
62           } catch (InterruptedException q)
63           {
64           }
65           ;
66           js = msaservice.getJobStatus(jobid);
67         } while (!js.equals(JobStatus.FAILED)
68                 && !js.equals(JobStatus.CANCELLED)
69                 && !js.equals(JobStatus.FINISHED));
70         assertEquals("Trial alignment failed. State was " + js.name(), js,
71                 JobStatus.FINISHED);
72         assertEquals(
73                 "Mismatch in number of input and result sequences - assume alignment service wasn't interacted with correctly",
74                 msaservice.getResult(jobid).getSequences().size(),
75                 iseqs.size());
76         for (FastaSequence t : msaservice.getResult(jobid).getSequences())
77         {
78           System.out.println(">" + t.getId());
79           System.out.println(t.getFormattedFasta());
80         }
81         // .forEach(new Consumer<FastaSequence>() {
82         // @Override
83         // public void accept(FastaSequence t) {
84         // System.out.println(">"+t.getId());
85         // System.out.println(t.getFormattedFasta());
86         // }
87         // });
88                         }
89
90                 }
91         }
92 }