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
  • Field Details

    • 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 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 returned Weld instance 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 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 returned AutoCloseable 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
    • iterator

      public Iterator<Object> iterator()
      Specified by:
      iterator in interface Iterable<Object>
    • get

      public Object get()
      Specified by:
      get in interface jakarta.inject.Provider<Object>
    • select

      public org.jboss.weld.inject.WeldInstance<Object> select(Annotation... qualifiers)
      Specified by:
      select in interface jakarta.enterprise.inject.Instance<Object>
    • select

      public <U> org.jboss.weld.inject.WeldInstance<U> select(Class<U> subtype, Annotation... qualifiers)
      Specified by:
      select in interface jakarta.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 interface jakarta.enterprise.inject.Instance<Object>
    • isUnsatisfied

      public boolean isUnsatisfied()
      Specified by:
      isUnsatisfied in interface jakarta.enterprise.inject.Instance<Object>
    • isAmbiguous

      public boolean isAmbiguous()
      Specified by:
      isAmbiguous in interface jakarta.enterprise.inject.Instance<Object>
    • destroy

      public void destroy(Object instance)
      Specified by:
      destroy in interface jakarta.enterprise.inject.Instance<Object>
    • getHandle

      public jakarta.enterprise.inject.Instance.Handle<Object> getHandle()
      Specified by:
      getHandle in interface jakarta.enterprise.inject.Instance<Object>
    • handles

      public Iterable<? extends jakarta.enterprise.inject.Instance.Handle<Object>> handles()
      Specified by:
      handles in interface jakarta.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 interface org.jboss.weld.environment.ContainerInstance
    • getId

      public String getId()
      Specified by:
      getId in interface org.jboss.weld.environment.ContainerInstance
    • shutdown

      public void shutdown()
      Note that any container-based operation will result in IllegalStateException after shutdown.
      Specified by:
      shutdown in interface org.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()