test/jdk/tools/jpackage/junit/jdk/jpackage/internal/ApplicationLayoutTest.java
branchJDK-8200758-branch
changeset 58994 b09ba68c6a19
parent 58993 b5e1baa9d2c3
child 58995 de1413ae214c
equal deleted inserted replaced
58993:b5e1baa9d2c3 58994:b09ba68c6a19
     1 /*
       
     2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 package jdk.jpackage.internal;
       
    26 
       
    27 import java.io.IOException;
       
    28 import java.nio.file.Files;
       
    29 import java.nio.file.Path;
       
    30 import org.junit.Test;
       
    31 import org.junit.Rule;
       
    32 import org.junit.rules.TemporaryFolder;
       
    33 import static org.junit.Assert.*;
       
    34 
       
    35 
       
    36 public class ApplicationLayoutTest {
       
    37 
       
    38     @Rule
       
    39     public final TemporaryFolder tempFolder = new TemporaryFolder();
       
    40 
       
    41     private void fillLinuxAppImage() throws IOException {
       
    42         appImage = tempFolder.newFolder("Foo").toPath();
       
    43 
       
    44         Path base = appImage.getFileName();
       
    45 
       
    46         tempFolder.newFolder(base.toString(), "bin");
       
    47         tempFolder.newFolder(base.toString(), "lib", "app", "mods");
       
    48         tempFolder.newFolder(base.toString(), "lib", "runtime", "bin");
       
    49         tempFolder.newFile(base.resolve("bin/Foo").toString());
       
    50         tempFolder.newFile(base.resolve("lib/app/Foo.cfg").toString());
       
    51         tempFolder.newFile(base.resolve("lib/app/hello.jar").toString());
       
    52         tempFolder.newFile(base.resolve("lib/Foo.png").toString());
       
    53         tempFolder.newFile(base.resolve("lib/libapplauncher.so").toString());
       
    54         tempFolder.newFile(base.resolve("lib/runtime/bin/java").toString());
       
    55     }
       
    56 
       
    57     @Test
       
    58     public void testLinux() throws IOException {
       
    59         fillLinuxAppImage();
       
    60         testApplicationLayout(ApplicationLayout.linuxAppImage());
       
    61     }
       
    62 
       
    63     private void testApplicationLayout(ApplicationLayout layout) throws IOException {
       
    64         ApplicationLayout srcLayout = layout.resolveAt(appImage);
       
    65         assertApplicationLayout(srcLayout);
       
    66 
       
    67         ApplicationLayout dstLayout = layout.resolveAt(
       
    68                 appImage.getParent().resolve(
       
    69                         "Copy" + appImage.getFileName().toString()));
       
    70         srcLayout.move(dstLayout);
       
    71         Files.deleteIfExists(appImage);
       
    72         assertApplicationLayout(dstLayout);
       
    73 
       
    74         dstLayout.copy(srcLayout);
       
    75         assertApplicationLayout(srcLayout);
       
    76         assertApplicationLayout(dstLayout);
       
    77     }
       
    78 
       
    79     private void assertApplicationLayout(ApplicationLayout layout) throws IOException {
       
    80         assertTrue(Files.isRegularFile(layout.appDirectory().resolve("Foo.cfg")));
       
    81         assertTrue(Files.isRegularFile(layout.appDirectory().resolve("hello.jar")));
       
    82         assertTrue(Files.isDirectory(layout.appModsDirectory()));
       
    83         assertTrue(Files.isRegularFile(layout.launchersDirectory().resolve("Foo")));
       
    84         assertTrue(Files.isRegularFile(layout.destktopIntegrationDirectory().resolve("Foo.png")));
       
    85         assertTrue(Files.isRegularFile(layout.dllDirectory().resolve("libapplauncher.so")));
       
    86         assertTrue(Files.isRegularFile(layout.runtimeDirectory().resolve("bin/java")));
       
    87     }
       
    88 
       
    89     private Path appImage;
       
    90 }