Package org.apache.sling.junit.jupiter.osgi

# Annotation Type Service

@Retention(RUNTIME) @Target({TYPE,CONSTRUCTOR,METHOD,PARAMETER}) @Repeatable(Services.class) @Inherited public @interface Service
The `@Service` annotation is to be used for test classes or methods annotated with the `@OSGi` annotation. Note that tests using this annotation are expected to be run within an OSGi environment. It is a repeatable annotation and can be used to specify a number of different services using the `service type` and an optional `LDAP filter expression`.
Supported parameter types are the service type itself for unary references (1..1), a `Collection` or `List` of the service type for optional and multiple references (0..n).
Additionally it is possible to refine the cardinality by specifying the `cardinality` attribute in order to require or not the presence of at least one service instance, thus achieving cardinalities (0..1) and (1..n).
When used on a test class, the specified services are made available for injection as parameters to all of the test's methods.
When used on a test method, the specified services are made available for injection as parameters to exactly that method.
When used on a method parameter, the specified service is made available for injection for exactly that parameter. In this case, the `service type` need not be specified, it can be inferred from the parameter's type. However, it may still be useful to specify a filter expression.

See Also:
  - `ServiceCardinality`

## Optional Element Summary

Optional Elements
Modifier and Type
Optional Element
Description
`ServiceCardinality`
`cardinality`
Whether or not injection fails in the absence of a suitable service.
`String`
`filter`
An optional filter expression conforming to the LDAP filter syntax used in OSGi `Filter`s.
`Class<?>`
`value`
The type of the service to be injected.

## Element Details

### value

Class<?> value
The type of the service to be injected.
May be omitted if the annotation is used to annotate a method parameter, as the service type can be inferred from the parameter's type.

Returns:
  the service interface or class

Default:
  `java.lang.Object.class`

### filter

String filter
An optional filter expression conforming to the LDAP filter syntax used in OSGi `Filter`s.

Returns:
  the filter expression or an empty string if none is specified

Default:
  `""`

### cardinality

ServiceCardinality cardinality
Whether or not injection fails in the absence of a suitable service.

Returns:
  the desired cardinality for the injected service
See Also:
  - `ServiceCardinality`

Default:
  `AUTO`