Debian Codegraph @

src/test/java/org/jboss/modules/xml/PermissionsTest.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.xml;
20
21 import static org.junit.Assert.*;
22
23 import java.io.File;
24 import java.io.FilePermission;
25 import java.security.Permission;
26 import java.util.Enumeration;
27
28 import org.jboss.modules.AbstractModuleTestCase;
29 import org.jboss.modules.LocalModuleLoader;
30 import org.jboss.modules.Module;
31 import org.jboss.modules.ModuleLoader;
32 import org.junit.Before;
33 import org.junit.Test;
34
35 /**
36 * Test to verify the functionality of module permissions
37 *
38 * @author <a href="mailto:[email protected]">Jason Shepherd</a>
39 */
40 public class PermissionsTest extends AbstractModuleTestCase {
41 private static final String JBOSS_HOME_DIR_VALUE = "someDir/someOtherDir";
42 protected static final String MODULE_WITH_INVALID_EXPANSION = "test.permissions";
43 private ModuleLoader moduleLoader;
44
45 @Before
46 public void setupModuleLoader() throws Exception {
47 System.setProperty("jboss.home.dir", JBOSS_HOME_DIR_VALUE);
48 System.setProperty("foo.bar", "substituted_value");
49 final File repoRoot = getResource("test/repo");
50 moduleLoader = new LocalModuleLoader(new File[] {repoRoot});
51 }
52
53 @Test
54 public void testExpansion() throws Exception {
55 Module module = moduleLoader.loadModule(MODULE_WITH_INVALID_EXPANSION);
56 assertTrue(module.getExportedResource("active.txt").toString().contains("substituted_value"));
57 Enumeration<Permission> permissions = module.getPermissionCollection().elements();
58 assertTrue(permissions.hasMoreElements());
59 Permission firstPermission = permissions.nextElement();
60 assertEquals(FilePermission.class.getName(), firstPermission.getClass().getName());
61 assertFalse(permissions.hasMoreElements());
62 }
63 }