KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > system > controller > configure > binding > test > ServiceBindingTest


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

39 public abstract class ServiceBindingTest extends AbstractControllerTest
40 {
41    public ServiceBindingTest(String JavaDoc name)
42    {
43       super(name);
44    }
45    
46    public void testServiceBinding() throws Exception JavaDoc
47    {
48       TestServiceBinding binding = setServiceBinding(false);
49       try
50       {
51          ObjectName JavaDoc name = SimpleMBean.OBJECT_NAME;
52          assertInstall(name);
53          try
54          {
55             assertEquals(name, binding.getInvoked());
56             
57             Simple simple = getSimple();
58             assertEquals("fromxml", simple.getAttribute1());
59             assertEquals("frombinding", simple.getAttribute2());
60          }
61          finally
62          {
63             assertUninstall(name);
64          }
65       }
66       finally
67       {
68          unsetServiceBinding();
69       }
70    }
71    
72    public void testServiceBindingError() throws Exception JavaDoc
73    {
74       TestServiceBinding binding = setServiceBinding(true);
75       try
76       {
77          ObjectName JavaDoc name = SimpleMBean.OBJECT_NAME;
78          assertInstall(name);
79          try
80          {
81             assertEquals(name, binding.getInvoked());
82             
83             Simple simple = getSimple();
84             assertEquals("fromxml", simple.getAttribute1());
85             assertEquals("fromxml", simple.getAttribute2());
86          }
87          finally
88          {
89             assertUninstall(name);
90          }
91       }
92       finally
93       {
94          unsetServiceBinding();
95       }
96    }
97
98    protected Simple getSimple() throws Exception JavaDoc
99    {
100       MBeanServer JavaDoc server = getServer();
101       Simple simple = (Simple) server.getAttribute(SimpleMBean.OBJECT_NAME, "Instance");
102       assertNotNull(simple);
103       return simple;
104    }
105    
106    protected TestServiceBinding setServiceBinding(boolean error)
107    {
108       MBeanServer JavaDoc server = getServer();
109       ServiceControllerMBean controller = getController();
110       TestServiceBinding serviceBinding = new TestServiceBinding(server, error);
111       controller.setServiceBinding(serviceBinding);
112       return serviceBinding;
113    }
114    
115    protected void unsetServiceBinding()
116    {
117       ServiceControllerMBean controller = getController();
118       controller.setServiceBinding(null);
119    }
120 }
121
Popular Tags