Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/query/QuerySubstringTest.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 488603326* @summary Query.{initial,any,final}SubString fail if the27* matching constraint string contains wildcards.28* @author Luis-Miguel Alventosa29* @run clean QuerySubstringTest30* @run build QuerySubstringTest31* @run main QuerySubstringTest32*/3334import java.lang.management.ManagementFactory;35import javax.management.MBeanServer;36import javax.management.ObjectName;37import javax.management.Query;38import javax.management.QueryExp;3940public class QuerySubstringTest {4142public static interface SimpleMBean {43public String getString();44}4546public static class Simple implements SimpleMBean {47public Simple(String value) {48this.value = value;49}50public String getString() {51return value;52}53private String value;54}5556private static String[][] data = {57{ "a*b?c\\d[e-f]", "OK", "OK", "OK" },58{ "a*b?c\\d[e-f]g", "OK", "OK", "KO" },59{ "za*b?c\\d[e-f]", "KO", "OK", "OK" },60{ "za*b?c\\d[e-f]g", "KO", "OK", "KO" },61{ "a*b?c\\de", "KO", "KO", "KO" },62{ "a*b?c\\deg", "KO", "KO", "KO" },63{ "za*b?c\\de", "KO", "KO", "KO" },64{ "za*b?c\\deg", "KO", "KO", "KO" },65{ "a*b?c\\df", "KO", "KO", "KO" },66{ "a*b?c\\dfg", "KO", "KO", "KO" },67{ "za*b?c\\df", "KO", "KO", "KO" },68{ "za*b?c\\dfg", "KO", "KO", "KO" },69{ "axxbxc\\de", "KO", "KO", "KO" },70{ "axxbxc\\deg", "KO", "KO", "KO" },71{ "zaxxbxc\\de", "KO", "KO", "KO" },72{ "zaxxbxc\\deg", "KO", "KO", "KO" },73{ "axxbxc\\df", "KO", "KO", "KO" },74{ "axxbxc\\dfg", "KO", "KO", "KO" },75{ "zaxxbxc\\df", "KO", "KO", "KO" },76{ "zaxxbxc\\dfg", "KO", "KO", "KO" },77};7879private static int query(MBeanServer mbs,80int type,81String substring,82String[][] data) throws Exception {8384int error = 0;8586String querySubString = null;87switch (type) {88case 1:89querySubString = "InitialSubString";90break;91case 2:92querySubString = "AnySubString";93break;94case 3:95querySubString = "FinalSubString";96break;97}9899System.out.println("\n" + querySubString + " = " + substring + "\n");100101for (int i = 0; i < data.length; i++) {102ObjectName on = new ObjectName("test:type=Simple,query=" +103querySubString + ",name=" + i);104Simple s = new Simple(data[i][0]);105mbs.registerMBean(s, on);106QueryExp q = null;107switch (type) {108case 1:109q = Query.initialSubString(Query.attr("String"),110Query.value(substring));111break;112case 2:113q = Query.anySubString(Query.attr("String"),114Query.value(substring));115break;116case 3:117q = Query.finalSubString(Query.attr("String"),118Query.value(substring));119break;120}121q.setMBeanServer(mbs);122boolean r = q.apply(on);123System.out.print("Attribute Value = " +124mbs.getAttribute(on, "String"));125if (r && "OK".equals(data[i][type])) {126System.out.println(" OK");127} else if (!r && "KO".equals(data[i][type])) {128System.out.println(" KO");129} else {130System.out.println(" Error");131error++;132}133}134135return error;136}137138public static void main(String[] args) throws Exception {139140int error = 0;141142String pattern = "a*b?c\\d[e-f]";143144System.out.println(145"\n--- Test javax.management.Query.{initial|any|final}SubString ---");146147MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();148149error += query(mbs, 1, pattern, data);150151error += query(mbs, 2, pattern, data);152153error += query(mbs, 3, pattern, data);154155if (error > 0) {156System.out.println("\nTest failed! " + error + " errors.\n");157throw new IllegalArgumentException("Test failed");158} else {159System.out.println("\nTest passed!\n");160}161}162}163164165