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: A_WsGen.java 4617 2004-04-16 16:42:47Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jtests.clients.wsgen;
025:
026: import java.io.File;
027: import java.io.FileOutputStream;
028: import java.io.IOException;
029: import java.io.InputStream;
030: import java.util.Enumeration;
031: import java.util.jar.JarFile;
032: import java.util.zip.ZipEntry;
033:
034: import org.objectweb.jonas.jtests.util.JWebServicesTestCase;
035:
036: public abstract class A_WsGen extends JWebServicesTestCase {
037: private String jonasbase = null;
038: private String resources = null;
039: private String basedir = null;
040:
041: public A_WsGen(String name) {
042: super (name);
043: }
044:
045: public void setUp() throws Exception {
046: super .setUp();
047:
048: jonasbase = System.getProperty("jonasbase");
049: resources = System.getProperty("ws.resources");
050: basedir = System.getProperty("basedir");
051:
052: }
053:
054: public void tearDown() throws Exception {
055: super .tearDown();
056: }
057:
058: protected String getJonasBaseFile(String path) {
059: return jonasbase + File.separator + path;
060: }
061:
062: protected String getResourceFile(String path) {
063: return resources + File.separator + path;
064: }
065:
066: protected String getTestFile(String path) {
067: return basedir + File.separator + path;
068: }
069:
070: protected static boolean deleteDirectory(String dir)
071: throws IOException {
072: File file = new File(dir);
073: boolean isDestroy = true;
074: if (file.isDirectory()) {
075: // destroy all childs
076: File[] childs = file.listFiles();
077: for (int i = 0; i < childs.length; i++) {
078: isDestroy &= deleteDirectory(childs[i]
079: .getAbsolutePath());
080: }
081: }
082: return isDestroy && file.delete();
083:
084: }
085:
086: protected static String unpackJar(JarFile file) throws IOException {
087: String tmp = createTempDir();
088:
089: for (Enumeration e = file.entries(); e.hasMoreElements();) {
090: ZipEntry ze = (ZipEntry) e.nextElement();
091: String newFilename = tmp
092: + File.separator
093: + ze.getName().replace('/',
094: File.separator.charAt(0));
095: File entryFile = new File(newFilename);
096:
097: entryFile.getParentFile().mkdirs();
098: FileOutputStream fos = new FileOutputStream(entryFile);
099: InputStream is = file.getInputStream(ze);
100:
101: int n = 0;
102: byte[] buffer = new byte[1024];
103:
104: while ((n = is.read(buffer)) > 0) {
105: fos.write(buffer, 0, n);
106: }
107:
108: fos.close();
109: is.close();
110: }
111:
112: return tmp;
113: }
114:
115: protected static String createTempDir() throws IOException {
116: File tmpDir = File.createTempFile("wsgen-tests", null, null);
117: tmpDir.delete();
118: tmpDir.mkdir();
119: return tmpDir.getAbsolutePath();
120: }
121:
122: }
|