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