Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/query/QueryMatchTest.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 626643826* @summary Query.match code for character sequences like [a-z] is wrong.27* @author Luis-Miguel Alventosa28* @run clean QueryMatchTest29* @run build QueryMatchTest30* @run main QueryMatchTest31*/3233import java.lang.management.ManagementFactory;34import javax.management.MBeanServer;35import javax.management.ObjectName;36import javax.management.Query;37import javax.management.QueryExp;3839public class QueryMatchTest {4041public static interface SimpleMBean {42public String getStringNumber();43}4445public static class Simple implements SimpleMBean {46public Simple(String number) {47this.number = number;48}49public String getStringNumber() {50return number;51}52private String number;53}5455// Pattern = 2[7-9]56private static String[][] data11 = {57{ "20", "KO" },58{ "21", "KO" },59{ "22", "KO" },60{ "23", "KO" },61{ "24", "KO" },62{ "25", "KO" },63{ "26", "KO" },64{ "27", "OK" },65{ "28", "OK" },66{ "29", "OK" },67{ "2-", "KO" },68};6970// Pattern = 2[7-9]571private static String[][] data12 = {72{ "205", "KO" },73{ "215", "KO" },74{ "225", "KO" },75{ "235", "KO" },76{ "245", "KO" },77{ "255", "KO" },78{ "265", "KO" },79{ "275", "OK" },80{ "285", "OK" },81{ "295", "OK" },82{ "2-5", "KO" },83};8485// Pattern = 2[-9]86private static String[][] data13 = {87{ "20", "KO" },88{ "21", "KO" },89{ "22", "KO" },90{ "23", "KO" },91{ "24", "KO" },92{ "25", "KO" },93{ "26", "KO" },94{ "27", "KO" },95{ "28", "KO" },96{ "29", "OK" },97{ "2-", "OK" },98};99100// Pattern = 2[-9]5101private static String[][] data14 = {102{ "205", "KO" },103{ "215", "KO" },104{ "225", "KO" },105{ "235", "KO" },106{ "245", "KO" },107{ "255", "KO" },108{ "265", "KO" },109{ "275", "KO" },110{ "285", "KO" },111{ "295", "OK" },112{ "2-5", "OK" },113};114115// Pattern = 2[9-]116private static String[][] data15 = {117{ "20", "KO" },118{ "21", "KO" },119{ "22", "KO" },120{ "23", "KO" },121{ "24", "KO" },122{ "25", "KO" },123{ "26", "KO" },124{ "27", "KO" },125{ "28", "KO" },126{ "29", "OK" },127{ "2-", "OK" },128};129130// Pattern = 2[9-]5131private static String[][] data16 = {132{ "205", "KO" },133{ "215", "KO" },134{ "225", "KO" },135{ "235", "KO" },136{ "245", "KO" },137{ "255", "KO" },138{ "265", "KO" },139{ "275", "KO" },140{ "285", "KO" },141{ "295", "OK" },142{ "2-5", "OK" },143};144145// Pattern = 2[-]146private static String[][] data17 = {147{ "20", "KO" },148{ "21", "KO" },149{ "22", "KO" },150{ "23", "KO" },151{ "24", "KO" },152{ "25", "KO" },153{ "26", "KO" },154{ "27", "KO" },155{ "28", "KO" },156{ "29", "KO" },157{ "2-", "OK" },158};159160// Pattern = 2[-]5161private static String[][] data18 = {162{ "205", "KO" },163{ "215", "KO" },164{ "225", "KO" },165{ "235", "KO" },166{ "245", "KO" },167{ "255", "KO" },168{ "265", "KO" },169{ "275", "KO" },170{ "285", "KO" },171{ "295", "KO" },172{ "2-5", "OK" },173};174175// Pattern = 2[1-36-8]176private static String[][] data19 = {177{ "20", "KO" },178{ "21", "OK" },179{ "22", "OK" },180{ "23", "OK" },181{ "24", "KO" },182{ "25", "KO" },183{ "26", "OK" },184{ "27", "OK" },185{ "28", "OK" },186{ "29", "KO" },187{ "2-", "KO" },188};189190// Pattern = 2[1-36-8]5191private static String[][] data20 = {192{ "205", "KO" },193{ "215", "OK" },194{ "225", "OK" },195{ "235", "OK" },196{ "245", "KO" },197{ "255", "KO" },198{ "265", "OK" },199{ "275", "OK" },200{ "285", "OK" },201{ "295", "KO" },202{ "2-5", "KO" },203};204205// Pattern = 2[!7-9]206private static String[][] data21 = {207{ "20", "OK" },208{ "21", "OK" },209{ "22", "OK" },210{ "23", "OK" },211{ "24", "OK" },212{ "25", "OK" },213{ "26", "OK" },214{ "27", "KO" },215{ "28", "KO" },216{ "29", "KO" },217{ "2-", "OK" },218};219220// Pattern = 2[!7-9]5221private static String[][] data22 = {222{ "205", "OK" },223{ "215", "OK" },224{ "225", "OK" },225{ "235", "OK" },226{ "245", "OK" },227{ "255", "OK" },228{ "265", "OK" },229{ "275", "KO" },230{ "285", "KO" },231{ "295", "KO" },232{ "2-5", "OK" },233};234235// Pattern = 2[!-9]236private static String[][] data23 = {237{ "20", "OK" },238{ "21", "OK" },239{ "22", "OK" },240{ "23", "OK" },241{ "24", "OK" },242{ "25", "OK" },243{ "26", "OK" },244{ "27", "OK" },245{ "28", "OK" },246{ "29", "KO" },247{ "2-", "KO" },248};249250// Pattern = 2[!-9]5251private static String[][] data24 = {252{ "205", "OK" },253{ "215", "OK" },254{ "225", "OK" },255{ "235", "OK" },256{ "245", "OK" },257{ "255", "OK" },258{ "265", "OK" },259{ "275", "OK" },260{ "285", "OK" },261{ "295", "KO" },262{ "2-5", "KO" },263};264265// Pattern = 2[!9-]266private static String[][] data25 = {267{ "20", "OK" },268{ "21", "OK" },269{ "22", "OK" },270{ "23", "OK" },271{ "24", "OK" },272{ "25", "OK" },273{ "26", "OK" },274{ "27", "OK" },275{ "28", "OK" },276{ "29", "KO" },277{ "2-", "KO" },278};279280// Pattern = 2[!9-]5281private static String[][] data26 = {282{ "205", "OK" },283{ "215", "OK" },284{ "225", "OK" },285{ "235", "OK" },286{ "245", "OK" },287{ "255", "OK" },288{ "265", "OK" },289{ "275", "OK" },290{ "285", "OK" },291{ "295", "KO" },292{ "2-5", "KO" },293};294295// Pattern = 2[!-]296private static String[][] data27 = {297{ "20", "OK" },298{ "21", "OK" },299{ "22", "OK" },300{ "23", "OK" },301{ "24", "OK" },302{ "25", "OK" },303{ "26", "OK" },304{ "27", "OK" },305{ "28", "OK" },306{ "29", "OK" },307{ "2-", "KO" },308};309310// Pattern = 2[!-]5311private static String[][] data28 = {312{ "205", "OK" },313{ "215", "OK" },314{ "225", "OK" },315{ "235", "OK" },316{ "245", "OK" },317{ "255", "OK" },318{ "265", "OK" },319{ "275", "OK" },320{ "285", "OK" },321{ "295", "OK" },322{ "2-5", "KO" },323};324325// Pattern = 2[!1-36-8]326private static String[][] data29 = {327{ "20", "OK" },328{ "21", "KO" },329{ "22", "KO" },330{ "23", "KO" },331{ "24", "OK" },332{ "25", "OK" },333{ "26", "KO" },334{ "27", "KO" },335{ "28", "KO" },336{ "29", "OK" },337{ "2-", "OK" },338};339340// Pattern = 2[!1-36-8]5341private static String[][] data30 = {342{ "205", "OK" },343{ "215", "KO" },344{ "225", "KO" },345{ "235", "KO" },346{ "245", "OK" },347{ "255", "OK" },348{ "265", "KO" },349{ "275", "KO" },350{ "285", "KO" },351{ "295", "OK" },352{ "2-5", "OK" },353};354355// Pattern = a*b?c[d-e]356private static String[][] data31 = {357{ "a*b?cd", "OK" },358{ "a*b?ce", "OK" },359{ "a*b?cde", "KO" },360{ "[a]*b?[c]", "KO" },361{ "abc", "KO" },362{ "ab?c", "KO" },363{ "a*bc", "KO" },364{ "axxbxc", "KO" },365{ "axxbxcd", "OK" },366};367368// Pattern = a\*b\?c\[d-e]369private static String[][] data32 = {370{ "a*b?cd", "KO" },371{ "a*b?ce", "KO" },372{ "a*b?cde", "KO" },373{ "[a]*b?[c]", "KO" },374{ "abc", "KO" },375{ "ab?c", "KO" },376{ "a*bc", "KO" },377{ "axxbxc", "KO" },378{ "axxbxcd", "KO" },379{ "a*b?c[d]", "KO" },380{ "a*b?c[e]", "KO" },381{ "a*b?c[d-e]", "OK" },382};383384// Pattern = a\*b\?c\[de]385private static String[][] data33 = {386{ "a*b?cd", "KO" },387{ "a*b?ce", "KO" },388{ "a*b?cde", "KO" },389{ "[a]*b?[c]", "KO" },390{ "abc", "KO" },391{ "ab?c", "KO" },392{ "a*bc", "KO" },393{ "axxbxc", "KO" },394{ "axxbxcd", "KO" },395{ "a*b?c[d]", "KO" },396{ "a*b?c[e]", "KO" },397{ "a*b?c[d-e]", "KO" },398{ "a*b?c[de]", "OK" },399};400401// Pattern = abc[de]f402private static String[][] data34 = {403{ "abcdf", "OK" },404{ "abcef", "OK" },405{ "abcdef", "KO" },406{ "abcedf", "KO" },407{ "abcd", "KO" },408{ "abce", "KO" },409{ "abcf", "KO" },410};411412// Pattern = abc[d]e413private static String[][] data35 = {414{ "abcde", "OK" },415{ "abcd", "KO" },416{ "abcdf", "KO" },417{ "abcdef", "KO" },418};419420// Pattern = a[b]421private static String[][] data36 = {422{ "a", "KO" },423{ "ab", "OK" },424{ "a[b]", "KO" },425};426427// Pattern = a\b428private static String[][] data37 = {429{ "a", "KO" },430{ "ab", "KO" },431{ "a\\b", "OK" },432};433434private static Object[][] tests = {435{ "2[7-9]", data11 },436{ "2[7-9]5", data12 },437{ "2[-9]", data13 },438{ "2[-9]5", data14 },439{ "2[9-]", data15 },440{ "2[9-]5", data16 },441{ "2[-]", data17 },442{ "2[-]5", data18 },443{ "2[1-36-8]", data19 },444{ "2[1-36-8]5", data20 },445{ "2[!7-9]", data21 },446{ "2[!7-9]5", data22 },447{ "2[!-9]", data23 },448{ "2[!-9]5", data24 },449{ "2[!9-]", data25 },450{ "2[!9-]5", data26 },451{ "2[!-]", data27 },452{ "2[!-]5", data28 },453{ "2[!1-36-8]", data29 },454{ "2[!1-36-8]5", data30 },455{ "a*b?c[d-e]", data31 },456{ "a\\*b\\?c\\[d-e]", data32 },457{ "a\\*b\\?c\\[de]", data33 },458{ "abc[de]f", data34 },459{ "abc[d]e", data35 },460{ "a[b]", data36 },461{ "a\\\\b", data37 },462};463464private static int query(MBeanServer mbs,465String pattern,466String[][] data) throws Exception {467468int error = 0;469470System.out.println("\nAttribute Value Pattern = " + pattern + "\n");471for (int i = 0; i < data.length; i++) {472ObjectName on = new ObjectName("domain:type=Simple,pattern=" +473ObjectName.quote(pattern) +474",name=" + i);475Simple s = new Simple(data[i][0]);476mbs.registerMBean(s, on);477QueryExp q =478Query.match(Query.attr("StringNumber"), Query.value(pattern));479q.setMBeanServer(mbs);480boolean r = q.apply(on);481System.out.print("Attribute Value = " +482mbs.getAttribute(on, "StringNumber"));483if (r && "OK".equals(data[i][1])) {484System.out.println(" OK");485} else if (!r && "KO".equals(data[i][1])) {486System.out.println(" KO");487} else {488System.out.println(" Error");489error++;490}491}492493return error;494}495496public static void main(String[] args) throws Exception {497498int error = 0;499500System.out.println("\n--- Test javax.management.Query.match ---");501502MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();503504for (int i = 0; i < tests.length; i++) {505error += query(mbs, (String) tests[i][0], (String[][]) tests[i][1]);506}507508if (error > 0) {509System.out.println("\nTest failed! " + error + " errors.\n");510throw new IllegalArgumentException("Test failed");511} else {512System.out.println("\nTest passed!\n");513}514}515}516517518