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