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