Path: blob/master/test/jdk/tools/jpackage/macosx/HostArchPkgTest.java
41152 views
/*1* Copyright (c) 2021, 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.nio.file.Files;24import java.nio.file.Path;25import javax.xml.parsers.DocumentBuilder;26import javax.xml.parsers.DocumentBuilderFactory;27import javax.xml.xpath.XPath;28import javax.xml.xpath.XPathConstants;29import javax.xml.xpath.XPathFactory;30import jdk.jpackage.test.JPackageCommand;31import jdk.jpackage.test.PackageTest;32import jdk.jpackage.test.PackageType;33import jdk.jpackage.test.TKit;34import jdk.jpackage.test.Annotations.Test;3536/**37* Test will generation default pkg package and will validate "hostArchitectures"38* attribute in unpacked pkg package inside Distribution file. See JDK-8266179.39*/4041/*42* @test43* @summary jpackage test to validate "hostArchitectures" attribute44* @library ../helpers45* @build jdk.jpackage.test.*46* @modules jdk.jpackage/jdk.jpackage.internal47* @compile HostArchPkgTest.java48* @requires (os.family == "mac")49* @key jpackagePlatformPackage50* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main51* --jpt-run=HostArchPkgTest52*/53public class HostArchPkgTest {5455private static void verifyHostArch(JPackageCommand cmd) throws Exception {56Path distributionFile = cmd.pathToUnpackedPackageFile(Path.of("/"))57.toAbsolutePath()58.getParent()59.resolve("data")60.resolve("Distribution");6162DocumentBuilderFactory dbf63= DocumentBuilderFactory.newDefaultInstance();64dbf.setFeature("http://apache.org/xml/features/" +65"nonvalidating/load-external-dtd", false);66DocumentBuilder b = dbf.newDocumentBuilder();67org.w3c.dom.Document doc68= b.parse(Files.newInputStream(distributionFile));6970XPath xPath = XPathFactory.newInstance().newXPath();7172String v = (String) xPath.evaluate(73"/installer-gui-script/options/@hostArchitectures",74doc, XPathConstants.STRING);7576if ("aarch64".equals(System.getProperty("os.arch"))) {77TKit.assertEquals(v, "arm64",78"Check value of \"hostArchitectures\" attribute");79} else {80TKit.assertEquals(v, "x86_64",81"Check value of \"hostArchitectures\" attribute");82}83}8485@Test86public static void test() {87new PackageTest()88.forTypes(PackageType.MAC_PKG)89.configureHelloApp()90.addInstallVerifier(HostArchPkgTest::verifyHostArch)91.run(PackageTest.Action.CREATE_AND_UNPACK);92}93}949596