Skip to content

Commit 00fe9f7

Browse files
author
Alexey Semenyuk
committed
8343100: Consolidate EmptyFolderTest and EmptyFolderPackageTest jpackage tests into single java file
Reviewed-by: almatvee
1 parent 9f6d5b4 commit 00fe9f7

File tree

5 files changed

+108
-167
lines changed

5 files changed

+108
-167
lines changed

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -673,26 +673,40 @@ public static void assertPathExists(Path path, boolean exists) {
673673
assertTrue(path.toFile().exists(), String.format(
674674
"Check [%s] path exists", path));
675675
} else {
676-
assertFalse(path.toFile().exists(), String.format(
676+
assertTrue(!path.toFile().exists(), String.format(
677677
"Check [%s] path doesn't exist", path));
678678
}
679679
}
680680

681-
public static void assertPathNotEmptyDirectory(Path path) {
682-
if (Files.isDirectory(path)) {
681+
public static void assertDirectoryNotEmpty(Path path) {
682+
assertDirectoryExists(path, Optional.of(false));
683+
}
684+
685+
public static void assertDirectoryEmpty(Path path) {
686+
assertDirectoryExists(path, Optional.of(true));
687+
}
688+
689+
public static void assertDirectoryExists(Path path, Optional<Boolean> isEmptyCheck) {
690+
assertPathExists(path, true);
691+
boolean isDirectory = Files.isDirectory(path);
692+
if (isEmptyCheck.isEmpty() || !isDirectory) {
693+
assertTrue(isDirectory, String.format("Check [%s] is a directory", path));
694+
} else {
683695
ThrowingRunnable.toRunnable(() -> {
684696
try (var files = Files.list(path)) {
685-
TKit.assertFalse(files.findFirst().isEmpty(), String.format
686-
("Check [%s] is not an empty directory", path));
697+
boolean actualIsEmpty = files.findFirst().isEmpty();
698+
if (isEmptyCheck.get()) {
699+
TKit.assertTrue(actualIsEmpty, String.format("Check [%s] is not an empty directory", path));
700+
} else {
701+
TKit.assertTrue(!actualIsEmpty, String.format("Check [%s] is an empty directory", path));
702+
}
687703
}
688704
}).run();
689-
}
705+
}
690706
}
691707

692708
public static void assertDirectoryExists(Path path) {
693-
assertPathExists(path, true);
694-
assertTrue(path.toFile().isDirectory(), String.format(
695-
"Check [%s] is a directory", path));
709+
assertDirectoryExists(path, Optional.empty());
696710
}
697711

698712
public static void assertSymbolicLinkExists(Path path) {

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ private void verifyStartMenuShortcut(Path shortcutsRoot, boolean exists) {
322322
Path shortcutPath = shortcutsRoot.resolve(startMenuShortcutPath);
323323
verifyShortcut(shortcutPath, exists);
324324
if (!exists) {
325-
TKit.assertPathNotEmptyDirectory(shortcutPath.getParent());
325+
TKit.assertDirectoryNotEmpty(shortcutPath.getParent());
326326
}
327327
}
328328

test/jdk/tools/jpackage/share/EmptyFolderBase.java

Lines changed: 0 additions & 72 deletions
This file was deleted.

test/jdk/tools/jpackage/share/EmptyFolderPackageTest.java

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 84 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,44 +21,113 @@
2121
* questions.
2222
*/
2323

24+
import java.io.IOException;
25+
import java.nio.file.Files;
2426
import java.nio.file.Path;
25-
import jdk.jpackage.test.JPackageCommand;
27+
import jdk.jpackage.test.PackageTest;
2628
import jdk.jpackage.test.Annotations.Test;
27-
import jdk.jpackage.internal.ApplicationLayout;
29+
import jdk.jpackage.test.JPackageCommand;
30+
import jdk.jpackage.test.PackageType;
31+
import jdk.jpackage.test.TKit;
2832

2933
/**
30-
* Tests generation of app image with input folder containing empty folders.
34+
* Tests generation of packages and app image with input folder containing empty folders.
35+
*/
36+
37+
/*
38+
* @test
39+
* @summary jpackage for package with input containing empty folders
40+
* @library ../helpers
41+
* @library /test/lib
42+
* @key jpackagePlatformPackage
43+
* @build jdk.jpackage.test.*
44+
* @build EmptyFolderTest
45+
* @modules jdk.jpackage/jdk.jpackage.internal
46+
* @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main
47+
* --jpt-run=EmptyFolderTest.testPackage
3148
*/
3249

3350
/*
3451
* @test
35-
* @summary jpackage with input containing empty folders
52+
* @summary jpackage for app image with input containing empty folders
3653
* @library ../helpers
3754
* @library /test/lib
38-
* @build EmptyFolderBase
3955
* @build jdk.jpackage.test.*
4056
* @build EmptyFolderTest
4157
* @modules jdk.jpackage/jdk.jpackage.internal
4258
* @run main/othervm -Xmx512m jdk.jpackage.test.Main
43-
* --jpt-run=EmptyFolderTest
59+
* --jpt-run=EmptyFolderTest.testAppImage
4460
*/
61+
4562
public class EmptyFolderTest {
4663

4764
@Test
48-
public static void test() throws Exception {
49-
JPackageCommand cmd = JPackageCommand.helloAppImage();
65+
public static void testPackage() {
66+
new PackageTest()
67+
.configureHelloApp()
68+
.addInitializer(EmptyFolderTest::createDirTree)
69+
.addInitializer(cmd -> {
70+
cmd.setArgumentValue("--name", "EmptyFolderPackageTest");
71+
})
72+
.addInstallVerifier(EmptyFolderTest::validateDirTree)
73+
.run();
74+
}
75+
76+
@Test
77+
public static void testAppImage() throws IOException {
78+
var cmd = JPackageCommand.helloAppImage();
5079

5180
// Add more files into input folder
52-
Path input = cmd.inputDir();
53-
EmptyFolderBase.createDirStrcture(input);
81+
createDirTree(cmd);
5482

5583
// Create app image
5684
cmd.executeAndAssertHelloAppImageCreated();
5785

58-
// Verify directory strcture
59-
ApplicationLayout appLayout = cmd.appLayout();
60-
Path appDir = appLayout.appDirectory();
61-
EmptyFolderBase.validateDirStrcture(appDir);
86+
// Verify directory structure
87+
validateDirTree(cmd);
88+
}
89+
90+
private static void createDirTree(JPackageCommand cmd) throws IOException {
91+
var baseDir = cmd.inputDir();
92+
for (var path : DIR_STRUCT) {
93+
path = baseDir.resolve(path);
94+
if (isFile(path)) {
95+
Files.createDirectories(path.getParent());
96+
Files.write(path, new byte[0]);
97+
} else {
98+
Files.createDirectories(path);
99+
}
100+
}
101+
}
102+
103+
private static void validateDirTree(JPackageCommand cmd) {
104+
var outputBaseDir = cmd.appLayout().appDirectory();
105+
var inputBaseDir = cmd.inputDir();
106+
for (var path : DIR_STRUCT) {
107+
Path outputPath = outputBaseDir.resolve(path);
108+
if (isFile(outputPath)) {
109+
TKit.assertFileExists(outputPath);
110+
} else if (!PackageType.WINDOWS.contains(cmd.packageType())) {
111+
TKit.assertDirectoryExists(outputPath);
112+
} else if (inputBaseDir.resolve(path).toFile().list().length == 0) {
113+
// MSI packages don't support empty folders
114+
TKit.assertPathExists(outputPath, false);
115+
} else {
116+
TKit.assertDirectoryNotEmpty(outputPath);
117+
}
118+
}
119+
}
120+
121+
private static boolean isFile(Path path) {
122+
return path.getFileName().toString().endsWith(".txt");
62123
}
63124

125+
// Note: To specify file use ".txt" extension.
126+
private static final Path [] DIR_STRUCT = {
127+
Path.of("folder-empty"),
128+
Path.of("folder-not-empty"),
129+
Path.of("folder-not-empty", "folder-empty"),
130+
Path.of("folder-not-empty", "another-folder-empty"),
131+
Path.of("folder-not-empty", "folder-non-empty2", "file.txt")
132+
};
64133
}

0 commit comments

Comments
 (0)