Skip to content

Commit 4733787

Browse files
committed
Added testcases for symlink capability support. Can be used to determine what features are supported os-level
1 parent 8526687 commit 4733787

File tree

3 files changed

+93
-3
lines changed

3 files changed

+93
-3
lines changed

pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@
5656
<artifactId>commons-io</artifactId>
5757
<version>2.2</version>
5858
</dependency>
59+
<dependency>
60+
<groupId>junit</groupId>
61+
<artifactId>junit</artifactId>
62+
<version>4.12</version>
63+
<scope>test</scope>
64+
</dependency>
65+
5966
</dependencies>
6067

6168
<build>

src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
package org.codehaus.plexus.components.io.attributes;
2-
31
/*
4-
* Copyright 2007 The Codehaus Foundation.
2+
* Copyright 2016 Plexus developers.
53
*
64
* Licensed under the Apache License, Version 2.0 (the "License");
75
* you may not use this file except in compliance with the License.
@@ -16,6 +14,9 @@
1614
* limitations under the License.
1715
*/
1816

17+
package org.codehaus.plexus.components.io.attributes;
18+
19+
1920

2021
public class FileAttributesTest
2122
extends AbstractResourceAttributesTCK
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2016 Plexus developers.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.codehaus.plexus.components.io.attributes;
18+
19+
import org.apache.commons.io.FileUtils;
20+
import org.junit.Before;
21+
import org.junit.Test;
22+
23+
import java.io.File;
24+
import java.io.IOException;
25+
import java.nio.file.Files;
26+
27+
import static org.junit.Assert.*;
28+
29+
public class SymlinkUtilsTest
30+
{
31+
File target = new File( "target/symlinkCapabilities");
32+
String expected = "This is a filed that we'll be symlinking to\n";
33+
34+
35+
@Before
36+
public void setup()
37+
throws IOException
38+
{
39+
FileUtils.deleteDirectory(target );
40+
Files.createDirectories(target.toPath());
41+
}
42+
43+
@Test
44+
public void testName()
45+
throws Exception
46+
{
47+
48+
}
49+
50+
@Test
51+
public void create_read_symbolic_link_to_file()
52+
throws Exception
53+
{
54+
File symlink = new File( target, "symlinkToTarget");
55+
File relativePath = createTargetFile( target );
56+
SymlinkUtils.createSymbolicLink( symlink, relativePath);
57+
assertEquals( expected, FileUtils.readFileToString( symlink ) );
58+
assertEquals( new File("actualFile"), SymlinkUtils.readSymbolicLink( new File(target, "symlinkToTarget") ));
59+
}
60+
61+
@Test
62+
public void create_read_symbolic_link_to_directory()
63+
throws Exception
64+
{
65+
File subDir = new File( target, "aSubDir");
66+
createTargetFile( subDir );
67+
File symlink = new File( target, "symlinkToDir");
68+
SymlinkUtils.createSymbolicLink( symlink, new File("aSubDir"));
69+
assertEquals( expected, FileUtils.readFileToString( new File(symlink, "actualFile" )) );
70+
assertEquals( new File("aSubDir"), SymlinkUtils.readSymbolicLink( new File(target, "symlinkToDir") ));
71+
72+
}
73+
74+
private File createTargetFile( File target )
75+
throws IOException
76+
{
77+
File relativePath = new File("actualFile");
78+
File actualFile = new File( target, relativePath.getPath());
79+
FileUtils.write( actualFile, expected );
80+
return relativePath;
81+
}
82+
}

0 commit comments

Comments
 (0)