Debian Codegraph @

src/test/java/org/jboss/modules/ConditionalResourceTest.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 static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertNull;
23
24 import java.io.File;
25 import java.lang.reflect.Method;
26 import java.net.URL;
27 import java.nio.file.Paths;
28
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31
32 /**
33 * Test to verify conditional expressions
34 *
35 * @author Stuart Douglas
36 */
37 public class ConditionalResourceTest extends AbstractModuleTestCase {
38
39 @BeforeClass
40 public static void beforeClass() throws Exception {
41 final Method method = ModuleLoader.class.getDeclaredMethod("installMBeanServer");
42 method.setAccessible(true);
43 method.invoke(null);
44 System.setProperty("test-prop", "testval");
45 }
46
47 /**
48 * Validate that system property conditional expressions work correctly
49 * @throws Exception
50 */
51 @Test
52 public void testMultipleServices() throws Exception {
53 final File repoRoot = getResource("test/repo");
54 final String item = Paths.get("").toAbsolutePath().resolve("./target/test-classes/test/repo").normalize().toString();
55 final String[] classPath = { item };
56 final String deps = "test.conditional-active,test.conditional-not-active";
57 final String mainClass = null;
58 final ModuleLoader moduleLoader = new DelegatingModuleLoader(Module.getSystemModuleLoader(), new ClassPathModuleFinder(new LocalModuleLoader(new File[] { repoRoot }), classPath, deps, mainClass));
59 final Module module = moduleLoader.loadModule(item);
60 final ClassLoader classLoader = module.getClassLoader();
61 final URL active = classLoader.getResource("active.txt");
62 final URL notActive = classLoader.getResource("not-active.txt");
63 assertNotNull(active);
64 assertNull(notActive);
65 }
66 }