KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > microcontainer > junit > AbstractProxyTestDelegate


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.aop.microcontainer.junit;
23
24 import java.net.URL JavaDoc;
25
26 import org.jboss.aop.AspectXmlLoader;
27 import org.jboss.test.AbstractTestDelegate;
28
29 /**
30  * AbstractProxyTestDelegate.
31  *
32  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
33  * @version $Revision: 44908 $
34  */

35 public class AbstractProxyTestDelegate extends AbstractTestDelegate
36 {
37    /**
38     * Create a new AbstractProxyTestDelegate.
39     *
40     * @param clazz the test class
41     * @throws Exception for any error
42     */

43    public AbstractProxyTestDelegate(Class JavaDoc clazz) throws Exception JavaDoc
44    {
45       super(clazz);
46    }
47
48    public void setUp() throws Exception JavaDoc
49    {
50       super.setUp();
51       
52       log.debug("Security enabled: " + enableSecurity);
53       
54       try
55       {
56          deploy();
57       }
58       catch (RuntimeException JavaDoc e)
59       {
60          throw e;
61       }
62       catch (Exception JavaDoc e)
63       {
64          throw e;
65       }
66       catch (Error JavaDoc e)
67       {
68          throw e;
69       }
70       catch (Throwable JavaDoc e)
71       {
72          throw new RuntimeException JavaDoc(e);
73       }
74    }
75
76    public void tearDown() throws Exception JavaDoc
77    {
78       super.tearDown();
79       undeploy();
80    }
81    
82    /**
83     * Deploy the aop config
84     *
85     * @throws Exception for any error
86     */

87    protected void deploy() throws Exception JavaDoc
88    {
89       String JavaDoc testName = clazz.getName();
90       testName = testName.replace('.', '/') + ".xml";
91       URL JavaDoc url = clazz.getClassLoader().getResource(testName);
92       if (url != null)
93          deploy(url);
94       else
95          throw new RuntimeException JavaDoc("No test specific deployment " + testName);
96    }
97
98    /**
99     * Undeploy the aop config
100     */

101    protected void undeploy()
102    {
103       String JavaDoc testName = clazz.getName();
104       testName = testName.replace('.', '/') + ".xml";
105       URL JavaDoc url = clazz.getClassLoader().getResource(testName);
106       if (url != null)
107          undeploy(url);
108       else
109          log.debug("No test specific deployment " + testName);
110    }
111    
112    /**
113     * Get the test url
114     *
115     * @return the test url
116     */

117    protected URL JavaDoc getTestURL()
118    {
119       String JavaDoc testName = clazz.getName();
120       testName = testName.replace('.', '/') + ".xml";
121       return clazz.getClassLoader().getResource(testName);
122    }
123    
124    /**
125     * Deploy the aop config
126     *
127     * @param url the url
128     * @throws Exception for any error
129     */

130    protected void deploy(URL JavaDoc url) throws Exception JavaDoc
131    {
132       log.debug("Deploying " + url);
133       AspectXmlLoader.deployXML(url);
134    }
135
136    /**
137     * Undeploy the aop config
138     *
139     * @param url the url
140     */

141    protected void undeploy(URL JavaDoc url)
142    {
143       try
144       {
145          log.debug("Undeploying " + url);
146          AspectXmlLoader.undeployXML(url);
147       }
148       catch (Exception JavaDoc e)
149       {
150          log.warn("Ignored error undeploying " + url, e);
151       }
152    }
153 }
154
Popular Tags