8343100: Consolidate EmptyFolderTest and EmptyFolderPackageTest jpackage tests into single java file
Reviewed-by: almatvee
This commit is contained in:
parent
9f6d5b46ce
commit
00fe9f7bdf
@ -673,26 +673,40 @@ final public class TKit {
|
||||
assertTrue(path.toFile().exists(), String.format(
|
||||
"Check [%s] path exists", path));
|
||||
} else {
|
||||
assertFalse(path.toFile().exists(), String.format(
|
||||
assertTrue(!path.toFile().exists(), String.format(
|
||||
"Check [%s] path doesn't exist", path));
|
||||
}
|
||||
}
|
||||
|
||||
public static void assertPathNotEmptyDirectory(Path path) {
|
||||
if (Files.isDirectory(path)) {
|
||||
public static void assertDirectoryNotEmpty(Path path) {
|
||||
assertDirectoryExists(path, Optional.of(false));
|
||||
}
|
||||
|
||||
public static void assertDirectoryEmpty(Path path) {
|
||||
assertDirectoryExists(path, Optional.of(true));
|
||||
}
|
||||
|
||||
public static void assertDirectoryExists(Path path, Optional<Boolean> isEmptyCheck) {
|
||||
assertPathExists(path, true);
|
||||
boolean isDirectory = Files.isDirectory(path);
|
||||
if (isEmptyCheck.isEmpty() || !isDirectory) {
|
||||
assertTrue(isDirectory, String.format("Check [%s] is a directory", path));
|
||||
} else {
|
||||
ThrowingRunnable.toRunnable(() -> {
|
||||
try (var files = Files.list(path)) {
|
||||
TKit.assertFalse(files.findFirst().isEmpty(), String.format
|
||||
("Check [%s] is not an empty directory", path));
|
||||
boolean actualIsEmpty = files.findFirst().isEmpty();
|
||||
if (isEmptyCheck.get()) {
|
||||
TKit.assertTrue(actualIsEmpty, String.format("Check [%s] is not an empty directory", path));
|
||||
} else {
|
||||
TKit.assertTrue(!actualIsEmpty, String.format("Check [%s] is an empty directory", path));
|
||||
}
|
||||
}
|
||||
}).run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void assertDirectoryExists(Path path) {
|
||||
assertPathExists(path, true);
|
||||
assertTrue(path.toFile().isDirectory(), String.format(
|
||||
"Check [%s] is a directory", path));
|
||||
assertDirectoryExists(path, Optional.empty());
|
||||
}
|
||||
|
||||
public static void assertSymbolicLinkExists(Path path) {
|
||||
|
@ -322,7 +322,7 @@ public class WindowsHelper {
|
||||
Path shortcutPath = shortcutsRoot.resolve(startMenuShortcutPath);
|
||||
verifyShortcut(shortcutPath, exists);
|
||||
if (!exists) {
|
||||
TKit.assertPathNotEmptyDirectory(shortcutPath.getParent());
|
||||
TKit.assertDirectoryNotEmpty(shortcutPath.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import jdk.jpackage.test.TKit;
|
||||
|
||||
public class EmptyFolderBase {
|
||||
|
||||
// Note: To specify file use ".txt" extension.
|
||||
// Note: createDirStrcture() will call mkdir() or createNewFile() for paths defined
|
||||
// in dirStruct, so make sure paths are defined in order.
|
||||
|
||||
// folder-empty
|
||||
// folder-not-empty
|
||||
// folder-not-empty/folder-empty
|
||||
// folder-not-empty/another-folder-empty
|
||||
// folder-not-empty/folder-non-empty2
|
||||
// folder-not-empty/folder-non-empty2/file.txt
|
||||
private static final String [] DIR_STRUCT = {
|
||||
"folder-empty",
|
||||
"folder-not-empty",
|
||||
"folder-not-empty" + File.separator + "folder-empty",
|
||||
"folder-not-empty" + File.separator + "another-folder-empty",
|
||||
"folder-not-empty" + File.separator + "folder-non-empty2",
|
||||
"folder-not-empty" + File.separator + "folder-non-empty2" + File.separator +
|
||||
"file.txt"
|
||||
};
|
||||
|
||||
// See dirStruct
|
||||
public static void createDirStrcture(Path inputPath) throws IOException {
|
||||
File input = new File(inputPath.toString());
|
||||
input.mkdir();
|
||||
|
||||
for (String p : DIR_STRUCT) {
|
||||
File f = new File(input, p);
|
||||
if (p.endsWith(".txt")) {
|
||||
f.createNewFile();
|
||||
} else {
|
||||
f.mkdir();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void validateDirStrcture(Path appDirPath) {
|
||||
for (String p : DIR_STRUCT) {
|
||||
Path path = appDirPath.resolve(p);
|
||||
TKit.assertPathExists(path, true);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.nio.file.Path;
|
||||
import jdk.jpackage.internal.ApplicationLayout;
|
||||
import jdk.jpackage.test.PackageTest;
|
||||
import jdk.jpackage.test.PackageType;
|
||||
import jdk.jpackage.test.Annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests generation of packages with input folder containing empty folders.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary jpackage with input containing empty folders
|
||||
* @library ../helpers
|
||||
* @library /test/lib
|
||||
* @key jpackagePlatformPackage
|
||||
* @build EmptyFolderBase
|
||||
* @build jdk.jpackage.test.*
|
||||
* @build EmptyFolderPackageTest
|
||||
* @modules jdk.jpackage/jdk.jpackage.internal
|
||||
* @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main
|
||||
* --jpt-run=EmptyFolderPackageTest
|
||||
*/
|
||||
public class EmptyFolderPackageTest {
|
||||
|
||||
@Test
|
||||
public static void test() throws Exception {
|
||||
new PackageTest().configureHelloApp()
|
||||
.addInitializer(cmd -> {
|
||||
Path input = cmd.inputDir();
|
||||
EmptyFolderBase.createDirStrcture(input);
|
||||
})
|
||||
.addInstallVerifier(cmd -> {
|
||||
if (cmd.packageType() == PackageType.WIN_MSI) {
|
||||
if (cmd.isPackageUnpacked("Not running file "
|
||||
+ "structure check for empty folders")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ApplicationLayout appLayout = cmd.appLayout();
|
||||
Path appDir = appLayout.appDirectory();
|
||||
EmptyFolderBase.validateDirStrcture(appDir);
|
||||
})
|
||||
.run();
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -21,44 +21,113 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import jdk.jpackage.test.JPackageCommand;
|
||||
import jdk.jpackage.test.PackageTest;
|
||||
import jdk.jpackage.test.Annotations.Test;
|
||||
import jdk.jpackage.internal.ApplicationLayout;
|
||||
import jdk.jpackage.test.JPackageCommand;
|
||||
import jdk.jpackage.test.PackageType;
|
||||
import jdk.jpackage.test.TKit;
|
||||
|
||||
/**
|
||||
* Tests generation of app image with input folder containing empty folders.
|
||||
* Tests generation of packages and app image with input folder containing empty folders.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary jpackage with input containing empty folders
|
||||
* @summary jpackage for package with input containing empty folders
|
||||
* @library ../helpers
|
||||
* @library /test/lib
|
||||
* @key jpackagePlatformPackage
|
||||
* @build jdk.jpackage.test.*
|
||||
* @build EmptyFolderTest
|
||||
* @modules jdk.jpackage/jdk.jpackage.internal
|
||||
* @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main
|
||||
* --jpt-run=EmptyFolderTest.testPackage
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary jpackage for app image with input containing empty folders
|
||||
* @library ../helpers
|
||||
* @library /test/lib
|
||||
* @build EmptyFolderBase
|
||||
* @build jdk.jpackage.test.*
|
||||
* @build EmptyFolderTest
|
||||
* @modules jdk.jpackage/jdk.jpackage.internal
|
||||
* @run main/othervm -Xmx512m jdk.jpackage.test.Main
|
||||
* --jpt-run=EmptyFolderTest
|
||||
* --jpt-run=EmptyFolderTest.testAppImage
|
||||
*/
|
||||
|
||||
public class EmptyFolderTest {
|
||||
|
||||
@Test
|
||||
public static void test() throws Exception {
|
||||
JPackageCommand cmd = JPackageCommand.helloAppImage();
|
||||
public static void testPackage() {
|
||||
new PackageTest()
|
||||
.configureHelloApp()
|
||||
.addInitializer(EmptyFolderTest::createDirTree)
|
||||
.addInitializer(cmd -> {
|
||||
cmd.setArgumentValue("--name", "EmptyFolderPackageTest");
|
||||
})
|
||||
.addInstallVerifier(EmptyFolderTest::validateDirTree)
|
||||
.run();
|
||||
}
|
||||
|
||||
@Test
|
||||
public static void testAppImage() throws IOException {
|
||||
var cmd = JPackageCommand.helloAppImage();
|
||||
|
||||
// Add more files into input folder
|
||||
Path input = cmd.inputDir();
|
||||
EmptyFolderBase.createDirStrcture(input);
|
||||
createDirTree(cmd);
|
||||
|
||||
// Create app image
|
||||
cmd.executeAndAssertHelloAppImageCreated();
|
||||
|
||||
// Verify directory strcture
|
||||
ApplicationLayout appLayout = cmd.appLayout();
|
||||
Path appDir = appLayout.appDirectory();
|
||||
EmptyFolderBase.validateDirStrcture(appDir);
|
||||
// Verify directory structure
|
||||
validateDirTree(cmd);
|
||||
}
|
||||
|
||||
private static void createDirTree(JPackageCommand cmd) throws IOException {
|
||||
var baseDir = cmd.inputDir();
|
||||
for (var path : DIR_STRUCT) {
|
||||
path = baseDir.resolve(path);
|
||||
if (isFile(path)) {
|
||||
Files.createDirectories(path.getParent());
|
||||
Files.write(path, new byte[0]);
|
||||
} else {
|
||||
Files.createDirectories(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateDirTree(JPackageCommand cmd) {
|
||||
var outputBaseDir = cmd.appLayout().appDirectory();
|
||||
var inputBaseDir = cmd.inputDir();
|
||||
for (var path : DIR_STRUCT) {
|
||||
Path outputPath = outputBaseDir.resolve(path);
|
||||
if (isFile(outputPath)) {
|
||||
TKit.assertFileExists(outputPath);
|
||||
} else if (!PackageType.WINDOWS.contains(cmd.packageType())) {
|
||||
TKit.assertDirectoryExists(outputPath);
|
||||
} else if (inputBaseDir.resolve(path).toFile().list().length == 0) {
|
||||
// MSI packages don't support empty folders
|
||||
TKit.assertPathExists(outputPath, false);
|
||||
} else {
|
||||
TKit.assertDirectoryNotEmpty(outputPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isFile(Path path) {
|
||||
return path.getFileName().toString().endsWith(".txt");
|
||||
}
|
||||
|
||||
// Note: To specify file use ".txt" extension.
|
||||
private static final Path [] DIR_STRUCT = {
|
||||
Path.of("folder-empty"),
|
||||
Path.of("folder-not-empty"),
|
||||
Path.of("folder-not-empty", "folder-empty"),
|
||||
Path.of("folder-not-empty", "another-folder-empty"),
|
||||
Path.of("folder-not-empty", "folder-non-empty2", "file.txt")
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user