Path: blob/master/test/jdk/javax/management/ObjectName/ValueWildcardTest.java
41149 views
/*1* Copyright (c) 2005, 2015, 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*29* @run clean ValueWildcardTest30* @run build ValueWildcardTest31* @run main ValueWildcardTest32*/3334import java.util.Hashtable;35import javax.management.ObjectName;3637public class ValueWildcardTest {3839private static int createObjectName(int i,40String s,41String d,42String k,43String v,44Hashtable<String,String> t,45boolean plp,46boolean pvp)47throws Exception {4849System.out.println("----------------------------------------------");50switch (i) {51case 1:52System.out.println("ObjectName = " + s);53break;54case 2:55System.out.println("ObjectName.Domain = " + d);56System.out.println("ObjectName.Key = " + k);57System.out.println("ObjectName.Value = " + v);58break;59case 3:60System.out.println("ObjectName.Domain = " + d);61System.out.println("ObjectName.Hashtable = " + t);62break;63default:64throw new Exception("Test incorrect: case: " + i);65}66int error = 0;67ObjectName on = null;68try {69switch (i) {70case 1:71on = new ObjectName(s);72break;73case 2:74on = new ObjectName(d, k, v);75break;76case 3:77on = new ObjectName(d, t);78break;79default:80throw new Exception("Test incorrect: case: " + i);81}82System.out.println("Got Expected ObjectName = " +83on.getCanonicalName());84boolean isPattern = on.isPattern();85boolean isDomainPattern = on.isDomainPattern();86boolean isPropertyPattern = on.isPropertyPattern();87boolean isPropertyListPattern = on.isPropertyListPattern();88boolean isPropertyValuePattern = on.isPropertyValuePattern();89System.out.println("ObjectName.isPattern = " +90isPattern);91System.out.println("ObjectName.isDomainPattern = " +92isDomainPattern);93System.out.println("ObjectName.isPropertyPattern = " +94isPropertyPattern);95System.out.println("ObjectName.isPropertyListPattern = " +96isPropertyListPattern);97System.out.println("ObjectName.isPropertyValuePattern = " +98isPropertyValuePattern);99int error2 = 0;100if (isDomainPattern) {101error2++;102System.out.println("Error: Shouldn't be domain pattern!");103}104if (!plp && isPropertyListPattern) {105error2++;106System.out.println("Error: Shouldn't be property list pattern!");107}108if (!pvp && isPropertyValuePattern) {109error2++;110System.out.println("Error: Shouldn't be property value pattern!");111}112if (plp &&113!isPattern && !isPropertyPattern && !isPropertyListPattern) {114error2++;115System.out.println("Error: Should be property list pattern!");116}117if (pvp &&118!isPattern && !isPropertyPattern && !isPropertyValuePattern) {119error2++;120System.out.println("Error: Should be property value pattern!");121}122if (error2 > 0) {123error++;124System.out.println("Test failed!");125} else {126System.out.println("Test passed!");127}128} catch (Exception e) {129error++;130System.out.println("Got Unexpected Exception = " + e.toString());131}132System.out.println("----------------------------------------------");133return error;134}135136private static int createObjectName1(String s,137boolean plp,138boolean pvp)139throws Exception {140return createObjectName(1, s, null, null, null, null, plp, pvp);141}142143private static int createObjectName2(String d,144String k,145String v,146boolean plp,147boolean pvp)148throws Exception {149return createObjectName(2, null, d, k, v, null, plp, pvp);150}151152private static int createObjectName3(String d,153Hashtable<String,String> t,154boolean plp,155boolean pvp)156throws Exception {157return createObjectName(3, null, d, null, null, t, plp, pvp);158}159160public static void main(String[] args) throws Exception {161162int error = 0;163164error += createObjectName1("d:k=*", false, true);165error += createObjectName1("d:k=a*b", false, true);166error += createObjectName1("d:k=a*b,*", true, true);167error += createObjectName1("d:*,k=a*b", true, true);168169error += createObjectName1("d:k=?", false, true);170error += createObjectName1("d:k=a?b", false, true);171error += createObjectName1("d:k=a?b,*", true, true);172error += createObjectName1("d:*,k=a?b", true, true);173174error += createObjectName1("d:k=?*", false, true);175error += createObjectName1("d:k=a?bc*d", false, true);176error += createObjectName1("d:k=a?bc*d,*", true, true);177error += createObjectName1("d:*,k=a?bc*d", true, true);178179error += createObjectName1("d:k1=?,k2=*", false, true);180error += createObjectName1("d:k1=a?b,k2=c*d", false, true);181error += createObjectName1("d:k1=a?b,k2=c*d,*", true, true);182error += createObjectName1("d:*,k1=a?b,k2=c*d", true, true);183184error += createObjectName1("d:k=\"*\"", false, true);185error += createObjectName1("d:k=\"a*b\"", false, true);186error += createObjectName1("d:k=\"a*b\",*", true, true);187error += createObjectName1("d:*,k=\"a*b\"", true, true);188189error += createObjectName1("d:k=\"?\"", false, true);190error += createObjectName1("d:k=\"a?b\"", false, true);191error += createObjectName1("d:k=\"a?b\",*", true, true);192error += createObjectName1("d:*,k=\"a?b\"", true, true);193194error += createObjectName1("d:k=\"?*\"", false, true);195error += createObjectName1("d:k=\"a?bc*d\"", false, true);196error += createObjectName1("d:k=\"a?bc*d\",*", true, true);197error += createObjectName1("d:*,k=\"a?bc*d\"", true, true);198199error += createObjectName1("d:k1=\"?\",k2=\"*\"", false, true);200error += createObjectName1("d:k1=\"a?b\",k2=\"c*d\"", false, true);201error += createObjectName1("d:k1=\"a?b\",k2=\"c*d\",*", true, true);202error += createObjectName1("d:*,k1=\"a?b\",k2=\"c*d\"", true, true);203204error += createObjectName2("d", "k", "*", false, true);205error += createObjectName2("d", "k", "a*b", false, true);206error += createObjectName2("d", "k", "?", false, true);207error += createObjectName2("d", "k", "a?b", false, true);208error += createObjectName2("d", "k", "?*", false, true);209error += createObjectName2("d", "k", "a?bc*d", false, true);210211error += createObjectName2("d", "k", "\"*\"", false, true);212error += createObjectName2("d", "k", "\"a*b\"", false, true);213error += createObjectName2("d", "k", "\"?\"", false, true);214error += createObjectName2("d", "k", "\"a?b\"", false, true);215error += createObjectName2("d", "k", "\"?*\"", false, true);216error += createObjectName2("d", "k", "\"a?bc*d\"", false, true);217218Hashtable<String,String> h1 = new Hashtable<String,String>();219h1.put("k", "*");220error += createObjectName3("d", h1, false, true);221Hashtable<String,String> h2 = new Hashtable<String,String>();222h2.put("k", "a*b");223error += createObjectName3("d", h2, false, true);224225Hashtable<String,String> h3 = new Hashtable<String,String>();226h3.put("k", "?");227error += createObjectName3("d", h3, false, true);228Hashtable<String,String> h4 = new Hashtable<String,String>();229h4.put("k", "a?b");230error += createObjectName3("d", h4, false, true);231232Hashtable<String,String> h5 = new Hashtable<String,String>();233h5.put("k", "?*");234error += createObjectName3("d", h5, false, true);235Hashtable<String,String> h6 = new Hashtable<String,String>();236h6.put("k", "a?bc*d");237error += createObjectName3("d", h6, false, true);238239Hashtable<String,String> h7 = new Hashtable<String,String>();240h7.put("k1", "?");241h7.put("k2", "*");242error += createObjectName3("d", h7, false, true);243Hashtable<String,String> h8 = new Hashtable<String,String>();244h8.put("k1", "a?b");245h8.put("k2", "c*d");246error += createObjectName3("d", h8, false, true);247248Hashtable<String,String> h9 = new Hashtable<String,String>();249h9.put("k", "\"*\"");250error += createObjectName3("d", h9, false, true);251Hashtable<String,String> h10 = new Hashtable<String,String>();252h10.put("k", "\"a*b\"");253error += createObjectName3("d", h10, false, true);254255Hashtable<String,String> h11 = new Hashtable<String,String>();256h11.put("k", "\"?\"");257error += createObjectName3("d", h11, false, true);258Hashtable<String,String> h12 = new Hashtable<String,String>();259h12.put("k", "\"a?b\"");260error += createObjectName3("d", h12, false, true);261262Hashtable<String,String> h13 = new Hashtable<String,String>();263h13.put("k", "\"?*\"");264error += createObjectName3("d", h13, false, true);265Hashtable<String,String> h14 = new Hashtable<String,String>();266h14.put("k", "\"a?bc*d\"");267error += createObjectName3("d", h14, false, true);268269Hashtable<String,String> h15 = new Hashtable<String,String>();270h15.put("k1", "\"?\"");271h15.put("k2", "\"*\"");272error += createObjectName3("d", h15, false, true);273Hashtable<String,String> h16 = new Hashtable<String,String>();274h16.put("k1", "\"a?b\"");275h16.put("k2", "\"c*d\"");276error += createObjectName3("d", h16, false, true);277278if (error > 0) {279final String msg = "Test FAILED! Got " + error + " error(s)";280System.out.println(msg);281throw new IllegalArgumentException(msg);282} else {283System.out.println("Test PASSED!");284}285}286}287288289