Search in sources :

Example 6 with JMXAgentContext

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);
}
Also used : Bundle(org.osgi.framework.Bundle) JMXAgentContext(org.apache.aries.jmx.agent.JMXAgentContext) ServiceReference(org.osgi.framework.ServiceReference) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

JMXAgentContext (org.apache.aries.jmx.agent.JMXAgentContext)6 Test (org.junit.Test)6 BundleContext (org.osgi.framework.BundleContext)6 Logger (org.apache.aries.jmx.Logger)4 Bundle (org.osgi.framework.Bundle)3 ServiceReference (org.osgi.framework.ServiceReference)3 StandardMBean (javax.management.StandardMBean)2 JMXAgent (org.apache.aries.jmx.agent.JMXAgent)2 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)1 PackageAdmin (org.osgi.service.packageadmin.PackageAdmin)1 ProvisioningService (org.osgi.service.provisioning.ProvisioningService)1 StartLevel (org.osgi.service.startlevel.StartLevel)1