KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > proxyfactory > 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.test.proxyfactory;
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: 41089 $
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       try
53       {
54          deploy();
55       }
56       catch (RuntimeException JavaDoc e)
57       {
58          throw e;
59       }
60       catch (Exception JavaDoc e)
61       {
62          throw e;
63       }
64       catch (Error JavaDoc e)
65       {
66          throw e;
67       }
68       catch (Throwable JavaDoc e)
69       {
70          throw new RuntimeException JavaDoc(e);
71       }
72    }
73
74    public void tearDown() throws Exception JavaDoc
75    {
76       super.tearDown();
77       undeploy();
78    }
79    
80    /**
81     * Deploy the aop config
82     *
83     * @throws Exception for any error
84     */

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

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

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

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

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