use of org.osgi.service.cm.ConfigurationAdmin in project aries by apache.
the class AbstractTransactionTest method clearConfiguration.
private void clearConfiguration() {
ConfigurationAdmin cm = getService(ConfigurationAdmin.class, 5000);
org.osgi.service.cm.Configuration[] cfgs = null;
try {
cfgs = cm.listConfigurations(null);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (cfgs != null) {
for (org.osgi.service.cm.Configuration cfg : cfgs) {
try {
cfg.delete();
} catch (Exception e) {
}
}
try {
Thread.sleep(250);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
use of org.osgi.service.cm.ConfigurationAdmin in project aries by apache.
the class JPALifecycleTest method testDeleteOfConfig.
@Test
public void testDeleteOfConfig() throws Exception {
Message m = new Message();
m.message = "Hello World";
txControl.required(() -> {
em.persist(m);
return null;
});
assertEquals(m.message, txControl.notSupported(() -> em.find(Message.class, m.id).message));
ConfigurationAdmin cm = getService(ConfigurationAdmin.class, 5000);
Configuration[] configurations = cm.listConfigurations("(service.factoryPid=org.apache.aries.tx.control.jpa.*)");
assertNotNull(configurations);
assertEquals(1, configurations.length);
configurations[0].delete();
Thread.sleep(2000);
try {
assertEquals(m.message, txControl.notSupported(() -> em.find(Message.class, m.id).message));
fail("Should not be accessible " + (Boolean.getBoolean(IS_XA) ? "xa" : "local"));
} 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());
}
}
use of org.osgi.service.cm.ConfigurationAdmin in project aries by apache.
the class JPALifecycleTest method testUpdateOfConfig.
@Test
public void testUpdateOfConfig() throws Exception {
Message m = new Message();
m.message = "Hello World";
txControl.required(() -> {
em.persist(m);
return null;
});
assertEquals(m.message, txControl.notSupported(() -> em.find(Message.class, m.id).message));
ConfigurationAdmin cm = getService(ConfigurationAdmin.class, 5000);
Configuration[] configurations = cm.listConfigurations("(service.factoryPid=org.apache.aries.tx.control.jpa.*)");
assertNotNull(configurations);
assertEquals(1, configurations.length);
configurations[0].update();
Thread.sleep(2000);
try {
assertEquals(m.message, txControl.notSupported(() -> em.find(Message.class, m.id).message));
fail("Should not be accessible " + (Boolean.getBoolean(IS_XA) ? "xa" : "local"));
} 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());
}
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class Activator method doStart.
@Override
protected void doStart() throws Exception {
ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class);
JdbcServiceImpl service = new JdbcServiceImpl();
service.setBundleContext(bundleContext);
service.setConfigAdmin(configurationAdmin);
register(JdbcService.class, service);
JdbcMBeanImpl mbean = new JdbcMBeanImpl();
mbean.setJdbcService(service);
registerMBean(mbean, "type=jdbc");
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class AppendTest method testLoad.
public void testLoad() throws Exception {
System.setProperty("karaf.data", "data");
System.setProperty("karaf.etc", "etc");
RepositoryImpl r = new RepositoryImpl(getClass().getResource("internal/service/f08.xml").toURI());
// Check repo
Feature[] features = r.getFeatures();
assertNotNull(features);
assertEquals(1, features.length);
Feature feature = features[0];
ConfigInfo configInfo = feature.getConfigurations().get(0);
assertNotNull(configInfo);
assertTrue(configInfo.isAppend());
Properties properties = configInfo.getProperties();
assertNotNull(properties);
String property = properties.getProperty("javax.servlet.context.tempdir");
assertNotNull(property);
assertFalse(property.contains("${"));
assertEquals(property, "data/pax-web-jsp");
ConfigurationAdmin admin = EasyMock.createMock(ConfigurationAdmin.class);
Configuration config = EasyMock.createMock(Configuration.class);
EasyMock.expect(admin.listConfigurations(EasyMock.eq("(service.pid=org.ops4j.pax.web)"))).andReturn(new Configuration[] { config });
Hashtable<String, Object> original = new Hashtable<>();
original.put("javax.servlet.context.tempdir", "data/pax-web-jsp");
EasyMock.expect(config.getProperties()).andReturn(original);
Hashtable<String, Object> expected = new Hashtable<>();
expected.put("org.ops4j.pax.web", "data/pax-web-jsp");
expected.put("org.apache.karaf.features.configKey", "org.ops4j.pax.web");
expected.put("foo", "bar");
EasyMock.expectLastCall();
EasyMock.replay(admin, config);
FeatureConfigInstaller installer = new FeatureConfigInstaller(admin);
installer.installFeatureConfigs(feature);
EasyMock.verify(admin, config);
EasyMock.reset(admin, config);
EasyMock.expect(admin.listConfigurations(EasyMock.eq("(service.pid=org.ops4j.pax.web)"))).andReturn(new Configuration[] { config });
original = new Hashtable<>();
original.put("org.apache.karaf.features.configKey", "org.ops4j.pax.web");
original.put("javax.servlet.context.tempdir", "value");
original.put("foo", "bar");
EasyMock.expect(config.getProperties()).andReturn(original);
EasyMock.replay(admin, config);
installer.installFeatureConfigs(feature);
EasyMock.verify(admin, config);
}
Aggregations