Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/ObjectName/ValueWildcardTest.java
38838 views
/*1* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 471680726* @summary Test wildcards in ObjectName key properties value part.27* @author Luis-Miguel Alventosa28* @run clean ValueWildcardTest29* @run build ValueWildcardTest30* @run main ValueWildcardTest31*/3233import java.util.Hashtable;34import javax.management.ObjectName;3536public class ValueWildcardTest {3738private static int createObjectName(int i,39String s,40String d,41String k,42String v,43Hashtable<String,String> t,44boolean plp,45boolean pvp)46throws Exception {4748System.out.println("----------------------------------------------");49switch (i) {50case 1:51System.out.println("ObjectName = " + s);52break;53case 2:54System.out.println("ObjectName.Domain = " + d);55System.out.println("ObjectName.Key = " + k);56System.out.println("ObjectName.Value = " + v);57break;58case 3:59System.out.println("ObjectName.Domain = " + d);60System.out.println("ObjectName.Hashtable = " + t);61break;62default:63throw new Exception("Test incorrect: case: " + i);64}65int error = 0;66ObjectName on = null;67try {68switch (i) {69case 1:70on = new ObjectName(s);71break;72case 2:73on = new ObjectName(d, k, v);74break;75case 3:76on = new ObjectName(d, t);77break;78default:79throw new Exception("Test incorrect: case: " + i);80}81System.out.println("Got Expected ObjectName = " +82on.getCanonicalName());83boolean isPattern = on.isPattern();84boolean isDomainPattern = on.isDomainPattern();85boolean isPropertyPattern = on.isPropertyPattern();86boolean isPropertyListPattern = on.isPropertyListPattern();87boolean isPropertyValuePattern = on.isPropertyValuePattern();88System.out.println("ObjectName.isPattern = " +89isPattern);90System.out.println("ObjectName.isDomainPattern = " +91isDomainPattern);92System.out.println("ObjectName.isPropertyPattern = " +93isPropertyPattern);94System.out.println("ObjectName.isPropertyListPattern = " +95isPropertyListPattern);96System.out.println("ObjectName.isPropertyValuePattern = " +97isPropertyValuePattern);98int error2 = 0;99if (isDomainPattern) {100error2++;101System.out.println("Error: Shouldn't be domain pattern!");102}103if (!plp && isPropertyListPattern) {104error2++;105System.out.println("Error: Shouldn't be property list pattern!");106}107if (!pvp && isPropertyValuePattern) {108error2++;109System.out.println("Error: Shouldn't be property value pattern!");110}111if (plp &&112!isPattern && !isPropertyPattern && !isPropertyListPattern) {113error2++;114System.out.println("Error: Should be property list pattern!");115}116if (pvp &&117!isPattern && !isPropertyPattern && !isPropertyValuePattern) {118error2++;119System.out.println("Error: Should be property value pattern!");120}121if (error2 > 0) {122error++;123System.out.println("Test failed!");124} else {125System.out.println("Test passed!");126}127} catch (Exception e) {128error++;129System.out.println("Got Unexpected Exception = " + e.toString());130}131System.out.println("----------------------------------------------");132return error;133}134135private static int createObjectName1(String s,136boolean plp,137boolean pvp)138throws Exception {139return createObjectName(1, s, null, null, null, null, plp, pvp);140}141142private static int createObjectName2(String d,143String k,144String v,145boolean plp,146boolean pvp)147throws Exception {148return createObjectName(2, null, d, k, v, null, plp, pvp);149}150151private static int createObjectName3(String d,152Hashtable<String,String> t,153boolean plp,154boolean pvp)155throws Exception {156return createObjectName(3, null, d, null, null, t, plp, pvp);157}158159public static void main(String[] args) throws Exception {160161int error = 0;162163error += createObjectName1("d:k=*", false, true);164error += createObjectName1("d:k=a*b", false, true);165error += createObjectName1("d:k=a*b,*", true, true);166error += createObjectName1("d:*,k=a*b", true, true);167168error += createObjectName1("d:k=?", false, true);169error += createObjectName1("d:k=a?b", false, true);170error += createObjectName1("d:k=a?b,*", true, true);171error += createObjectName1("d:*,k=a?b", true, true);172173error += createObjectName1("d:k=?*", false, true);174error += createObjectName1("d:k=a?bc*d", false, true);175error += createObjectName1("d:k=a?bc*d,*", true, true);176error += createObjectName1("d:*,k=a?bc*d", true, true);177178error += createObjectName1("d:k1=?,k2=*", false, true);179error += createObjectName1("d:k1=a?b,k2=c*d", false, true);180error += createObjectName1("d:k1=a?b,k2=c*d,*", true, true);181error += createObjectName1("d:*,k1=a?b,k2=c*d", true, true);182183error += createObjectName1("d:k=\"*\"", false, true);184error += createObjectName1("d:k=\"a*b\"", false, true);185error += createObjectName1("d:k=\"a*b\",*", true, true);186error += createObjectName1("d:*,k=\"a*b\"", true, true);187188error += createObjectName1("d:k=\"?\"", false, true);189error += createObjectName1("d:k=\"a?b\"", false, true);190error += createObjectName1("d:k=\"a?b\",*", true, true);191error += createObjectName1("d:*,k=\"a?b\"", true, true);192193error += createObjectName1("d:k=\"?*\"", false, true);194error += createObjectName1("d:k=\"a?bc*d\"", false, true);195error += createObjectName1("d:k=\"a?bc*d\",*", true, true);196error += createObjectName1("d:*,k=\"a?bc*d\"", true, true);197198error += createObjectName1("d:k1=\"?\",k2=\"*\"", false, true);199error += createObjectName1("d:k1=\"a?b\",k2=\"c*d\"", false, true);200error += createObjectName1("d:k1=\"a?b\",k2=\"c*d\",*", true, true);201error += createObjectName1("d:*,k1=\"a?b\",k2=\"c*d\"", true, true);202203error += createObjectName2("d", "k", "*", false, true);204error += createObjectName2("d", "k", "a*b", false, true);205error += createObjectName2("d", "k", "?", false, true);206error += createObjectName2("d", "k", "a?b", false, true);207error += createObjectName2("d", "k", "?*", false, true);208error += createObjectName2("d", "k", "a?bc*d", false, true);209210error += createObjectName2("d", "k", "\"*\"", false, true);211error += createObjectName2("d", "k", "\"a*b\"", false, true);212error += createObjectName2("d", "k", "\"?\"", false, true);213error += createObjectName2("d", "k", "\"a?b\"", false, true);214error += createObjectName2("d", "k", "\"?*\"", false, true);215error += createObjectName2("d", "k", "\"a?bc*d\"", false, true);216217Hashtable<String,String> h1 = new Hashtable<String,String>();218h1.put("k", "*");219error += createObjectName3("d", h1, false, true);220Hashtable<String,String> h2 = new Hashtable<String,String>();221h2.put("k", "a*b");222error += createObjectName3("d", h2, false, true);223224Hashtable<String,String> h3 = new Hashtable<String,String>();225h3.put("k", "?");226error += createObjectName3("d", h3, false, true);227Hashtable<String,String> h4 = new Hashtable<String,String>();228h4.put("k", "a?b");229error += createObjectName3("d", h4, false, true);230231Hashtable<String,String> h5 = new Hashtable<String,String>();232h5.put("k", "?*");233error += createObjectName3("d", h5, false, true);234Hashtable<String,String> h6 = new Hashtable<String,String>();235h6.put("k", "a?bc*d");236error += createObjectName3("d", h6, false, true);237238Hashtable<String,String> h7 = new Hashtable<String,String>();239h7.put("k1", "?");240h7.put("k2", "*");241error += createObjectName3("d", h7, false, true);242Hashtable<String,String> h8 = new Hashtable<String,String>();243h8.put("k1", "a?b");244h8.put("k2", "c*d");245error += createObjectName3("d", h8, false, true);246247Hashtable<String,String> h9 = new Hashtable<String,String>();248h9.put("k", "\"*\"");249error += createObjectName3("d", h9, false, true);250Hashtable<String,String> h10 = new Hashtable<String,String>();251h10.put("k", "\"a*b\"");252error += createObjectName3("d", h10, false, true);253254Hashtable<String,String> h11 = new Hashtable<String,String>();255h11.put("k", "\"?\"");256error += createObjectName3("d", h11, false, true);257Hashtable<String,String> h12 = new Hashtable<String,String>();258h12.put("k", "\"a?b\"");259error += createObjectName3("d", h12, false, true);260261Hashtable<String,String> h13 = new Hashtable<String,String>();262h13.put("k", "\"?*\"");263error += createObjectName3("d", h13, false, true);264Hashtable<String,String> h14 = new Hashtable<String,String>();265h14.put("k", "\"a?bc*d\"");266error += createObjectName3("d", h14, false, true);267268Hashtable<String,String> h15 = new Hashtable<String,String>();269h15.put("k1", "\"?\"");270h15.put("k2", "\"*\"");271error += createObjectName3("d", h15, false, true);272Hashtable<String,String> h16 = new Hashtable<String,String>();273h16.put("k1", "\"a?b\"");274h16.put("k2", "\"c*d\"");275error += createObjectName3("d", h16, false, true);276277if (error > 0) {278final String msg = "Test FAILED! Got " + error + " error(s)";279System.out.println(msg);280throw new IllegalArgumentException(msg);281} else {282System.out.println("Test PASSED!");283}284}285}286287288