Debian Codegraph @

src/test/java/org/jboss/modules/SymlinkResourceLoaderTest.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 java.io.File;
22 import java.nio.file.FileSystemException;
23 import java.nio.file.Files;
24 import java.security.AccessController;
25
26 import org.jboss.modules.filter.PathFilter;
27 import org.junit.After;
28 import org.junit.Assert;
29 import org.junit.Assume;
30
31 /**
32 * Test the functionality of the PathResourceLoader with resources containing symbolic links
33 *
34 * @author Bartosz Spyrko-Smietanko
35 */
36 public class SymlinkResourceLoaderTest extends AbstractResourceLoaderTestCase {
37
38 private File resourceRoot;
39
40 @After
41 public void tearDown() throws Exception {
42 File base = getResource("test");
43 File symlink = new File(base, "symlink");
44 if (symlink.exists()) {
45 symlink.delete();
46 }
47 }
48
49 protected ResourceLoader createLoader(final PathFilter exportFilter) throws Exception {
50 File base = getResource("test");
51 File realRoot = getResource("test/fileresourceloader");
52 try {
53 resourceRoot = Files.createSymbolicLink(new File(base, "symlink").toPath(), realRoot.toPath()).toFile();
54 } catch (UnsupportedOperationException | FileSystemException e) {
55 Assume.assumeNoException(e);
56 }
57
58 // Copy the classfile over
59 copyResource("org/jboss/modules/test/TestClass.class", "test/fileresourceloader", "org/jboss/modules/test");
60 return new PathResourceLoader("test-root", resourceRoot.toPath(), AccessController.getContext());
61 }
62
63 @Override
64 protected void assertResource(Resource resource, String fileName) {
65 final File resourceFile = getExpectedFile(fileName);
66
67 Assert.assertEquals(resourceFile.length(), resource.getSize());
68 }
69
70 public void testGetClassSpec() throws Exception {
71 super.testGetClassSpec();
72 }
73
74 protected File getExpectedFile(String fileName) {
75 return new File(resourceRoot, fileName);
76 }
77 }