Skip to content

Commit

Permalink
WELD-2757 Support inspectable CC and Contextual in CDI TCK SPI
Browse files Browse the repository at this point in the history
  • Loading branch information
manovotn committed Oct 25, 2023
1 parent 884e436 commit e063827
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 13 deletions.
4 changes: 2 additions & 2 deletions jboss-as/pom.xml
Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>cdi-tck-ext-lib</artifactId>
<version>${cdi.tck-4-0.version}</version>
<version>${cdi.tck-4-1.version}</version>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
Expand Down Expand Up @@ -314,7 +314,7 @@
<target>
<copy todir="${env.JBOSS_HOME}/standalone/lib/ext" overwrite="true">
<fileset dir="target/dependency/lib">
<include name="cdi-tck-ext-lib-${cdi.tck-4-0.version}.jar" />
<include name="cdi-tck-ext-lib-${cdi.tck-4-1.version}.jar" />
</fileset>
</copy>
</target>
Expand Down
14 changes: 7 additions & 7 deletions jboss-tck-runner/pom.xml
Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>cdi-tck-api</artifactId>
<version>${cdi.tck-4-0.version}</version>
<version>${cdi.tck-4-1.version}</version>
<exclusions>
<exclusion>
<groupId>jakarta.el</groupId>
Expand All @@ -82,7 +82,7 @@
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>cdi-tck-core-impl</artifactId>
<version>${cdi.tck-4-0.version}</version>
<version>${cdi.tck-4-1.version}</version>
<type>xml</type>
<classifier>suite</classifier>
<scope>test</scope>
Expand All @@ -105,7 +105,7 @@
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>cdi-tck-core-impl</artifactId>
<version>${cdi.tck-4-0.version}</version>
<version>${cdi.tck-4-1.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -260,7 +260,7 @@
<artifactItem>
<groupId>jakarta.enterprise</groupId>
<artifactId>cdi-tck-core-impl</artifactId>
<version>${cdi.tck-4-0.version}</version>
<version>${cdi.tck-4-1.version}</version>
<type>xml</type>
<classifier>suite</classifier>
<overWrite>false</overWrite>
Expand All @@ -269,7 +269,7 @@
<artifactItem>
<groupId>jakarta.enterprise</groupId>
<artifactId>cdi-tck-web-impl</artifactId>
<version>${cdi.tck-4-0.version}</version>
<version>${cdi.tck-4-1.version}</version>
<type>xml</type>
<classifier>suite</classifier>
<overWrite>false</overWrite>
Expand Down Expand Up @@ -378,7 +378,7 @@
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>cdi-tck-web-impl</artifactId>
<version>${cdi.tck-4-0.version}</version>
<version>${cdi.tck-4-1.version}</version>
<type>xml</type>
<classifier>suite</classifier>
<scope>test</scope>
Expand All @@ -401,7 +401,7 @@
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>cdi-tck-web-impl</artifactId>
<version>${cdi.tck-4-0.version}</version>
<version>${cdi.tck-4-1.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down
2 changes: 1 addition & 1 deletion lang-model-tck/pom.xml
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>cdi-tck-lang-model</artifactId>
<version>${cdi.tck-4-0.version}</version>
<version>${cdi.tck-4-1.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -61,7 +61,7 @@
<arquillian.jetty.version>1.0.0.Final</arquillian.jetty.version>
<atinject.tck.version>2.0.1</atinject.tck.version>
<!-- Version of the CDI 4.x release TCK -->
<cdi.tck-4-0.version>4.0.10</cdi.tck-4-0.version>
<cdi.tck-4-1.version>4.1.0.Alpha4</cdi.tck-4-1.version>
<!-- By default, each mvn profile uses corresponding file from TCK repo, see jboss-tck-runner/pom.xml -->
<!-- We can also use our own file, needed for relaxed mode testing (see WeldMethodInterceptor) -->
<!-- Our variant is under src/test/tck/tck-tests.xml -->
Expand Down
2 changes: 1 addition & 1 deletion porting-package/pom.xml
Expand Up @@ -44,7 +44,7 @@
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>cdi-tck-api</artifactId>
<version>${cdi.tck-4-0.version}</version>
<version>${cdi.tck-4-1.version}</version>
<exclusions>
<exclusion>
<groupId>jakarta.el</groupId>
Expand Down
@@ -0,0 +1,52 @@
package org.jboss.weld.tck;

import jakarta.enterprise.context.spi.Context;
import jakarta.enterprise.context.spi.CreationalContext;

import org.jboss.cdi.tck.spi.Contextuals;

public class ContextualsImpl implements Contextuals {
@Override
public <T> Inspectable<T> create(T instance, Context context) {
return new InspectableContextual<>(instance);
}

static class InspectableContextual<T> implements Inspectable<T> {
private final T instanceToReturn;

private CreationalContext<T> createCC;
private T destroyInstance;
private CreationalContext<T> destroyCC;

InspectableContextual(T instanceToReturn) {
this.instanceToReturn = instanceToReturn;
}

@Override
public T create(CreationalContext<T> creationalContext) {
createCC = creationalContext;
return instanceToReturn;
}

@Override
public void destroy(T instance, CreationalContext<T> creationalContext) {
destroyInstance = instance;
destroyCC = creationalContext;
}

@Override
public CreationalContext<T> getCreationalContextPassedToCreate() {
return createCC;
}

@Override
public T getInstancePassedToDestroy() {
return destroyInstance;
}

@Override
public CreationalContext<T> getCreationalContextPassedToDestroy() {
return destroyCC;
}
}
}
@@ -0,0 +1,57 @@
package org.jboss.weld.tck;

import jakarta.enterprise.context.spi.Contextual;

import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.weld.contexts.CreationalContextImpl;

public class CreationalContextsImpl implements CreationalContexts {
@Override
public <T> Inspectable<T> create(Contextual<T> contextual) {
return new InspectableCreationalContext<>(contextual);
}

static class InspectableCreationalContext<T> extends CreationalContextImpl<T> implements Inspectable<T> {
private Object lastBeanPushed = null;
private boolean pushCalled = false;
private boolean releaseCalled = false;

public InspectableCreationalContext(Contextual<T> contextual) {
super(contextual);
}

public void push(T incompleteInstance) {
pushCalled = true;
lastBeanPushed = incompleteInstance;
super.push(incompleteInstance);
}

public Object getLastBeanPushed() {
return lastBeanPushed;
}

public boolean isPushCalled() {
return pushCalled;
}

public boolean isReleaseCalled() {
return releaseCalled;
}

/**
* We need to override this method because internally, Weld uses this enhanced method to release CCs so long
* as the CC is instance of {@link org.jboss.weld.contexts.WeldCreationalContext} which will hold true for
* this impl as well.
*/
public void release(Contextual<T> contextual, T instance) {
releaseCalled = true;
super.release(contextual, instance);
}

public void release() {
releaseCalled = true;
super.release();
}

}
}
@@ -1,4 +1,6 @@
# CDI TCK configuration - porting package
org.jboss.cdi.tck.spi.Beans=org.jboss.weld.tck.BeansImpl
org.jboss.cdi.tck.spi.Contexts=org.jboss.weld.tck.ContextsImpl
org.jboss.cdi.tck.spi.EL=org.jboss.weld.tck.ELImpl
org.jboss.cdi.tck.spi.EL=org.jboss.weld.tck.ELImpl
org.jboss.cdi.tck.spi.CreationalContexts=org.jboss.weld.tck.CreationalContextsImpl
org.jboss.cdi.tck.spi.Contextuals=org.jboss.weld.tck.ContextualsImpl

0 comments on commit e063827

Please sign in to comment.