| 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 java.io.File; |
| 22 |
import org.junit.Before; |
| 23 |
import org.junit.Test; |
| 24 |
|
| 25 |
import static org.junit.Assert.assertEquals; |
| 26 |
import static org.junit.Assert.assertNull; |
| 27 |
import static org.junit.Assert.fail; |
| 28 |
|
| 29 |
/** |
| 30 |
* Test to verify the functionality of module properties. |
| 31 |
* |
| 32 |
* @author <a href="mailto:[email protected]">David M. Lloyd</a> |
| 33 |
*/ |
| 34 |
public class ModulePropertyTest extends AbstractModuleTestCase { |
| 35 |
private ModuleLoader moduleLoader; |
| 36 |
|
| 37 |
@Before |
| 38 |
public void setupModuleLoader() throws Exception { |
| 39 |
final File repoRoot = getResource("test/repo"); |
| 40 |
moduleLoader = new LocalModuleLoader(new File[] {repoRoot}); |
| 41 |
} |
| 42 |
|
| 43 |
@Test |
| 44 |
public void testBasic() throws Exception { |
| 45 |
Module module = moduleLoader.loadModule("test.test"); |
| 46 |
assertNull(module.getProperty("non-existent")); |
| 47 |
assertEquals("blah", module.getProperty("non-existent", "blah")); |
| 48 |
assertEquals("true", module.getProperty("test.prop.1")); |
| 49 |
assertEquals("propertyValue", module.getProperty("test.prop.2")); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* This test parses properties attached to module dependencies. |
| 54 |
* The properties are currently not exposed via the dependency spec API, |
| 55 |
* so the test simply makes sure they can be parsed w/o errors. |
| 56 |
* @throws Exception |
| 57 |
*/ |
| 58 |
@Test |
| 59 |
public void testModuleDependencyProperties() throws Exception { |
| 60 |
Module module = moduleLoader.loadModule("test.dep-props"); |
| 61 |
assertNull(module.getProperty("non-existent")); |
| 62 |
assertEquals("blah", module.getProperty("non-existent", "blah")); |
| 63 |
|
| 64 |
final DependencySpec[] deps = module.getDependencies(); |
| 65 |
int testedDepsTotal = 0; |
| 66 |
for(DependencySpec dep : deps) { |
| 67 |
if(!(dep instanceof ModuleDependencySpec)) { |
| 68 |
continue; |
| 69 |
} |
| 70 |
final ModuleDependencySpec moduleDep = (ModuleDependencySpec) dep; |
| 71 |
String depName = moduleDep.getName(); |
| 72 |
if(!depName.startsWith("test.")) { |
| 73 |
continue; |
| 74 |
} |
| 75 |
++testedDepsTotal; |
| 76 |
depName = depName.substring("test.".length()); |
| 77 |
if(depName.equals("test")) { |
| 78 |
} else { |
| 79 |
fail("Unexpected module dependency " + moduleDep); |
| 80 |
} |
| 81 |
} |
| 82 |
assertEquals(1, testedDepsTotal); |
| 83 |
} |
| 84 |
} |