KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > system > controller > lifecycle > seperated > test > DependsBrokenTest


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.system.controller.lifecycle.seperated.test;
23
24 import java.util.List JavaDoc;
25
26 import javax.management.ObjectName JavaDoc;
27
28 import org.jboss.mx.util.ObjectNameFactory;
29 import org.jboss.test.system.controller.AbstractControllerTest;
30
31 /**
32  * DependsBrokenTest.
33  *
34  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
35  * @version $Revision: 1.1 $
36  */

37 public abstract class DependsBrokenTest extends AbstractControllerTest
38 {
39    private static ObjectName JavaDoc NAME_ONE = ObjectNameFactory.create("test:name=1");
40    private static ObjectName JavaDoc NAME_TWO = ObjectNameFactory.create("test:name=2");
41    
42    private String JavaDoc resourceName1;
43    private String JavaDoc resourceName2;
44
45    public DependsBrokenTest(String JavaDoc name)
46    {
47       super(name);
48
49       String JavaDoc resourceName = getClass().getName();
50       int index= resourceName.lastIndexOf('.');
51       if (index != -1)
52          resourceName= resourceName.substring(index + 1, resourceName.length());
53       index = resourceName.indexOf("NewUnitTestCase");
54       if (index != -1)
55          resourceName = resourceName.substring(0, index);
56       index = resourceName.indexOf("OldUnitTestCase");
57       if (index != -1)
58          resourceName = resourceName.substring(0, index);
59       
60       resourceName1 = resourceName + "_bad.xml";
61       resourceName2 = resourceName + "_good.xml";
62    }
63    
64    public void deployBrokenFirstMaybeDeployFailure(int expectedState, Class JavaDoc<? extends Throwable JavaDoc> expected) throws Exception JavaDoc
65    {
66       boolean error = false;
67
68       List JavaDoc<ObjectName JavaDoc> mbeans1 = assertMaybeDeployFailure(resourceName1, NAME_ONE, expected);
69       try
70       {
71          List JavaDoc<ObjectName JavaDoc> mbeans2 = deploy(resourceName2);
72          try
73          {
74             assertServiceState(NAME_TWO, expectedState);
75          }
76          catch (Exception JavaDoc e)
77          {
78             error = true;
79             throw e;
80          }
81          catch (Error JavaDoc e)
82          {
83             error = true;
84             throw e;
85          }
86          finally
87          {
88             undeploy(mbeans2);
89
90             if (error == false)
91             {
92                assertNoService(NAME_TWO);
93                assertNotRegistered(NAME_TWO);
94             }
95          }
96       }
97       catch (Exception JavaDoc e)
98       {
99          error = true;
100          throw e;
101       }
102       catch (Error JavaDoc e)
103       {
104          error = true;
105          throw e;
106       }
107       finally
108       {
109          undeploy(mbeans1);
110
111          if (error == false)
112          {
113             assertNoService(NAME_ONE);
114             assertNotRegistered(NAME_ONE);
115             assertNoService(NAME_TWO);
116             assertNotRegistered(NAME_TWO);
117          }
118       }
119    }
120    
121    public void deployBrokenSecondMaybeDeployFailure(int expectedState, Class JavaDoc<? extends Throwable JavaDoc> expected) throws Exception JavaDoc
122    {
123       boolean error = false;
124
125       List JavaDoc<ObjectName JavaDoc> mbeans2 = deploy(resourceName2);
126       try
127       {
128          assertServiceState(NAME_TWO, expectedState);
129          assertRegistered(NAME_TWO);
130
131          List JavaDoc<ObjectName JavaDoc> mbeans1 = assertMaybeDeployFailure(resourceName1, NAME_ONE, expected);
132          try
133          {
134             assertServiceState(NAME_TWO, expectedState);
135             assertRegistered(NAME_TWO);
136          }
137          catch (Exception JavaDoc e)
138          {
139             error = true;
140             throw e;
141          }
142          catch (Error JavaDoc e)
143          {
144             error = true;
145             throw e;
146          }
147          finally
148          {
149             undeploy(mbeans1);
150
151             if (error == false)
152             {
153                assertServiceState(NAME_TWO, expectedState);
154                assertRegistered(NAME_TWO);
155             }
156          }
157       }
158       catch (Exception JavaDoc e)
159       {
160          error = true;
161          throw e;
162       }
163       catch (Error JavaDoc e)
164       {
165          error = true;
166          throw e;
167       }
168       finally
169       {
170          undeploy(mbeans2);
171
172          if (error == false)
173          {
174             assertNoService(NAME_ONE);
175             assertNotRegistered(NAME_ONE);
176             assertNoService(NAME_TWO);
177             assertNotRegistered(NAME_TWO);
178          }
179       }
180    }
181    
182    public void deployBrokenFirstDeployFailure(int expectedState, Class JavaDoc<? extends Throwable JavaDoc> expected) throws Exception JavaDoc
183    {
184       boolean error = false;
185
186       List JavaDoc<ObjectName JavaDoc> mbeans1 = assertDeployFailure(resourceName1, NAME_ONE, expected);
187       try
188       {
189          List JavaDoc<ObjectName JavaDoc> mbeans2 = deploy(resourceName2);
190          try
191          {
192             assertServiceState(NAME_TWO, expectedState);
193          }
194          catch (Exception JavaDoc e)
195          {
196             error = true;
197             throw e;
198          }
199          catch (Error JavaDoc e)
200          {
201             error = true;
202             throw e;
203          }
204          finally
205          {
206             undeploy(mbeans2);
207
208             if (error == false)
209             {
210                assertNoService(NAME_TWO);
211                assertNotRegistered(NAME_TWO);
212             }
213          }
214       }
215       catch (Exception JavaDoc e)
216       {
217          error = true;
218          throw e;
219       }
220       catch (Error JavaDoc e)
221       {
222          error = true;
223          throw e;
224       }
225       finally
226       {
227          undeploy(mbeans1);
228
229          if (error == false)
230          {
231             assertNoService(NAME_ONE);
232             assertNotRegistered(NAME_ONE);
233             assertNoService(NAME_TWO);
234             assertNotRegistered(NAME_TWO);
235          }
236       }
237    }
238    
239    public void deployBrokenSecondDeployFailure(int expectedState, Class JavaDoc<? extends Throwable JavaDoc> expected) throws Exception JavaDoc
240    {
241       deployBrokenSecondDeployFailure(expectedState, expectedState, expectedState, expected);
242    }
243    
244    public void deployBrokenSecondDeployFailure(int expectedState, int brokenExpectedState, Class JavaDoc<? extends Throwable JavaDoc> expected) throws Exception JavaDoc
245    {
246       deployBrokenSecondDeployFailure(expectedState, expectedState, brokenExpectedState, expected);
247    }
248    
249    public void deployBrokenSecondDeployFailure(int beforeExpectedState, int afterExpectedState, int brokenExpectedState, Class JavaDoc<? extends Throwable JavaDoc> expected) throws Exception JavaDoc
250    {
251       boolean error = false;
252
253       List JavaDoc<ObjectName JavaDoc> mbeans2 = deploy(resourceName2);
254       try
255       {
256          assertServiceState(NAME_TWO, beforeExpectedState);
257          assertRegistered(NAME_TWO);
258
259          List JavaDoc<ObjectName JavaDoc> mbeans1 = assertDeployFailure(resourceName1, NAME_ONE, expected);
260          try
261          {
262             assertServiceState(NAME_TWO, afterExpectedState);
263             assertRegistered(NAME_TWO);
264          }
265          catch (Exception JavaDoc e)
266          {
267             error = true;
268             throw e;
269          }
270          catch (Error JavaDoc e)
271          {
272             error = true;
273             throw e;
274          }
275          finally
276          {
277             undeploy(mbeans1);
278
279             if (error == false)
280             {
281                assertServiceState(NAME_TWO, brokenExpectedState);
282                assertRegistered(NAME_TWO);
283             }
284          }
285       }
286       catch (Exception JavaDoc e)
287       {
288          error = true;
289          throw e;
290       }
291       catch (Error JavaDoc e)
292       {
293          error = true;
294          throw e;
295       }
296       finally
297       {
298          undeploy(mbeans2);
299
300          if (error == false)
301          {
302             assertNoService(NAME_ONE);
303             assertNotRegistered(NAME_ONE);
304             assertNoService(NAME_TWO);
305             assertNotRegistered(NAME_TWO);
306          }
307       }
308    }
309    
310    public void deployBrokenSecondInitialDeployFailure(int expectedState, Class JavaDoc<? extends Throwable JavaDoc> expected) throws Exception JavaDoc
311    {
312       boolean error = false;
313
314       List JavaDoc<ObjectName JavaDoc> mbeans2 = deploy(resourceName2);
315       try
316       {
317          assertServiceState(NAME_TWO, expectedState);
318          assertRegistered(NAME_TWO);
319
320          assertInitialDeployFailure(resourceName1, NAME_ONE, expected);
321          try
322          {
323             assertServiceState(NAME_TWO, expectedState);
324             assertRegistered(NAME_TWO);
325          }
326          catch (Exception JavaDoc e)
327          {
328             error = true;
329             throw e;
330          }
331          catch (Error JavaDoc e)
332          {
333             error = true;
334             throw e;
335          }
336          finally
337          {
338             if (error == false)
339             {
340                assertServiceState(NAME_TWO, expectedState);
341                assertRegistered(NAME_TWO);
342             }
343          }
344       }
345       catch (Exception JavaDoc e)
346       {
347          error = true;
348          throw e;
349       }
350       catch (Error JavaDoc e)
351       {
352          error = true;
353          throw e;
354       }
355       finally
356       {
357          undeploy(mbeans2);
358
359          if (error == false)
360          {
361             assertNoService(NAME_ONE);
362             assertNotRegistered(NAME_ONE);
363             assertNoService(NAME_TWO);
364             assertNotRegistered(NAME_TWO);
365          }
366       }
367    }
368 }
369
Popular Tags