Class MockOsgi
java.lang.Object
org.apache.sling.testing.mock.osgi.MockOsgi
Factory for mock OSGi objects.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanSimulates activation of a DS component instance.static booleanactivate(@NotNull Object target, @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull Object @NotNull ... properties) Simulates activation of a DS component instance.static booleanactivate(@NotNull Object target, @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable Dictionary<String, Object> properties) Simulates activation of a DS component instance.static booleanactivate(@NotNull Object target, @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable Map<String, Object> properties) Simulates activation of a DS component instance.static <T> TactivateInjectServices(@NotNull Class<T> targetClass, @NotNull org.osgi.framework.BundleContext bundleContext) Simulates OSGi DS dependency injection and activation.static <T> TactivateInjectServices(@NotNull Class<T> targetClass, @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull Object @NotNull ... properties) Simulates OSGi DS dependency injection and activation.static <T> TactivateInjectServices(@NotNull Class<T> targetClass, @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable Map<String, Object> properties) Simulates OSGi DS dependency injection and activation.static @NotNull ComponentContextBuilderstatic booleandeactivate(@NotNull Object target, @NotNull org.osgi.framework.BundleContext bundleContext) Simulates deactivation of a DS component instance.static booleandeactivate(@NotNull Object target, @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull Object @NotNull ... properties) Simulates deactivation of a DS component instance.static booleandeactivate(@NotNull Object target, @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable Dictionary<String, Object> properties) Simulates deactivation of a DS component instance.static booleandeactivate(@NotNull Object target, @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable Map<String, Object> properties) Simulates deactivation of a DS component instance.static booleaninjectServices(@NotNull Object target, @NotNull org.osgi.framework.BundleContext bundleContext) Simulates OSGi DS dependency injection.static booleaninjectServices(@NotNull Object target, @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable Map<String, Object> properties) Simulates OSGi DS dependency injection.static booleanmodified(@NotNull Object target, @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull Object @NotNull ... properties) Simulates configuration modification of a DS component instance.static booleanmodified(@NotNull Object target, @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable Dictionary<String, Object> properties) Simulates configuration modification of a DS component instance.static booleanmodified(@NotNull Object target, @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable Map<String, Object> properties) Simulates configuration modification of a DS component instance.static @NotNull org.osgi.framework.BundleContextstatic @NotNull org.osgi.service.component.ComponentContextstatic @NotNull org.osgi.service.component.ComponentContextnewComponentContext(@NotNull Object @NotNull ... properties) static @NotNull org.osgi.service.component.ComponentContextnewComponentContext(@NotNull org.osgi.framework.BundleContext bundleContext, @NotNull Object @NotNull ... properties) static @NotNull org.osgi.service.component.ComponentContextnewComponentContext(@NotNull org.osgi.framework.BundleContext bundleContext, @Nullable Dictionary<String, Object> properties) static @NotNull org.osgi.service.component.ComponentContextnewComponentContext(@NotNull org.osgi.framework.BundleContext bundleContext, @Nullable Map<String, Object> properties) static @NotNull org.osgi.service.component.ComponentContextnewComponentContext(@Nullable Dictionary<String, Object> properties) static @NotNull org.osgi.service.component.ComponentContextnewComponentContext(@Nullable Map<String, Object> properties) static @NotNull org.osgi.service.log.LogServicenewLogService(@NotNull Class<?> loggerContext) static final <T> TregisterInjectActivateService(@NotNull Class<T> dsComponentClass, @NotNull org.osgi.framework.BundleContext bundleContext) Injects dependencies, activates and registers a DS component in the mocked OSGi environment.static final <T> TregisterInjectActivateService(@NotNull Class<T> dsComponentClass, @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull Object @NotNull ... properties) Injects dependencies, activates and registers a DS component in the mocked OSGi environment.static final <T> TregisterInjectActivateService(@NotNull Class<T> dsComponentClass, @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable Map<String, Object> properties) Injects dependencies, activates and registers a DS component in the mocked OSGi environment.static final <T> voidregisterInjectActivateService(T component, @NotNull org.osgi.framework.BundleContext bundleContext) Injects dependencies, activates and registers a DS component in the mocked OSGi environment.static final <T> voidregisterInjectActivateService(T component, @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull Object @NotNull ... properties) Injects dependencies, activates and registers a DS component in the mocked OSGi environment.static final <T> voidregisterInjectActivateService(T component, @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable Map<String, Object> properties) Injects dependencies, activates and registers a DS component in the mocked OSGi environment.static voidsendBundleEvent(@NotNull org.osgi.framework.BundleContext bundleContext, @NotNull org.osgi.framework.BundleEvent bundleEvent) Simulates a bundle event on the given bundle context (that is forwarded to registered bundle listeners).static voidsetConfigForPid(@NotNull org.osgi.framework.BundleContext bundleContext, @NotNull String pid, @NotNull Object @NotNull ... properties) Set configuration via ConfigurationAdmin service in bundle context for component with given pid.static voidsetConfigForPid(@NotNull org.osgi.framework.BundleContext bundleContext, @NotNull String pid, @Nullable Map<String, Object> properties) Set configuration via ConfigurationAdmin service in bundle context for component with given pid.static voidshutdown(@NotNull org.osgi.framework.BundleContext bundleContext) Deactivates all bundles registered in the mocked bundle context.
-
Method Details
-
newBundleContext
@NotNull public static @NotNull org.osgi.framework.BundleContext newBundleContext()- Returns:
- Mocked
BundleContextinstance
-
sendBundleEvent
public static void sendBundleEvent(@NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull @NotNull org.osgi.framework.BundleEvent bundleEvent) Simulates a bundle event on the given bundle context (that is forwarded to registered bundle listeners).- Parameters:
bundleContext- Bundle contextbundleEvent- Bundle event
-
newComponentContext
@NotNull public static @NotNull org.osgi.service.component.ComponentContext newComponentContext()- Returns:
- Mocked
ComponentContextinstance
-
newComponentContext
@NotNull public static @NotNull org.osgi.service.component.ComponentContext newComponentContext(@Nullable @Nullable Dictionary<String, Object> properties) - Parameters:
properties- Properties- Returns:
- Mocked
ComponentContextinstance
-
newComponentContext
@NotNull public static @NotNull org.osgi.service.component.ComponentContext newComponentContext(@Nullable @Nullable Map<String, Object> properties) - Parameters:
properties- Properties- Returns:
- Mocked
ComponentContextinstance
-
newComponentContext
@NotNull public static @NotNull org.osgi.service.component.ComponentContext newComponentContext(@NotNull @NotNull Object @NotNull ... properties) - Parameters:
properties- Properties- Returns:
- Mocked
ComponentContextinstance
-
newComponentContext
@NotNull public static @NotNull org.osgi.service.component.ComponentContext newComponentContext(@NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable @Nullable Dictionary<String, Object> properties) - Parameters:
bundleContext- Bundle contextproperties- Properties- Returns:
- Mocked
ComponentContextinstance
-
newComponentContext
@NotNull public static @NotNull org.osgi.service.component.ComponentContext newComponentContext(@NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable @Nullable Map<String, Object> properties) - Parameters:
bundleContext- Bundle contextproperties- Properties- Returns:
- Mocked
ComponentContextinstance
-
newComponentContext
@NotNull public static @NotNull org.osgi.service.component.ComponentContext newComponentContext(@NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull @NotNull Object @NotNull ... properties) - Parameters:
bundleContext- Bundle contextproperties- Properties- Returns:
- Mocked
ComponentContextinstance
-
componentContext
- Returns:
ComponentContextBuilderto build a mockedComponentContext
-
newLogService
@NotNull public static @NotNull org.osgi.service.log.LogService newLogService(@NotNull @NotNull Class<?> loggerContext) - Parameters:
loggerContext- Context class for logging- Returns:
- Mocked
LogServiceinstance
-
injectServices
public static boolean injectServices(@NotNull @NotNull Object target, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext) Simulates OSGi DS dependency injection. Injects direct references and multiple references. If a some references could not be injected no error is thrown.- Parameters:
target- Service instancebundleContext- Bundle context from which services are fetched to inject.- Returns:
- true if all dependencies could be injected, false if the service has no dependencies.
-
injectServices
public static boolean injectServices(@NotNull @NotNull Object target, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable @Nullable Map<String, Object> properties) Simulates OSGi DS dependency injection. Injects direct references and multiple references. If a some references could not be injected no error is thrown.- Parameters:
target- Service instancebundleContext- Bundle context from which services are fetched to inject.properties- Service properties (used to resolve dynamic reference properties)- Returns:
- true if all dependencies could be injected, false if the service has no dependencies.
-
activateInjectServices
@NotNull public static <T> T activateInjectServices(@NotNull @NotNull Class<T> targetClass, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext) Simulates OSGi DS dependency injection and activation. Injects direct references and multiple references. If a some references could not be injected no error is thrown. This method instantiates the service instance and also supports constructor injection.- Type Parameters:
T- Target class type- Parameters:
targetClass- Component/service classbundleContext- Bundle context from which services are fetched to inject.- Returns:
- Component/service instances with injected services
-
activateInjectServices
@NotNull public static <T> T activateInjectServices(@NotNull @NotNull Class<T> targetClass, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable @Nullable Map<String, Object> properties) Simulates OSGi DS dependency injection and activation. Injects direct references and multiple references. If a some references could not be injected no error is thrown. This method instantiates the service instance and also supports constructor injection.- Type Parameters:
T- Target class type- Parameters:
targetClass- Component/service classbundleContext- Bundle context from which services are fetched to inject.properties- Service properties (used to resolve dynamic reference properties)- Returns:
- Component/service instances with injected services
-
activateInjectServices
@NotNull public static <T> T activateInjectServices(@NotNull @NotNull Class<T> targetClass, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull @NotNull Object @NotNull ... properties) Simulates OSGi DS dependency injection and activation. Injects direct references and multiple references. If a some references could not be injected no error is thrown. This method instantiates the service instance and also supports constructor injection.- Type Parameters:
T- Target class type- Parameters:
targetClass- Component/service classbundleContext- Bundle context from which services are fetched to inject.properties- Service properties (used to resolve dynamic reference properties)- Returns:
- Component/service instances with injected services
-
registerInjectActivateService
@NotNull public static final <T> void registerInjectActivateService(@NotNull T component, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext) Injects dependencies, activates and registers a DS component in the mocked OSGi environment.- Type Parameters:
T- DS Component type- Parameters:
component- a DS component instancebundleContext- Bundle context from which services are fetched to inject and which is used for registering new services
-
registerInjectActivateService
@NotNull public static final <T> void registerInjectActivateService(@NotNull T component, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable @Nullable Map<String, Object> properties) Injects dependencies, activates and registers a DS component in the mocked OSGi environment.- Type Parameters:
T- DS Component type- Parameters:
component- a DS component instancebundleContext- Bundle context from which services are fetched to inject and which is used for registering new servicesproperties- component properties (optional)
-
registerInjectActivateService
@NotNull public static final <T> void registerInjectActivateService(@NotNull T component, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull @NotNull Object @NotNull ... properties) Injects dependencies, activates and registers a DS component in the mocked OSGi environment.- Type Parameters:
T- DS Component type- Parameters:
component- a DS component instancebundleContext- Bundle context from which services are fetched to inject and which is used for registering new services.properties- component properties (optional)
-
registerInjectActivateService
@NotNull public static final <T> T registerInjectActivateService(@NotNull @NotNull Class<T> dsComponentClass, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext) Injects dependencies, activates and registers a DS component in the mocked OSGi environment.- Type Parameters:
T- DS component type- Parameters:
dsComponentClass- DS component classbundleContext- Bundle context from which services are fetched to inject and which is used for registering new services- Returns:
- Registered component instance
-
registerInjectActivateService
@NotNull public static final <T> T registerInjectActivateService(@NotNull @NotNull Class<T> dsComponentClass, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable @Nullable Map<String, Object> properties) Injects dependencies, activates and registers a DS component in the mocked OSGi environment.- Type Parameters:
T- DS component type- Parameters:
dsComponentClass- DS component classbundleContext- Bundle context from which services are fetched to inject and which is used for registering new servicesproperties- component properties (optional)- Returns:
- Registered component instance
-
registerInjectActivateService
@NotNull public static final <T> T registerInjectActivateService(@NotNull @NotNull Class<T> dsComponentClass, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull @NotNull Object @NotNull ... properties) Injects dependencies, activates and registers a DS component in the mocked OSGi environment.- Type Parameters:
T- DS component type- Parameters:
dsComponentClass- DS component classbundleContext- Bundle context from which services are fetched to inject and which is used for registering new servicesproperties- component properties (optional)- Returns:
- Registered component instance
-
activate
public static boolean activate(@NotNull @NotNull Object target, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext) Simulates activation of a DS component instance. Invokes the @Activate annotated method.- Parameters:
target- DS component instancebundleContext- Bundle context- Returns:
- true if activation method was called. False if no activate method is defined.
-
activate
public static boolean activate(@NotNull @NotNull Object target, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable @Nullable Dictionary<String, Object> properties) Simulates activation of a DS component instance. Invokes the @Activate annotated method.- Parameters:
target- DS component instancebundleContext- Bundle contextproperties- Properties- Returns:
- true if activation method was called. False if no activate method is defined.
-
activate
public static boolean activate(@NotNull @NotNull Object target, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable @Nullable Map<String, Object> properties) Simulates activation of a DS component instance. Invokes the @Activate annotated method.- Parameters:
target- DS component instancebundleContext- Bundle contextproperties- Properties- Returns:
- true if activation method was called. False if no activate method is defined.
-
activate
public static boolean activate(@NotNull @NotNull Object target, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull @NotNull Object @NotNull ... properties) Simulates activation of a DS component instance. Invokes the @Activate annotated method.- Parameters:
target- DS component instancebundleContext- Bundle contextproperties- Properties- Returns:
- true if activation method was called. False if no activate method is defined.
-
deactivate
public static boolean deactivate(@NotNull @NotNull Object target, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext) Simulates deactivation of a DS component instance. Invokes the @Deactivate annotated method.- Parameters:
target- Service instance.bundleContext- Bundle context.- Returns:
- true if deactivation method was called. False if no deactivate method is defined.
-
deactivate
public static boolean deactivate(@NotNull @NotNull Object target, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable @Nullable Dictionary<String, Object> properties) Simulates deactivation of a DS component instance. Invokes the @Deactivate annotated method.- Parameters:
target- DS component instancebundleContext- Bundle contextproperties- Properties- Returns:
- true if deactivation method was called. False if no deactivate method is defined.
-
deactivate
public static boolean deactivate(@NotNull @NotNull Object target, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable @Nullable Map<String, Object> properties) Simulates deactivation of a DS component instance. Invokes the @Deactivate annotated method.- Parameters:
target- DS component instancebundleContext- Bundle contextproperties- Properties- Returns:
- true if deactivation method was called. False if no deactivate method is defined.
-
deactivate
public static boolean deactivate(@NotNull @NotNull Object target, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull @NotNull Object @NotNull ... properties) Simulates deactivation of a DS component instance. Invokes the @Deactivate annotated method.- Parameters:
target- DS component instancebundleContext- Bundle contextproperties- Properties- Returns:
- true if deactivation method was called. False if no deactivate method is defined.
-
modified
public static boolean modified(@NotNull @NotNull Object target, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable @Nullable Dictionary<String, Object> properties) Simulates configuration modification of a DS component instance. Invokes the @Modified annotated method.- Parameters:
target- DS component instancebundleContext- Bundle contextproperties- Properties- Returns:
- true if modified method was called. False if no modified method is defined.
-
modified
public static boolean modified(@NotNull @NotNull Object target, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @Nullable @Nullable Map<String, Object> properties) Simulates configuration modification of a DS component instance. Invokes the @Modified annotated method.- Parameters:
target- DS component instancebundleContext- Bundle contextproperties- Properties- Returns:
- true if modified method was called. False if no modified method is defined.
-
modified
public static boolean modified(@NotNull @NotNull Object target, @NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull @NotNull Object @NotNull ... properties) Simulates configuration modification of a DS component instance. Invokes the @Modified annotated method.- Parameters:
target- DS component instancebundleContext- Bundle contextproperties- Properties- Returns:
- true if modified method was called. False if no modified method is defined.
-
setConfigForPid
public static void setConfigForPid(@NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull @NotNull String pid, @Nullable @Nullable Map<String, Object> properties) Set configuration via ConfigurationAdmin service in bundle context for component with given pid.- Parameters:
bundleContext- Bundle contextpid- PIDproperties- Configuration properties
-
setConfigForPid
public static void setConfigForPid(@NotNull @NotNull org.osgi.framework.BundleContext bundleContext, @NotNull @NotNull String pid, @NotNull @NotNull Object @NotNull ... properties) Set configuration via ConfigurationAdmin service in bundle context for component with given pid.- Parameters:
bundleContext- Bundle contextpid- PIDproperties- Configuration properties
-
shutdown
public static void shutdown(@NotNull @NotNull org.osgi.framework.BundleContext bundleContext) Deactivates all bundles registered in the mocked bundle context.- Parameters:
bundleContext- Bundle context
-