JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / test / jalview / ws / jabaws / MinJabawsClientTests.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.ws.jabaws;
22
23 import static org.testng.AssertJUnit.assertEquals;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import org.testng.Assert;
29 import org.testng.annotations.Test;
30
31 import compbio.data.msa.MsaWS;
32 import compbio.data.msa.RegistryWS;
33 import compbio.data.sequence.FastaSequence;
34 import compbio.metadata.JobStatus;
35 import compbio.ws.client.Jws2Client;
36 import compbio.ws.client.Services;
37
38 public class MinJabawsClientTests
39 {
40
41   /**
42    * simple test for the benefit of JAL-1338
43    * 
44    * @throws Exception
45    */
46   @SuppressWarnings("rawtypes")
47   @Test(groups = { "Network" })
48   public void msaTest() throws Exception
49   {
50     String url;
51     RegistryWS registry = Jws2Client
52             .connectToRegistry(url = "http://www.compbio.dundee.ac.uk/jabaws");
53     if (registry != null)
54     {
55
56       MsaWS msaservice = null;
57       for (Services service : registry.getSupportedServices())
58       {
59         if (service.equals(Services.ClustalOWS))
60         {
61           msaservice = (MsaWS) Jws2Client.connect(url, service);
62           if (msaservice != null)
63           {
64             break;
65           }
66         }
67       }
68       if (msaservice == null)
69       {
70         Assert.fail("couldn't find a clustalO service on the public registry");
71       }
72       FastaSequence fsq = new FastaSequence("seqA",
73               "SESESESESESESESSESESSESESESESESESESESESEEEEEESSESESESESSSSESESESESESESE");
74       List<FastaSequence> iseqs = new ArrayList<FastaSequence>();
75       for (int i = 0; i < 9; i++)
76       {
77         iseqs.add(new FastaSequence(fsq.getId() + i, fsq.getSequence()
78                 + fsq.getSequence().substring(i + 3, i + 3 + i)));
79       }
80
81       String jobid = msaservice.align(iseqs);
82       if (jobid != null)
83       {
84         JobStatus js = null;
85         do
86         {
87           try
88           {
89             Thread.sleep(500);
90           } catch (InterruptedException q)
91           {
92           }
93           ;
94           js = msaservice.getJobStatus(jobid);
95         } while (!js.equals(JobStatus.FAILED)
96                 && !js.equals(JobStatus.CANCELLED)
97                 && !js.equals(JobStatus.FINISHED));
98         assertEquals("Trial alignment failed. State was " + js.name(), js,
99                 JobStatus.FINISHED);
100         assertEquals(
101                 "Mismatch in number of input and result sequences - assume alignment service wasn't interacted with correctly",
102                 msaservice.getResult(jobid).getSequences().size(),
103                 iseqs.size());
104         for (FastaSequence t : msaservice.getResult(jobid).getSequences())
105         {
106           System.out.println(">" + t.getId());
107           System.out.println(t.getFormattedFasta());
108         }
109         // .forEach(new Consumer<FastaSequence>() {
110         // @Override
111         // public void accept(FastaSequence t) {
112         // System.out.println(">"+t.getId());
113         // System.out.println(t.getFormattedFasta());
114         // }
115         // });
116       }
117
118     }
119   }
120 }