Jakarta Dependency Injection (DI) TCK
This project contains the Jakarta Dependency Injection TCK and user guide.
Software Requirements
-
A Java SE 11 or 8 runtime
-
Maven 3.3.x
Installation
Download the TCK zip and unpack it to create a jakarta-di-tck-x.y directory containing this README and a jakarta-di-tck-x.y.jar file containing the TCK classes.
Install the TCK jar Into Local Repo
Use the following command to install the TCK jar into your local maven repository:
mvn org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file \
-Dfile=<path-to-tck-jar>/jakarta.inject-tck-x.y.jar
making sure your replace <path-to-tck-jar> with the expanded download TCK archive directory and the x.y with the corresponding version found in the TCK download, e.g.:
mvn org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file \ -Dfile=jakarta.inject-tck-2.0.0/jakarta.inject-tck-2.0.0.jar
Running the TCK
The DI TCK expects to be embedded a JUnit 4.x Test suite that is bootstrapped from within the DI implementation being tested. An example that uses the 4.0.0-SNAPSHOT implementation and the standard Java SE bootstrap can be found in the example subdirectory. The Junit suite bootstrap code is as follows:
import junit.framework.Test;
import org.atinject.tck.Tck;
import org.atinject.tck.auto.Car;
import jakarta.enterprise.inject.se.SeContainer;
import jakarta.enterprise.inject.se.SeContainerInitializer;
public class SampleBootstrapTCK {
public static Test suite() {
SeContainer container = SeContainerInitializer.newInstance().initialize(); // (1)
Car tckCar = container.select(Car.class).get(); // (2)
return Tck.testsFor(tckCar, false, true); // (3)
}
}
-
Intialize the dependency container, in this case a CDI container.
-
Resolve the
org.atinject.tck.auto.Car
instance. -
Pass the fully resolved car instance to the DI TCK to build the full testsuite which validates the expected object relationships.
The full signature of the org.atinject.tck.Tck#testsFor(…)
method is:
/**
* Constructs a JUnit test suite for the given {@link Car} instance.
*
* @param Car to test
* @param supportsStatic true if the injector supports static member injection
* @param supportsPrivate true if the injector supports private member injection
*
* @throws NullPointerException if car is null
* @throws ClassCastException if car doesn't extend {@link Convertible Convertible}
*/
public static Test testsFor(Car car, boolean supportsStatic,
boolean supportsPrivate);
Configuring the DI Environment
The org.atinject.tck.Tck
class defines the expected conditions that need to be configured in the DI container in order for the tests to pass:
-
org.atinject.tck.auto.Car
is implemented byorg.atinject.tck.auto.Convertible
. -
@org.atinject.tck.auto.Drivers org.atinject.tck.auto.Seat1 is implemented by `org.atinject.tck.auto.DriversSeat DriversSeat
. -
org.atinject.tck.auto.Seat
is implemented byorg.atinject.tck.auto.Seat
itself, andorg.atinject.tck.auto.Tire
byorg.atinject.tck.auto.Tire
itself (not subclasses). -
org.atinject.tck.auto.Engine
is implemented byorg.atinject.tck.auto.V8Engine
. -
@jakarta.inject.Named("spare") org.atinject.tck.auto.Tire
is implemented byorg.atinject.tck.auto.accessories.SpareTire
. -
The following classes may also be injected directly:
-
org.atinject.tck.auto.accessories.Cupholder
-
org.atinject.tck.auto.accessories.SpareTire
and -
org.atinject.tck.auto.FuelTank
.
-
Static and private member injection support is optional, but if your injector supports those features, it must pass the respective tests. If static member injection is supported, the static members of the following types shall also be injected once:
-
org.atinject.tck.auto.Convertible
, -
org.atinject.tck.auto.Tire
, and -
org.atinject.tck.auto.accessories.SpareTire
.
The Weld example accomplishes this by excluding inspection of certain beans via a beans.xml and with a TCKProducers
class with producer methods that refine the values for the expected injection types.
Running the Example
You can run the Weld bootstrap example as follows:
Scotts-iMac:example starksm$ mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] -------------< jakarta.inject:jakarta.inject-tck-example >--------------
[INFO] Building Jakarta Dependency Injection API TCK Example 2.0.0
[INFO] --------------------------------[ jar ]---------------------------------
...
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running SampleBootstrapTCK
Jul 06, 2020 10:47:23 PM org.jboss.weld.bootstrap.WeldStartup <clinit>
INFO: WELD-000900: 4.0.0 (Alpha2)
Jul 06, 2020 10:47:23 PM org.jboss.weld.bootstrap.WeldStartup startContainer
INFO: WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
Jul 06, 2020 10:47:23 PM org.jboss.weld.environment.se.WeldContainer fireContainerInitializedEvent
INFO: WELD-ENV-002003: Weld SE container 8f6770d3-d00a-444d-97ec-b1b7d090512a initialized
[INFO] Tests run: 50, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.553 s - in SampleBootstrapTCK
Weld SE container 8f6770d3-d00a-444d-97ec-b1b7d090512a shut down by shutdown hook
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 50, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.276 s
[INFO] Finished at: 2020-07-06T22:47:24-05:00
[INFO] ------------------------------------------------------------------------
Where to file challenges
Challenges and bug reports should be filed against the TCK project issue tracker at https://github.com/eclipse-ee4j/injection-tck/issues