use of org.mule.runtime.container.api.MuleModule in project mule by mulesoft.
the class ClasspathModuleDiscovererTestCase method discoversModuleWithExportedJavaPackages.
@Test
public void discoversModuleWithExportedJavaPackages() throws Exception {
List<URL> moduleProperties = new ArrayList();
moduleProperties.add(getClass().getClassLoader().getResource("moduleJavaPackages.properties"));
when(classLoader.getResources(ClasspathModuleDiscoverer.MODULE_PROPERTIES)).thenReturn(new EnumerationAdapter(moduleProperties));
List<MuleModule> muleModules = moduleDiscoverer.discover();
assertThat(muleModules, hasSize(1));
MuleModule muleModule = muleModules.get(0);
assertThat(muleModule.getName(), is("moduleJavaPackages"));
assertThat(muleModule.getExportedPackages(), contains("org.foo", "org.bar"));
assertThat(muleModule.getExportedPaths(), is(empty()));
assertThat(muleModule.getPrivilegedExportedPackages(), is(empty()));
assertThat(muleModule.getPrivilegedArtifacts(), is(empty()));
assertThat(muleModule.getExportedServices(), is(empty()));
}
use of org.mule.runtime.container.api.MuleModule in project mule by mulesoft.
the class CompositeModuleDiscovererTestCase method delegatesToComposedDiscovers.
@Test
public void delegatesToComposedDiscovers() throws Exception {
final ModuleDiscoverer discoverer1 = mock(ModuleDiscoverer.class);
MuleModule module1 = new MuleModule("module1", emptySet(), emptySet(), emptySet(), emptySet(), emptyList());
final List<MuleModule> modules1 = new ArrayList<>();
modules1.add(module1);
when(discoverer1.discover()).thenReturn(modules1);
MuleModule module2 = new MuleModule("module1", emptySet(), emptySet(), emptySet(), emptySet(), emptyList());
final List<MuleModule> modules2 = new ArrayList<>();
modules2.add(module2);
final ModuleDiscoverer discoverer2 = mock(ModuleDiscoverer.class);
when(discoverer2.discover()).thenReturn(modules2);
final CompositeModuleDiscoverer composite = new CompositeModuleDiscoverer(discoverer1, discoverer2);
final List<MuleModule> discovered = composite.discover();
assertThat(discovered.size(), equalTo(2));
assertThat(discovered, contains(module1, module2));
}
use of org.mule.runtime.container.api.MuleModule in project mule by mulesoft.
the class ContainerClassLoaderFilterFactoryTestCase method acceptsExportedSystemPackages.
@Test
public void acceptsExportedSystemPackages() throws Exception {
final List<MuleModule> muleModules = new ArrayList<>();
final Set<String> bootPackages = singleton("org.foo1");
final ClassLoaderFilter classLoaderFilter = factory.create(bootPackages, muleModules);
assertThat(classLoaderFilter.exportsClass("org.foo1.Foo"), is(true));
assertThat(classLoaderFilter.exportsClass("org.foo1.bar.Bar"), is(true));
assertThat(classLoaderFilter.exportsClass("org.bar.Bar"), is(false));
}
use of org.mule.runtime.container.api.MuleModule in project mule by mulesoft.
the class JreModuleDiscovererTestCase method discoversJreModule.
@Test
public void discoversJreModule() throws Exception {
final List<MuleModule> muleModules = moduleDiscoverer.discover();
assertThat(muleModules.size(), equalTo(1));
final MuleModule muleModule = muleModules.get(0);
assertThat(muleModule.getName(), equalTo(JRE_MODULE_NAME));
assertThat(muleModule.getExportedPaths(), is(not(empty())));
assertThat(muleModule.getExportedPackages(), is(not(empty())));
assertThat(muleModule.getExportedServices(), is(not(empty())));
}
use of org.mule.runtime.container.api.MuleModule in project mule by mulesoft.
the class ContainerClassLoaderFactory method buildClassLoaderLookupStrategy.
/**
* Creates a {@link Map<String, LookupStrategy>} for the packages exported on the container.
*
* @param containerClassLoader class loader containing container's classes. Non null.
* @param modules to be used for collecting the exported packages. Non null
* @return a {@link Map<String, LookupStrategy>} for the packages exported on the container
*/
private Map<String, LookupStrategy> buildClassLoaderLookupStrategy(ClassLoader containerClassLoader, List<MuleModule> modules) {
checkArgument(containerClassLoader != null, "containerClassLoader cannot be null");
checkArgument(modules != null, "modules cannot be null");
ContainerOnlyLookupStrategy containerOnlyLookupStrategy = new ContainerOnlyLookupStrategy(containerClassLoader);
final Map<String, LookupStrategy> result = new HashMap<>();
for (MuleModule muleModule : modules) {
for (String exportedPackage : muleModule.getExportedPackages()) {
// Lets artifacts to extend javax packages
result.put(exportedPackage, exportedPackage.startsWith("javax.") ? PARENT_FIRST : containerOnlyLookupStrategy);
}
}
return result;
}
Aggregations