83f9cd787c824b235d9e03b4ab0a9778397607b7
[jabaws.git] / testsrc / compbio / test / CategoryTester.java
1 package compbio.test;\r
2 \r
3 import java.net.ConnectException;\r
4 import java.util.Set;\r
5 \r
6 import javax.xml.ws.WebServiceException;\r
7 \r
8 import org.testng.Assert;\r
9 import org.testng.annotations.BeforeTest;\r
10 import org.testng.annotations.Test;\r
11 \r
12 import compbio.data.msa.Category;\r
13 import compbio.data.msa.RegistryWS;\r
14 import compbio.metadata.AllTestSuit;\r
15 import compbio.ws.client.Jws2Client;\r
16 import compbio.ws.client.Services;\r
17 import compbio.ws.client.WSTesterTester;\r
18 \r
19 public class CategoryTester {\r
20 \r
21         // test category membership from string constants\r
22         RegistryWS registry = null;\r
23 \r
24         @BeforeTest(groups = AllTestSuit.test_group_webservices)\r
25         public void setupTest() {\r
26                 try {\r
27                         /*\r
28                          * registry = Jws2Client .connectToRegistry(\r
29                          * "http://webserv1.cluster.lifesci.dundee.ac.uk:8089/jaba");\r
30                          */\r
31                         registry = Jws2Client.connectToRegistry(WSTesterTester.SERVER);\r
32 \r
33                 } catch (ConnectException e) {\r
34                         e.printStackTrace();\r
35                         Assert.fail(e.getMessage());\r
36                 } catch (WebServiceException e) {\r
37                         e.printStackTrace();\r
38                         Assert.fail(e.getMessage());\r
39                 }\r
40 \r
41         }\r
42 \r
43         /*\r
44          * This test will FAIL unless a connection to a running JABAWS web server is\r
45          * made!\r
46          */\r
47         @Test(groups = AllTestSuit.test_group_webservices)\r
48         public void categoryTest() {\r
49                 Set<Category> servicecategories = registry.getServiceCategories();\r
50 \r
51                 boolean found = false;\r
52                 for (Category svccategory : servicecategories) {\r
53 \r
54                         Set<Services> catservices;\r
55 \r
56                         for (String category : new String[]{Category.CATEGORY_ALIGNMENT,\r
57                                         Category.CATEGORY_CONSERVATION, Category.CATEGORY_DISORDER}) {\r
58                                 if (category.equals(svccategory.name)) {\r
59                                         found = true;\r
60                                         catservices = svccategory.getServices();\r
61                                         System.out.println("Found " + catservices.size()\r
62                                                         + " services in category " + category\r
63                                                         + "(service category string " + svccategory + ")");\r
64                                 }\r
65                         }\r
66                 }\r
67                 if (!found) {\r
68                         Assert.fail("Could not match any category to one of the given category constants");\r
69                 }\r
70         }\r
71 \r
72 }\r