Search in sources :

Example 11 with Configuration

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

the class ConfigurationAdmin method updateForLocation.

/**
     * @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#updateForLocation(java.lang.String, java.lang.String, javax.management.openmbean.TabularData)
     */
@SuppressWarnings("unchecked")
public void updateForLocation(String pid, String location, TabularData configurationTable) throws IOException {
    if (pid == null || pid.length() < 1) {
        throw new IOException("Argument pid cannot be null or empty");
    }
    if (configurationTable == null) {
        throw new IOException("Argument configurationTable cannot be null");
    }
    if (!PROPERTIES_TYPE.equals(configurationTable.getTabularType())) {
        throw new IOException("Invalid TabularType [" + configurationTable.getTabularType() + "]");
    }
    Dictionary<String, Object> configurationProperties = new Hashtable<String, Object>();
    Collection<CompositeData> compositeData = (Collection<CompositeData>) configurationTable.values();
    for (CompositeData row : compositeData) {
        PropertyData<? extends Class<?>> propertyData = PropertyData.from(row);
        configurationProperties.put(propertyData.getKey(), propertyData.getValue());
    }
    Configuration config = configurationAdmin.getConfiguration(pid, location);
    config.update(configurationProperties);
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) IOException(java.io.IOException)

Example 12 with Configuration

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

the class ConnectionLifecycleTest method testDeleteOfConfig.

@Test
public void testDeleteOfConfig() throws Exception {
    Assume.assumeTrue("Not a configuration test", isConfigured());
    txControl.required(() -> connection.createStatement().execute("Insert into TEST_TABLE values ( 'Hello World!' )"));
    assertEquals("Hello World!", txControl.notSupported(() -> {
        ResultSet rs = connection.createStatement().executeQuery("Select * from TEST_TABLE");
        rs.next();
        return rs.getString(1);
    }));
    ConfigurationAdmin cm = getService(ConfigurationAdmin.class, 5000);
    Configuration[] configurations = cm.listConfigurations("(service.factoryPid=org.apache.aries.tx.control.jdbc.*)");
    assertNotNull(configurations);
    assertEquals(1, configurations.length);
    configurations[0].delete();
    Thread.sleep(2000);
    try {
        assertEquals("Hello World!", txControl.notSupported(() -> {
            ResultSet rs = connection.createStatement().executeQuery("Select * from TEST_TABLE");
            rs.next();
            return rs.getString(1);
        }));
        fail("Should not be accessible");
    } catch (ScopedWorkException swe) {
        assertTrue(swe.getCause().toString(), swe.getCause() instanceof TransactionException);
        assertEquals("There was a problem getting hold of a database connection", swe.getCause().getMessage());
    }
}
Also used : ScopedWorkException(org.osgi.service.transaction.control.ScopedWorkException) TransactionException(org.osgi.service.transaction.control.TransactionException) Configuration(org.osgi.service.cm.Configuration) ResultSet(java.sql.ResultSet) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Test(org.junit.Test)

Example 13 with Configuration

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

the class ConfigurationAdminTest method testGetFactoryPid.

@Test
public void testGetFactoryPid() throws Exception {
    org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
    String factoryPid = "org.apache.aries.jmx.factory.mock";
    Configuration config = mock(Configuration.class);
    when(admin.getConfiguration(eq(factoryPid + "-1260133982371-0"), anyString())).thenReturn(config);
    when(config.getFactoryPid()).thenReturn(factoryPid);
    ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
    assertEquals(factoryPid, mbean.getFactoryPid(factoryPid + "-1260133982371-0"));
    assertEquals(factoryPid, mbean.getFactoryPidForLocation(factoryPid + "-1260133982371-0", "location"));
}
Also used : Configuration(org.osgi.service.cm.Configuration) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 14 with Configuration

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

the class ConfigurationAdminTest method testDeleteConfigurations.

@Test
public void testDeleteConfigurations() throws Exception {
    org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
    String filter = "(" + Constants.SERVICE_PID + "=org.apache.aries.jmx.mock)";
    Configuration a = mock(Configuration.class);
    Configuration b = mock(Configuration.class);
    when(admin.listConfigurations(filter)).thenReturn(new Configuration[] { a, b });
    ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
    mbean.deleteConfigurations(filter);
    verify(a).delete();
    verify(b).delete();
}
Also used : Configuration(org.osgi.service.cm.Configuration) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 15 with Configuration

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

the class ConfigurationAdminTest method testCreateFactoryConfiguration.

@Test
public void testCreateFactoryConfiguration() throws Exception {
    org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
    String fpid = "org.apache.aries.jmx.mock.factory";
    Configuration config = mock(Configuration.class);
    when(admin.createFactoryConfiguration(eq(fpid))).thenReturn(config);
    when(admin.createFactoryConfiguration(eq(fpid), anyString())).thenReturn(config);
    when(config.getPid()).thenReturn(fpid + "-1260133982371-0");
    ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
    assertEquals(fpid + "-1260133982371-0", mbean.createFactoryConfiguration(fpid));
    assertEquals(fpid + "-1260133982371-0", mbean.createFactoryConfigurationForLocation(fpid, "/bundlex"));
}
Also used : Configuration(org.osgi.service.cm.Configuration) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

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