158b9aedc436d84d6c0d4c6fd46cd12391fd8135
[proteocache.git] / testsrc / compbio / ws / client / TestIUPredWS.java
1 package compbio.ws.client;
2
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertNotNull;
5 import static org.testng.Assert.fail;
6
7 import java.io.File;
8 import java.io.FileInputStream;
9 import java.io.FileNotFoundException;
10 import java.io.IOException;
11 import java.net.ConnectException;
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import javax.xml.ws.WebServiceException;
16
17 import org.testng.annotations.BeforeTest;
18 import org.testng.annotations.Test;
19
20 import compbio.data.msa.JABAService;
21 import compbio.data.msa.SequenceAnnotation;
22 import compbio.data.sequence.ConservationMethod;
23 import compbio.data.sequence.FastaSequence;
24 import compbio.data.sequence.ScoreManager;
25 import compbio.data.sequence.SequenceUtil;
26 import compbio.metadata.AllTestSuit;
27 import compbio.metadata.JobSubmissionException;
28 import compbio.metadata.LimitExceededException;
29 import compbio.metadata.Option;
30 import compbio.metadata.PresetManager;
31 import compbio.metadata.ResultNotAvailableException;
32 import compbio.metadata.RunnerConfig;
33 import compbio.metadata.UnsupportedRuntimeException;
34 import compbio.metadata.WrongParameterException;
35 import compbio.runner.conservation.AACon;
36 import compbio.util.SysPrefs;
37 import compbio.ws.server.IUPredWS;
38
39 public class TestIUPredWS {
40
41         SequenceAnnotation<IUPredWS> msaws;
42
43         @BeforeTest(groups = {AllTestSuit.test_group_webservices})
44         void initConnection() {
45                 /*
46                  * URL url = null; try { url = new
47                  * URL("http://localhost:8080/jabaws/AAConWS?wsdl"); } catch
48                  * (MalformedURLException e) { e.printStackTrace();
49                  * fail(e.getLocalizedMessage()); } String namespace =
50                  * "http://msa.data.compbio/01/12/2010/"; QName qname = new
51                  * QName(namespace, "AAConWS"); Service serv = Service.create(url,
52                  * qname); msaws = serv.getPort(new QName(namespace, "AAConWSPort"),
53                  * Annotation.class);
54                  */try {
55                         JABAService client = Jws2Client.connect(
56                                         "http://localhost:8080/jabaws", Services.IUPredWS);
57                         msaws = (SequenceAnnotation<IUPredWS>) client;
58                 } catch (ConnectException e) {
59                         e.printStackTrace();
60                         fail(e.getMessage());
61                 } catch (WebServiceException e) {
62                         e.printStackTrace();
63                         fail(e.getMessage());
64                 }
65         }
66
67         @Test(groups = {AllTestSuit.test_group_webservices})
68         public void testCustomAnalize() throws FileNotFoundException, IOException {
69
70                 String CURRENT_DIRECTORY = SysPrefs.getCurrentDirectory()
71                                 + File.separator;
72
73                 List<FastaSequence> fsl = SequenceUtil.readFasta(new FileInputStream(
74                                 CURRENT_DIRECTORY + "testsrc" + File.separator + "testdata"
75                                                 + File.separator + "TO1381.fasta"));
76
77                 try {
78                         List<Option<IUPredWS>> opts=new ArrayList<Option<IUPredWS>>();
79                         opts.add(msaws.getRunnerOptions().getArgumentByOptionName("Long"));
80                         String jobId = msaws.customAnalize(fsl,opts);
81                         System.out.println("J: " + jobId);
82                         ScoreManager result = msaws.getAnnotation(jobId);
83                         assertNotNull(result);
84 //                      assertEquals(result.asSet().size(), 1);
85
86                 } catch (UnsupportedRuntimeException e) {
87                         e.printStackTrace();
88                         fail(e.getMessage());
89                 } catch (LimitExceededException e) {
90                         e.printStackTrace();
91                         fail(e.getMessage());
92                 } catch (JobSubmissionException e) {
93                         e.printStackTrace();
94                         fail(e.getMessage());
95                 } catch (ResultNotAvailableException e) {
96                         e.printStackTrace();
97                         fail(e.getMessage());
98                 } catch (WrongParameterException e) {
99                         e.printStackTrace();
100                         fail(e.getMessage());
101                 }
102
103         }
104 }