KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > system > controller > integration > test > AbstractIntegrationTest


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.system.controller.integration.test;
23
24 import java.net.URL JavaDoc;
25
26 import org.jboss.dependency.spi.ControllerContext;
27 import org.jboss.dependency.spi.ControllerState;
28 import org.jboss.kernel.spi.deployment.KernelDeployment;
29 import org.jboss.test.AbstractTestDelegate;
30 import org.jboss.test.system.controller.AbstractControllerTest;
31
32 /**
33  * An integration Test.
34  *
35  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
36  * @version $Revision: 1.2 $
37  */

38 public abstract class AbstractIntegrationTest extends AbstractControllerTest
39 {
40    /**
41     * Create a new integration test.
42     *
43     * @param name the test name
44     */

45    public AbstractIntegrationTest(String JavaDoc name)
46    {
47       super(name);
48    }
49    
50    public static AbstractTestDelegate getDelegate(Class JavaDoc clazz) throws Exception JavaDoc
51    {
52       IntegrationTestDelegate delegate = new IntegrationTestDelegate(clazz);
53       // @todo delegate.enableSecurity = true;
54
return delegate;
55    }
56
57    /**
58     * Get a bean
59     *
60     * @param name the bean name
61     * @return the bean
62     * @throws IllegalStateException when the bean does not exist
63     */

64    protected Object JavaDoc getBean(Object JavaDoc name)
65    {
66       return getBean(name, ControllerState.INSTALLED);
67    }
68    
69    /**
70     * Get a bean
71     *
72     * @param name the name of the bean
73     * @param state the state of the bean
74     * @return the bean
75     * @throws IllegalStateException when the bean does not exist at that state
76     */

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

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

102    protected ControllerContext getControllerContext(Object JavaDoc name, ControllerState state)
103    {
104       return getIntegrationDelegate().getControllerContext(name, state);
105    }
106    
107    /**
108     * Deploy a url
109     *
110     * @param url the deployment url
111     * @return the deployment
112     * @throws Throwable for any error
113     */

114    protected KernelDeployment deployMC(URL JavaDoc url) throws Exception JavaDoc
115    {
116       return getIntegrationDelegate().deployMC(url);
117    }
118    
119    /**
120     * Deploy a resource
121     *
122     * @param resource the deployment resource
123     * @return the deployment
124     * @throws Throwable for any error
125     */

126    protected KernelDeployment deployMC(String JavaDoc resource) throws Exception JavaDoc
127    {
128       URL JavaDoc url = getClass().getResource(resource);
129       if (url == null)
130          throw new IllegalArgumentException JavaDoc("Resource not found: " + resource);
131       return getIntegrationDelegate().deployMC(url);
132    }
133    
134    /**
135     * Undeploy a deployment
136     *
137     * @param deployment the deployment
138     */

139    protected void undeployMC(KernelDeployment deployment)
140    {
141       getIntegrationDelegate().undeployMC(deployment);
142    }
143    
144    /**
145     * Undeploy a deployment
146     *
147     * @param resource the url
148     */

149    protected void undeployMC(String JavaDoc resource)
150    {
151       URL JavaDoc url = getClass().getResource(resource);
152       if (url == null)
153          throw new IllegalArgumentException JavaDoc("Resource not found: " + resource);
154       getIntegrationDelegate().undeployMC(url);
155    }
156    
157    /**
158     * Validate
159     *
160     * @throws Exception for any error
161     */

162    protected void validateMC() throws Exception JavaDoc
163    {
164       getIntegrationDelegate().validateMC();
165    }
166
167    protected IntegrationTestDelegate getIntegrationDelegate()
168    {
169       return (IntegrationTestDelegate) getDelegate();
170    }
171 }
172
Popular Tags