test/jdk/java/util/jar/Manifest/WriteBinaryStructure.java
author rriggs
Fri, 21 Dec 2018 09:54:32 -0500
changeset 53095 33a51275fee0
permissions -rw-r--r--
8066619: Fix deprecation warnings in java.util.jar Reviewed-by: rriggs, lancea Contributed-by: philipp.kunz@paratix.ch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53095
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
     1
/*
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
     4
 *
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
     8
 *
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    13
 * accompanied this code).
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    14
 *
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    18
 *
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    21
 * questions.
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    22
 */
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    23
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    24
import static java.nio.charset.StandardCharsets.UTF_8;
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    25
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    26
import java.io.ByteArrayOutputStream;
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    27
import java.io.IOException;
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    28
import java.util.jar.Attributes;
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    29
import java.util.jar.Attributes.Name;
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    30
import java.util.jar.Manifest;
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    31
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    32
import org.testng.annotations.Test;
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    33
import static org.testng.Assert.*;
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    34
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    35
/**
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    36
 * @test
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    37
 * @bug 8066619
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    38
 * @run testng WriteBinaryStructure
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    39
 * @summary Tests that jar manifests are written in a particular structure
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    40
 */
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    41
public class WriteBinaryStructure {
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    42
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    43
    @Test
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    44
    public void testMainAttributes() throws IOException {
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    45
        Manifest mf = new Manifest();
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    46
        mf.getMainAttributes().put(Name.MANIFEST_VERSION, "1.0");
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    47
        mf.getMainAttributes().put(new Name("Key"), "Value");
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    48
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    49
        mf.write(buf);
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    50
        assertEquals(buf.toByteArray(), (
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    51
                "Manifest-Version: 1.0\r\n" +
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    52
                "Key: Value\r\n" +
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    53
                "\r\n").getBytes(UTF_8));
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    54
    }
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    55
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    56
    @Test
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    57
    public void testIndividualSection() throws IOException {
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    58
        Manifest mf = new Manifest();
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    59
        mf.getMainAttributes().put(Name.MANIFEST_VERSION, "1.0");
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    60
        Attributes attributes = new Attributes();
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    61
        mf.getEntries().put("Individual-Section-Name", attributes);
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    62
        attributes.put(new Name("Key"), "Value");
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    63
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    64
        mf.write(buf);
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    65
        assertEquals(buf.toByteArray(), (
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    66
                "Manifest-Version: 1.0\r\n" +
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    67
                "\r\n" +
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    68
                "Name: Individual-Section-Name\r\n" +
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    69
                "Key: Value\r\n" +
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    70
                "\r\n").getBytes(UTF_8));
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    71
    }
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    72
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents:
diff changeset
    73
}