Patch for redundancy removal
[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                                 JobStatus js = null;
55                                 do {
56                                         try {
57                                                 Thread.sleep(500);
58                                         } catch (InterruptedException q) {
59                                         }
60                                         ;
61                                         js = msaservice.getJobStatus(jobid);
62                                 } while (!js.equals(JobStatus.FAILED)
63                                                 && !js.equals(JobStatus.CANCELLED)
64                                                 && !js.equals(JobStatus.FINISHED));
65                                 assertEquals("Trial alignment failed. State was " + js.name(),
66                                                 js, JobStatus.FINISHED);
67                                 assertEquals(
68                                                 "Mismatch in number of input and result sequences - assume alignment service wasn't interacted with correctly",
69                                                 msaservice.getResult(jobid).getSequences().size(),
70                                                 iseqs.size());
71                                 List<FastaSequence> seqList = msaservice.getResult(jobid).getSequences();
72                                 for(FastaSequence fSeq : seqList){
73                                         System.out.println(">"+fSeq.getId());
74                                         System.out.println(fSeq.getFormattedFasta());
75                                 }
76                         }
77
78                 }
79         }
80 }