1 22 package org.jboss.aop.junit; 23 24 import java.net.URL ; 25 import java.util.Iterator ; 26 27 import org.jboss.aop.AspectXmlLoader; 28 import org.jboss.test.AbstractTestDelegate; 29 30 import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArrayList; 31 32 38 public class AOPTestDelegate extends AbstractTestDelegate 39 { 40 41 private static final CopyOnWriteArrayList urls = new CopyOnWriteArrayList(); 42 43 49 public AOPTestDelegate(Class clazz) throws Exception 50 { 51 super(clazz); 52 } 53 54 public void setUp() throws Exception 55 { 56 super.setUp(); 57 58 try 59 { 60 deploy(); 61 } 62 catch (RuntimeException e) 63 { 64 throw e; 65 } 66 catch (Exception e) 67 { 68 throw e; 69 } 70 catch (Error e) 71 { 72 throw e; 73 } 74 catch (Throwable e) 75 { 76 throw new RuntimeException (e); 77 } 78 } 79 80 public void tearDown() throws Exception 81 { 82 super.tearDown(); 83 undeploy(); 84 } 85 86 91 protected void deploy() throws Exception 92 { 93 String testName = clazz.getName(); 94 testName = testName.replace('.', '/') + "-aop.xml"; 95 URL url = clazz.getClassLoader().getResource(testName); 96 if (url != null) 97 deploy(url); 98 else 99 log.debug("No test specific deployment " + testName); 100 } 101 102 protected void undeploy() 103 { 104 for (Iterator i = urls.iterator(); i.hasNext();) 105 { 106 URL url = (URL ) i.next(); 107 undeploy(url); 108 } 109 } 110 111 117 protected void deploy(URL url) throws Exception 118 { 119 log.debug("Deploying " + url); 120 urls.add(url); 121 AspectXmlLoader.deployXML(url); 122 } 123 124 129 protected void undeploy(URL url) 130 { 131 try 132 { 133 log.debug("Undeploying " + url); 134 urls.remove(url); 135 AspectXmlLoader.undeployXML(url); 136 } 137 catch (Exception e) 138 { 139 log.warn("Ignored error undeploying " + url, e); 140 } 141 } 142 } 143 | Popular Tags |