Skip to content

jakartaee/inject-tck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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=/tmp/jakarta.inject-tck-2.0.1.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 5.0.0.CR2 Weld implementation and the standard Java SE bootstrap can be found in the example subdirectory. The Junit suite bootstrap code is as follows:

package weld;

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()
                .addExtensions(AtInjectTCKExtension.class)
                .addPackages(true, Tck.class)
                .initialize();
        Car tckCar = container.select(Car.class).get();
        return Tck.testsFor(tckCar, false, true);
    }
}
  1. Intialize the dependency container, in this case a CDI container.

  2. Resolve the org.atinject.tck.auto.Car instance.

  3. 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 by org.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 by org.atinject.tck.auto.Seat itself, and org.atinject.tck.auto.Tire by org.atinject.tck.auto.Tire itself (not subclasses).

  • org.atinject.tck.auto.Engine is implemented by org.atinject.tck.auto.V8Engine.

  • @jakarta.inject.Named("spare") org.atinject.tck.auto.Tire is implemented by org.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.1
[INFO] --------------------------------[ jar ]---------------------------------
...
[INFO] Building Jakarta Dependency Injection API TCK Example 2.0.1
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running weld.SampleBootstrapTCK
Jun 13, 2022 7:34:10 PM org.jboss.weld.bootstrap.WeldStartup <clinit>
INFO: WELD-000900: 5.0.0 (SP2)
Jun 13, 2022 7:34:11 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.
Added @Spare to [BackedAnnotatedField] @Inject org.atinject.tck.auto.Convertible.spareTire
Added @Drivers to: [BackedAnnotatedType] public  class org.atinject.tck.auto.DriversSeat
Added @Named('spare') to: [BackedAnnotatedType] public  class org.atinject.tck.auto.accessories.SpareTire
Jun 13, 2022 7:34:12 PM org.jboss.weld.environment.se.WeldContainer fireContainerInitializedEvent
INFO: WELD-ENV-002003: Weld SE container 19d8ee8b-cc7c-4131-930c-3350bb374196 initialized
[INFO] Tests run: 50, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.504 s - in weld.SampleBootstrapTCK
Weld SE container 19d8ee8b-cc7c-4131-930c-3350bb374196 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] ------------------------------------------------------------------------

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

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages