test/jdk/tools/jpackage/junit/jdk/jpackage/internal/PathGroupTest.java
author herrick
Tue, 24 Sep 2019 13:43:58 -0400
branchJDK-8200758-branch
changeset 58302 718bd56695b3
child 58696 61c44899b4eb
permissions -rw-r--r--
8231277 : Adjust Linux application image layout Submitted-by: asemenyuk Reviewed-by: herrick, almatvee
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) 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.  Oracle designates this
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    10
 *
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    11
 * 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
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    14
 * 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
    15
 * accompanied this code).
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    16
 *
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    20
 *
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    23
 * questions.
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    24
 */
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    25
package jdk.jpackage.internal;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    26
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    27
import java.nio.file.Path;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    28
import java.util.Collections;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    29
import java.util.List;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    30
import java.util.Map;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    31
import static org.hamcrest.CoreMatchers.equalTo;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    32
import static org.hamcrest.CoreMatchers.not;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    33
import static org.junit.Assert.*;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    34
import org.junit.Test;
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    35
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    36
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    37
public class PathGroupTest {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    38
    public PathGroupTest() {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    39
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    40
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    41
    @Test(expected = NullPointerException.class)
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    42
    public void testNullId() {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    43
         new PathGroup(Map.of()).getPath(null);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    44
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    45
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    46
    @Test
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    47
    public void testEmptyPathGroup() {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    48
        PathGroup pg = new PathGroup(Map.of());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    49
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    50
        assertNull(pg.getPath("foo"));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    51
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    52
        assertEquals(0, pg.paths().size());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    53
        assertEquals(0, pg.roots().size());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    54
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    55
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    56
    @Test
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    57
    public void testRootsSinglePath() {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    58
        final PathGroup pg = new PathGroup(Map.of("main", PATH_FOO));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    59
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    60
        List<Path> paths = pg.paths();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    61
        assertEquals(1, paths.size());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    62
        assertEquals(PATH_FOO, paths.iterator().next());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    63
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    64
        List<Path> roots = pg.roots();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    65
        assertEquals(1, roots.size());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    66
        assertEquals(PATH_FOO, roots.iterator().next());
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 testDuplicatedRoots() {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    71
        final PathGroup pg = new PathGroup(Map.of("main", PATH_FOO, "another",
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    72
                PATH_FOO, "root", PATH_EMPTY));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    73
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    74
        List<Path> paths = pg.paths();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    75
        Collections.sort(paths);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    76
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    77
        assertEquals(3, paths.size());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    78
        assertEquals(PATH_EMPTY, paths.get(0));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    79
        assertEquals(PATH_FOO, paths.get(1));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    80
        assertEquals(PATH_FOO, paths.get(2));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    81
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    82
        List<Path> roots = pg.roots();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    83
        assertEquals(1, roots.size());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    84
        assertEquals(PATH_EMPTY, roots.get(0));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    85
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    86
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    87
    @Test
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    88
    public void testRoots() {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    89
        final PathGroup pg = new PathGroup(Map.of(1, Path.of("foo"), 2, Path.of(
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    90
                "foo", "bar"), 3, Path.of("foo", "bar", "buz")));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    91
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    92
        List<Path> paths = pg.paths();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    93
        assertEquals(3, paths.size());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    94
        assertTrue(paths.contains(Path.of("foo")));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    95
        assertTrue(paths.contains(Path.of("foo", "bar")));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    96
        assertTrue(paths.contains(Path.of("foo", "bar", "buz")));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    97
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    98
        List<Path> roots = pg.roots();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
    99
        assertEquals(1, roots.size());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   100
        assertEquals(Path.of("foo"), roots.get(0));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   101
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   102
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   103
    @Test
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   104
    public void testResolveAt() {
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   105
        final PathGroup pg = new PathGroup(Map.of(0, PATH_FOO, 1, PATH_BAR, 2,
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   106
                PATH_EMPTY));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   107
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   108
        final Path aPath = Path.of("a");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   109
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   110
        final PathGroup pg2 = pg.resolveAt(aPath);
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   111
        assertThat(pg, not(equalTo(pg2)));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   112
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   113
        List<Path> paths = pg.paths();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   114
        assertEquals(3, paths.size());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   115
        assertTrue(paths.contains(PATH_EMPTY));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   116
        assertTrue(paths.contains(PATH_FOO));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   117
        assertTrue(paths.contains(PATH_BAR));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   118
        assertEquals(PATH_EMPTY, pg.roots().get(0));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   119
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   120
        paths = pg2.paths();
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   121
        assertEquals(3, paths.size());
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   122
        assertTrue(paths.contains(aPath.resolve(PATH_EMPTY)));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   123
        assertTrue(paths.contains(aPath.resolve(PATH_FOO)));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   124
        assertTrue(paths.contains(aPath.resolve(PATH_BAR)));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   125
        assertEquals(aPath, pg2.roots().get(0));
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   126
    }
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   127
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   128
    private final static Path PATH_FOO = Path.of("foo");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   129
    private final static Path PATH_BAR = Path.of("bar");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   130
    private final static Path PATH_EMPTY = Path.of("");
718bd56695b3 8231277 : Adjust Linux application image layout
herrick
parents:
diff changeset
   131
}