Search in sources :

Example 1 with JMXAgentContext

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

Example 2 with JMXAgentContext

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

Example 3 with JMXAgentContext

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

Example 4 with JMXAgentContext

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);
}
Also used : StandardMBean(javax.management.StandardMBean) ProvisioningService(org.osgi.service.provisioning.ProvisioningService) JMXAgentContext(org.apache.aries.jmx.agent.JMXAgentContext) Logger(org.apache.aries.jmx.Logger) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 5 with JMXAgentContext

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);
}
Also used : StandardMBean(javax.management.StandardMBean) JMXAgentContext(org.apache.aries.jmx.agent.JMXAgentContext) Logger(org.apache.aries.jmx.Logger) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) 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