6af831fecee531f91b431eba73c818c80b1db5fd
[jalview.git] / test / jalview / ws / jabaws / MinJabawsClientTests.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ 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 jalview.gui.JvOptionPane;
26
27 import java.util.ArrayList;
28 import java.util.List;
29
30 import org.testng.Assert;
31 import org.testng.annotations.BeforeClass;
32 import org.testng.annotations.Test;
33
34 import compbio.data.msa.MsaWS;
35 import compbio.data.msa.RegistryWS;
36 import compbio.data.sequence.FastaSequence;
37 import compbio.metadata.JobStatus;
38 import compbio.ws.client.Jws2Client;
39 import compbio.ws.client.Services;
40
41 public class MinJabawsClientTests
42 {
43
44   @BeforeClass(alwaysRun = true)
45   public void setUpJvOptionPane()
46   {
47     JvOptionPane.setInteractiveMode(false);
48     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
49   }
50
51   /**
52    * simple test for the benefit of JAL-1338
53    * 
54    * @throws Exception
55    */
56   @SuppressWarnings("rawtypes")
57   @Test(groups = { "Network" })
58   public void msaTest() throws Exception
59   {
60     String url;
61     RegistryWS registry = Jws2Client
62             .connectToRegistry(url = "http://www.compbio.dundee.ac.uk/jabaws");
63     if (registry != null)
64     {
65
66       MsaWS msaservice = null;
67       for (Services service : registry.getSupportedServices())
68       {
69         if (service == null)
70         {
71           // the 'unsupported service'
72           continue;
73         }
74         if (service.equals(Services.ClustalOWS))
75         {
76           msaservice = (MsaWS) Jws2Client.connect(url, service);
77           if (msaservice != null)
78           {
79             break;
80           }
81         }
82       }
83       if (msaservice == null)
84       {
85         Assert.fail("couldn't find a clustalO service on the public registry");
86       }
87       FastaSequence fsq = new FastaSequence("seqA",
88               "SESESESESESESESSESESSESESESESESESESESESEEEEEESSESESESESSSSESESESESESESE");
89       List<FastaSequence> iseqs = new ArrayList<FastaSequence>();
90       for (int i = 0; i < 9; i++)
91       {
92         iseqs.add(new FastaSequence(fsq.getId() + i, fsq.getSequence()
93                 + fsq.getSequence().substring(i + 3, i + 3 + i)));
94       }
95
96       String jobid = msaservice.align(iseqs);
97       if (jobid != null)
98       {
99         JobStatus js = null;
100         do
101         {
102           try
103           {
104             Thread.sleep(500);
105           } catch (InterruptedException q)
106           {
107           }
108           ;
109           js = msaservice.getJobStatus(jobid);
110         } while (!js.equals(JobStatus.FAILED)
111                 && !js.equals(JobStatus.CANCELLED)
112                 && !js.equals(JobStatus.FINISHED));
113         assertEquals("Trial alignment failed. State was " + js.name(), js,
114                 JobStatus.FINISHED);
115         assertEquals(
116                 "Mismatch in number of input and result sequences - assume alignment service wasn't interacted with correctly",
117                 msaservice.getResult(jobid).getSequences().size(),
118                 iseqs.size());
119         for (FastaSequence t : msaservice.getResult(jobid).getSequences())
120         {
121           System.out.println(">" + t.getId());
122           System.out.println(t.getFormattedFasta());
123         }
124         // .forEach(new Consumer<FastaSequence>() {
125         // @Override
126         // public void accept(FastaSequence t) {
127         // System.out.println(">"+t.getId());
128         // System.out.println(t.getFormattedFasta());
129         // }
130         // });
131       }
132
133     }
134   }
135 }