KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > deployment > CoadunationParserTest


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * CoadunationParserTest.java
20  *
21  * JUnit based test
22  */

23
24 package com.rift.coad.lib.deployment;
25
26 import java.util.List JavaDoc;
27 import java.util.Vector JavaDoc;
28 import junit.framework.*;
29 import javax.xml.parsers.SAXParserFactory JavaDoc;
30 import javax.xml.parsers.SAXParser JavaDoc;
31 import org.xml.sax.InputSource JavaDoc;
32 import org.xml.sax.helpers.DefaultHandler JavaDoc;
33 import java.io.StringReader JavaDoc;
34 import org.xml.sax.SAXException JavaDoc;
35 import org.xml.sax.Attributes JavaDoc;
36 import com.rift.coad.lib.common.ResourceReader;
37
38 /**
39  *
40  * @author mincemeat
41  */

42 public class CoadunationParserTest extends TestCase {
43     
44     public CoadunationParserTest(String JavaDoc testName) {
45         super(testName);
46     }
47
48     protected void setUp() throws Exception JavaDoc {
49     }
50
51     protected void tearDown() throws Exception JavaDoc {
52     }
53
54     public static Test suite() {
55         TestSuite suite = new TestSuite(CoadunationParserTest.class);
56         
57         return suite;
58     }
59
60     /**
61      * Test of getDeploymentInfo method, of class com.rift.coad.lib.deployment.CoadunationParser.
62      */

63     public void testGetDeploymentInfo() throws Exception JavaDoc {
64         System.out.println("getDeploymentInfo");
65         
66         ResourceReader resourceReader = new ResourceReader(
67                 "com/rift/coad/lib/deployment/coadunation-test.xml");
68         if (resourceReader.getDocument() == null) {
69             fail("Document not retrieved.");
70             return;
71         }
72         
73         System.out.println("Parse the document");
74         CoadunationParser instance = new CoadunationParser(
75                 resourceReader.getDocument());
76         System.out.println("Get the results");
77         
78         DeploymentInfo result = instance.getDeploymentInfo();
79         
80         // basic result test
81
if (result.getVersion().equals("1") == false) {
82             fail("The parser failed to retrieve the correct version");
83             return;
84         } else if (result.getName().equals("CoadunationTest") == false) {
85             fail("The parser failed to retrieve the correct name");
86             return;
87         } else if (result.getName().equals("CoadunationTest") == false) {
88             fail("The parser failed to retrieve the correct name");
89             return;
90         } else if (result.getDescription().equals("The test coadunationfile")
91             == false) {
92             fail("Failed to retrieve the description.");
93             return;
94         }
95         
96         // web service test
97
java.util.Map JavaDoc map = result.getWebServices();
98         if (map.size() != 2) {
99             fail("Two web service must exist [" + map.size() + "]");
100             return;
101         }
102         com.rift.coad.lib.deployment.WebServiceInfo webServiceInfo =
103                 (com.rift.coad.lib.deployment.WebServiceInfo)map.get(
104                 "com.test.webservice");
105         if (webServiceInfo == null) {
106             fail("The web service value is not set correctly.");
107             return;
108         } else if (webServiceInfo.getClassName().equals("com.test.webservice")
109             == false) {
110             fail("Class name not set to com.test.webservice");
111             return;
112         } else if (webServiceInfo.getPath().equals("/WebService")
113             == false) {
114             fail("Path not set to /WebService");
115             return;
116         } else if (webServiceInfo.getRole().equals("test")
117             == false) {
118             fail("Role not set to test");
119             return;
120         } else if (webServiceInfo.getWSDLPath().equals(
121                 "com/webservicetest/webservice/WebService.wsdl")
122             == false) {
123             fail("WSDL path not set to " +
124                     "com/webservicetest/webservice/WebService.wsdl");
125             return;
126         } else if (webServiceInfo.getTransaction()) {
127             fail("The transaction was set");
128             return;
129         }
130         webServiceInfo =
131                 (com.rift.coad.lib.deployment.WebServiceInfo)map.get(
132                 "com.test.webservice2");
133         if (webServiceInfo == null) {
134             fail("The web service value is not set correctly.");
135             return;
136         } else if (webServiceInfo.getClassName().equals("com.test.webservice2")
137             == false) {
138             fail("Class name not set to com.test.webservice2");
139             return;
140         } else if (webServiceInfo.getPath().equals("/WebService2")
141             == false) {
142             fail("Path not set to /WebService2");
143             return;
144         } else if (webServiceInfo.getRole().equals("test")
145             == false) {
146             fail("Role not set to test");
147             return;
148         } else if (webServiceInfo.getWSDLPath().equals(
149                 "com/webservicetest/webservice/WebService2.wsdl")
150             == false) {
151             fail("WSDL path not set to " +
152                     "com/webservicetest/webservice/WebService2.wsdl");
153             return;
154         } else if (!webServiceInfo.getTransaction()) {
155             fail("The transaction was not set");
156             return;
157         }
158         
159         // test the jmx beans
160
map = result.getJmxBeans();
161         if (map.size() != 1) {
162             fail("One jmx bean must exist [" + map.size() + "]");
163             return;
164         }
165         
166         com.rift.coad.lib.deployment.JMXBeanInfo jmxBeanInfo =
167                 (com.rift.coad.lib.deployment.JMXBeanInfo)map.get(
168                 "com.test2.jmxbean");
169         if (jmxBeanInfo == null) {
170             fail("The JMX beans are not set.");
171             return;
172         } else if (jmxBeanInfo.getInterfaceName().equals("com.test2.jmxbeaninter")
173             == false) {
174             fail("JMX Interface name not set to com.test2.jmxbeaninter");
175             return;
176         } else if (jmxBeanInfo.getClassName().equals("com.test2.jmxbean")
177             == false) {
178             fail("JMX Class name not set to com.test2.jmxbean");
179             return;
180         } else if (jmxBeanInfo.getObjectName().equals("com.test2:type=jmxbean")
181             == false) {
182             fail("JMX object name not set to com.test2:type=jmxbean");
183             return;
184         } else if (jmxBeanInfo.getBindName().equals("jmxbean")
185             == false) {
186             fail("JMX bind name not set to jmxbean");
187             return;
188         } else if (jmxBeanInfo.getRole().equals("test")
189             == false) {
190             fail("JMX role not set to test");
191             return;
192         } else if (jmxBeanInfo.getUsername().equals("testuser")
193             == false) {
194             fail("JMX username not set to testuser [" +
195                     jmxBeanInfo.getUsername() + "]");
196             return;
197         } else if (!jmxBeanInfo.getCacheResults()) {
198             fail("JMX Bean cache result is set to false should be set to true");
199             return;
200         } else if (jmxBeanInfo.getCacheTimeout() != 10) {
201             fail("The cache time out is not set to 10 meaning default.");
202             return;
203         } else if (jmxBeanInfo.getTransaction() != true) {
204             fail("The transaction is not set");
205             return;
206         }
207         Vector JavaDoc classes = jmxBeanInfo.getClasses();
208         checkForClass(classes, "com.test2.returnbean");
209         checkForClass(classes, "com.test2.returnbean2");
210                 
211         // check jmx threads
212
List JavaDoc threadList = jmxBeanInfo.getThreadInfoList();
213         if (threadList.size() != 1) {
214             fail("There must be one thread in the list [" +
215                     threadList.size() + "]");
216         }
217         DeploymentThreadInfo threadInfo =
218                 (DeploymentThreadInfo)threadList.get(0);
219         
220         if (threadInfo.getClassName().equals("com.test2.thread") == false) {
221             fail("Thread class name is set incorrectly to [" +
222                     threadInfo.getClassName() + "]");
223         } else if (threadInfo.getUsername().equals("test") == false) {
224             fail("Thread username is set incorrectly to [" +
225                     threadInfo.getUsername() + "]");
226         } else if (threadInfo.getThreadNumber() != 1) {
227             fail("Thread number is set incorrectly to [" +
228                     threadInfo.getThreadNumber() + "]");
229         }
230         
231         
232         // test the jmx beans
233
map = result.getBeans();
234         if (map.size() != 2) {
235             fail("One coadunation bean must exist [" + map.size() + "]");
236             return;
237         }
238         
239         com.rift.coad.lib.deployment.BeanInfo beanInfo =
240                 (com.rift.coad.lib.deployment.BeanInfo)map.get(
241                 "com.test3.testbean");
242         if (beanInfo == null) {
243             fail("Failed to retrieve the coaduantion test bean info.");
244             return;
245         } else if (beanInfo.getClassName().equals("com.test3.testbean")
246             == false) {
247             fail("Coadunation bean Class name not set to com.test3.testbean");
248             return;
249         } else if (beanInfo.getInterfaceName().equals("com.test3.testinter")
250             == false) {
251             fail("Coadunation bean interface name not set to com.test3.testinter");
252             return;
253         } else if (beanInfo.getRole().equals("test")
254             == false) {
255             fail("Coadunation bean role name not set to test");
256             return;
257         } else if (beanInfo.getBindName().equals("testbean")
258             == false) {
259             fail("Coadunation bean bind name not bean set to testbean");
260             return;
261         } else if (beanInfo.getUsername().equals("testuser")
262             == false) {
263             fail("Coadunation username not set to testuser");
264             return;
265         } else if (!beanInfo.getCacheResults()) {
266             fail("Coadunation bean cache result is set to false should be " +
267                     "set to true");
268             return;
269         } else if (beanInfo.getCacheTimeout() != 10) {
270             fail("The cache timeout is not set to 10 : " +
271                     beanInfo.getCacheTimeout());
272             return;
273         } else if (beanInfo.getTransaction() != true) {
274             fail("The transaction is not set to true");
275             return;
276         }
277         
278         classes = beanInfo.getClasses();
279         checkForClass(classes, "com.test3.returnbean");
280         checkForClass(classes, "com.test3.returnbean2");
281         
282         // check coadunation threads
283
threadList = beanInfo.getThreadInfoList();
284         if (threadList.size() != 1) {
285             fail("There must be one thread in the list [" +
286                     threadList.size() + "]");
287         }
288         threadInfo =
289                 (DeploymentThreadInfo)threadList.get(0);
290         
291         if (threadInfo.getClassName().equals("com.test3.thread") == false) {
292             fail("Thread class name is set incorrectly to [" +
293                     threadInfo.getClassName() + "]");
294         } else if (threadInfo.getUsername().equals("test") == false) {
295             fail("Thread username is set incorrectly to [" +
296                     threadInfo.getUsername() + "]");
297         } else if (threadInfo.getThreadNumber() != 1) {
298             fail("Thread number is set incorrectly to [" +
299                     threadInfo.getThreadNumber() + "]");
300         }
301         
302         
303         beanInfo = (com.rift.coad.lib.deployment.BeanInfo)map.get(
304                 "com.test4.testbean");
305         if (beanInfo.getTransaction() != false) {
306             fail("The transaction is not set to false");
307             return;
308         }
309     }
310     
311     /**
312      * Check for the class name
313      */

314     private void checkForClass(Vector JavaDoc classes, String JavaDoc className) {
315         for (int index = 0; index < classes.size(); index++) {
316             String JavaDoc testName = (String JavaDoc)classes.get(index);
317             if (testName.equals(className)) {
318                 return;
319             }
320         }
321         fail("The class [" + className + "] was not found.");
322     }
323     
324 }
325
Popular Tags