1 25 26 package org.objectweb.jonas.jtests.clients.wsgen; 27 28 import java.io.File ; 29 import java.io.FileOutputStream ; 30 import java.io.IOException ; 31 import java.io.InputStream ; 32 import java.util.Enumeration ; 33 import java.util.jar.JarFile ; 34 import java.util.zip.ZipEntry ; 35 36 import org.objectweb.jonas.jtests.util.JWebServicesTestCase; 37 38 public abstract class A_WsGen extends JWebServicesTestCase { 39 private String jonasbase = null; 40 private String resources = null; 41 private String basedir = null; 42 43 public A_WsGen(String name) { 44 super(name); 45 } 46 47 public void setUp() throws Exception { 48 super.setUp(); 49 50 jonasbase = System.getProperty("jonasbase"); 51 resources = System.getProperty("ws.resources"); 52 basedir = System.getProperty("basedir"); 53 54 } 55 56 public void tearDown() throws Exception { 57 super.tearDown(); 58 } 59 60 protected String getJonasBaseFile(String path) { 61 return jonasbase + File.separator + path; 62 } 63 64 protected String getResourceFile(String path) { 65 return resources + File.separator + path; 66 } 67 68 protected String getTestFile(String path) { 69 return basedir + File.separator + path; 70 } 71 72 protected static boolean deleteDirectory(String dir) throws IOException { 73 File file = new File (dir); 74 boolean isDestroy = true; 75 if (file.isDirectory()) { 76 File [] childs = file.listFiles(); 78 for (int i = 0; i < childs.length; i++) { 79 isDestroy &= deleteDirectory(childs[i].getAbsolutePath()); 80 } 81 } 82 return isDestroy && file.delete(); 83 84 } 85 86 protected static String unpackJar(JarFile file) throws IOException { 87 String tmp = createTempDir(); 88 89 for (Enumeration e = file.entries(); e.hasMoreElements(); ) { 90 ZipEntry ze = (ZipEntry ) e.nextElement(); 91 String newFilename = tmp + File.separator 92 + ze.getName().replace('/', File.separator.charAt(0)); 93 File entryFile = new File (newFilename); 94 95 entryFile.getParentFile().mkdirs(); 96 FileOutputStream fos = new FileOutputStream (entryFile); 97 InputStream is = file.getInputStream(ze); 98 99 int n = 0; 100 byte[] buffer = new byte[1024]; 101 102 while ((n = is.read(buffer)) > 0) { 103 fos.write(buffer, 0, n); 104 } 105 106 fos.close(); 107 is.close(); 108 } 109 110 return tmp; 111 } 112 113 protected static String createTempDir() throws IOException { 114 File tmpDir = File.createTempFile("wsgen-tests", null, null); 115 tmpDir.delete(); 116 tmpDir.mkdir(); 117 return tmpDir.getAbsolutePath(); 118 } 119 120 } 121 | Popular Tags |