public class TestContainerClassLoaderFactory extends ContainerClassLoaderFactory implements AutoCloseable
ContainerClassLoaderFactory for testing in order to add boot packages and build a
ClassLoader for the container that do resolves classes instead of delegating to its parent and also allows to create
the container ClassLoaderLookupPolicy based on a ClassLoader.BOOT_PACKAGES, SYSTEM_PACKAGES| Constructor and Description |
|---|
TestContainerClassLoaderFactory(List<String> extraBootPackages,
URL[] urls,
ModuleRepository moduleRepository)
Factory class that extends the default way to create a container
ArtifactClassLoader in order to support the
differences when running applications in standalone container vs junit. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected org.mule.runtime.module.artifact.classloader.ArtifactClassLoader |
createArtifactClassLoader(ClassLoader parentClassLoader,
List<MuleModule> muleModules,
org.mule.runtime.module.artifact.classloader.ClassLoaderLookupPolicy containerLookupPolicy,
org.mule.runtime.module.artifact.descriptor.ArtifactDescriptor artifactDescriptor)
Overrides the method in order to create a
ArtifactClassLoader that will have a CHILD_FIRST
ClassLoaderLookupPolicy, it is needed due to as difference from a mule standalone container where the parent
ClassLoader for the container only has bootstrap jars plugins mule modules and third-party libraries when the runner
runs this tests using has a full class path with all the artifacts declared as dependencies for the artifact so we have to
change that and change the look strategy to be CHILD_FIRST for the container. |
org.mule.runtime.module.artifact.classloader.ArtifactClassLoader |
createContainerClassLoader(ClassLoader parentClassLoader)
Overrides method due to it has to use the
ClassLoader set to this factory in order to discover modules. |
Set<String> |
getBootPackages() |
org.mule.runtime.module.artifact.classloader.ArtifactClassLoader |
getContainerClassLoader() |
org.mule.runtime.module.artifact.classloader.ClassLoaderLookupPolicy |
getContainerClassLoaderLookupPolicy(ClassLoader classLoader) |
createContainerFilteringClassLoader, getContainerClassLoaderLookupPolicypublic TestContainerClassLoaderFactory(List<String> extraBootPackages, URL[] urls, ModuleRepository moduleRepository)
ArtifactClassLoader in order to support the
differences when running applications in standalone container vs junit.extraBootPackages - List of Strings extra boot packages that need to be appended to the container (junit
for instance)urls - URLs that were classified to be added to the container ClassLoadermoduleRepository - provides access to the modules available on the container. Non null.public org.mule.runtime.module.artifact.classloader.ArtifactClassLoader createContainerClassLoader(ClassLoader parentClassLoader)
ClassLoader set to this factory in order to discover modules.createContainerClassLoader in class ContainerClassLoaderFactoryparentClassLoader - parent classLoader. Can be null.ArtifactClassLoader containing container code that can be used as parent classloader for other
mule artifacts.protected org.mule.runtime.module.artifact.classloader.ArtifactClassLoader createArtifactClassLoader(ClassLoader parentClassLoader, List<MuleModule> muleModules, org.mule.runtime.module.artifact.classloader.ClassLoaderLookupPolicy containerLookupPolicy, org.mule.runtime.module.artifact.descriptor.ArtifactDescriptor artifactDescriptor)
ArtifactClassLoader that will have a CHILD_FIRST
ClassLoaderLookupPolicy, it is needed due to as difference from a mule standalone container where the parent
ClassLoader for the container only has bootstrap jars plugins mule modules and third-party libraries when the runner
runs this tests using has a full class path with all the artifacts declared as dependencies for the artifact so we have to
change that and change the look strategy to be CHILD_FIRST for the container.
The muleModules parameter will be ignored due to it has all the modules in classpath, instead they are discovered
once again but using a URLClassLoader that has the URL's classified for the container ClassLoader.createArtifactClassLoader in class ContainerClassLoaderFactoryparentClassLoader - the parent ClassLoader to delegate PARENT look upsmuleModules - MuleModule discovered from the launcher ClassLoader but will be not considered here due to
it has all the class pathcontainerLookupPolicy - the default ClassLoaderLookupPolicy defined for a container but will be ignored due to
it has to be different when running with a full class path as parent ClassLoaderartifactDescriptor - ArtifactClassLoader to be used for the containerpublic org.mule.runtime.module.artifact.classloader.ArtifactClassLoader getContainerClassLoader()
public Set<String> getBootPackages()
getBootPackages in class ContainerClassLoaderFactoryContainerClassLoaderFactory plus extra packages needed to be
added in order to allow tests to run with isolation. For instance, junit is an extra package that has to be handled
as boot package.public org.mule.runtime.module.artifact.classloader.ClassLoaderLookupPolicy getContainerClassLoaderLookupPolicy(ClassLoader classLoader)
public void close()
close in interface AutoCloseableCopyright © 2003–2017 MuleSoft, Inc.. All rights reserved.