View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2.provider.local;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertTrue;
21  
22  import java.io.File;
23  import java.io.IOException;
24  import java.net.URISyntaxException;
25  import java.net.URL;
26  import java.nio.file.Files;
27  
28  import org.apache.commons.vfs2.FileObject;
29  import org.apache.commons.vfs2.FileSystemManager;
30  import org.apache.commons.vfs2.VFS;
31  import org.junit.Ignore;
32  import org.junit.Test;
33  
34  /**
35   * Tests conversion from VFS to File.
36   * <p>
37   * VFS-443 Need an easy way to convert from a FileObject to a File.
38   */
39  public class ConversionTestCase {
40  
41      @Test
42      @Ignore
43      public void testFileNameWithCharacters() throws URISyntaxException, IOException {
44          final File file = new File("target", "+# %&.txt");
45          final String fileURL = file.toURI().toURL().toExternalForm();
46          assertEquals(file.getAbsoluteFile(), new File(file.toURI().getPath()));
47          assertEquals(file.getAbsoluteFile(), new File(new URL(fileURL).toURI().getPath()));
48          try {
49              Files.newOutputStream(file.toPath()).close();
50              assertTrue(file.exists());
51  
52              final FileSystemManager manager = VFS.getManager();
53              final FileObject fo = manager.resolveFile(fileURL);
54              assertTrue(fo.exists());
55              assertEquals(file.getAbsoluteFile(), new File(new URL(fo.getURL().toExternalForm()).toURI().getPath()));
56          } finally {
57              file.delete();
58          }
59      }
60  
61      @Test
62      @Ignore
63      public void testFileNameWithSpaces() throws URISyntaxException, IOException {
64          final File file = new File("target", "a name.txt");
65          final String fileURL = file.toURI().toURL().toExternalForm();
66          assertEquals(file.getAbsoluteFile(), new File(file.toURI().getPath()));
67          assertEquals(file.getAbsoluteFile(), new File(new URL(fileURL).toURI().getPath()));
68  
69          final FileSystemManager manager = VFS.getManager();
70          final FileObject fo = manager.resolveFile(fileURL);
71          assertEquals(file.getAbsoluteFile(), new File(new URL(fo.getURL().toExternalForm()).toURI().getPath()));
72      }
73  
74  }