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 ClassesModifier and TypeClassDescriptionprotected static classAbstractWeldInitiator.AbstractBuilder<I extends AbstractWeldInitiator,T extends AbstractWeldInitiator.AbstractBuilder<I, T>> protected classNested classes/interfaces inherited from interface jakarta.enterprise.inject.Instance
jakarta.enterprise.inject.Instance.Handle<T extends Object> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Set<jakarta.enterprise.inject.spi.Bean<?>>protected org.jboss.weld.environment.se.WeldContainerprotected final org.jboss.weld.junit.WeldCDIExtensionprotected final List<AbstractWeldInitiator.ToInject>protected final Set<Class<? extends Annotation>>protected final org.jboss.weld.environment.se.Weld -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractWeldInitiator(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
Modifier and TypeMethodDescriptionorg.jboss.weld.environment.se.WeldContainerThis method should be used when a Weld-specific API is needed.static org.jboss.weld.environment.se.WeldThe returnedWeldinstance has: automatic discovery disabled concurrent deployment disabledprotected AbstractWeldInitiator.ToInjectcreateToInject(Object instanceToInject) voidjakarta.enterprise.event.Event<Object>event()Allows to fire events.get()jakarta.enterprise.inject.spi.BeanManagerjakarta.enterprise.inject.Instance.Handle<Object>getId()handles()protected org.jboss.weld.environment.se.WeldContainerinitWeldContainer(org.jboss.weld.environment.se.Weld weld) protected voidinjectNonContextual(Object target) Injects the given non-contextual instance immediately.booleanbooleanbooleaniterator()protected void<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) voidshutdown()Note that any container-based operation will result inIllegalStateExceptionafter shutdown.protected voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jakarta.enterprise.inject.Instance
handlesStream, isResolvable, streamMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
weld
protected final org.jboss.weld.environment.se.Weld weld -
instancesToInject
-
scopesToActivate
-
beans
-
extension
protected final org.jboss.weld.junit.WeldCDIExtension extension -
container
protected volatile org.jboss.weld.environment.se.WeldContainer container
-
-
Constructor Details
-
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 Details
-
createDefaultWeld
public static org.jboss.weld.environment.se.Weld createDefaultWeld()The returnedWeldinstance has:- automatic discovery disabled
- concurrent deployment disabled
This method is not meant to be invoked directly! Use the
WeldInitiator#createWeld()of the given impl (JUnit 4/5, Spock).- Returns:
- a new
Weldinstance suitable for testing
-
createToInject
-
injectNonContextual
Injects the given non-contextual instance immediately. The returnedAutoCloseableshould 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
AutoCloseableto release the creational context
-
iterator
-
get
- Specified by:
getin interfacejakarta.inject.Provider<Object>
-
select
- Specified by:
selectin interfacejakarta.enterprise.inject.Instance<Object>
-
select
- Specified by:
selectin 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:
selectin interfacejakarta.enterprise.inject.Instance<Object>
-
isUnsatisfied
public boolean isUnsatisfied()- Specified by:
isUnsatisfiedin interfacejakarta.enterprise.inject.Instance<Object>
-
isAmbiguous
public boolean isAmbiguous()- Specified by:
isAmbiguousin interfacejakarta.enterprise.inject.Instance<Object>
-
destroy
- Specified by:
destroyin interfacejakarta.enterprise.inject.Instance<Object>
-
getHandle
- Specified by:
getHandlein interfacejakarta.enterprise.inject.Instance<Object>
-
handles
- Specified by:
handlesin interfacejakarta.enterprise.inject.Instance<Object>
-
event
Allows to fire events.- Returns:
- an event object
-
getBeanManager
public jakarta.enterprise.inject.spi.BeanManager getBeanManager()- Specified by:
getBeanManagerin interfaceorg.jboss.weld.environment.ContainerInstance
-
getId
- Specified by:
getIdin interfaceorg.jboss.weld.environment.ContainerInstance
-
shutdown
public void shutdown()Note that any container-based operation will result inIllegalStateExceptionafter shutdown.- Specified by:
shutdownin interfaceorg.jboss.weld.environment.ContainerInstance
-
isRunning
public boolean isRunning()- Returns:
trueif the container was initialized completely and is not shut down yet,falseotherwise
-
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()
-