/*-
 * Copyright (c) 2014 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.fedoraproject.xmvn.tools.install.impl;

import java.io.IOException;
import java.nio.file.Paths;

import org.junit.Test;

/**
 * @author Mikolaj Izdebski
 */
public class DirectoryTest
    extends AbstractFileTest
{
    /**
     * Basic test for directory installation
     * 
     * @throws Exception
     */
    @Test
    public void testSingleDirectoryInstallation()
        throws Exception
    {
        add( new Directory( Paths.get( "usr/src/sys/kern" ) ) );
        performInstallation();

        assertDirectoryStructure( "D /usr", "D /usr/src", "D /usr/src/sys", "D /usr/src/sys/kern" );
    }

    /**
     * Test if installing directory which already exists doesn't cause I/O (or other) errors
     * 
     * @throws Exception
     */
    @Test
    public void testExistentDirectoryInstallation()
        throws Exception
    {
        add( new Directory( Paths.get( "etc/sysconfig/java" ) ) );
        add( new Directory( Paths.get( "etc/xmvn" ) ) );
        add( new Directory( Paths.get( "etc" ) ) );
        performInstallation();

        assertDirectoryStructure( "D /etc", "D /etc/sysconfig", "D /etc/sysconfig/java", "D /etc/xmvn" );
    }

    /**
     * Test if directory installation fails if target already exists and is not a directory.
     */
    @Test( expected = IOException.class )
    public void testExistentTargetFile()
        throws Exception
    {
        add( new RegularFile( Paths.get( "foo/bar" ), new byte[0] ) );
        add( new Directory( Paths.get( "foo/bar" ) ) );
        performInstallation();
    }

    /**
     * Test if directory installation fails if component of target directory target already exists and is not a
     * directory.
     */
    @Test( expected = IOException.class )
    public void testDirectoryCOmponentIsAFile()
        throws Exception
    {
        add( new RegularFile( Paths.get( "a/b/c/d" ), new byte[0] ) );
        add( new Directory( Paths.get( "a/b/c/d/e/f/g/h" ) ) );
        performInstallation();
    }
}

@@ -1200,24 +1200,107 @@
 sys/kern%22 );
+%0A%0A        assertDescriptorEquals( %22%25attr(0755,root,root) %25dir /usr/src/sys/kern%22 );
 %0A    %7D%0A%0A    
@@ -1839,24 +1839,216 @@
 etc/xmvn%22 );
+%0A%0A        assertDescriptorEquals( %22%25attr(0755,root,root) %25dir /etc%22, %22%25attr(0755,root,root) %25dir /etc/sysconfig/java%22,%0A                                %22%25attr(0755,root,root) %25dir /etc/xmvn%22 );
 %0A    %7D%0A%0A    

Add descriptor assertions to Directory test case