001: /*
002: * CoadunationLib: The coaduntion implementation library.
003: * Copyright (C) 2006 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * CoadunationParserTest.java
020: *
021: * JUnit based test
022: */
023:
024: package com.rift.coad.lib.deployment;
025:
026: import java.util.List;
027: import java.util.Vector;
028: import junit.framework.*;
029: import javax.xml.parsers.SAXParserFactory;
030: import javax.xml.parsers.SAXParser;
031: import org.xml.sax.InputSource;
032: import org.xml.sax.helpers.DefaultHandler;
033: import java.io.StringReader;
034: import org.xml.sax.SAXException;
035: import org.xml.sax.Attributes;
036: import com.rift.coad.lib.common.ResourceReader;
037:
038: /**
039: *
040: * @author mincemeat
041: */
042: public class CoadunationParserTest extends TestCase {
043:
044: public CoadunationParserTest(String testName) {
045: super (testName);
046: }
047:
048: protected void setUp() throws Exception {
049: }
050:
051: protected void tearDown() throws Exception {
052: }
053:
054: public static Test suite() {
055: TestSuite suite = new TestSuite(CoadunationParserTest.class);
056:
057: return suite;
058: }
059:
060: /**
061: * Test of getDeploymentInfo method, of class com.rift.coad.lib.deployment.CoadunationParser.
062: */
063: public void testGetDeploymentInfo() throws Exception {
064: System.out.println("getDeploymentInfo");
065:
066: ResourceReader resourceReader = new ResourceReader(
067: "com/rift/coad/lib/deployment/coadunation-test.xml");
068: if (resourceReader.getDocument() == null) {
069: fail("Document not retrieved.");
070: return;
071: }
072:
073: System.out.println("Parse the document");
074: CoadunationParser instance = new CoadunationParser(
075: resourceReader.getDocument());
076: System.out.println("Get the results");
077:
078: DeploymentInfo result = instance.getDeploymentInfo();
079:
080: // basic result test
081: if (result.getVersion().equals("1") == false) {
082: fail("The parser failed to retrieve the correct version");
083: return;
084: } else if (result.getName().equals("CoadunationTest") == false) {
085: fail("The parser failed to retrieve the correct name");
086: return;
087: } else if (result.getName().equals("CoadunationTest") == false) {
088: fail("The parser failed to retrieve the correct name");
089: return;
090: } else if (result.getDescription().equals(
091: "The test coadunationfile") == false) {
092: fail("Failed to retrieve the description.");
093: return;
094: }
095:
096: // web service test
097: java.util.Map map = result.getWebServices();
098: if (map.size() != 2) {
099: fail("Two web service must exist [" + map.size() + "]");
100: return;
101: }
102: com.rift.coad.lib.deployment.WebServiceInfo webServiceInfo = (com.rift.coad.lib.deployment.WebServiceInfo) map
103: .get("com.test.webservice");
104: if (webServiceInfo == null) {
105: fail("The web service value is not set correctly.");
106: return;
107: } else if (webServiceInfo.getClassName().equals(
108: "com.test.webservice") == false) {
109: fail("Class name not set to com.test.webservice");
110: return;
111: } else if (webServiceInfo.getPath().equals("/WebService") == false) {
112: fail("Path not set to /WebService");
113: return;
114: } else if (webServiceInfo.getRole().equals("test") == false) {
115: fail("Role not set to test");
116: return;
117: } else if (webServiceInfo.getWSDLPath().equals(
118: "com/webservicetest/webservice/WebService.wsdl") == false) {
119: fail("WSDL path not set to "
120: + "com/webservicetest/webservice/WebService.wsdl");
121: return;
122: } else if (webServiceInfo.getTransaction()) {
123: fail("The transaction was set");
124: return;
125: } else if (webServiceInfo.getClasses().size() != 2) {
126: fail("There is no list of classes for the web service.");
127: return;
128: } else if (webServiceInfo.getClasses().size() == 2) {
129: if (!webServiceInfo.getClasses().get(0).equals(
130: "com.test2.returnbean")) {
131: fail("Expected com.test2.returnbean");
132: }
133: if (!webServiceInfo.getClasses().get(1).equals(
134: "com.test2.returnbean2")) {
135: fail("Expected com.test2.returnbean2");
136: }
137: }
138:
139: webServiceInfo = (com.rift.coad.lib.deployment.WebServiceInfo) map
140: .get("com.test.webservice2");
141: if (webServiceInfo == null) {
142: fail("The web service value is not set correctly.");
143: return;
144: } else if (webServiceInfo.getClassName().equals(
145: "com.test.webservice2") == false) {
146: fail("Class name not set to com.test.webservice2");
147: return;
148: } else if (webServiceInfo.getPath().equals("/WebService2") == false) {
149: fail("Path not set to /WebService2");
150: return;
151: } else if (webServiceInfo.getRole().equals("test") == false) {
152: fail("Role not set to test");
153: return;
154: } else if (webServiceInfo.getWSDLPath().equals(
155: "com/webservicetest/webservice/WebService2.wsdl") == false) {
156: fail("WSDL path not set to "
157: + "com/webservicetest/webservice/WebService2.wsdl");
158: return;
159: } else if (!webServiceInfo.getTransaction()) {
160: fail("The transaction was not set");
161: return;
162: }
163:
164: // test the jmx beans
165: map = result.getJmxBeans();
166: if (map.size() != 1) {
167: fail("One jmx bean must exist [" + map.size() + "]");
168: return;
169: }
170:
171: com.rift.coad.lib.deployment.JMXBeanInfo jmxBeanInfo = (com.rift.coad.lib.deployment.JMXBeanInfo) map
172: .get("com.test2.jmxbean");
173: if (jmxBeanInfo == null) {
174: fail("The JMX beans are not set.");
175: return;
176: } else if (jmxBeanInfo.getInterfaceName().equals(
177: "com.test2.jmxbeaninter") == false) {
178: fail("JMX Interface name not set to com.test2.jmxbeaninter");
179: return;
180: } else if (jmxBeanInfo.getClassName().equals(
181: "com.test2.jmxbean") == false) {
182: fail("JMX Class name not set to com.test2.jmxbean");
183: return;
184: } else if (jmxBeanInfo.getObjectName().equals(
185: "com.test2:type=jmxbean") == false) {
186: fail("JMX object name not set to com.test2:type=jmxbean");
187: return;
188: } else if (jmxBeanInfo.getBindName().equals("jmxbean") == false) {
189: fail("JMX bind name not set to jmxbean");
190: return;
191: } else if (jmxBeanInfo.getRole().equals("test") == false) {
192: fail("JMX role not set to test");
193: return;
194: } else if (jmxBeanInfo.getUsername().equals("testuser") == false) {
195: fail("JMX username not set to testuser ["
196: + jmxBeanInfo.getUsername() + "]");
197: return;
198: } else if (!jmxBeanInfo.getCacheResults()) {
199: fail("JMX Bean cache result is set to false should be set to true");
200: return;
201: } else if (jmxBeanInfo.getCacheTimeout() != 10) {
202: fail("The cache time out is not set to 10 meaning default.");
203: return;
204: } else if (jmxBeanInfo.getTransaction() != true) {
205: fail("The transaction is not set");
206: return;
207: }
208: Vector classes = jmxBeanInfo.getClasses();
209: checkForClass(classes, "com.test2.returnbean");
210: checkForClass(classes, "com.test2.returnbean2");
211:
212: // check jmx threads
213: List threadList = jmxBeanInfo.getThreadInfoList();
214: if (threadList.size() != 1) {
215: fail("There must be one thread in the list ["
216: + threadList.size() + "]");
217: }
218: DeploymentThreadInfo threadInfo = (DeploymentThreadInfo) threadList
219: .get(0);
220:
221: if (threadInfo.getClassName().equals("com.test2.thread") == false) {
222: fail("Thread class name is set incorrectly to ["
223: + threadInfo.getClassName() + "]");
224: } else if (threadInfo.getUsername().equals("test") == false) {
225: fail("Thread username is set incorrectly to ["
226: + threadInfo.getUsername() + "]");
227: } else if (threadInfo.getThreadNumber() != 1) {
228: fail("Thread number is set incorrectly to ["
229: + threadInfo.getThreadNumber() + "]");
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 = (com.rift.coad.lib.deployment.BeanInfo) map
240: .get("com.test3.testbean");
241: if (beanInfo == null) {
242: fail("Failed to retrieve the coaduantion test bean info.");
243: return;
244: } else if (beanInfo.getClassName().equals("com.test3.testbean") == false) {
245: fail("Coadunation bean Class name not set to com.test3.testbean");
246: return;
247: } else if (beanInfo.getInterfaceName().equals(
248: "com.test3.testinter") == false) {
249: fail("Coadunation bean interface name not set to com.test3.testinter");
250: return;
251: } else if (beanInfo.getRole().equals("test") == false) {
252: fail("Coadunation bean role name not set to test");
253: return;
254: } else if (beanInfo.getBindName().equals("testbean") == false) {
255: fail("Coadunation bean bind name not bean set to testbean");
256: return;
257: } else if (beanInfo.getUsername().equals("testuser") == false) {
258: fail("Coadunation username not set to testuser");
259: return;
260: } else if (!beanInfo.getCacheResults()) {
261: fail("Coadunation bean cache result is set to false should be "
262: + "set to true");
263: return;
264: } else if (beanInfo.getCacheTimeout() != 10) {
265: fail("The cache timeout is not set to 10 : "
266: + beanInfo.getCacheTimeout());
267: return;
268: } else if (beanInfo.getTransaction() != true) {
269: fail("The transaction is not set to true");
270: return;
271: }
272:
273: classes = beanInfo.getClasses();
274: checkForClass(classes, "com.test3.returnbean");
275: checkForClass(classes, "com.test3.returnbean2");
276:
277: // check coadunation threads
278: threadList = beanInfo.getThreadInfoList();
279: if (threadList.size() != 1) {
280: fail("There must be one thread in the list ["
281: + threadList.size() + "]");
282: }
283: threadInfo = (DeploymentThreadInfo) threadList.get(0);
284:
285: if (threadInfo.getClassName().equals("com.test3.thread") == false) {
286: fail("Thread class name is set incorrectly to ["
287: + threadInfo.getClassName() + "]");
288: } else if (threadInfo.getUsername().equals("test") == false) {
289: fail("Thread username is set incorrectly to ["
290: + threadInfo.getUsername() + "]");
291: } else if (threadInfo.getThreadNumber() != 1) {
292: fail("Thread number is set incorrectly to ["
293: + threadInfo.getThreadNumber() + "]");
294: }
295:
296: beanInfo = (com.rift.coad.lib.deployment.BeanInfo) map
297: .get("com.test4.testbean");
298: if (beanInfo.getTransaction() != false) {
299: fail("The transaction is not set to false");
300: return;
301: }
302: }
303:
304: /**
305: * Check for the class name
306: */
307: private void checkForClass(Vector classes, String className) {
308: for (int index = 0; index < classes.size(); index++) {
309: String testName = (String) classes.get(index);
310: if (testName.equals(className)) {
311: return;
312: }
313: }
314: fail("The class [" + className + "] was not found.");
315: }
316:
317: }
|