package org.apache.commons.vfs2.provider.local.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.VFS;
import org.junit.Ignore;
import org.junit.Test;

/**
 * Tests conversion from VFS to File.
 * <p/>
 * VFS-443 Need an easy way to convert from a FileObject to a File.
 * 
 * @version $Id$
 */
public class ConversionTestCase
{

    @Test
    @Ignore
    public void testFileNameWithSpaces() throws URISyntaxException, IOException
    {
        final File file = new File("target", "a name.txt");
        final String fileURL = file.toURI().toURL().toExternalForm();
        assertEquals(file.getAbsoluteFile(), new File(file.toURI().getPath()));
        assertEquals(file.getAbsoluteFile(), new File(new URL(fileURL).toURI().getPath()));

        final FileSystemManager manager = VFS.getManager();
        final FileObject fo = manager.resolveFile(fileURL);
        assertEquals(file.getAbsoluteFile(), new File(new URL(fo.getURL().toExternalForm()).toURI().getPath()));
    }

    @Test
    @Ignore
    public void testFileNameWithCharacters() throws URISyntaxException, IOException
    {
        final File file = new File("target", "+# %&.txt");
        final String fileURL = file.toURI().toURL().toExternalForm();
        assertEquals(file.getAbsoluteFile(), new File(file.toURI().getPath()));
        assertEquals(file.getAbsoluteFile(), new File(new URL(fileURL).toURI().getPath()));
        try
        {
            new FileOutputStream(file).close();
            assertTrue(file.exists());

            final FileSystemManager manager = VFS.getManager();
            final FileObject fo = manager.resolveFile(fileURL);
            assertTrue(fo.exists());
            assertEquals(file.getAbsoluteFile(), new File(new URL(fo.getURL().toExternalForm()).toURI().getPath()));
        }
        finally
        {
            file.delete();
        }
    }

}

@@ -1,8 +1,811 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A
 package 

Add missing license header.