Search in sources :

Example 46 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project sling by apache.

the class BasicTeleportedIT method testConfigAdmin.

@Test
public void testConfigAdmin() throws IOException {
    final String pid = "TEST_" + getClass().getName() + UUID.randomUUID();
    // demonstrate that we can access OSGi services from teleported tests
    final ConfigurationAdmin ca = teleporter.getService(ConfigurationAdmin.class);
    assertNotNull("Teleporter should provide a ConfigurationAdmin", ca);
    final Configuration cfg = ca.getConfiguration(pid);
    assertNotNull("Expecting to get a Configuration", cfg);
    assertEquals("Expecting the correct pid", pid, cfg.getPid());
}
Also used : Configuration(org.osgi.service.cm.Configuration) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Test(org.junit.Test)

Example 47 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project sling by apache.

the class JobHandlingDistributionQueueProviderTest method testDisableQueueProcessing.

@Test
public void testDisableQueueProcessing() throws Exception {
    JobManager jobManager = mock(JobManager.class);
    ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class);
    Configuration config = mock(Configuration.class);
    when(configAdmin.createFactoryConfiguration(QueueConfiguration.class.getName(), null)).thenReturn(config);
    BundleContext context = mock(BundleContext.class);
    JobHandlingDistributionQueueProvider jobHandlingdistributionQueueProvider = new JobHandlingDistributionQueueProvider("dummy-agent", jobManager, context);
    jobHandlingdistributionQueueProvider.disableQueueProcessing();
}
Also used : QueueConfiguration(org.apache.sling.event.jobs.QueueConfiguration) Configuration(org.osgi.service.cm.Configuration) QueueConfiguration(org.apache.sling.event.jobs.QueueConfiguration) JobManager(org.apache.sling.event.jobs.JobManager) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 48 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project ddf by codice.

the class ApplicationServiceImplTest method testServiceChanged.

/**
     * Tests  the {@link ApplicationServiceImpl#setConfigFileName(String)} method
     *
     * @throws Exception
     */
@Test
public void testServiceChanged() throws Exception {
    Set<Repository> activeRepos = new HashSet<>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationServiceImpl appService = new ApplicationServiceImpl(bundleStateServices) {

        @Override
        protected BundleContext getContext() {
            return bundleContext;
        }
    };
    appService.setConfigFileName("foo");
    ServiceReference<ConfigurationAdmin> testConfigAdminRef = mock(ServiceReference.class);
    ConfigurationAdmin testConfigAdmin = mock(ConfigurationAdmin.class);
    Configuration testConfig = mock(Configuration.class);
    when(bundleContext.getServiceReference(ConfigurationAdmin.class)).thenReturn(testConfigAdminRef);
    when(bundleContext.getService(testConfigAdminRef)).thenReturn(testConfigAdmin);
    when(testConfigAdmin.getConfiguration(ApplicationServiceImpl.class.getName())).thenReturn(testConfig);
    Dictionary<String, Object> testProperties = new Hashtable<>();
    testProperties.put("test1", "foo");
    testProperties.put("test2", "bar");
    when(testConfig.getProperties()).thenReturn(testProperties);
    ServiceEvent serviceEvent = mock(ServiceEvent.class);
    when(serviceEvent.getType()).thenReturn(ServiceEvent.REGISTERED);
    appService.serviceChanged(serviceEvent);
    assertThat(testConfig.getProperties().size(), is(testProperties.size()));
    assertThat(testConfig.getProperties().get("test1"), is("foo"));
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) Mockito.anyString(org.mockito.Mockito.anyString) Repository(org.apache.karaf.features.Repository) ServiceEvent(org.osgi.framework.ServiceEvent) FeaturesService(org.apache.karaf.features.FeaturesService) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 49 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project ddf by codice.

the class SecurityTest method configureMocksForBundleContext.

private void configureMocksForBundleContext(String systemHostname) throws Exception {
    System.setProperty("org.codice.ddf.system.hostname", systemHostname);
    Bundle bundle = mock(Bundle.class);
    when(FrameworkUtil.getBundle(any(Class.class))).thenReturn(bundle);
    BundleContext bundleContext = mock(BundleContext.class);
    when(bundle.getBundleContext()).thenReturn(bundleContext);
    ServiceReference adminRef = mock(ServiceReference.class);
    ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class);
    Configuration config = mock(Configuration.class);
    when(configAdmin.getConfiguration(anyString(), anyString())).thenReturn(config);
    when(bundleContext.getService(adminRef)).thenReturn(configAdmin);
    ServiceReference securityRef = mock(ServiceReference.class);
    SecurityManager securityManager = mock(SecurityManager.class);
    when(securityManager.getSubject(any())).thenReturn(systemSubject);
    when(bundleContext.getService(securityRef)).thenReturn(securityManager);
    when(bundleContext.getServiceReference(ConfigurationAdmin.class)).thenReturn(adminRef);
    when(bundleContext.getServiceReference(SecurityManager.class)).thenReturn(securityRef);
}
Also used : Configuration(org.osgi.service.cm.Configuration) SecurityManager(ddf.security.service.SecurityManager) Bundle(org.osgi.framework.Bundle) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Example 50 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project ddf by codice.

the class TestRegistryReportActionProvider method setup.

@Before
public void setup() {
    metacard = new MetacardImpl();
    source = mock(Source.class);
    configurationAdmin = mock(ConfigurationAdmin.class);
    configuration = mock(Configuration.class);
    actionProvider = new RegistryReportActionProvider(ACTION_PROVIDER_ID);
    metacard.setId(SAMPLE_ID);
    metacard.setTags(SAMPLE_REGISTRY_TAGS);
    metacard.setSourceId(SAMPLE_SOURCE_ID);
    metacard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, SAMPLE_REGISTRY_ID);
}
Also used : Configuration(org.osgi.service.cm.Configuration) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Source(ddf.catalog.source.Source) Before(org.junit.Before)

Aggregations

ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)108 Configuration (org.osgi.service.cm.Configuration)42 Subject (javax.security.auth.Subject)24 Test (org.junit.Test)19 Hashtable (java.util.Hashtable)14 BundleContext (org.osgi.framework.BundleContext)14 ServiceReference (org.osgi.framework.ServiceReference)13 IOException (java.io.IOException)9 Dictionary (java.util.Dictionary)8 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)7 Method (java.lang.reflect.Method)6 Bundle (org.osgi.framework.Bundle)6 File (java.io.File)4 Properties (java.util.Properties)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 KarafMBeanServerGuard (org.apache.karaf.management.KarafMBeanServerGuard)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 CompositeData (javax.management.openmbean.CompositeData)3