public class WeldInitiator extends Object implements org.junit.rules.TestRule, org.jboss.weld.inject.WeldInstance<Object>, org.jboss.weld.environment.ContainerInstance
public class SimpleTest {
@Rule
public WeldInitiator weld = WeldInitiator.of(Foo.class);
@Test
public void testFoo() {
// Weld container is started automatically
// WeldInitiator can be used to perform programmatic lookup of beans
assertEquals("baz", weld.select(Foo.class).get().getBaz());
}
}
WeldInitiator implements Instance and therefore might be used to perform programmatic lookup of bean instances.
| Modifier and Type | Class and Description |
|---|---|
static class |
WeldInitiator.Builder
This builder can be used to customize the final
WeldInitiator instance, e.g. to activate a context for a given normal scope. |
| Modifier and Type | Method and Description |
|---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description) |
static org.jboss.weld.environment.se.Weld |
createWeld()
The returned
Weld instance has:
automatic discovery disabled
concurrent deployment disabled
|
void |
destroy(Object instance) |
javax.enterprise.event.Event<Object> |
event()
Allows to fire events.
|
static WeldInitiator.Builder |
from(Class<?>... beanClasses)
Create a builder instance.
|
static WeldInitiator.Builder |
from(org.jboss.weld.environment.se.Weld weld)
Create a builder instance.
|
static WeldInitiator.Builder |
fromTestPackage()
Create a builder instance.
|
Object |
get() |
javax.enterprise.inject.spi.BeanManager |
getBeanManager() |
org.jboss.weld.inject.WeldInstance.Handler<Object> |
getHandler() |
String |
getId() |
Iterable<org.jboss.weld.inject.WeldInstance.Handler<Object>> |
handlers() |
boolean |
isAmbiguous() |
boolean |
isResolvable() |
boolean |
isRunning() |
boolean |
isUnsatisfied() |
Iterator<Object> |
iterator() |
static WeldInitiator |
of(Class<?>... beanClasses)
The container is configured with the result of
createWeld() method and the given bean classes are added. |
static WeldInitiator |
of(org.jboss.weld.environment.se.Weld weld)
The container is configured through a provided
Weld instance. |
static WeldInitiator |
ofTestPackage()
The container is configured with the result of
createWeld() method and all the classes from the test class package are added. |
org.jboss.weld.inject.WeldInstance<Object> |
select(Annotation... qualifiers) |
<U> org.jboss.weld.inject.WeldInstance<U> |
select(Class<U> subtype,
Annotation... qualifiers) |
<U> org.jboss.weld.inject.WeldInstance<U> |
select(javax.enterprise.util.TypeLiteral<U> subtype,
Annotation... qualifiers) |
void |
shutdown()
Note that any container-based operation will result in
IllegalStateException after shutdown. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic static WeldInitiator of(Class<?>... beanClasses)
createWeld() method and the given bean classes are added.beanClasses - Weld.beanClasses(Class...)public static WeldInitiator of(org.jboss.weld.environment.se.Weld weld)
Weld instance.weld - public static WeldInitiator ofTestPackage()
createWeld() method and all the classes from the test class package are added.public static org.jboss.weld.environment.se.Weld createWeld()
Weld instance has:
Weld instance suitable for testingpublic static WeldInitiator.Builder from(Class<?>... beanClasses)
weld - of(Class...)public static WeldInitiator.Builder from(org.jboss.weld.environment.se.Weld weld)
weld - of(Weld)public static WeldInitiator.Builder fromTestPackage()
ofTestPackage()public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description)
apply in interface org.junit.rules.TestRulepublic org.jboss.weld.inject.WeldInstance<Object> select(Annotation... qualifiers)
public <U> org.jboss.weld.inject.WeldInstance<U> select(Class<U> subtype, Annotation... qualifiers)
public <U> org.jboss.weld.inject.WeldInstance<U> select(javax.enterprise.util.TypeLiteral<U> subtype,
Annotation... qualifiers)
public boolean isUnsatisfied()
isUnsatisfied in interface javax.enterprise.inject.Instance<Object>public boolean isAmbiguous()
isAmbiguous in interface javax.enterprise.inject.Instance<Object>public org.jboss.weld.inject.WeldInstance.Handler<Object> getHandler()
getHandler in interface org.jboss.weld.inject.WeldInstance<Object>public boolean isResolvable()
isResolvable in interface org.jboss.weld.inject.WeldInstance<Object>public Iterable<org.jboss.weld.inject.WeldInstance.Handler<Object>> handlers()
handlers in interface org.jboss.weld.inject.WeldInstance<Object>public void destroy(Object instance)
destroy in interface javax.enterprise.inject.Instance<Object>public javax.enterprise.event.Event<Object> event()
public javax.enterprise.inject.spi.BeanManager getBeanManager()
getBeanManager in interface org.jboss.weld.environment.ContainerInstancepublic String getId()
getId in interface org.jboss.weld.environment.ContainerInstancepublic void shutdown()
IllegalStateException after shutdown.shutdown in interface org.jboss.weld.environment.ContainerInstancepublic boolean isRunning()
true if the container was initialized completely and is not shut down yet, false otherwiseCopyright © 2017. All rights reserved.