use of org.apache.aries.jmx.agent.JMXAgentContext in project aries by apache.
the class CompendiumHandlerTest method testAddingServiceWillInitiateMBeanRegistration.
@Test
public void testAddingServiceWillInitiateMBeanRegistration() throws Exception {
Bundle mockSystemBundle = mock(Bundle.class);
when(mockSystemBundle.getSymbolicName()).thenReturn("the.sytem.bundle");
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);
when(bundleContext.getProperty(Constants.FRAMEWORK_UUID)).thenReturn("some-uuid");
when(bundleContext.getService(reference)).thenReturn(service);
when(bundleContext.getBundle(0)).thenReturn(mockSystemBundle);
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.addingService(reference);
//service only got once
verify(bundleContext).getService(reference);
//template method is invoked
verify(target).constructInjectMBean(service);
//registration is invoked on context
verify(agentContext).registerMBean(target);
}
Aggregations