|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.caucho.resin.ResinBeanContainer
public class ResinBeanContainer
Embeddable Resin context for testing of bean container components (CDI
managed beans, EJBs, JPA) in an environment that mirrors a production runtime
but without the overhead of the Resin server. The ResinBeanContainer can be
embedded into any Java SE environment, including a JUnit test. Note, the bean
container does not support Servlet-based APIs. In order to test the web tier,
ResinEmbed
should be used.
static void main(String []args)
{
ResinBeanContainer beans = new ResinBeanContainer();
beans.addModule("test.jar");
beans.start();
RequestContext req = beans.beginRequest();
try {
MyMain main = beans.getInstance(MyMain.class);
main.main(args);
} finally {
req.close();
}
beans.close();
}
<beans xmlns="http://caucho.com/ns/resin"
xmlns:resin="urn:java:com.caucho.resin">
<resin:import path="${__DIR__}/my-include.xml"/>
<database name="my-database">
<driver ...>
...
</driver>
</database>
<mypkg:MyBean xmlns:mypkg="urn:java:com.mycom.mypkg">
<my-property>my-data</my-property>
</mypkg:MyBean>
</beans>
Constructor Summary | |
---|---|
ResinBeanContainer()
Creates a new Resin context. |
Method Summary | ||
---|---|---|
void |
addBeansXml(java.lang.String pathName)
Adds a Resin beans configuration file, allowing creation of databases or bean configuration. |
|
void |
addClassPath(java.lang.String classPath)
Adds a new module (jar or exploded classes directory) |
|
void |
addPackageModule(java.lang.String packageName)
Adds a package in the classpath as module root. |
|
void |
addPackageModule(java.lang.String modulePath,
java.lang.String packageName)
Adds a package as module root. |
|
void |
addResourceRoot(Path path)
|
|
BeanContainerRequest |
beginRequest()
Enters the Resin context and begins a new request on the thread. |
|
void |
close()
Shuts the context down. |
|
void |
completeRequest(BeanContainerRequest context)
Completes the thread's request and exits the Resin context. |
|
java.lang.Object |
getBeanByName(java.lang.String name)
Returns an instance of the bean with the given name. |
|
InjectManager |
getCdiManager()
|
|
java.lang.ClassLoader |
getClassLoader()
|
|
|
getInstance(java.lang.Class<T> type,
java.lang.annotation.Annotation... qualifiers)
Returns a new instance of the given type with optional qualifiers. |
|
java.lang.Object |
getInstance(java.lang.String className,
java.lang.annotation.Annotation... qualifiers)
Returns a new instance of the given type with optional bindings. |
|
void |
request(java.lang.Runnable runnable)
Executes code in the Resin bean classloader and creates a request scope. |
|
void |
setId(java.lang.String id)
|
|
void |
setModule(java.lang.String modulePath)
|
|
void |
setWorkDirectory(java.lang.String path)
Sets the work directory for Resin to use when generating temporary files. |
|
void |
start()
Initializes the context. |
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ResinBeanContainer()
Method Detail |
---|
public void setId(java.lang.String id)
public InjectManager getCdiManager()
public void setModule(java.lang.String modulePath)
public void addClassPath(java.lang.String classPath)
public void addPackageModule(java.lang.String modulePath, java.lang.String packageName)
packageName
- the name of the package to be treated as a virtual module root.public void addPackageModule(java.lang.String packageName)
packageName
- the name of the package to be treated as a virtual module root.public void addBeansXml(java.lang.String pathName)
pathName
- URL/path to the configuration filepublic void addResourceRoot(Path path)
public void setWorkDirectory(java.lang.String path)
public void start()
public java.lang.Object getInstance(java.lang.String className, java.lang.annotation.Annotation... qualifiers)
className
- the className of the bean to instantiatequalifier
- optional @Qualifier annotations to select the beanpublic <T> T getInstance(java.lang.Class<T> type, java.lang.annotation.Annotation... qualifiers)
public java.lang.Object getBeanByName(java.lang.String name)
name
- the @Named of the bean to instantiatepublic void request(java.lang.Runnable runnable)
resinBean.request (new Runnable() {
doMyCode();
});
public BeanContainerRequest beginRequest()
ResinContext resinContext = ...;
RequestContext cxt = resinContext.beginRequest();
try {
// ... actions inside the Resin request context
} finally {
resinContext.completeRequest(cxt);
}
completeContext
public void completeRequest(BeanContainerRequest context)
public void close()
public java.lang.ClassLoader getClassLoader()
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |