Skip to content

Commit

Permalink
ArC: add AtInject TCK runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek committed Mar 3, 2023
1 parent f4a0cbd commit dfff4f9
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 0 deletions.
59 changes: 59 additions & 0 deletions independent-projects/arc/atinject-tck-runner/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.quarkus.arc</groupId>
<artifactId>arc-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>

<artifactId>arc-atinject-tck-runner</artifactId>
<name>ArC - AtInject TCK Runner</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${version.arquillian}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkus.arc</groupId>
<artifactId>arc-arquillian</artifactId>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-tck</artifactId>
<version>${version.atinject-tck}</version>
<exclusions>
<exclusion>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit4}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.quarkus.arc.tck;

import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension;
import jakarta.enterprise.inject.build.compatible.spi.ClassConfig;
import jakarta.enterprise.inject.build.compatible.spi.Discovery;
import jakarta.enterprise.inject.build.compatible.spi.Enhancement;
import jakarta.enterprise.inject.build.compatible.spi.MetaAnnotations;
import jakarta.enterprise.inject.build.compatible.spi.ScannedClasses;
import jakarta.enterprise.inject.literal.NamedLiteral;

import org.atinject.tck.auto.Convertible;
import org.atinject.tck.auto.Drivers;
import org.atinject.tck.auto.DriversSeat;
import org.atinject.tck.auto.FuelTank;
import org.atinject.tck.auto.Seat;
import org.atinject.tck.auto.Tire;
import org.atinject.tck.auto.V8Engine;
import org.atinject.tck.auto.accessories.Cupholder;
import org.atinject.tck.auto.accessories.SpareTire;

public class AtInjectTckExtension implements BuildCompatibleExtension {
@Discovery
public void discovery(ScannedClasses scan, MetaAnnotations meta) {
scan.add(Convertible.class.getName());
scan.add(DriversSeat.class.getName());
scan.add(FuelTank.class.getName());
scan.add(Seat.class.getName());
scan.add(Tire.class.getName());
scan.add(V8Engine.class.getName());

scan.add(Cupholder.class.getName());
scan.add(SpareTire.class.getName());
}

@Enhancement(types = Convertible.class)
public void convertible(ClassConfig clazz) {
clazz.fields()
.stream()
.filter(it -> "spareTire".equals(it.info().name()))
.forEach(it -> it.addAnnotation(Spare.class));
}

@Enhancement(types = DriversSeat.class)
public void driversSeat(ClassConfig clazz) {
clazz.addAnnotation(Drivers.class);
}

@Enhancement(types = SpareTire.class)
public void spareTire(ClassConfig clazz) {
clazz.addAnnotation(NamedLiteral.of("spare"))
.addAnnotation(Spare.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.quarkus.arc.tck;

import static org.junit.Assert.assertTrue;

import java.util.Enumeration;

import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension;

import org.atinject.tck.Tck;
import org.atinject.tck.auto.Car;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;

import io.quarkus.arc.Arc;

@RunWith(Arquillian.class)
public class AtInjectTest {
@Deployment
public static Archive<?> deployment() {
return ShrinkWrap.create(JavaArchive.class)
.addPackages(true, Tck.class.getPackage())
.addClasses(AtInjectTest.class, AtInjectTckExtension.class, Spare.class)
.addAsServiceProvider(BuildCompatibleExtension.class, AtInjectTckExtension.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}

@Test
public void test() {
Car instance = Arc.container().instance(Car.class).get();

junit.framework.Test test = Tck.testsFor(instance, /* supportsStatic */ false, /* supportsPrivate */ true);
junit.framework.TestResult result = new junit.framework.TestResult();
test.run(result);

// this is ugly and doesn't report failures properly, but I don't see a better way
if (!result.wasSuccessful()) {
int failuresCount = 0;
Enumeration<junit.framework.TestFailure> failures = result.failures();
while (failures.hasMoreElements()) {
System.out.println(failures.nextElement());
failuresCount++;
}

int errorsCount = 0;
Enumeration<junit.framework.TestFailure> errors = result.errors();
while (errors.hasMoreElements()) {
System.out.println(errors.nextElement());
errorsCount++;
}
System.out.println("Total " + failuresCount + " failures and " + errorsCount + " errors");
}

assertTrue(result.wasSuccessful());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkus.arc.tck;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import jakarta.inject.Qualifier;

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
public @interface Spare {
}
3 changes: 3 additions & 0 deletions independent-projects/arc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
<version.mutiny>2.1.0</version.mutiny>

<version.arquillian>1.7.0.Alpha14</version.arquillian>
<version.atinject-tck>2.0.1</version.atinject-tck>
<version.cdi-tck>4.0.7</version.cdi-tck>
<version.junit4>4.13.2</version.junit4>

<version.enforcer.plugin>3.2.1</version.enforcer.plugin>
<version.surefire.plugin>3.0.0-M9</version.surefire.plugin>
Expand All @@ -68,6 +70,7 @@
<module>tests</module>

<module>arquillian</module>
<module>atinject-tck-runner</module>
<module>cdi-tck-porting-pkg</module>
<module>cdi-tck-runner</module>
</modules>
Expand Down

0 comments on commit dfff4f9

Please sign in to comment.