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