KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > wsgen > F_WsGen


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: F_WsGen.java,v 1.8 2005/03/09 10:30:42 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.wsgen;
27
28 import java.io.File JavaDoc;
29 import java.util.Enumeration JavaDoc;
30 import java.util.jar.JarFile JavaDoc;
31 import java.util.zip.ZipEntry JavaDoc;
32
33 import junit.framework.Test;
34 import junit.framework.TestSuite;
35
36
37 /**
38  * test case for WsGen
39  */

40 public class F_WsGen extends A_WsGen {
41
42     public F_WsGen(String JavaDoc name) {
43         super(name);
44     }
45     
46     public static Test suite() {
47         return new TestSuite(F_WsGen.class);
48     }
49
50     public void setUp() throws Exception JavaDoc {
51         super.setUp();
52     }
53
54     public void tearDown() throws Exception JavaDoc {
55         super.tearDown();
56     }
57
58     /*
59      * Tests :
60      * - webapps (endpoint, clients, both, none) (various Schemas, DTD)
61      * - ejbjars (endpoint, clients, both, none) (various Schemas, DTD)
62      * - apps (combine above examples) + ()
63      */

64
65     public void testWebappEndpointAlone() throws Exception JavaDoc {
66
67         // Check entries in JarFile
68
String JavaDoc [] entries = new String JavaDoc[] { "META-INF/MANIFEST.MF",
69                                            "WEB-INF/wsdl/AddressBookPort.wsdl",
70                                            "WEB-INF/wsdl/AddressBook.xsd",
71                                            "WEB-INF/web.xml",
72                                            "WEB-INF/webservices.xml",
73                                            "WEB-INF/jonas-webservices.xml",
74                                            "WEB-INF/mapping.xml",
75                                            "WEB-INF/deploy-server-0.wsdd",
76                                            "WEB-INF/classes/org/objectweb/jonas/jtests/servlets/endpoint/Address.class",
77                                            "WEB-INF/classes/org/objectweb/jonas/jtests/servlets/endpoint/Address_Helper.class",
78                                            "WEB-INF/classes/org/objectweb/jonas/jtests/servlets/endpoint/AddressBook.class",
79                                            "WEB-INF/classes/org/objectweb/jonas/jtests/servlets/endpoint/AddressBookImpl.class",
80                                            "WEB-INF/classes/org/objectweb/jonas/jtests/servlets/endpoint/AddressBookException.class",
81                                            "WEB-INF/classes/org/objectweb/jonas/jtests/servlets/endpoint/AddressBookException_Helper.class"};
82
83         JarFile JavaDoc alone = new JarFile JavaDoc(getJonasBaseFile("webapps" + File.separator + "webendpoint.war"));
84         
85         checkEntries(entries, alone);
86         
87         assertEquals("entries number doesn't match", entries.length, countEntries(alone));
88
89     }
90
91     public void testWsClientEjb() throws Exception JavaDoc {
92
93         // Check entries in JarFile
94
String JavaDoc path = "org/objectweb/jonas/jtests/beans/wsclient/";
95         String JavaDoc [] entries = new String JavaDoc[] { "META-INF/MANIFEST.MF",
96                                            "META-INF/jonas-ejb-jar.xml",
97                                            "META-INF/ejb-jar.xml",
98                                            "META-INF/wsdl/query.wsdl"};
99
100         JarFile JavaDoc wsclient = new JarFile JavaDoc(getJonasBaseFile("ejbjars" + File.separator + "wsclient.jar"));
101         
102         checkEntries(entries, wsclient);
103
104     }
105
106     public void testTimeEndpoint() throws Exception JavaDoc {
107         // Check entries in JarFile (Wrapping Application)
108
String JavaDoc [] entries = new String JavaDoc[] { "META-INF/application.xml",
109                                            "META-INF/MANIFEST.MF",
110                                            "time.war",
111                                            "time.jar",
112                                            "time-client.jar"};
113
114         JarFile JavaDoc time = new JarFile JavaDoc(getJonasBaseFile("apps" + File.separator + "time-test.ear"));
115         
116         checkEntries(entries, time);
117         
118         assertEquals("entries number doesn't match", 5, countEntries(time));
119
120         // Check entries in JarFile (Wrapped WebApp)
121
String JavaDoc tmp = unpackJar(time);
122
123         // Check war correctly created
124
JarFile JavaDoc web = new JarFile JavaDoc(tmp + File.separator
125                                   + "time.war");
126         String JavaDoc [] webEntries = new String JavaDoc[] { "META-INF/MANIFEST.MF",
127                                               "WEB-INF/web.xml",
128                                               "WEB-INF/deploy-server-0.wsdd"};
129
130         // TODO should improve entries check : deploy-server-0 may be deploy-server-25 !!
131
//checkEntries(webEntries, web);
132
assertEquals("web entries number doesn't match", webEntries.length, countEntries(web));
133         
134         deleteDirectory(tmp);
135
136     }
137
138     public void checkEntries(String JavaDoc [] entries, JarFile JavaDoc file) {
139
140         for (int i = 0; i < entries.length; i++) {
141             ZipEntry JavaDoc ze = file.getEntry(entries[i]);
142             assertNotNull("missing entry '" + entries[i] + "' in '" + file.getName() + "'", ze);
143         }
144     }
145
146     public int countEntries(JarFile JavaDoc file) {
147         Enumeration JavaDoc e = file.entries();
148         int count = 0;
149         while (e.hasMoreElements()) {
150             ZipEntry JavaDoc ze = (ZipEntry JavaDoc) e.nextElement();
151             // not a directory
152
if (!ze.getName().endsWith("/")) {
153                 count++;
154             }
155             
156         }
157         return count;
158     }
159
160
161     public static void main (String JavaDoc args[]) {
162         String JavaDoc testtorun = null;
163         // Get args
164
for (int argn = 0; argn < args.length; argn++) {
165             String JavaDoc s_arg = args[argn];
166             if (s_arg.equals("-n")) {
167                 testtorun = args[++argn];
168             }
169         }
170         if (testtorun == null) {
171             junit.textui.TestRunner.run(suite());
172         } else {
173             junit.textui.TestRunner.run(new F_WsGen(testtorun));
174         }
175     }
176
177 }
178
Popular Tags