Search in sources :

Example 56 with Configuration

use of org.osgi.service.cm.Configuration 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 such 
    // 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 57 with Configuration

use of org.osgi.service.cm.Configuration 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 58 with Configuration

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

the class GetConfigServlet method getUniqueConfig.

private Configuration getUniqueConfig(String pid) throws ServletException {
    final String filter = "(service.pid=" + pid + ")";
    Configuration[] cfg = null;
    try {
        cfg = configAdmin.listConfigurations(filter);
    } catch (Exception e) {
        throw new ServletException("Error listing configs with filter " + filter, e);
    }
    if (cfg == null) {
        throw new ServletException("No config found with filter " + filter);
    }
    if (cfg.length > 1) {
        throw new ServletException("Expected 1 config, found " + cfg.length + " with filter " + filter);
    }
    return cfg[0];
}
Also used : ServletException(javax.servlet.ServletException) Configuration(org.osgi.service.cm.Configuration) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 59 with Configuration

use of org.osgi.service.cm.Configuration 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 60 with Configuration

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

the class AdminPollerServiceBean method allSourceInfo.

@Override
public List<Map<String, Object>> allSourceInfo() {
    // Get list of metatypes
    List<Map<String, Object>> metatypes = helper.getMetatypes();
    // Loop through each metatype and find its configurations
    for (Map metatype : metatypes) {
        try {
            List<Configuration> configs = helper.getConfigurations(metatype);
            ArrayList<Map<String, Object>> configurations = new ArrayList<>();
            if (configs != null) {
                for (Configuration config : configs) {
                    Map<String, Object> source = new HashMap<>();
                    boolean disabled = config.getPid().contains(DISABLED);
                    source.put(MAP_ENTRY_ID, config.getPid());
                    source.put(MAP_ENTRY_ENABLED, !disabled);
                    source.put(MAP_ENTRY_FPID, config.getFactoryPid());
                    if (!disabled) {
                        source.put(MAP_ENTRY_NAME, helper.getName(config));
                        source.put(MAP_ENTRY_BUNDLE_NAME, helper.getBundleName(config));
                        source.put(MAP_ENTRY_BUNDLE_LOCATION, config.getBundleLocation());
                        source.put(MAP_ENTRY_BUNDLE, helper.getBundleId(config));
                    } else {
                        source.put(MAP_ENTRY_NAME, config.getPid());
                    }
                    Dictionary<String, Object> properties = config.getProperties();
                    Map<String, Object> plist = new HashMap<>();
                    for (String key : Collections.list(properties.keys())) {
                        plist.put(key, properties.get(key));
                    }
                    source.put(MAP_ENTRY_PROPERTIES, plist);
                    source.put(MAP_ENTRY_REPORT_ACTIONS, getActions(config, reportActionProviders));
                    source.put(MAP_ENTRY_OPERATION_ACTIONS, getActions(config, operationActionProviders));
                    configurations.add(source);
                }
                metatype.put(MAP_ENTRY_CONFIGURATIONS, configurations);
            }
        } catch (Exception e) {
            LOGGER.info("Error getting source info: {}", e.getMessage());
        }
    }
    Collections.sort(metatypes, new Comparator<Map<String, Object>>() {

        @Override
        public int compare(Map<String, Object> o1, Map<String, Object> o2) {
            return ((String) o1.get("id")).compareToIgnoreCase((String) o2.get("id"));
        }
    });
    return metatypes;
}
Also used : Configuration(org.osgi.service.cm.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Configuration (org.osgi.service.cm.Configuration)226 Test (org.junit.Test)85 Hashtable (java.util.Hashtable)75 IOException (java.io.IOException)55 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)49 Dictionary (java.util.Dictionary)36 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 ServiceReference (org.osgi.framework.ServiceReference)19 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)18 Matchers.anyString (org.mockito.Matchers.anyString)16 BundleContext (org.osgi.framework.BundleContext)15 RegistrySourceConfiguration (org.codice.ddf.registry.federationadmin.service.internal.RegistrySourceConfiguration)11 Map (java.util.Map)10 Bundle (org.osgi.framework.Bundle)10 File (java.io.File)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 Mockito.anyString (org.mockito.Mockito.anyString)9 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)8 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)7