Search in sources :

Example 1 with JMXAgent

use of org.apache.aries.jmx.agent.JMXAgent 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 JMXAgent

use of org.apache.aries.jmx.agent.JMXAgent 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)

Aggregations

Logger (org.apache.aries.jmx.Logger)2 JMXAgent (org.apache.aries.jmx.agent.JMXAgent)2 JMXAgentContext (org.apache.aries.jmx.agent.JMXAgentContext)2 Test (org.junit.Test)2 Bundle (org.osgi.framework.Bundle)2 BundleContext (org.osgi.framework.BundleContext)2 ServiceReference (org.osgi.framework.ServiceReference)1 PackageAdmin (org.osgi.service.packageadmin.PackageAdmin)1 StartLevel (org.osgi.service.startlevel.StartLevel)1