test/jdk/tools/jpackage/junit/jdk/incubator/jpackage/internal/DeployParamsTest.java
author herrick
Fri, 08 Nov 2019 14:53:03 -0500
branchJDK-8200758-branch
changeset 58994 b09ba68c6a19
parent 58302 test/jdk/tools/jpackage/junit/jdk/jpackage/internal/DeployParamsTest.java@718bd56695b3
permissions -rw-r--r--
8233636 : Make jpackage an incubator and remove tool provider implementation Reviewed-by: asemenyuk, almatvee, kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58302
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     1
/*
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     4
 *
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     8
 *
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    13
 * accompanied this code).
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    14
 *
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    18
 *
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    21
 * questions.
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    22
 */
58994
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents: 58302
diff changeset
    23
package jdk.incubator.jpackage.internal;
58302
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    24
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    25
import java.io.File;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    26
import java.io.IOException;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    27
import org.hamcrest.BaseMatcher;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    28
import org.hamcrest.Description;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    29
import org.junit.Rule;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    30
import org.junit.Before;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    31
import org.junit.Test;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    32
import org.junit.rules.ExpectedException;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    33
import org.junit.rules.TemporaryFolder;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    34
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    35
/**
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    36
 * Test for JDK-8211285
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    37
 */
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    38
public class DeployParamsTest {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    39
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    40
    @Rule
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    41
    public final TemporaryFolder tempFolder = new TemporaryFolder();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    42
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    43
    @Rule
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    44
    public final ExpectedException thrown = ExpectedException.none();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    45
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    46
    @Before
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    47
    public void setUp() throws IOException {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    48
        testRoot = tempFolder.newFolder();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    49
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    50
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    51
    @Test
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    52
    public void testValidAppName() throws PackagerException {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    53
        initParamsAppName();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    54
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    55
        setAppNameAndValidate("Test");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    56
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    57
        setAppNameAndValidate("Test Name");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    58
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    59
        setAppNameAndValidate("Test - Name !!!");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    60
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    61
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    62
    @Test
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    63
    public void testInvalidAppName() throws PackagerException {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    64
        initForInvalidAppNamePackagerException();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    65
        initParamsAppName();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    66
        setAppNameAndValidate("Test\nName");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    67
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    68
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    69
    @Test
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    70
    public void testInvalidAppName2() throws PackagerException {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    71
        initForInvalidAppNamePackagerException();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    72
        initParamsAppName();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    73
        setAppNameAndValidate("Test\rName");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    74
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    75
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    76
    @Test
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    77
    public void testInvalidAppName3() throws PackagerException {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    78
        initForInvalidAppNamePackagerException();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    79
        initParamsAppName();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    80
        setAppNameAndValidate("TestName\\");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    81
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    82
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    83
    @Test
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    84
    public void testInvalidAppName4() throws PackagerException {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    85
        initForInvalidAppNamePackagerException();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    86
        initParamsAppName();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    87
        setAppNameAndValidate("Test \" Name");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    88
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    89
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    90
    private void initForInvalidAppNamePackagerException() {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    91
        thrown.expect(PackagerException.class);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    92
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    93
        String msg = "Error: Invalid Application name";
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    94
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    95
        // Unfortunately org.hamcrest.core.StringStartsWith is not available
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    96
        // with older junit, DIY
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    97
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    98
        // thrown.expectMessage(startsWith("Error: Invalid Application name"));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    99
        thrown.expectMessage(new BaseMatcher() {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   100
            @Override
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   101
            @SuppressWarnings("unchecked")
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   102
            public boolean matches(Object o) {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   103
                if (o instanceof String) {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   104
                    return ((String) o).startsWith(msg);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   105
                }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   106
                return false;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   107
            }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   108
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   109
            @Override
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   110
            public void describeTo(Description d) {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   111
                d.appendText(msg);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   112
            }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   113
        });
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   114
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   115
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   116
    // Returns deploy params initialized to pass all validation, except for
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   117
    // app name
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   118
    private void initParamsAppName() {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   119
        params = new DeployParams();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   120
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   121
        params.setOutput(testRoot);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   122
        params.addResource(testRoot, new File(testRoot, "test.jar"));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   123
        params.addBundleArgument(Arguments.CLIOptions.APPCLASS.getId(),
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   124
                "TestClass");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   125
        params.addBundleArgument(Arguments.CLIOptions.MAIN_JAR.getId(),
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   126
                "test.jar");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   127
        params.addBundleArgument(Arguments.CLIOptions.INPUT.getId(), "input");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   128
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   129
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   130
    private void setAppNameAndValidate(String appName) throws PackagerException {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   131
        params.addBundleArgument(Arguments.CLIOptions.NAME.getId(), appName);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   132
        params.validate();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   133
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   134
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   135
    private File testRoot = null;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   136
    private DeployParams params;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   137
}