Path: blob/master/test/jdk/tools/jpackage/linux/LinuxResourceTest.java
41149 views
/*1* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.IOException;24import java.nio.file.Path;25import jdk.jpackage.test.TKit;26import jdk.jpackage.test.PackageTest;27import jdk.jpackage.test.PackageType;28import jdk.jpackage.test.LinuxHelper;29import jdk.jpackage.test.Annotations.Test;30import java.util.List;3132/*33* @test34* @summary jpackage with --resource-dir35* @library ../helpers36* @build jdk.jpackage.test.*37* @requires (os.family == "linux")38* @modules jdk.jpackage/jdk.jpackage.internal39* @compile LinuxResourceTest.java40* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main41* --jpt-run=LinuxResourceTest42*/4344public class LinuxResourceTest {45@Test46public static void testHardcodedProperties() throws IOException {47new PackageTest()48.forTypes(PackageType.LINUX)49.configureHelloApp()50.addInitializer(cmd -> {51cmd52.setFakeRuntime()53.saveConsoleOutput(true)54.addArguments("--resource-dir", TKit.createTempDirectory("resources"));55})56.forTypes(PackageType.LINUX_DEB)57.addInitializer(cmd -> {58Path controlFile = Path.of(cmd.getArgumentValue("--resource-dir"),59"control");60TKit.createTextFile(controlFile, List.of(61"Package: dont-install-me",62"Version: 1.2.3-R2",63"Section: APPLICATION_SECTION",64"Maintainer: APPLICATION_MAINTAINER",65"Priority: optional",66"Architecture: bar",67"Provides: dont-install-me",68"Description: APPLICATION_DESCRIPTION",69"Installed-Size: APPLICATION_INSTALLED_SIZE",70"Depends: PACKAGE_DEFAULT_DEPENDENCIES"71));72})73.addBundleVerifier((cmd, result) -> {74TKit.assertTextStream("Using custom package resource [DEB control file]")75.predicate(String::contains)76.apply(result.getOutput().stream());77TKit.assertTextStream(String.format(78"Expected value of \"Package\" property is [%s]. Actual value in output package is [dont-install-me]",79LinuxHelper.getPackageName(cmd)))80.predicate(String::contains)81.apply(result.getOutput().stream());82TKit.assertTextStream(83"Expected value of \"Version\" property is [1.0-1]. Actual value in output package is [1.2.3-R2]")84.predicate(String::contains)85.apply(result.getOutput().stream());86TKit.assertTextStream(String.format(87"Expected value of \"Architecture\" property is [%s]. Actual value in output package is [bar]",88LinuxHelper.getDefaultPackageArch(cmd.packageType())))89.predicate(String::contains)90.apply(result.getOutput().stream());91})92.forTypes(PackageType.LINUX_RPM)93.addInitializer(cmd -> {94Path specFile = Path.of(cmd.getArgumentValue("--resource-dir"),95LinuxHelper.getPackageName(cmd) + ".spec");96TKit.createTextFile(specFile, List.of(97"Name: dont-install-me",98"Version: 1.2.3",99"Release: R2",100"Summary: APPLICATION_SUMMARY",101"License: APPLICATION_LICENSE_TYPE",102"Prefix: %{dirname:APPLICATION_DIRECTORY}",103"Provides: dont-install-me",104"%description",105"APPLICATION_DESCRIPTION",106"%prep",107"%build",108"%install",109"rm -rf %{buildroot}",110"install -d -m 755 %{buildroot}APPLICATION_DIRECTORY",111"cp -r %{_sourcedir}APPLICATION_DIRECTORY/* %{buildroot}APPLICATION_DIRECTORY",112"%files",113"APPLICATION_DIRECTORY"114));115})116.addBundleVerifier((cmd, result) -> {117TKit.assertTextStream("Using custom package resource [RPM spec file]")118.predicate(String::contains)119.apply(result.getOutput().stream());120TKit.assertTextStream(String.format(121"Expected value of \"Name\" property is [%s]. Actual value in output package is [dont-install-me]",122LinuxHelper.getPackageName(cmd)))123.predicate(String::contains)124.apply(result.getOutput().stream());125TKit.assertTextStream(126"Expected value of \"Version\" property is [1.0]. Actual value in output package is [1.2.3]")127.predicate(String::contains)128.apply(result.getOutput().stream());129TKit.assertTextStream(130"Expected value of \"Release\" property is [1]. Actual value in output package is [R2]")131.predicate(String::contains)132.apply(result.getOutput().stream());133})134.run();135}136}137138139