KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > system > controller > instantiate > test > NewNoMetaDataInstantiateUnitTestCase


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.instantiate.test;
23
24 import javax.management.MBeanServer JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26
27 import junit.framework.Test;
28
29 import org.jboss.system.ServiceController;
30 import org.jboss.test.AbstractTestDelegate;
31 import org.jboss.test.system.controller.AbstractControllerTest;
32 import org.jboss.test.system.controller.support.Simple;
33 import org.jboss.test.system.controller.support.SimpleMBean;
34
35 /**
36  * NewNoMetaDataInstantiateUnitTestCase.
37  *
38  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
39  * @version $Revision: 1.1 $
40  */

41 public class NewNoMetaDataInstantiateUnitTestCase extends AbstractControllerTest
42 {
43    public static Test suite()
44    {
45       return suite(NewNoMetaDataInstantiateUnitTestCase.class);
46    }
47
48    public NewNoMetaDataInstantiateUnitTestCase(String JavaDoc name)
49    {
50       super(name);
51    }
52
53    public static AbstractTestDelegate getDelegate(Class JavaDoc clazz) throws Exception JavaDoc
54    {
55       return getNewControllerDelegate(clazz);
56    }
57    
58    public void testNoMetaData() throws Throwable JavaDoc
59    {
60       ObjectName JavaDoc name = SimpleMBean.OBJECT_NAME;
61       Simple test = new Simple();
62
63       ServiceController serviceController = (ServiceController) getController();
64       serviceController.install(name, test);
65       try
66       {
67          assertServiceConfigured(name);
68          
69          MBeanServer JavaDoc server = getServer();
70          Object JavaDoc instance = server.getAttribute(name, "Instance");
71          assertNotNull(instance);
72          assertTrue(test == instance);
73       }
74       finally
75       {
76          try
77          {
78             serviceController.remove(name);
79          }
80          catch (Exception JavaDoc ignored)
81          {
82          }
83       }
84    }
85    
86    public void testNoMetaDataNoName() throws Throwable JavaDoc
87    {
88       ObjectName JavaDoc name = SimpleMBean.OBJECT_NAME;
89
90       Simple test = new Simple();
91       
92       ServiceController serviceController = (ServiceController) getController();
93       try
94       {
95          serviceController.install(null, test);
96       }
97       catch (Throwable JavaDoc t)
98       {
99          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
100       }
101       
102       assertNoService(name);
103    }
104    
105    public void testNoMetaDataNoObject() throws Throwable JavaDoc
106    {
107       ObjectName JavaDoc name = SimpleMBean.OBJECT_NAME;
108
109       ServiceController serviceController = (ServiceController) getController();
110       try
111       {
112          serviceController.install(name, null);
113       }
114       catch (Throwable JavaDoc t)
115       {
116          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
117       }
118    }
119 }
120
Popular Tags