public abstract class AbstractOSGiTest
extends java.lang.Object
| Constructor and Description |
|---|
AbstractOSGiTest(BundleContext bundleContext)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
after()
Cleanup Method
|
void |
before() |
protected <T> ServiceChecker<T> |
createCheckerTrackedForCleanUp(java.lang.Class<T> serviceClass)
Creates a ServiceChecker for a specific Service, where at least one Remove is expected.
|
protected Configuration |
createConfigForCleanup(java.lang.String factoryPid,
java.lang.String location,
java.util.Dictionary<java.lang.String,java.lang.Object> props)
A configuration is created and update will be called.
|
protected Configuration |
createConfigForCleanup(java.lang.String factoryPid,
java.lang.String name,
java.lang.String location,
java.util.Dictionary<java.lang.String,java.lang.Object> props)
A configuration is created and update will be called.
|
protected <T> ServiceChecker<T> |
createdCheckerTrackedForCleanUp(java.lang.String filter)
Creates a ServiceChecker for a specific Service, where at least one Remove is expected.
|
protected Filter |
createFilter(java.util.Dictionary<java.lang.String,java.lang.Object> properties)
Creates a filter String looking for all properties in the
Dictionary given. |
protected void |
deleteConfigurationAndRemoveFromCleanup(Configuration config)
The
Configuration to delete |
protected void |
deleteConfigurationAndRemoveFromCleanupBlocking(Configuration config)
The
Configuration to delete. |
protected void |
deleteConfigurationBlocking(Configuration config)
The
Configuration to delete. |
abstract void |
doAfter()
will be called in the before the test performs its cleanup, after the Abstract tests has initialized
|
abstract void |
doBefore()
will be called in the do before, after the Abstract tests has initialized
|
BundleContext |
getBundleContext()
Returns the bundleContext.
|
ConfigurationAdmin |
getConfigAdmin()
Returns the configAdmin.
|
protected <T> T |
getService(java.lang.Class<T> clazz)
This method will retrieve a Service and does a
Assert#assertNotNull(Object) check. |
protected <T> T |
getService(Filter filter,
long timeout)
This method will retrieve a Service and does a
Assert#assertNotNull(Object) check. |
protected void |
getServiceAssertNull(Filter filter)
This method will try to a Service and does a
Assert#assertNull(Object) check. |
protected ServiceChecker<?> |
getServiceCheckerForConfiguration(Configuration configuration)
Returns a service checker for the configuration
|
protected <T> <any> |
getServiceObjects(java.lang.Class<T> clazz)
This method will retrieve a Service and does a
Assert#assertNotNull(Object) check. |
protected <T> <any> |
getServiceObjects(java.lang.Class<T> clazz,
java.lang.String filter)
This method will retrieve a Service and does a
Assert#assertNotNull(Object) check. |
java.util.Dictionary<java.lang.String,java.lang.Object> |
getServiceProperties(java.lang.Object service)
returns the service properties of the
ServiceRegistration for the given Service |
protected <T> <any> |
getServiceReference(java.lang.Class<T> clazz)
This method will retrieve a Service and does a
Assert#assertNotNull(Object) check. |
boolean |
isRemoveConfigurationTrackServices()
Returns
true, if service are tracked for removal when cleaning up configurations. |
protected void |
registerServiceForCleanup(java.lang.Class<?> clazz,
java.lang.Object service,
java.util.Dictionary<java.lang.String,?> properties)
Registers the given service Object.
|
protected void |
registerServiceForCleanup(java.lang.Object service,
java.util.Dictionary<java.lang.String,?> properties,
java.lang.Class<?> clazz)
Registers the given service Object.
|
protected void |
registerServiceForCleanup(java.lang.Object service,
java.util.Dictionary<java.lang.String,?> properties,
java.lang.String... classes)
Registers the given service Object.
|
void |
setRemoveConfigurationTrackServices(boolean track)
Enables or disables tracking of services when removing configurations.
|
protected void |
ungetService(java.lang.Object service)
Cleanly ungets the given service, if it was retrieved via the getService method.
|
protected void |
unregisterService(java.lang.Object service)
Asserts that the given Object is not null and that we know about a
ServiceRegistration. |
void |
updateServiceRegistration(java.lang.Object service,
java.util.Dictionary<java.lang.String,?> properties)
Updates the given Service with the given Properties
|
public AbstractOSGiTest(BundleContext bundleContext)
public void before()
public abstract void doBefore()
public boolean isRemoveConfigurationTrackServices()
true, if service are tracked for removal when cleaning up configurations.public void setRemoveConfigurationTrackServices(boolean track)
track - the value to setprotected void ungetService(java.lang.Object service)
service - the service to ungetprotected <T> <any> getServiceReference(java.lang.Class<T> clazz)
Assert#assertNotNull(Object) check. When the test ends, the service will be unget as well.clazz - The Service Class desiredServiceReferenceprotected <T> <any> getServiceObjects(java.lang.Class<T> clazz)
Assert#assertNotNull(Object) check. When the test ends, the service will be unget as well.clazz - The Service Class desiredServiceObjectsprotected <T> <any> getServiceObjects(java.lang.Class<T> clazz,
java.lang.String filter)
throws InvalidSyntaxException
Assert#assertNotNull(Object) check. When the test ends, the service will be unget as well.clazz - The Service Class desiredfilter - the filter to apply as wellServiceObjectsInvalidSyntaxExceptionprotected <T> T getService(java.lang.Class<T> clazz)
Assert#assertNotNull(Object) check. When the test ends, the service will be unget as well.clazz - The Service Class desiredprotected <T> T getService(Filter filter,
long timeout)
throws java.lang.InterruptedException
Assert#assertNotNull(Object) check. When the test ends, the service will be unget as well.filter - the Filter to usejava.lang.InterruptedExceptionprotected void getServiceAssertNull(Filter filter)
throws java.lang.InterruptedException
Assert#assertNull(Object) check.filter - the Filter to usejava.lang.InterruptedExceptionprotected Configuration createConfigForCleanup(java.lang.String factoryPid,
java.lang.String location,
java.util.Dictionary<java.lang.String,java.lang.Object> props)
throws java.io.IOException
factoryPid - the factoryPid of the servicelocation - the location of the configurationprops - the properties for the servicejava.io.IOExceptionprotected Configuration createConfigForCleanup(java.lang.String factoryPid,
java.lang.String name,
java.lang.String location,
java.util.Dictionary<java.lang.String,java.lang.Object> props)
throws java.io.IOException
factoryPid - the factoryPid of the servicename - the addition configuration name of the servicelocation - the location of the configurationprops - the properties for the servicejava.io.IOExceptionprotected ServiceChecker<?> getServiceCheckerForConfiguration(Configuration configuration)
configuration - the configuration to get a tracker forServiceChecker or nullprotected void deleteConfigurationAndRemoveFromCleanup(Configuration config)
throws java.io.IOException
Configuration to deleteconfig - the Configuration to removejava.io.IOExceptionprotected void deleteConfigurationAndRemoveFromCleanupBlocking(Configuration config)
throws java.io.IOException,
java.lang.InterruptedException
Configuration to delete. The method will block, until it receives the notification, that the service is removed.
The method will throw a RuntimeException after 5 seconds if nothing happens.config - the Configuration to removejava.io.IOExceptionjava.lang.InterruptedExceptionprotected void deleteConfigurationBlocking(Configuration config)
throws java.io.IOException,
java.lang.InterruptedException
Configuration to delete. The method will block, until it receives the notification, that the service is removed.
The method will throw a RuntimeException after 5 seconds if nothing happens.config - the Configuration to removejava.io.IOExceptionjava.lang.InterruptedExceptionprotected void registerServiceForCleanup(java.lang.Object service,
java.util.Dictionary<java.lang.String,?> properties,
java.lang.Class<?> clazz)
unregisterService(Object) to unregister your service.service - the Service Object to registerproperties - the properties connected with this serviceclazz - the clazz to register the service underprotected void registerServiceForCleanup(java.lang.Class<?> clazz,
java.lang.Object service,
java.util.Dictionary<java.lang.String,?> properties)
unregisterService(Object) to unregister your service.service - the Service Object to registerproperties - the properties connected with this serviceclazz - the clazz to register the service underprotected void registerServiceForCleanup(java.lang.Object service,
java.util.Dictionary<java.lang.String,?> properties,
java.lang.String... classes)
unregisterService(Object) to unregister your service.service - the Service Object to registerproperties - the properties connected with this serviceclasses - the classes to register the service underpublic void updateServiceRegistration(java.lang.Object service,
java.util.Dictionary<java.lang.String,?> properties)
service - the service to updateproperties - the properties to usepublic java.util.Dictionary<java.lang.String,java.lang.Object> getServiceProperties(java.lang.Object service)
ServiceRegistration for the given Serviceservice - the service to look forprotected void unregisterService(java.lang.Object service)
ServiceRegistration. The service will then be unregistered.service - the service to unregister.protected Filter createFilter(java.util.Dictionary<java.lang.String,java.lang.Object> properties)
Dictionary given.properties - the Dictionary with the service properties.Filter Objectprotected <T> ServiceChecker<T> createCheckerTrackedForCleanUp(java.lang.Class<T> serviceClass)
filter - the OSGi filter String to create the checker withServiceCheckerInvalidSyntaxException - if the filter syntax is wrongprotected <T> ServiceChecker<T> createdCheckerTrackedForCleanUp(java.lang.String filter) throws InvalidSyntaxException
filter - the OSGi filter String to create the checker withServiceCheckerInvalidSyntaxException - if the filter syntax is wrongpublic void after()
throws java.lang.Exception
java.lang.Exceptionpublic abstract void doAfter()
public ConfigurationAdmin getConfigAdmin()
public BundleContext getBundleContext()
Data In Motion Consulting GmbH