1 /*
2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * @test
26  * @bug 8190987
27  * @summary Test verifies that individual Package.VersionInfo elements can be
28  *          supplied and retrieved even if no other elements are set.
29  * @run testng PackageVersionTest
30  */
31 
32 
33 import java.net.URL;
34 import org.testng.Assert;
35 import org.testng.annotations.Test;
36 
37 public class PackageVersionTest {
38 
39     @Test
testSpecTitle()40     public static void testSpecTitle() {
41         TestClassLoader loader = new TestClassLoader();
42         Package p = loader.definePackage("testSpecTitle", "SpecTitle",
43                                          null, null, null,
44                                          null, null, null);
45         Assert.assertEquals(p.getSpecificationTitle(), "SpecTitle",
46                             "Package specification titles do not match!");
47     }
48 
49     @Test
testSpecVersion()50     public static void testSpecVersion() {
51         TestClassLoader loader = new TestClassLoader();
52         Package p = loader.definePackage("testSpecVersion", null,
53                                          "1.0", null, null,
54                                          null, null, null);
55         Assert.assertEquals(p.getSpecificationVersion(), "1.0",
56                             "Package specification versions do not match!");
57     }
58 
59     @Test
testSpecVendor()60     public static void testSpecVendor() {
61         TestClassLoader loader = new TestClassLoader();
62         Package p = loader.definePackage("testSpecVendor", null,
63                                          null, "SpecVendor", null,
64                                          null, null, null);
65         Assert.assertEquals(p.getSpecificationVendor(), "SpecVendor",
66                             "Package specification vendors do not match!");
67     }
68 
69     @Test
testImplTitle()70     public static void testImplTitle() {
71         TestClassLoader loader = new TestClassLoader();
72         Package p = loader.definePackage("testImplTitle", null,
73                                          null, null, "ImplTitle",
74                                          null, null, null);
75         Assert.assertEquals(p.getImplementationTitle(), "ImplTitle",
76                             "Package implementation titles do not match!");
77     }
78 
79     @Test
testImplVersion()80     public static void testImplVersion() {
81         TestClassLoader loader = new TestClassLoader();
82         Package p = loader.definePackage("testImplVersion", null,
83                                          null, null, null,
84                                          "1.0", null, null);
85         Assert.assertEquals(p.getImplementationVersion(), "1.0",
86                             "Package implementation versions do not match!");
87     }
88 
89     @Test
testImplVendor()90     public static void testImplVendor() {
91         TestClassLoader loader = new TestClassLoader();
92         Package p = loader.definePackage("testImplVendor", null,
93                                          null, null, null,
94                                          null, "ImplVendor", null);
95         Assert.assertEquals(p.getImplementationVendor(), "ImplVendor",
96                             "Package implementation vendors do not match!");
97     }
98 }
99 
100 class TestClassLoader extends ClassLoader {
101     @Override
definePackage(String name, String specTitle, String specVersion, String specVendor, String implTitle, String implVersion, String implVendor, URL sealBase)102     protected Package definePackage(String name, String specTitle,
103                                     String specVersion, String specVendor,
104                                     String implTitle, String implVersion,
105                                     String implVendor, URL sealBase) {
106         return super.definePackage(name, specTitle, specVersion, specVendor,
107                                    implTitle, implVersion, implVendor, sealBase);
108     }
109 }
110