Debian Codegraph @

src/test/java/org/jboss/modules/LocalModuleLoaderTest.java

raw
1 /*
2 * JBoss, Home of Professional Open Source.
3 * Copyright 2014 Red Hat, Inc., and individual contributors
4 * as indicated by the @author tags.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.jboss.modules;
20
21 import org.junit.Before;
22 import org.junit.Test;
23
24 import java.io.File;
25 import java.util.Iterator;
26
27 import static org.junit.Assert.assertNotEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.fail;
30
31 /**
32 * Test to verify the functionality of the LocalModuleLoader.
33 *
34 * @author John Bailey
35 */
36 public class LocalModuleLoaderTest extends AbstractModuleTestCase {
37 private ModuleLoader moduleLoader;
38
39 @Before
40 public void setupModuleLoader() throws Exception {
41 final File repoRoot = getResource("test/repo");
42 System.setProperty("foo.bar", "substituted_value");
43 moduleLoader = new LocalModuleLoader(new File[] {repoRoot});
44 }
45
46 @Test
47 public void testBasicLoad() throws Exception {
48 Module module = moduleLoader.loadModule("test.test");
49 assertNotNull(module);
50 }
51
52 @Test
53 public void testCurrent() throws Exception {
54 ModuleLoader loader = Module.getCallerModuleLoader();
55 System.out.println(loader);
56 }
57
58
59 @Test
60 public void testLoadWithDeps() throws Exception {
61 Module module = moduleLoader.loadModule("test.with-deps");
62 assertNotNull(module);
63 }
64
65 @Test
66 public void testLoadWithBadDeps() throws Exception {
67 try {
68 moduleLoader.loadModule("test.bad-deps.1_0");
69 fail("Should have thrown a ModuleNotFoundException");
70 } catch(ModuleNotFoundException expected) {}
71 }
72
73 @Test
74 public void testLoadWithCircularDeps() throws Exception {
75 assertNotNull(moduleLoader.loadModule("test.circular-deps-A"));
76 assertNotNull(moduleLoader.loadModule("test.circular-deps-B"));
77 assertNotNull(moduleLoader.loadModule("test.circular-deps-C"));
78 assertNotNull(moduleLoader.loadModule("test.circular-deps-D"));
79 }
80
81 @Test
82 public void testAbsentModule() throws Exception {
83 try {
84 moduleLoader.loadModule("test.absent");
85 fail("Should have thrown a ModuleNotFoundException");
86 } catch(ModuleNotFoundException expected) {}
87 }
88
89 @Test
90 public void testIterateModules() throws Exception {
91 Iterator<String> names = moduleLoader.iterateModules((String) null, true);
92 while (names.hasNext()) {
93 String name = names.next();
94 assertNotEquals("test.absent", name);
95 if (!name.equals("test.bad-deps")) {
96 Module module = moduleLoader.loadModule(name);
97 assertNotNull(module);
98 }
99 }
100 }
101 }