8231604: Expand junit test added with JDK-8230920 JDK-8200758-branch
authorherrick
Tue, 15 Oct 2019 13:39:58 -0400
branchJDK-8200758-branch
changeset 58606 6e02ff008c16
parent 58584 910b14f4fe3a
child 58607 7451b17b40d3
8231604: Expand junit test added with JDK-8230920 Reviewed-by: asemenyuk
test/jdk/tools/jpackage/junit/jdk/jpackage/internal/AppImageFileTest.java
--- a/test/jdk/tools/jpackage/junit/jdk/jpackage/internal/AppImageFileTest.java	Mon Oct 14 14:36:45 2019 -0400
+++ b/test/jdk/tools/jpackage/junit/jdk/jpackage/internal/AppImageFileTest.java	Tue Oct 15 13:39:58 2019 -0400
@@ -1,146 +1,167 @@
-/*
- * Copyright (c) 2019, 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * 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.
- */
-package jdk.jpackage.internal;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.StandardOpenOption;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.LinkedHashMap;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
-
-public class AppImageFileTest {
-
-    @Rule
-    public final TemporaryFolder tempFolder = new TemporaryFolder();
-
-    @Test
-    public void testIdentity() throws IOException {
-        Map<String, ? super Object> params = new LinkedHashMap<>();
-        params.put("name", "Foo");
-        params.put("app-version", "2.3");
-        params.put("description", "Duck is the King");
-        AppImageFile aif = create(params);
-
-        Assert.assertEquals("Foo", aif.getLauncherName());
-    }
-
-    @Test
-    public void testInvalidCommandLine() throws IOException {
-        // Just make sure AppImageFile will tolerate jpackage params that would
-        // never create app image at both load/save phases.
-        // People would edit this file just because they can.
-        // We should be ready to handle curious minds.
-        Map<String, ? super Object> params = new LinkedHashMap<>();
-        params.put("invalidParamName", "randomStringValue");
-        create(params);
-
-        params = new LinkedHashMap<>();
-        params.put("name", "foo");
-        params.put("app-version", "");
-        create(params);
-    }
-
-    @Test
-    public void testInavlidXml() throws IOException {
-        assertInvalid(createFromXml("<foo/>"));
-        assertInvalid(createFromXml("<jpackage-state/>"));
-        assertInvalid(createFromXml(
-                "<jpackage-state>",
-                    "<main-launcher></main-launcher>",
-                "</jpackage-state>"));
-    }
-
-    @Test
-    public void testValidXml() throws IOException {
-        Assert.assertEquals("Foo", (createFromXml(
-                "<jpackage-state>",
-                    "<main-launcher>Foo</main-launcher>",
-                "</jpackage-state>")).getLauncherName());
-
-        Assert.assertEquals("Foo", (createFromXml(
-                "<jpackage-state>",
-                    "<main-launcher>Foo</main-launcher>",
-                    "<main-launcher>Bar</main-launcher>",
-                "</jpackage-state>")).getLauncherName());
-
-        var file = createFromXml(
-                "<jpackage-state>",
-                    "<main-launcher>Foo</main-launcher>",
-                    "<launcher></launcher>",
-                "</jpackage-state>");
-        Assert.assertEquals("Foo", file.getLauncherName());
-        Assert.assertArrayEquals(new String[0],
-                file.getAddLauncherNames().toArray(String[]::new));
-    }
-
-    @Test
-    public void testMainLauncherName() throws IOException {
-        Map<String, ? super Object> params = new LinkedHashMap<>();
-        params.put("name", "Foo");
-        params.put("description", "Duck App Description");
-        AppImageFile aif = create(params);
-
-        Assert.assertEquals("Foo", aif.getLauncherName());
-    }
-
-    @Test
-    public void testAddLauncherNames() throws IOException {
-    }
-
-    private AppImageFile create(Map<String, Object> params) throws IOException {
-        AppImageFile.save(tempFolder.getRoot().toPath(), params);
-        return AppImageFile.load(tempFolder.getRoot().toPath());
-    }
-
-    private void assertInvalid(AppImageFile file) {
-        Assert.assertNull(file.getLauncherName());
-        Assert.assertNull(file.getAddLauncherNames());
-    }
-
-    private AppImageFile createFromXml(String... xmlData) throws IOException {
-        Path directory = tempFolder.getRoot().toPath();
-        Path path = directory.resolve(AppImageFile.XML_FILENAME);
-        path.toFile().mkdirs();
-        Files.delete(path);
-
-        ArrayList<String> data = new ArrayList();
-        data.add("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>");
-        data.addAll(List.of(xmlData));
-
-        Files.write(path, data, StandardOpenOption.CREATE,
-                    StandardOpenOption.TRUNCATE_EXISTING);
-
-        AppImageFile image = AppImageFile.load(directory);
-        return image;
-    }
-
-}
+/*
+ * Copyright (c) 2019, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+package jdk.jpackage.internal;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.LinkedHashMap;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
+
+public class AppImageFileTest {
+
+    @Rule
+    public final TemporaryFolder tempFolder = new TemporaryFolder();
+
+    @Test
+    public void testIdentity() throws IOException {
+        Map<String, ? super Object> params = new LinkedHashMap<>();
+        params.put("name", "Foo");
+        params.put("app-version", "2.3");
+        params.put("description", "Duck is the King");
+        AppImageFile aif = create(params);
+
+        Assert.assertEquals("Foo", aif.getLauncherName());
+    }
+
+    @Test
+    public void testInvalidCommandLine() throws IOException {
+        // Just make sure AppImageFile will tolerate jpackage params that would
+        // never create app image at both load/save phases.
+        // People would edit this file just because they can.
+        // We should be ready to handle curious minds.
+        Map<String, ? super Object> params = new LinkedHashMap<>();
+        params.put("invalidParamName", "randomStringValue");
+        create(params);
+
+        params = new LinkedHashMap<>();
+        params.put("name", "foo");
+        params.put("app-version", "");
+        create(params);
+    }
+
+    @Test
+    public void testInavlidXml() throws IOException {
+        assertInvalid(createFromXml("<foo/>"));
+        assertInvalid(createFromXml("<jpackage-state/>"));
+        assertInvalid(createFromXml(
+                "<jpackage-state>",
+                    "<main-launcher></main-launcher>",
+                "</jpackage-state>"));
+    }
+
+    @Test
+    public void testValidXml() throws IOException {
+        Assert.assertEquals("Foo", (createFromXml(
+                "<jpackage-state>",
+                    "<main-launcher>Foo</main-launcher>",
+                "</jpackage-state>")).getLauncherName());
+
+        Assert.assertEquals("Foo", (createFromXml(
+                "<jpackage-state>",
+                    "<main-launcher>Foo</main-launcher>",
+                    "<main-launcher>Bar</main-launcher>",
+                "</jpackage-state>")).getLauncherName());
+
+        var file = createFromXml(
+                "<jpackage-state>",
+                    "<main-launcher>Foo</main-launcher>",
+                    "<launcher></launcher>",
+                "</jpackage-state>");
+        Assert.assertEquals("Foo", file.getLauncherName());
+        Assert.assertArrayEquals(new String[0],
+                file.getAddLauncherNames().toArray(String[]::new));
+    }
+
+    @Test
+    public void testMainLauncherName() throws IOException {
+        Map<String, ? super Object> params = new LinkedHashMap<>();
+        params.put("name", "Foo");
+        params.put("description", "Duck App Description");
+        AppImageFile aif = create(params);
+
+        Assert.assertEquals("Foo", aif.getLauncherName());
+    }
+
+    @Test
+    public void testAddLauncherNames() throws IOException {
+        Map<String, ? super Object> params = new LinkedHashMap<>();
+        List<Map<String, ? super Object>> launchersAsMap = new ArrayList<>();
+
+        Map<String, ? super Object> addLauncher2Params = new LinkedHashMap();
+        addLauncher2Params.put("name", "Launcher2Name");
+        launchersAsMap.add(addLauncher2Params);
+
+        Map<String, ? super Object> addLauncher3Params = new LinkedHashMap();
+        addLauncher3Params.put("name", "Launcher3Name");
+        launchersAsMap.add(addLauncher3Params);
+
+        params.put("name", "Duke App");
+        params.put("description", "Duke App Description");
+        params.put("add-launcher", launchersAsMap);
+        AppImageFile aif = create(params);
+
+	List<String> addLauncherNames = aif.getAddLauncherNames();
+        Assert.assertEquals(2, addLauncherNames.size());
+        Assert.assertTrue(addLauncherNames.contains("Launcher2Name"));
+        Assert.assertTrue(addLauncherNames.contains("Launcher3Name"));
+
+    }
+
+    private AppImageFile create(Map<String, Object> params) throws IOException {
+        AppImageFile.save(tempFolder.getRoot().toPath(), params);
+        return AppImageFile.load(tempFolder.getRoot().toPath());
+    }
+
+    private void assertInvalid(AppImageFile file) {
+        Assert.assertNull(file.getLauncherName());
+        Assert.assertNull(file.getAddLauncherNames());
+    }
+
+    private AppImageFile createFromXml(String... xmlData) throws IOException {
+        Path directory = tempFolder.getRoot().toPath();
+        Path path = directory.resolve(AppImageFile.XML_FILENAME);
+        path.toFile().mkdirs();
+        Files.delete(path);
+
+        ArrayList<String> data = new ArrayList();
+        data.add("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>");
+        data.addAll(List.of(xmlData));
+
+        Files.write(path, data, StandardOpenOption.CREATE,
+                    StandardOpenOption.TRUNCATE_EXISTING);
+
+        AppImageFile image = AppImageFile.load(directory);
+        return image;
+    }
+
+}