KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > system > controller > configure > value > inject > test > NewInjectionValueUnitTestCase


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.configure.value.inject.test;
23
24 import java.util.List JavaDoc;
25
26 import javax.management.InvalidAttributeValueException JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28
29 import junit.framework.Test;
30
31 import org.jboss.joinpoint.spi.JoinpointException;
32 import org.jboss.mx.util.ObjectNameFactory;
33 import org.jboss.system.ServiceContext;
34 import org.jboss.test.AbstractTestDelegate;
35 import org.jboss.test.system.controller.AbstractControllerTest;
36 import org.jboss.test.system.controller.support.Simple;
37 import org.jboss.test.system.controller.support.SimpleMBean;
38
39 /**
40  * NewInjectionValueUnitTestCase.
41  *
42  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
43  * @version $Revision: 1.1 $
44  */

45 public class NewInjectionValueUnitTestCase extends AbstractControllerTest
46 {
47    private static ObjectName JavaDoc OTHER = ObjectNameFactory.create("jboss.test:type=depends");
48    
49    public static Test suite()
50    {
51       return suite(NewInjectionValueUnitTestCase.class);
52    }
53
54    public static AbstractTestDelegate getDelegate(Class JavaDoc clazz) throws Exception JavaDoc
55    {
56       return getNewControllerDelegate(clazz);
57    }
58
59    public NewInjectionValueUnitTestCase(String JavaDoc name)
60    {
61       super(name);
62    }
63
64    public void testInjection() throws Exception JavaDoc
65    {
66       ObjectName JavaDoc name = SimpleMBean.OBJECT_NAME;
67       
68       List JavaDoc<ObjectName JavaDoc> names = assertDeploy(name);
69       try
70       {
71          Simple test = getSimple();
72          Simple other = getMBean(Simple.class, OTHER, "Instance");
73          
74          assertEquals(other, test.getSimple());
75       }
76       finally
77       {
78          assertUndeploy(name, names);
79       }
80    }
81
82    public void testInjectionNoBean() throws Exception JavaDoc
83    {
84       assertDeployFailure(SimpleMBean.OBJECT_NAME, ServiceContext.INSTALLED, null);
85    }
86
87    public void testInjectionBeanEmpty() throws Exception JavaDoc
88    {
89       assertDeployFailure(SimpleMBean.OBJECT_NAME, ServiceContext.INSTALLED, null);
90    }
91
92    public void testInjectionNotFound() throws Exception JavaDoc
93    {
94       assertDeployFailure(SimpleMBean.OBJECT_NAME, ServiceContext.INSTALLED, null);
95    }
96
97    public void testInjectionWrongType() throws Exception JavaDoc
98    {
99       assertDeployFailure(SimpleMBean.OBJECT_NAME, InvalidAttributeValueException JavaDoc.class);
100    }
101
102    public void testInjectionProperty() throws Exception JavaDoc
103    {
104       ObjectName JavaDoc name = SimpleMBean.OBJECT_NAME;
105       
106       List JavaDoc<ObjectName JavaDoc> names = assertDeploy(name);
107       try
108       {
109          Simple test = getSimple();
110          
111          assertEquals("PropertyInjection", test.getAString());
112       }
113       finally
114       {
115          assertUndeploy(name, names);
116       }
117    }
118
119    public void testInjectionPropertyState() throws Exception JavaDoc
120    {
121       ObjectName JavaDoc name = SimpleMBean.OBJECT_NAME;
122       
123       List JavaDoc<ObjectName JavaDoc> names = assertDeploy(name);
124       try
125       {
126          Simple test = getSimple();
127          
128          assertEquals("Instantiated", test.getAString());
129       }
130       finally
131       {
132          assertUndeploy(name, names);
133       }
134    }
135
136    public void testInjectionPropertyNotFound() throws Exception JavaDoc
137    {
138       assertDeployFailure(SimpleMBean.OBJECT_NAME, JoinpointException.class);
139    }
140
141    public void testInjectionPropertyWrongType() throws Exception JavaDoc
142    {
143       assertDeployFailure(SimpleMBean.OBJECT_NAME, InvalidAttributeValueException JavaDoc.class);
144    }
145 }
146
Popular Tags