KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > kernel > junit > MicrocontainerTest


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, 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.kernel.junit;
23
24 import java.net.URL JavaDoc;
25
26 import org.jboss.dependency.spi.ControllerState;
27 import org.jboss.kernel.spi.dependency.KernelControllerContext;
28 import org.jboss.kernel.spi.deployment.KernelDeployment;
29 import org.jboss.test.AbstractTestCaseWithSetup;
30 import org.jboss.test.AbstractTestDelegate;
31
32 /**
33  * A MicrocontainerTest.
34  *
35  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
36  * @version $Revision: 57133 $
37  */

38 public class MicrocontainerTest extends AbstractTestCaseWithSetup
39 {
40    /**
41     * Get the test delegate
42     *
43     * @param clazz the test class
44     * @return the delegate
45     * @throws Exception for any error
46     */

47    public static AbstractTestDelegate getDelegate(Class JavaDoc clazz) throws Exception JavaDoc
48    {
49       return new MicrocontainerTestDelegate(clazz);
50    }
51    
52    /**
53     * Create a new Microcontainer test
54     *
55     * @param name the test name
56     */

57    public MicrocontainerTest(String JavaDoc name)
58    {
59       super(name);
60    }
61    
62    protected void setUp() throws Exception JavaDoc
63    {
64       super.setUp();
65       configureLogging();
66       // Validate everything deployed
67
getMCDelegate().validate();
68    }
69
70    /**
71     * Get a bean
72     *
73     * @param name the bean name
74     * @return the bean
75     * @throws IllegalStateException when the bean does not exist
76     */

77    protected Object JavaDoc getBean(Object JavaDoc name)
78    {
79       return getBean(name, ControllerState.INSTALLED);
80    }
81    
82    /**
83     * Get a bean
84     *
85     * @param name the name of the bean
86     * @param state the state of the bean
87     * @return the bean
88     * @throws IllegalStateException when the bean does not exist at that state
89     */

90    protected Object JavaDoc getBean(Object JavaDoc name, ControllerState state)
91    {
92       return getMCDelegate().getBean(name, state);
93    }
94
95    /**
96     * Get a context
97     *
98     * @param name the bean name
99     * @return the context
100     * @throws IllegalStateException when the context does not exist
101     */

102    protected KernelControllerContext getControllerContext(Object JavaDoc name)
103    {
104       return getControllerContext(name, ControllerState.INSTALLED);
105    }
106    
107    /**
108     * Get a context
109     *
110     * @param name the name of the bean
111     * @param state the state of the bean
112     * @return the context
113     * @throws IllegalStateException when the context does not exist at that state
114     */

115    protected KernelControllerContext getControllerContext(Object JavaDoc name, ControllerState state)
116    {
117       return getMCDelegate().getControllerContext(name, state);
118    }
119    
120    /**
121     * Deploy a url
122     *
123     * @param url the deployment url
124     * @return the deployment
125     * @throws Exception for any error
126     */

127    protected KernelDeployment deploy(URL JavaDoc url) throws Exception JavaDoc
128    {
129       return getMCDelegate().deploy(url);
130    }
131    
132    /**
133     * Deploy a resource
134     *
135     * @param resource the deployment resource
136     * @return the deployment
137     * @throws Exception for any error
138     */

139    protected KernelDeployment deploy(String JavaDoc resource) throws Exception JavaDoc
140    {
141       URL JavaDoc url = getClass().getResource(resource);
142       if (url == null)
143          throw new IllegalArgumentException JavaDoc("Resource not found: " + resource);
144       return getMCDelegate().deploy(url);
145    }
146    
147    /**
148     * Undeploy a deployment
149     *
150     * @param deployment the deployment
151     */

152    protected void undeploy(KernelDeployment deployment)
153    {
154       getMCDelegate().undeploy(deployment);
155    }
156    
157    /**
158     * Undeploy a deployment
159     *
160     * @param resource the url
161     */

162    protected void undeploy(String JavaDoc resource)
163    {
164       URL JavaDoc url = getClass().getResource(resource);
165       if (url == null)
166          throw new IllegalArgumentException JavaDoc("Resource not found: " + resource);
167       getMCDelegate().undeploy(url);
168    }
169    
170    /**
171     * Validate
172     *
173     * @throws Exception for any error
174     */

175    protected void validate() throws Exception JavaDoc
176    {
177       getMCDelegate().validate();
178    }
179
180    /**
181     * Get the delegate
182     *
183     * @return the delegate
184     */

185    protected MicrocontainerTestDelegate getMCDelegate()
186    {
187       return (MicrocontainerTestDelegate) getDelegate();
188    }
189 }
190
Popular Tags