use of org.apache.aries.jmx.agent.JMXAgentContext in project aries by apache.
the class ServiceStateMBeanHandlerTest method testOpen.
@Test
public void testOpen() throws Exception {
BundleContext context = mock(BundleContext.class);
when(context.getProperty(Constants.FRAMEWORK_UUID)).thenReturn("some-uuid");
Logger logger = mock(Logger.class);
Bundle mockSystemBundle = mock(Bundle.class);
when(mockSystemBundle.getSymbolicName()).thenReturn("the.sytem.bundle");
when(context.getBundle(0)).thenReturn(mockSystemBundle);
JMXAgent agent = mock(JMXAgent.class);
JMXAgentContext agentContext = new JMXAgentContext(context, agent, logger);
ServiceStateMBeanHandler handler = new ServiceStateMBeanHandler(agentContext, new StateConfig());
handler.open();
assertNotNull(handler.getMbean());
}
use of org.apache.aries.jmx.agent.JMXAgentContext in project aries by apache.
the class BundleStateMBeanHandlerTest method testOpenAndClose.
@Test
public void testOpenAndClose() throws Exception {
BundleContext context = mock(BundleContext.class);
when(context.getProperty(Constants.FRAMEWORK_UUID)).thenReturn("some-uuid");
Logger logger = mock(Logger.class);
Bundle mockSystemBundle = mock(Bundle.class);
when(mockSystemBundle.getSymbolicName()).thenReturn("the.sytem.bundle");
when(context.getBundle(0)).thenReturn(mockSystemBundle);
ServiceReference packageAdminRef = mock(ServiceReference.class);
PackageAdmin packageAdmin = mock(PackageAdmin.class);
when(context.getServiceReference(PackageAdmin.class.getName())).thenReturn(packageAdminRef);
when(context.getService(packageAdminRef)).thenReturn(packageAdmin);
ServiceReference startLevelRef = mock(ServiceReference.class);
StartLevel startLevel = mock(StartLevel.class);
when(context.getServiceReference(StartLevel.class.getName())).thenReturn(startLevelRef);
when(context.getService(startLevelRef)).thenReturn(startLevel);
JMXAgent agent = mock(JMXAgent.class);
JMXAgentContext agentContext = new JMXAgentContext(context, agent, logger);
BundleStateMBeanHandler handler = new BundleStateMBeanHandler(agentContext, new StateConfig());
handler.open();
assertNotNull(handler.getMbean());
handler.close();
verify(context).ungetService(packageAdminRef);
verify(context).ungetService(startLevelRef);
}
use of org.apache.aries.jmx.agent.JMXAgentContext in project aries by apache.
the class CompendiumHandlerTest method testRemovedServiceWillUnregisterMBean.
@Test
public void testRemovedServiceWillUnregisterMBean() throws Exception {
Object service = new Object();
ServiceReference reference = mock(ServiceReference.class);
when(reference.getProperty(Constants.SERVICE_ID)).thenReturn(1L);
when(reference.getProperty(Constants.OBJECTCLASS)).thenReturn("the class");
BundleContext bundleContext = mock(BundleContext.class);
Logger agentLogger = mock(Logger.class);
JMXAgentContext agentContext = mock(JMXAgentContext.class);
when(agentContext.getBundleContext()).thenReturn(bundleContext);
when(agentContext.getLogger()).thenReturn(agentLogger);
AbstractCompendiumHandler concreteHandler = new CompendiumHandler(agentContext, "org.osgi.service.Xxx");
target = spy(concreteHandler);
target.trackedId.set(1);
String name = "osgi.compendium:service=xxx,version=1.0";
doReturn(name).when(target).getName();
target.removedService(reference, service);
// service unget
verify(bundleContext).ungetService(reference);
// unregister is invoked on context
verify(agentContext).unregisterMBean(target);
}
use of org.apache.aries.jmx.agent.JMXAgentContext in project aries by apache.
the class ProvisioningServiceMBeanHandlerTest method testConstructInjectMBean.
@Test
public void testConstructInjectMBean() {
BundleContext bundleContext = mock(BundleContext.class);
Logger agentLogger = mock(Logger.class);
JMXAgentContext agentContext = new JMXAgentContext(bundleContext, null, agentLogger);
ProvisioningService provService = mock(ProvisioningService.class);
ProvisioningServiceMBeanHandler handler = new ProvisioningServiceMBeanHandler(agentContext);
StandardMBean mbean = handler.constructInjectMBean(provService);
assertNotNull(mbean);
}
use of org.apache.aries.jmx.agent.JMXAgentContext in project aries by apache.
the class ConfigurationAdminMBeanHandlerTest method testConstructInjectMBean.
@Test
public void testConstructInjectMBean() {
BundleContext bundleContext = mock(BundleContext.class);
Logger agentLogger = mock(Logger.class);
JMXAgentContext agentContext = new JMXAgentContext(bundleContext, null, agentLogger);
ConfigurationAdmin cAdmin = mock(ConfigurationAdmin.class);
ConfigurationAdminMBeanHandler handler = new ConfigurationAdminMBeanHandler(agentContext);
StandardMBean mbean = handler.constructInjectMBean(cAdmin);
assertNotNull(mbean);
}
Aggregations