001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: F_WsGen.java 7517 2005-10-18 08:14:02Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jtests.clients.wsgen;
025:
026: import java.io.File;
027: import java.util.Enumeration;
028: import java.util.jar.JarFile;
029: import java.util.zip.ZipEntry;
030:
031: import junit.framework.Test;
032: import junit.framework.TestSuite;
033:
034: /**
035: * test case for WsGen
036: */
037: public class F_WsGen extends A_WsGen {
038:
039: public F_WsGen(String name) {
040: super (name);
041: }
042:
043: public static Test suite() {
044: return new TestSuite(F_WsGen.class);
045: }
046:
047: public void setUp() throws Exception {
048: super .setUp();
049: }
050:
051: public void tearDown() throws Exception {
052: super .tearDown();
053: }
054:
055: /*
056: * Tests :
057: * - webapps (endpoint, clients, both, none) (various Schemas, DTD)
058: * - ejbjars (endpoint, clients, both, none) (various Schemas, DTD)
059: * - apps (combine above examples) + ()
060: */
061:
062: public void testWebappEndpointAlone() throws Exception {
063:
064: // Check entries in JarFile
065: String[] entries = new String[] {
066: "META-INF/MANIFEST.MF",
067: "WEB-INF/wsdl/AddressBookPort.wsdl",
068: "WEB-INF/wsdl/AddressBook.xsd",
069: "WEB-INF/web.xml",
070: "WEB-INF/webservices.xml",
071: "WEB-INF/jonas-webservices.xml",
072: "WEB-INF/mapping.xml",
073: "WEB-INF/classes/org/objectweb/jonas/jtests/servlets/endpoint/Address.class",
074: "WEB-INF/classes/org/objectweb/jonas/jtests/servlets/endpoint/AddressBook.class",
075: "WEB-INF/classes/org/objectweb/jonas/jtests/servlets/endpoint/AddressBookImpl.class",
076: "WEB-INF/classes/org/objectweb/jonas/jtests/servlets/endpoint/AddressBookException.class" };
077:
078: JarFile alone = new JarFile(getJonasBaseFile("webapps"
079: + File.separator + "webendpoint.war"));
080:
081: checkEntries(entries, alone);
082:
083: assertEquals("entries number doesn't match", entries.length,
084: countEntries(alone));
085:
086: }
087:
088: public void testWsClientEjb() throws Exception {
089:
090: // Check entries in JarFile
091: String path = "org/objectweb/jonas/jtests/beans/wsclient/";
092: String[] entries = new String[] { "META-INF/MANIFEST.MF",
093: "META-INF/jonas-ejb-jar.xml", "META-INF/ejb-jar.xml",
094: "META-INF/wsdl/query.wsdl" };
095:
096: JarFile wsclient = new JarFile(getJonasBaseFile("ejbjars"
097: + File.separator + "wsclient.jar"));
098:
099: checkEntries(entries, wsclient);
100:
101: }
102:
103: public void testTimeEndpoint() throws Exception {
104: // Check entries in JarFile (Wrapping Application)
105: String[] entries = new String[] { "META-INF/application.xml",
106: "META-INF/MANIFEST.MF", "time.war", "time.jar",
107: "time-client.jar" };
108:
109: JarFile time = new JarFile(getJonasBaseFile("apps"
110: + File.separator + "time-test.ear"));
111:
112: checkEntries(entries, time);
113:
114: assertEquals("entries number doesn't match", 5,
115: countEntries(time));
116:
117: // Check entries in JarFile (Wrapped WebApp)
118: String tmp = unpackJar(time);
119:
120: // Check war correctly created
121: JarFile web = new JarFile(tmp + File.separator + "time.war");
122: String[] webEntries = new String[] { "META-INF/MANIFEST.MF",
123: "WEB-INF/web.xml", "WEB-INF/web-jetty.xml",
124: "META-INF/context.xml",
125: "WEB-INF/sources/deploy-server-0.wsdd",
126: "WEB-INF/deploy-server-0.wsdd" };
127:
128: // TODO should improve entries check : deploy-server-0 may be deploy-server-25 !!
129: //checkEntries(webEntries, web);
130: assertEquals("web entries number doesn't match",
131: webEntries.length, countEntries(web));
132:
133: deleteDirectory(tmp);
134:
135: }
136:
137: public void checkEntries(String[] entries, JarFile file) {
138:
139: for (int i = 0; i < entries.length; i++) {
140: ZipEntry ze = file.getEntry(entries[i]);
141: assertNotNull("missing entry '" + entries[i] + "' in '"
142: + file.getName() + "'", ze);
143: }
144: }
145:
146: public int countEntries(JarFile file) {
147: Enumeration e = file.entries();
148: int count = 0;
149: while (e.hasMoreElements()) {
150: ZipEntry ze = (ZipEntry) e.nextElement();
151: // not a directory
152: if (!ze.getName().endsWith("/")) {
153: count++;
154: }
155:
156: }
157: return count;
158: }
159:
160: public static void main(String args[]) {
161: String testtorun = null;
162: // Get args
163: for (int argn = 0; argn < args.length; argn++) {
164: String s_arg = args[argn];
165: if (s_arg.equals("-n")) {
166: testtorun = args[++argn];
167: }
168: }
169: if (testtorun == null) {
170: junit.textui.TestRunner.run(suite());
171: } else {
172: junit.textui.TestRunner.run(new F_WsGen(testtorun));
173: }
174: }
175:
176: }
|