Class TestContainer


  • public class TestContainer
    extends Object

    Wrapper over Weld, exposing operations commonly required for executing tests with Weld. TestContainer exposes a "Mock Java EE 6" view of Weld, allowing Weld to discover EE components, but not to invoke them.

    In general, we recommend using Arquillian to test CDI/Weld applications, however sometimes it useful to have greater control over the test, and in that case you may wish to use TestContainer.

    Note that we can easily mix fine-grained calls to bootstrap, and coarse grained calls to TestContainer.

    Author:
    Pete Muir
    • Constructor Detail

      • TestContainer

        public TestContainer​(org.jboss.weld.bootstrap.spi.BeansXml beansXml,
                             Collection<Class<?>> classes)
        Create a container, specifying the classes and beans.xml to deploy
        Parameters:
        lifecycle -
        classes -
        beansXml -
      • TestContainer

        public TestContainer​(String beanArchiveId,
                             org.jboss.weld.bootstrap.spi.BeansXml beansXml,
                             Collection<Class<?>> classes)
      • TestContainer

        public TestContainer​(String beanArchiveId,
                             org.jboss.weld.bootstrap.spi.BeansXml beansXml,
                             Collection<Class<?>> classes,
                             org.jboss.weld.bootstrap.api.Environment environment,
                             boolean merge)
      • TestContainer

        public TestContainer​(org.jboss.weld.bootstrap.spi.BeansXml beansXml,
                             Class<?>... classes)
        Create a container, specifying the classes and beans.xml to deploy
        Parameters:
        lifecycle -
        classes -
        beansXml -
      • TestContainer

        public TestContainer​(Class<?>... classes)
      • TestContainer

        public TestContainer​(org.jboss.weld.bootstrap.spi.Deployment deployment)
    • Method Detail

      • ensureRequestActive

        public TestContainer ensureRequestActive()
      • startContainer

        public TestContainer startContainer​(org.jboss.weld.bootstrap.api.Environment environment)
        Starts the container and begins the application
      • getBeanManager

        public org.jboss.weld.manager.api.WeldManager getBeanManager​(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive beanDeploymentArchive)
      • getDeployment

        public org.jboss.weld.bootstrap.spi.Deployment getDeployment()
      • stopContainer

        public TestContainer stopContainer()
        Clean up the container, ending any active contexts
      • instance

        public jakarta.enterprise.inject.Instance<jakarta.enterprise.context.spi.Context> instance()
      • getBootstrap

        public org.jboss.weld.bootstrap.api.Bootstrap getBootstrap()