1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
|
// Copyright (C) 2007 Andrew John Hughes <gnu_andrew@member.fsf.org>
// This file is part of Mauve.
// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING. If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
// Tags: JDK1.5
package gnu.testlet.javax.management.ObjectName;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
public class Parsing implements Testlet
{
public void test(TestHarness h)
{
ObjectName name;
try
{
h.checkPoint("Default name");
name = new ObjectName("*:*");
h.check(true);
h.check(name.isDomainPattern(), true);
h.check(name.isPropertyPattern(), true);
h.check(name.isPattern(), true);
h.check(name.getDomain(), "*");
h.check(name.getKeyPropertyListString(), "");
h.checkPoint("Mixed keys and wildcards");
name =
new ObjectName("jboss.management.local:j2eeType=ServiceModule,*,name=jbossmq-httpil.sar");
h.check(true);
h.check(name.isDomainPattern(), false);
h.check(name.isPropertyPattern(), true);
h.check(name.isPattern(), true);
h.check(name.getDomain(), "jboss.management.local");
h.check(name.getKeyPropertyListString(), "j2eeType=ServiceModule,name=jbossmq-httpil.sar");
h.checkPoint("Match any domain with specific keys");
name = new ObjectName("*:library=Classpath,project=GNU");
h.check(true);
h.check(name.isDomainPattern(), true);
h.check(name.isPropertyPattern(), false);
h.check(name.isPattern(), true);
h.check(name.getDomain(), "*");
h.check(name.getCanonicalKeyPropertyListString(), "library=Classpath,project=GNU");
h.check(name.getKeyPropertyListString(), "library=Classpath,project=GNU");
h.checkPoint("Match any domain with specific keys and wildcard at end");
name = new ObjectName("*:library=Classpath,project=GNU,*");
h.check(true);
h.check(name.isDomainPattern(), true);
h.check(name.isPropertyPattern(), true);
h.check(name.isPattern(), true);
h.check(name.getDomain(), "*");
h.check(name.getKeyPropertyListString(), "library=Classpath,project=GNU");
h.checkPoint("Match any domain beginning with 'fs' with specific keys");
name = new ObjectName("fs?:library=Classpath,project=GNU");
h.check(true);
h.check(name.isDomainPattern(), true);
h.check(name.isPropertyPattern(), false);
h.check(name.isPattern(), true);
h.check(name.getDomain(), "fs?");
h.check(name.getKeyPropertyListString(), "library=Classpath,project=GNU");
h.checkPoint("Match any domain beginning with 'fs' with specific keys " +
"and wildcard at end");
name = new ObjectName("fs?:library=Classpath,project=GNU,*");
h.check(true);
h.check(name.isDomainPattern(), true);
h.check(name.isPropertyPattern(), true);
h.check(name.isPattern(), true);
h.check(name.getDomain(), "fs?");
h.check(name.getKeyPropertyListString(), "library=Classpath,project=GNU");
h.checkPoint("Match the FSF domain with specific keys and wildcard at end");
name = new ObjectName("fsf:library=Classpath,project=GNU,*");
h.check(true);
h.check(name.isDomainPattern(), false);
h.check(name.isPropertyPattern(), true);
h.check(name.isPattern(), true);
h.check(name.getDomain(), "fsf");
h.check(name.getKeyPropertyListString(), "library=Classpath,project=GNU");
h.checkPoint("Match the FSF domain with specific keys");
name = new ObjectName("fsf:library=Classpath,project=GNU");
h.check(true);
h.check(name.isDomainPattern(), false);
h.check(name.isPropertyPattern(), false);
h.check(name.isPattern(), false);
h.check(name.getDomain(), "fsf");
h.check(name.getKeyPropertyListString(), "library=Classpath,project=GNU");
h.checkPoint("Match the FSF domain with specific keys and quoted values");
name = new ObjectName("fsf:library=\"Classpath\",project=GNU");
h.check(true);
h.check(name.isDomainPattern(), false);
h.check(name.isPropertyPattern(), false);
h.check(name.isPattern(), false);
h.check(name.getDomain(), "fsf");
h.check(name.getKeyProperty("library"), "\"Classpath\"");
h.check(name.getKeyPropertyListString(), "library=\"Classpath\",project=GNU");
h.checkPoint("Match the FSF domain with specific keys and quoted values with "+
"escaped quote");
name = new ObjectName("fsf:library=\"Class\\\"path\",project=GNU");
h.check(true);
h.check(name.isDomainPattern(), false);
h.check(name.isPropertyPattern(), false);
h.check(name.isPattern(), false);
h.check(name.getDomain(), "fsf");
h.check(name.getKeyProperty("library"), "\"Class\\\"path\"");
h.check(name.getKeyPropertyListString(), "library=\"Class\\\"path\",project=GNU");
h.checkPoint("Match the FSF domain with specific keys and quoted values with "+
"escaped newline");
name = new ObjectName("fsf:library=\"Class\\npath\",project=GNU");
h.check(true);
h.check(name.isDomainPattern(), false);
h.check(name.isPropertyPattern(), false);
h.check(name.isPattern(), false);
h.check(name.getDomain(), "fsf");
h.check(name.getKeyProperty("library"), "\"Class\\npath\"");
h.check(name.getKeyPropertyListString(), "library=\"Class\\npath\",project=GNU");
h.checkPoint("Match the FSF domain with specific keys and quoted values with "+
"escaped backslash");
name = new ObjectName("fsf:library=\"Class\\\\path\",project=GNU");
h.check(true);
h.check(name.isDomainPattern(), false);
h.check(name.isPropertyPattern(), false);
h.check(name.isPattern(), false);
h.check(name.getDomain(), "fsf");
h.check(name.getKeyProperty("library"), "\"Class\\\\path\"");
h.check(name.getKeyPropertyListString(), "library=\"Class\\\\path\",project=GNU");
h.checkPoint("Match the FSF domain with space preservation");
name = new ObjectName("fsf: library = Classpath ");
h.check(true);
h.check(name.isDomainPattern(), false);
h.check(name.isPropertyPattern(), false);
h.check(name.isPattern(), false);
h.check(name.getDomain(), "fsf");
h.check(name.getKeyProperty(" library "), " Classpath ");
h.check(name.getKeyPropertyListString(), " library = Classpath ");
h.checkPoint("Key ordering");
name = new ObjectName("fsf:project=GNU,library=Classpath");
h.check(true);
h.check(name.isDomainPattern(), false);
h.check(name.isPropertyPattern(), false);
h.check(name.isPattern(), false);
h.check(name.getDomain(), "fsf");
h.check(name.getCanonicalKeyPropertyListString(), "library=Classpath,project=GNU");
h.check(name.getKeyPropertyListString(), "project=GNU,library=Classpath");
}
catch (MalformedObjectNameException e)
{
h.debug(e);
h.check(false);
}
try
{
name = new ObjectName("fsf:lib,rary=Classpath,project=GNU");
h.fail("Comma allowed in key name");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Comma in key name caught");
}
try
{
name = new ObjectName("fsf:lib=rary=Classpath,project=GNU");
h.fail("Equals allowed in key name");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Equals in key name caught");
}
try
{
name = new ObjectName("fsf:lib:rary=Classpath,project=GNU");
h.fail("Colon allowed in key name");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Colon in key name caught");
}
try
{
name = new ObjectName("fsf:lib*rary=Classpath,project=GNU");
h.fail("Asterisk allowed in key name");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Asterisk in key name caught");
}
try
{
name = new ObjectName("fsf:lib?rary=Classpath,project=GNU");
h.fail("Question mark allowed in key name");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Question mark in key name caught");
}
try
{
name = new ObjectName("fsf:library=Classpath,library=Sun,project=GNU");
h.fail("Duplicate key allowed");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Duplicate key caught");
}
try
{
name = new ObjectName("fsf:library=Clas,path,project=GNU");
h.fail("Comma allowed in unquoted value");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Comma in unquoted value caught");
}
try
{
name = new ObjectName("fsf:library=Clas=path,project=GNU");
h.fail("Equals allowed in unquoted value");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Equals in unquoted value caught");
}
try
{
name = new ObjectName("fsf:library=Clas:path,project=GNU");
h.fail("Colon allowed in unquoted value");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Colon in unquoted value caught");
}
try
{
name = new ObjectName("fsf:library=Clas\"path,project=GNU");
h.fail("Quote allowed in unquoted value");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Quote in unquoted value caught");
}
try
{
name = new ObjectName("fsf:library=\"Classpath,project=GNU");
h.fail("Unclosed quotes allowed");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Unclosed quotes caught");
}
try
{
name = new ObjectName("fsf:library=\"Class\"path\",project=GNU");
h.debug(name.getKeyProperty("library"));
h.fail("Unescaped quote allowed");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Unescaped quote caught");
}
try
{
name = new ObjectName("fsf:");
h.fail("Non-pattern with no keys allowed");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Non-pattern with no keys caught");
}
try
{
name = new ObjectName("fsf:*,*");
h.fail("Pattern with multiple asterisks in properties allowed");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Pattern with multiple asterisks in properties caught");
}
try
{
name = new ObjectName("f\nsf:library=Classpath");
h.fail("Domain with newline allowed");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Domain with newline caught");
}
try
{
name = new ObjectName("fsf:lib\nrary=Classpath");
h.fail("Key with newline allowed");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Key with newline caught");
}
try
{
name = new ObjectName("fsf:library=Class\npath");
h.fail("Unquoted value with newline allowed");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Unquoted value with newline caught");
}
try
{
name = new ObjectName("fsf:library=\"Class\npath\"");
h.fail("Quoted value with newline allowed");
}
catch (MalformedObjectNameException e)
{
h.check(true, "Quoted value with newline caught");
}
}
}
|