Package org.jboss.modules.util

Examples of org.jboss.modules.util.TestModuleLoader


    }


    @Test
    public void testResources() throws Exception {
        final TestModuleLoader moduleLoader = new TestModuleLoader();

        ModuleSpec.Builder builder = ModuleSpec.build(MODULE_A);
        //builder.addDependency(DependencySpec.createModuleDependencySpec(PathFilters.match("org/jboss/modules/**"), PathFilters.rejectAll(), null, ModuleIdentifier.SYSTEM, false));
        moduleLoader.addModuleSpec(builder.create());

        Module module = moduleLoader.loadModule(MODULE_A);
        ClassLoader cl = module.getClassLoader();

        Enumeration<URL> resources = cl.getResources("javax/activation/DataHandler.class");
        Assert.assertTrue(resources.hasMoreElements());

View Full Code Here


    private TestModuleLoader moduleLoader;

    @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)
View Full Code Here

    private static final ModuleIdentifier MODULE_A = ModuleIdentifier.fromString("a");
    private static final ModuleIdentifier MODULE_B = ModuleIdentifier.fromString("b");

    @Test
    public void testMetaInfServicesIterator() throws Exception {
        TestModuleLoader moduleLoader = new TestModuleLoader();

        ModuleSpec.Builder builder = ModuleSpec.build(MODULE_A);
        builder.addDependency(DependencySpec.createModuleDependencySpec(MODULE_B, false, false));
        PathFilter importFilter = PathFilters.getMetaInfServicesFilter();
        PathFilter exportFilter = PathFilters.acceptAll();
        builder.addDependency(DependencySpec.createModuleDependencySpec(importFilter, exportFilter, moduleLoader, MODULE_B, false));
        moduleLoader.addModuleSpec(builder.create());

        builder = ModuleSpec.build(MODULE_B);
        ResourceLoader resB = new JarFileResourceLoader("jarB", toJarFile(getModuleB()));
        builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(resB));
        builder.addDependency(DependencySpec.createLocalDependencySpec());
        moduleLoader.addModuleSpec(builder.create());

        Module moduleA = moduleLoader.loadModule(MODULE_A);
        Iterator<Resource> itres = moduleA.iterateResources(PathFilters.getMetaInfServicesFilter());
        Assert.assertTrue("Found a resource", itres.hasNext());
        Assert.assertEquals("META-INF/services/org/apache/camel/component/jms", itres.next().getName());
        Assert.assertFalse("No other resource", itres.hasNext());
    }
View Full Code Here

    private static final ModuleIdentifier MODULE_C = ModuleIdentifier.fromString("c");
    private static final ModuleIdentifier MODULE_D = ModuleIdentifier.fromString("d");

    @Test
    public void testExportDependencies() throws Exception {
        final TestModuleLoader moduleLoader = new TestModuleLoader();

        ModuleSpec.Builder builder = ModuleSpec.build(MODULE_A);
        builder.addDependency(DependencySpec.createModuleDependencySpec(MODULE_B, true, false));
        moduleLoader.addModuleSpec(builder.create());

        builder = ModuleSpec.build(MODULE_B);
        builder.addDependency(DependencySpec.createModuleDependencySpec(MODULE_C, true, false));
        builder.addDependency(DependencySpec.createModuleDependencySpec(MODULE_D));
        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());
    }
View Full Code Here

    }

    @SuppressWarnings({ "unchecked" })
    @Test
    public void testImportPaths() throws Exception {
        final TestModuleLoader moduleLoader = new TestModuleLoader();

        ModuleSpec.Builder builder = ModuleSpec.build(MODULE_A);
        builder.addDependency(DependencySpec.createModuleDependencySpec(MODULE_B, true));
        moduleLoader.addModuleSpec(builder.create());

        builder = ModuleSpec.build(MODULE_B);
        builder.addDependency(DependencySpec.createModuleDependencySpec(MODULE_C, true));
        builder.addDependency(DependencySpec.createModuleDependencySpec(MODULE_D));
        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());
View Full Code Here

    @Before
    public void setupModuleLoader() throws Exception {
        jdkApiFilter = PathFilters.any(PathFilters.match("javax/**"),
                       PathFilters.match("org/w3c/**"),
                       PathFilters.match("org/xml/**"));
        moduleLoader = new TestModuleLoader();

        ModuleSpec.Builder moduleWithContentBuilder = ModuleSpec.build(ModuleIdentifier.fromString("test-jaxp"));
        moduleWithContentBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(
                TestResourceLoader.build()
                .addClass(JAXPCaller.class)
View Full Code Here

    private TestModuleLoader moduleLoader;

    @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)
View Full Code Here

TOP

Related Classes of org.jboss.modules.util.TestModuleLoader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.