1 22 package org.jboss.test.system.controller.configure.binding.test; 23 24 import javax.management.MBeanServer ; 25 import javax.management.ObjectName ; 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 39 public abstract class ServiceBindingTest extends AbstractControllerTest 40 { 41 public ServiceBindingTest(String name) 42 { 43 super(name); 44 } 45 46 public void testServiceBinding() throws Exception 47 { 48 TestServiceBinding binding = setServiceBinding(false); 49 try 50 { 51 ObjectName 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 73 { 74 TestServiceBinding binding = setServiceBinding(true); 75 try 76 { 77 ObjectName 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 99 { 100 MBeanServer 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 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 |