1 22 package org.jboss.test.ws; 23 24 import junit.extensions.TestSetup; 25 import junit.framework.TestSuite; 26 27 import java.util.StringTokenizer ; 28 import java.util.List ; 29 import java.util.ArrayList ; 30 import java.net.URLClassLoader ; 31 import java.net.URL ; 32 33 39 public class JBossWSTestSetup extends TestSetup 40 { 41 private JBossWSTestHelper delegate = new JBossWSTestHelper(); 42 private String [] archives; 43 44 protected JBossWSTestSetup(Class testClass, String archiveList) 45 { 46 super(new TestSuite(testClass)); 47 48 StringTokenizer st = new StringTokenizer (archiveList, ", "); 49 archives = new String [st.countTokens()]; 50 51 for (int i = 0; i < archives.length; i++) 52 archives[i] = st.nextToken(); 53 } 54 55 public static JBossWSTestSetup newTestSetup(Class testClass, String archiveList) 56 { 57 return new JBossWSTestSetup(testClass, archiveList); 58 } 59 60 protected void setUp() throws Exception 61 { 62 List clientJars = new ArrayList (); 63 for (int i = 0; i < archives.length; i++) 64 { 65 String archive = archives[i]; 66 boolean isJ2EEClient = archive.endsWith("-client.jar"); 67 if (delegate.isTargetServerJBoss() || isJ2EEClient == false) 68 { 69 try 70 { 71 delegate.deploy(archive); 72 } 73 catch (Exception ex) 74 { 75 ex.printStackTrace(); 76 delegate.undeploy(archive); 77 } 78 } 79 if (isJ2EEClient) 80 { 81 URL archiveURL = delegate.getArchiveURL(archive); 82 clientJars.add(archiveURL); 83 } 84 } 85 86 if( !clientJars.isEmpty() ) 88 { 89 ClassLoader parent = Thread.currentThread().getContextClassLoader(); 90 URL [] urls = new URL [clientJars.size()]; 91 for(int i=0; i<clientJars.size(); i++) 92 { 93 urls[i] = (URL )clientJars.get(i); 94 } 95 URLClassLoader cl = new URLClassLoader (urls, parent); 96 Thread.currentThread().setContextClassLoader(cl); 97 } 98 } 99 100 protected void tearDown() throws Exception 101 { 102 for (int i = 0; i < archives.length; i++) 103 { 104 String archive = archives[archives.length - i - 1]; 105 boolean isJ2EEClient = archive.endsWith("-client.jar"); 106 if (delegate.isTargetServerJBoss() || isJ2EEClient == false) 107 { 108 delegate.undeploy(archive); 109 } 110 } 111 } 112 } 113 | Popular Tags |