/*
 * Copyright 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.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import org.junit.Test;

/**
 *
 * @author Michael Simacek
 */
public class RegularFileTest extends AbstractFileTest {

    @Test
    public void testFileInstallationFromArray() throws Exception {
        Path jar = getResource( "example.jar" );
        byte content[] = Files.readAllBytes( jar );
        add( new Directory( Paths.get( "usr/share/java" ) ) );
        add( new RegularFile( Paths.get( "usr/share/java/foobar.jar" ), content) );
        Path root = performInstallation();
        assertDirectoryStructure( "D /usr", "D /usr/share", "D /usr/share/java",
                "F /usr/share/java/foobar.jar" );
        assertFilesEqual(jar, root.resolve( Paths.get("usr/share/java/foobar.jar") ) );
    }

    @Test
    public void testFileInstallationFromFile() throws Exception {
        Path jar = getResource( "example.jar" );
        add( new Directory( Paths.get( "usr/share/java" )));
        add( new RegularFile(Paths.get( "usr/share/java/foobar.jar" ), jar ) );
        Path root = performInstallation();
        assertDirectoryStructure( "D /usr", "D /usr/share", "D /usr/share/java",
                "F /usr/share/java/foobar.jar" );
        assertFilesEqual(jar, root.resolve( Paths.get("usr/share/java/foobar.jar") ) );
    }

    @Test(expected = IOException.class)
    public void testNonexistentFile() throws Exception {
        add( new Directory( Paths.get( "usr/share/java" )));
        add( new RegularFile(Paths.get( "usr/share/java/foobar.jar" ), Paths.get( "not-here" )) );
        performInstallation();
    }
}

@@ -1452,32 +1452,197 @@
 oobar.jar%22) ) );
+%0A%0A        assertDescriptorEquals( %22%25attr(0755,root,root) %25dir /usr/share/java%22,%0A                                %22%25attr(0644,root,root) /usr/share/java/foobar.jar%22 );
 %0A    %7D%0A%0A    @Tes
@@ -2461,11 +2461,1201 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testAccessMode() throws Exception %7B%0A        Path jar = getResource( %22example.jar%22);%0A        add( new Directory( Paths.get( %22usr/share/java%22 )));%0A        add( new RegularFile(Paths.get( %22usr/share/java/foobar.jar%22 ), jar, 0666 ) );%0A        Path root = performInstallation();%0A        assertDirectoryStructure( %22D /usr%22, %22D /usr/share%22, %22D /usr/share/java%22,%0A                %22F /usr/share/java/foobar.jar%22 );%0A        assertFilesEqual(jar, root.resolve( Paths.get(%22usr/share/java/foobar.jar%22) ) );%0A%0A        assertDescriptorEquals( %22%25attr(0755,root,root) %25dir /usr/share/java%22,%0A                                %22%25attr(0666,root,root) /usr/share/java/foobar.jar%22 );%0A    %7D%0A%0A    @Test(expected = IllegalArgumentException.class)%0A    public void testIncorrectMode() throws Exception %7B%0A        Path jar = getResource( %22example.jar%22 );%0A        add( new RegularFile(Paths.get( %22usr/share/java/foobar.jar%22 ), jar, 01000) );%0A    %7D%0A%0A    @Test(expected = IllegalArgumentException.class)%0A    public void testNegativeMode() throws Exception %7B%0A        Path jar = getResource( %22example.jar%22 );%0A        add( new RegularFile(Paths.get( %22usr/share/java/foobar.jar%22 ), jar, -0644) );%0A    %7D
 %0A%7D%0A

Add descriptor assertions to RegularFileTest