use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class ExtraServicePropertiesTest method testExtraFactoryServiceProperties.
/**
* Tests if a Service instantiated by a Factory set can provide its service properties from its start method.
*/
public void testExtraFactoryServiceProperties() {
Ensure e = new Ensure();
ServiceRegistration sr = register(e, ExtraFactoryServiceProperties.ENSURE);
e.waitForStep(3, 10000);
sr.unregister();
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class FELIX5337Test method testCatchAllServicesUsingAnnotation.
public void testCatchAllServicesUsingAnnotation() {
Ensure e = new Ensure();
ServiceRegistration sr = register(e, FELIX5337.ENSURE);
// wait for S to be started
e.waitForStep(2, 5000);
// remove our sequencer: this will stop S
sr.unregister();
// ensure that S is stopped and destroyed
e.waitForStep(3, 5000);
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class FactoryConfigurationAdapterAnnotationTest method testFactoryConfigurationAdapterAnnotation.
@SuppressWarnings("serial")
public void testFactoryConfigurationAdapterAnnotation() throws Throwable {
Ensure e = new Ensure();
ServiceRegistration sr = register(e, ServiceProvider.ENSURE);
ConfigurationAdmin cm = (ConfigurationAdmin) context.getService(context.getServiceReference(ConfigurationAdmin.class.getName()));
try {
// Create a factory configuration in order to instantiate the ServiceProvider
org.osgi.service.cm.Configuration cf = cm.createFactoryConfiguration("FactoryPidTest", null);
cf.update(new Hashtable() {
{
put("foo2", "bar2");
}
});
// Wait for the ServiceProvider activation.
e.waitForStep(2, MAXWAIT);
// Update conf
cf.update(new Hashtable() {
{
put("foo2", "bar2_modified");
}
});
// Wait for effective update
e.waitForStep(4, MAXWAIT);
// Remove configuration.
cf.delete();
// Check if ServiceProvider has been stopped.
e.waitForStep(6, MAXWAIT);
e.ensure();
sr.unregister();
} catch (IOException err) {
err.printStackTrace();
Assert.fail("can't create factory configuration");
}
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class Felix4357Test method testSingleProperty.
public void testSingleProperty() {
Ensure e = new Ensure();
ServiceRegistration sr = register(e, Felix4357.ENSURE);
// wait for S to be started
e.waitForStep(30, 10000);
// remove our sequencer: this will stop S
sr.unregister();
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class ResourceAdapterDependencyAddAndRemoveTest2 method testBasicResourceAdapter.
public void testBasicResourceAdapter() throws Exception {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a resource provider
ResourceProvider provider = new ResourceProvider(context, new URL("file://localhost/path/to/file1.txt"));
// activate it
Hashtable<String, String> props = new Hashtable<String, String>();
props.put("id", "1");
m.add(m.createComponent().setInterface(ServiceInterface.class.getName(), props).setImplementation(new ServiceProvider(e)));
props = new Hashtable<String, String>();
props.put("id", "2");
m.add(m.createComponent().setInterface(ServiceInterface.class.getName(), props).setImplementation(new ServiceProvider(e)));
m.add(m.createComponent().setImplementation(provider).add(m.createServiceDependency().setService(ResourceHandler.class).setCallbacks("add", "remove")));
// create a resource adapter for our single resource
// note that we can provide an actual implementation instance here because there will be only one
// adapter, normally you'd want to specify a Class here
Dependency d = m.createServiceDependency().setService(ServiceInterface.class, "(id=1)").setRequired(true);
ResourceAdapter service = new ResourceAdapter(e, d);
CallbackInstance callbackInstance = new CallbackInstance(e, d);
Component component = m.createResourceAdapterService("(&(path=/path/to/*.txt)(host=localhost))", false, callbackInstance, "changed").setImplementation(service).setCallbacks(callbackInstance, "init", "start", "stop", "destroy");
component.add(new ComponentStateListenerImpl(e));
m.add(component);
// wait until the single resource is available
e.waitForStep(1, 5000);
// trigger a 'change' in our resource
provider.change();
// wait until the changed callback is invoked
e.waitForStep(2, 5000);
System.out.println("Done!");
m.clear();
}
Aggregations