-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WELD-2757 Support inspectable CC and Contextual in CDI TCK SPI
- Loading branch information
Showing
8 changed files
with
124 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
porting-package/src/main/java/org/jboss/weld/tck/ContextualsImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
porting-package/src/main/java/org/jboss/weld/tck/CreationalContextsImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
porting-package/src/main/resources/META-INF/cdi-tck.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |