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