Skip to content

Commit

Permalink
Update the example TCK runner to work with Weld 5 after the remvoval …
Browse files Browse the repository at this point in the history
…of @New, #19

Signed-off-by: Scott M Stark <starksm64@gmail.com>
  • Loading branch information
starksm64 committed Jun 14, 2022
1 parent 2ef97bf commit e9c9767
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 138 deletions.
44 changes: 26 additions & 18 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ making sure your replace <path-to-tck-jar> with the expanded download TCK archiv
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
-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 4.0.0-SNAPSHOT implementation
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:

[source,java]
----
package weld;
import junit.framework.Test;
import org.atinject.tck.Tck;
import org.atinject.tck.auto.Car;
Expand All @@ -46,9 +48,14 @@ 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>
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);
}
}
----
Expand Down Expand Up @@ -113,22 +120,25 @@ 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] Building Jakarta Dependency Injection API TCK Example 2.0.1
[INFO] --------------------------------[ jar ]---------------------------------
...
[INFO]
[INFO] Building Jakarta Dependency Injection API TCK Example 2.0.1
[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] 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.
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
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]
Expand All @@ -137,9 +147,7 @@ Weld SE container 8f6770d3-d00a-444d-97ec-b1b7d090512a shut down by shutdown hoo
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.276 s
[INFO] Finished at: 2020-07-06T22:47:24-05:00
[INFO] ------------------------------------------------------------------------
----


Expand Down
3 changes: 1 addition & 2 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<properties>
<runSuite>**/SampleBootstrapTCK.class</runSuite>
<!-- Weld SE core version -->
<weld.version>4.0.0.Alpha2</weld.version>
<weld.version>5.0.0.SP2</weld.version>
<!-- dependency-injection api jar version -->
<atinject.version>2.0.0</atinject.version>
<maven.compiler.target>1.8</maven.compiler.target>
Expand Down Expand Up @@ -90,4 +90,3 @@
</plugins>
</build>
</project>

16 changes: 0 additions & 16 deletions example/src/test/java/SampleBootstrapTCK.java

This file was deleted.

93 changes: 0 additions & 93 deletions example/src/test/java/TCKProducers.java

This file was deleted.

72 changes: 72 additions & 0 deletions example/src/test/java/weld/AtInjectTCKExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2021, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package weld;

import org.atinject.tck.auto.Convertible;
import org.atinject.tck.auto.Drivers;
import org.atinject.tck.auto.DriversSeat;
import org.atinject.tck.auto.accessories.SpareTire;
import org.jboss.weld.literal.NamedLiteral;

import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.spi.Extension;
import jakarta.enterprise.inject.spi.ProcessAnnotatedType;
import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.inject.Qualifier;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class AtInjectTCKExtension implements Extension {
public void convertible(@Observes ProcessAnnotatedType<Convertible> pat) {
pat.configureAnnotatedType()
.filterFields(field -> "spareTire".equals(field.getJavaMember().getName()))
// add @Spare to the injection point, because the bean doesn't have @Default; see also below
.forEach(field -> {field.add(SpareLiteral.INSTANCE); System.out.printf("Added @Spare to %s\n", field.getAnnotated());});
}

public void driversSeat(@Observes ProcessAnnotatedType<DriversSeat> pat) {
pat.configureAnnotatedType()
.add(DriversLiteral.INSTANCE);
System.out.printf("Added @Drivers to: %s\n", pat.getAnnotatedType());
}

public void spareTire(@Observes ProcessAnnotatedType<SpareTire> pat) {
pat.configureAnnotatedType()
.add(new NamedLiteral("spare"))
// add @Spare to prevent adding @Default, otherwise there would be 2 beans for the Tire type
.add(SpareLiteral.INSTANCE);
System.out.printf("Added @Named('spare') to: %s\n", pat.getAnnotatedType());
}

static final class DriversLiteral extends AnnotationLiteral<Drivers> implements Drivers {
static final DriversLiteral INSTANCE = new DriversLiteral();

private DriversLiteral() {
}
}

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@interface Spare {
}

static final class SpareLiteral extends AnnotationLiteral<Spare> implements Spare {
static final SpareLiteral INSTANCE = new SpareLiteral();

private SpareLiteral() {
}
}
}
37 changes: 37 additions & 0 deletions example/src/test/java/weld/SampleBootstrapTCK.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2021, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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);
}
}
14 changes: 5 additions & 9 deletions example/src/test/resources/META-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<beans version="2.0"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd"
version="4.0"
bean-discovery-mode="all" >
<scan>
<exclude name="org.jboss.weld.**" />
<exclude name="org.atinject.tck.auto.DriversSeat" />
<exclude name="org.atinject.tck.auto.accessories.SpareTire" />
</scan>

</beans>

0 comments on commit e9c9767

Please sign in to comment.