Package org.jboss.weld.junit
Class AbstractWeldInitiator
- java.lang.Object
-
- org.jboss.weld.junit.AbstractWeldInitiator
-
- All Implemented Interfaces:
jakarta.enterprise.inject.Instance<Object>
,jakarta.inject.Provider<Object>
,Iterable<Object>
,org.jboss.weld.environment.ContainerInstance
public abstract class AbstractWeldInitiator extends Object implements jakarta.enterprise.inject.Instance<Object>, org.jboss.weld.environment.ContainerInstance
- Author:
- Matej Novotny
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractWeldInitiator.AbstractBuilder<I extends AbstractWeldInitiator,T extends AbstractWeldInitiator.AbstractBuilder<I,T>>
protected class
AbstractWeldInitiator.ToInject
-
Field Summary
Fields Modifier and Type Field Description protected Set<jakarta.enterprise.inject.spi.Bean<?>>
beans
protected org.jboss.weld.environment.se.WeldContainer
container
protected org.jboss.weld.junit.WeldCDIExtension
extension
protected List<AbstractWeldInitiator.ToInject>
instancesToInject
protected Set<Class<? extends Annotation>>
scopesToActivate
protected org.jboss.weld.environment.se.Weld
weld
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractWeldInitiator(org.jboss.weld.environment.se.Weld weld, List<Object> instancesToInject, Set<Class<? extends Annotation>> scopesToActivate, Set<jakarta.enterprise.inject.spi.Bean<?>> beans, Map<String,Object> resources, Function<jakarta.enterprise.inject.spi.InjectionPoint,Object> ejbFactory, Function<jakarta.enterprise.inject.spi.InjectionPoint,Object> persistenceUnitFactory, Function<jakarta.enterprise.inject.spi.InjectionPoint,Object> persistenceContextFactory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.jboss.weld.environment.se.WeldContainer
container()
This method should be used when a Weld-specific API is needed.protected AbstractWeldInitiator.ToInject
createToInject(Object instanceToInject)
static org.jboss.weld.environment.se.Weld
createWeld()
The returnedWeld
instance has: automatic discovery disabled concurrent deployment disabledvoid
destroy(Object instance)
jakarta.enterprise.event.Event<Object>
event()
Allows to fire events.Object
get()
jakarta.enterprise.inject.spi.BeanManager
getBeanManager()
String
getId()
protected org.jboss.weld.environment.se.WeldContainer
initWeldContainer(org.jboss.weld.environment.se.Weld weld)
protected void
injectInstances()
AutoCloseable
injectNonContextual(Object target)
Injects the given non-contextual instance immediately.boolean
isAmbiguous()
boolean
isRunning()
boolean
isUnsatisfied()
Iterator<Object>
iterator()
protected void
releaseInstances()
<U> org.jboss.weld.inject.WeldInstance<U>
select(jakarta.enterprise.util.TypeLiteral<U> subtype, Annotation... qualifiers)
org.jboss.weld.inject.WeldInstance<Object>
select(Annotation... qualifiers)
<U> org.jboss.weld.inject.WeldInstance<U>
select(Class<U> subtype, Annotation... qualifiers)
void
shutdown()
Note that any container-based operation will result inIllegalStateException
after shutdown.protected void
shutdownWeldContainer()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
weld
protected final org.jboss.weld.environment.se.Weld weld
-
instancesToInject
protected final List<AbstractWeldInitiator.ToInject> instancesToInject
-
scopesToActivate
protected final Set<Class<? extends Annotation>> scopesToActivate
-
beans
protected final Set<jakarta.enterprise.inject.spi.Bean<?>> beans
-
extension
protected final org.jboss.weld.junit.WeldCDIExtension extension
-
container
protected volatile org.jboss.weld.environment.se.WeldContainer container
-
-
Constructor Detail
-
AbstractWeldInitiator
protected AbstractWeldInitiator(org.jboss.weld.environment.se.Weld weld, List<Object> instancesToInject, Set<Class<? extends Annotation>> scopesToActivate, Set<jakarta.enterprise.inject.spi.Bean<?>> beans, Map<String,Object> resources, Function<jakarta.enterprise.inject.spi.InjectionPoint,Object> ejbFactory, Function<jakarta.enterprise.inject.spi.InjectionPoint,Object> persistenceUnitFactory, Function<jakarta.enterprise.inject.spi.InjectionPoint,Object> persistenceContextFactory)
-
-
Method Detail
-
createWeld
public static org.jboss.weld.environment.se.Weld createWeld()
The returnedWeld
instance has:- automatic discovery disabled
- concurrent deployment disabled
- Returns:
- a new
Weld
instance suitable for testing
-
createToInject
protected AbstractWeldInitiator.ToInject createToInject(Object instanceToInject)
-
injectNonContextual
public AutoCloseable injectNonContextual(Object target)
Injects the given non-contextual instance immediately. The returnedAutoCloseable
should be used to release the creational context once the injected beans are no longer needed.Example:
try (AutoCloseable contextReleaser = injectNonContextual(this)) { // do some things with the injected instances }
- Parameters:
target
- the target to inject- Returns:
- an
AutoCloseable
to release the creational context
-
select
public org.jboss.weld.inject.WeldInstance<Object> select(Annotation... qualifiers)
- Specified by:
select
in interfacejakarta.enterprise.inject.Instance<Object>
-
select
public <U> org.jboss.weld.inject.WeldInstance<U> select(Class<U> subtype, Annotation... qualifiers)
- Specified by:
select
in interfacejakarta.enterprise.inject.Instance<Object>
-
select
public <U> org.jboss.weld.inject.WeldInstance<U> select(jakarta.enterprise.util.TypeLiteral<U> subtype, Annotation... qualifiers)
- Specified by:
select
in interfacejakarta.enterprise.inject.Instance<Object>
-
isUnsatisfied
public boolean isUnsatisfied()
- Specified by:
isUnsatisfied
in interfacejakarta.enterprise.inject.Instance<Object>
-
isAmbiguous
public boolean isAmbiguous()
- Specified by:
isAmbiguous
in interfacejakarta.enterprise.inject.Instance<Object>
-
destroy
public void destroy(Object instance)
- Specified by:
destroy
in interfacejakarta.enterprise.inject.Instance<Object>
-
event
public jakarta.enterprise.event.Event<Object> event()
Allows to fire events.- Returns:
- an event object
-
getBeanManager
public jakarta.enterprise.inject.spi.BeanManager getBeanManager()
- Specified by:
getBeanManager
in interfaceorg.jboss.weld.environment.ContainerInstance
-
getId
public String getId()
- Specified by:
getId
in interfaceorg.jboss.weld.environment.ContainerInstance
-
shutdown
public void shutdown()
Note that any container-based operation will result inIllegalStateException
after shutdown.- Specified by:
shutdown
in interfaceorg.jboss.weld.environment.ContainerInstance
-
isRunning
public boolean isRunning()
- Returns:
true
if the container was initialized completely and is not shut down yet,false
otherwise
-
container
public org.jboss.weld.environment.se.WeldContainer container()
This method should be used when a Weld-specific API is needed.- Returns:
- the underlying container instance
-
injectInstances
protected void injectInstances()
-
releaseInstances
protected void releaseInstances()
-
initWeldContainer
protected org.jboss.weld.environment.se.WeldContainer initWeldContainer(org.jboss.weld.environment.se.Weld weld)
-
shutdownWeldContainer
protected void shutdownWeldContainer()
-
-