use of org.jboss.modules.util.TestModuleLoader in project jboss-modules by jboss-modules.
the class ModuleExportTest method testExportDependencies.
@Test
public void testExportDependencies() throws Exception {
final TestModuleLoader moduleLoader = new TestModuleLoader();
ModuleSpec.Builder builder = ModuleSpec.build(MODULE_A);
builder.addDependency(new ModuleDependencySpecBuilder().setName(MODULE_B.toString()).setExport(true).build());
moduleLoader.addModuleSpec(builder.create());
builder = ModuleSpec.build(MODULE_B);
builder.addDependency(new ModuleDependencySpecBuilder().setName(MODULE_C.toString()).setExport(true).build());
builder.addDependency(new ModuleDependencySpecBuilder().setName(MODULE_D.toString()).build());
moduleLoader.addModuleSpec(builder.create());
builder = ModuleSpec.build(MODULE_C);
moduleLoader.addModuleSpec(builder.create());
builder = ModuleSpec.build(MODULE_D);
moduleLoader.addModuleSpec(builder.create());
Module module = moduleLoader.loadModule(MODULE_A);
final Set<ModuleIdentifier> dependencyExports = new HashSet<ModuleIdentifier>();
getExportedModuleDeps(module, dependencyExports);
assertEquals(2, dependencyExports.size());
assertTrue(dependencyExports.contains(MODULE_B));
assertTrue(dependencyExports.contains(MODULE_C));
dependencyExports.clear();
module = moduleLoader.loadModule(MODULE_B);
getExportedModuleDeps(module, dependencyExports);
assertEquals(1, dependencyExports.size());
assertTrue(dependencyExports.contains(MODULE_C));
dependencyExports.clear();
module = moduleLoader.loadModule(MODULE_C);
getExportedModuleDeps(module, dependencyExports);
assertEquals(0, dependencyExports.size());
dependencyExports.clear();
module = moduleLoader.loadModule(MODULE_D);
getExportedModuleDeps(module, dependencyExports);
assertEquals(0, dependencyExports.size());
}
use of org.jboss.modules.util.TestModuleLoader in project jboss-modules by jboss-modules.
the class ModuleExportTest method testImportPaths.
@SuppressWarnings({ "unchecked" })
@Test
@Ignore("Disabled; relies on modules not inheriting full set of JDK paths which is incorrect behavior")
public void testImportPaths() throws Exception {
final TestModuleLoader moduleLoader = new TestModuleLoader();
ModuleSpec.Builder builder = ModuleSpec.build(MODULE_A);
builder.addDependency(new ModuleDependencySpecBuilder().setName(MODULE_B.toString()).setExport(true).build());
moduleLoader.addModuleSpec(builder.create());
builder = ModuleSpec.build(MODULE_B);
builder.addDependency(new ModuleDependencySpecBuilder().setName(MODULE_C.toString()).setExport(true).build());
builder.addDependency(new ModuleDependencySpecBuilder().setName(MODULE_D.toString()).build());
moduleLoader.addModuleSpec(builder.create());
builder = ModuleSpec.build(MODULE_C);
builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(TestResourceLoader.build().addClass(ImportedClass.class).create()));
builder.addDependency(DependencySpec.createLocalDependencySpec());
moduleLoader.addModuleSpec(builder.create());
builder = ModuleSpec.build(MODULE_D);
moduleLoader.addModuleSpec(builder.create());
Module module = moduleLoader.loadModule(MODULE_A);
module.getClassLoader().loadClass(ImportedClass.class.getName());
final Field pathsField = Module.class.getDeclaredField("linkage");
pathsField.setAccessible(true);
final Object paths = pathsField.get(module);
final Field allPathsField = paths.getClass().getDeclaredField("allPaths");
allPathsField.setAccessible(true);
final Map<String, List<LocalLoader>> allPaths = (Map<String, List<LocalLoader>>) allPathsField.get(paths);
Module moduleC = moduleLoader.loadModule(MODULE_C);
assertEquals(4, allPaths.size());
for (Map.Entry<String, List<LocalLoader>> entry : allPaths.entrySet()) {
assertEquals(1, entry.getValue().size());
assertEquals(moduleC.getClassLoaderPrivate().getLocalLoader(), entry.getValue().get(0));
}
}
use of org.jboss.modules.util.TestModuleLoader in project jboss-modules by jboss-modules.
the class ErrorHandlingTest method before.
@Before
public void before() throws Exception {
moduleLoader = new TestModuleLoader();
final ModuleSpec.Builder moduleABuilder = ModuleSpec.build(MODULE_A);
moduleABuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(TestResourceLoader.build().addClass(ClassA.class).create()));
moduleABuilder.addDependency(DependencySpec.OWN_DEPENDENCY);
moduleLoader.addModuleSpec(moduleABuilder.create());
}
use of org.jboss.modules.util.TestModuleLoader in project jboss-modules by jboss-modules.
the class JAXPModuleTest method setupModuleLoader.
@Before
public void setupModuleLoader() throws Exception {
moduleLoader = new TestModuleLoader();
ModuleSpec.Builder moduleWithContentBuilder = ModuleSpec.build(ModuleIdentifier.fromString("test-jaxp"));
moduleWithContentBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(TestResourceLoader.build().addClass(JAXPCaller.class).create()));
moduleWithContentBuilder.addDependency(DependencySpec.createSystemDependencySpec(JDKPaths.JDK));
moduleWithContentBuilder.addDependency(DependencySpec.createLocalDependencySpec());
moduleWithContentBuilder.setMainClass(JAXPCaller.class.getName());
moduleLoader.addModuleSpec(moduleWithContentBuilder.create());
moduleWithContentBuilder = ModuleSpec.build(FAKE_JAXP);
moduleWithContentBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(TestResourceLoader.build().addClass(FakeSAXParserFactory.class).addClass(FakeSAXParser.class).addClass(FakeDocumentBuilderFactory.class).addClass(FakeDocumentBuilder.class).addClass(FakeTransformerFactory.class).addClass(FakeTransformer.class).addClass(FakeTransformerHandler.class).addClass(FakeXMLEventFactory.class).addClass(FakeDTD.class).addClass(FakeXMLInputFactory.class).addClass(FakeXMLOutputFactory.class).addClass(FakeDatatypeFactory.class).addClass(FakeDuration.class).addClass(FakeXPathFactory.class).addClass(FakeXPath.class).addClass(FakeSchemaFactory.class).addClass(FakeSchema.class).addClass(FakeXMLReader.class).addResources(getResource("test/modulecontentloader/jaxp")).create()));
moduleWithContentBuilder.addDependency(DependencySpec.createModuleDependencySpec("java.xml"));
moduleWithContentBuilder.addDependency(DependencySpec.createLocalDependencySpec());
moduleLoader.addModuleSpec(moduleWithContentBuilder.create());
moduleWithContentBuilder = ModuleSpec.build(ModuleIdentifier.fromString("test-jaxp-import"));
moduleWithContentBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(TestResourceLoader.build().addClass(JAXPCaller.class).create()));
moduleWithContentBuilder.addDependency(DependencySpec.createModuleDependencySpec("java.xml"));
moduleWithContentBuilder.addDependency(new ModuleDependencySpecBuilder().setImportFilter(PathFilters.acceptAll()).setModuleLoader(moduleLoader).setName(FAKE_JAXP.toString()).setOptional(false).build());
moduleWithContentBuilder.addDependency(DependencySpec.createLocalDependencySpec());
moduleLoader.addModuleSpec(moduleWithContentBuilder.create());
}
use of org.jboss.modules.util.TestModuleLoader in project jboss-modules by jboss-modules.
the class ModuleClassLoaderTest method setupModuleLoader.
@Before
public void setupModuleLoader() throws Exception {
moduleLoader = new TestModuleLoader();
final ModuleSpec.Builder moduleWithContentBuilder = ModuleSpec.build(MODULE_WITH_CONTENT_ID);
moduleWithContentBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(TestResourceLoader.build().addClass(TestClass.class).addResources(getResource("test/modulecontentloader/rootOne")).create()));
moduleWithContentBuilder.addDependency(new ModuleDependencySpecBuilder().setName(MODULE_TO_IMPORT_ID.toString()).build());
moduleWithContentBuilder.addDependency(DependencySpec.createLocalDependencySpec());
moduleLoader.addModuleSpec(moduleWithContentBuilder.create());
final ModuleSpec.Builder moduleWithResourceBuilder = ModuleSpec.build(MODULE_WITH_RESOURCE_ID);
moduleWithResourceBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(TestResourceLoader.build().addClass(TestClass.class).addResources(getResource("class-resources")).create()));
moduleWithResourceBuilder.addDependency(new ModuleDependencySpecBuilder().setName(MODULE_TO_IMPORT_ID.toString()).build());
moduleWithResourceBuilder.addDependency(DependencySpec.createLocalDependencySpec());
moduleLoader.addModuleSpec(moduleWithResourceBuilder.create());
final ModuleSpec.Builder moduleToImportBuilder = ModuleSpec.build(MODULE_TO_IMPORT_ID);
moduleToImportBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(TestResourceLoader.build().addClass(ImportedClass.class).addClass(ImportedInterface.class).addResources(getResource("test/modulecontentloader/rootTwo")).create()));
moduleToImportBuilder.addDependency(DependencySpec.createLocalDependencySpec());
moduleLoader.addModuleSpec(moduleToImportBuilder.create());
final ModuleSpec.Builder moduleWithExportBuilder = ModuleSpec.build(MODULE_WITH_EXPORT_ID);
moduleWithExportBuilder.addDependency(new ModuleDependencySpecBuilder().setName(MODULE_TO_IMPORT_ID.toString()).setExport(true).setOptional(false).build());
moduleWithExportBuilder.addDependency(DependencySpec.createLocalDependencySpec());
moduleLoader.addModuleSpec(moduleWithExportBuilder.create());
final MultiplePathFilterBuilder nestedAndOrgJBossExcludingBuilder = PathFilters.multiplePathFilterBuilder(true);
nestedAndOrgJBossExcludingBuilder.addFilter(PathFilters.match("org/jboss/**"), false);
nestedAndOrgJBossExcludingBuilder.addFilter(PathFilters.match("nested"), false);
final ModuleSpec.Builder moduleWithExportFilterBuilder = ModuleSpec.build(MODULE_WITH_FILTERED_EXPORT_ID);
moduleWithExportFilterBuilder.addDependency(new ModuleDependencySpecBuilder().setExportFilter(nestedAndOrgJBossExcludingBuilder.create()).setModuleLoader(null).setName(MODULE_TO_IMPORT_ID.toString()).setOptional(false).build());
moduleWithExportFilterBuilder.addDependency(DependencySpec.createLocalDependencySpec());
moduleLoader.addModuleSpec(moduleWithExportFilterBuilder.create());
final ModuleSpec.Builder moduleWithImportFilterBuilder = ModuleSpec.build(MODULE_WITH_FILTERED_IMPORT_ID);
moduleWithImportFilterBuilder.addDependency(new ModuleDependencySpecBuilder().setImportFilter(nestedAndOrgJBossExcludingBuilder.create()).setName(MODULE_TO_IMPORT_ID.toString()).setOptional(false).build());
moduleWithImportFilterBuilder.addDependency(DependencySpec.createLocalDependencySpec());
moduleLoader.addModuleSpec(moduleWithImportFilterBuilder.create());
final ModuleSpec.Builder moduleWithDoubleExportBuilder = ModuleSpec.build(MODULE_WITH_DOUBLE_EXPORT_ID);
moduleWithDoubleExportBuilder.addDependency(new ModuleDependencySpecBuilder().setName(MODULE_TO_IMPORT_ID.toString()).setExport(true).build());
moduleWithDoubleExportBuilder.addDependency(new ModuleDependencySpecBuilder().setName(MODULE_WITH_CONTENT_ID.toString()).setExport(true).build());
moduleWithDoubleExportBuilder.addDependency(DependencySpec.createLocalDependencySpec());
moduleLoader.addModuleSpec(moduleWithDoubleExportBuilder.create());
final ModuleSpec.Builder moduleWithInvertedDoubleExportBuilder = ModuleSpec.build(MODULE_WITH_INVERTED_DOUBLE_EXPORT_ID);
moduleWithInvertedDoubleExportBuilder.addDependency(new ModuleDependencySpecBuilder().setName(MODULE_WITH_CONTENT_ID.toString()).setExport(true).build());
moduleWithInvertedDoubleExportBuilder.addDependency(new ModuleDependencySpecBuilder().setName(MODULE_TO_IMPORT_ID.toString()).setExport(true).build());
moduleWithInvertedDoubleExportBuilder.addDependency(DependencySpec.createLocalDependencySpec());
moduleLoader.addModuleSpec(moduleWithInvertedDoubleExportBuilder.create());
final ModuleSpec.Builder moduleWithFilteredDoubleExportBuilder = ModuleSpec.build(MODULE_WITH_FILTERED_DOUBLE_EXPORT_ID);
moduleWithFilteredDoubleExportBuilder.addDependency(new ModuleDependencySpecBuilder().setImportFilter(PathFilters.not(PathFilters.match("nested"))).setExport(true).setName(MODULE_TO_IMPORT_ID.toString()).build());
moduleWithFilteredDoubleExportBuilder.addDependency(new ModuleDependencySpecBuilder().setName(MODULE_WITH_EXPORT_ID.toString()).setExport(true).build());
moduleWithFilteredDoubleExportBuilder.addDependency(DependencySpec.createLocalDependencySpec());
moduleLoader.addModuleSpec(moduleWithFilteredDoubleExportBuilder.create());
}
Aggregations