|
14 | 14 | import org.testng.annotations.BeforeMethod;
|
15 | 15 | import org.testng.annotations.Test;
|
16 | 16 |
|
| 17 | +import static org.assertj.core.api.Assertions.assertThat; |
17 | 18 | import static org.testng.Assert.assertFalse;
|
18 | 19 | import static org.testng.Assert.assertTrue;
|
19 | 20 | import static org.testng.Assert.fail;
|
20 | 21 |
|
| 22 | +import java.util.Locale; |
| 23 | + |
21 | 24 | /**
|
22 | 25 | * Tests the {@link UUID} constraint.
|
23 | 26 | *
|
@@ -289,5 +292,121 @@ public void validOnlyIfConfiguredVariantMatches() {
|
289 | 292 |
|
290 | 293 | }
|
291 | 294 |
|
| 295 | + @Test |
| 296 | + public void versionNotInTheAllowedList() { |
| 297 | + char[] versions = new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; |
| 298 | + |
| 299 | + for ( int i = 0; i < versions.length; i++ ) { |
| 300 | + int version = Character.digit( versions[i], 16 ); |
| 301 | + descriptorBuilder.setAttribute( "version", new int[] { version } ); |
| 302 | + |
| 303 | + uuidAnnotation = descriptorBuilder.build().getAnnotation(); |
| 304 | + uuidValidator.initialize( uuidAnnotation ); |
| 305 | + |
| 306 | + for ( int j = 0; j < versions.length; j++ ) { |
| 307 | + if ( i == j ) { |
| 308 | + continue; |
| 309 | + } |
| 310 | + String uuid = String.format( Locale.ROOT, "24e6abaa-b2a8-%sa8e-0622-92adaaae229f", versions[j] ); |
| 311 | + assertThat( uuidValidator.isValid( uuid, null ) ) |
| 312 | + .as( "Expected uuid %s to be invalid because of the version %s not being allowed", uuid, versions[j] ) |
| 313 | + .isFalse(); |
| 314 | + } |
| 315 | + } |
| 316 | + } |
| 317 | + |
| 318 | + @Test |
| 319 | + public void variantNotInTheAllowedLis11t() { |
| 320 | + descriptorBuilder.setAttribute( "variant", new int[] { 1 } ); |
| 321 | + |
| 322 | + uuidAnnotation = descriptorBuilder.build().getAnnotation(); |
| 323 | + uuidValidator.initialize( uuidAnnotation ); |
| 324 | + |
| 325 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-c622-92adaaae229f", null ) ); |
| 326 | + } |
| 327 | + |
| 328 | + @Test |
| 329 | + public void variantNotInTheAllowedList() { |
| 330 | + // 0xxx 0 - 7 reserved (NCS backward compatible) |
| 331 | + // 10xx 8 - b DCE 1.1, ISO/IEC 11578:1996 |
| 332 | + // 110x c - d reserved (Microsoft GUID) |
| 333 | + // 1110 e reserved (future use) |
| 334 | + // 1111 f unknown / invalid. Must end with "0" |
| 335 | + |
| 336 | + descriptorBuilder.setAttribute( "variant", new int[] { 0 } ); |
| 337 | + |
| 338 | + uuidAnnotation = descriptorBuilder.build().getAnnotation(); |
| 339 | + uuidValidator.initialize( uuidAnnotation ); |
| 340 | + |
| 341 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-0622-92adaaae229f", null ) ); |
| 342 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-1622-92adaaae229f", null ) ); |
| 343 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-2622-92adaaae229f", null ) ); |
| 344 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-3622-92adaaae229f", null ) ); |
| 345 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-4622-92adaaae229f", null ) ); |
| 346 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-5622-92adaaae229f", null ) ); |
| 347 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-6622-92adaaae229f", null ) ); |
| 348 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-7622-92adaaae229f", null ) ); |
| 349 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-8622-92adaaae229f", null ) ); |
| 350 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-9622-92adaaae229f", null ) ); |
| 351 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-a622-92adaaae229f", null ) ); |
| 352 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-b622-92adaaae229f", null ) ); |
| 353 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-c622-92adaaae229f", null ) ); |
| 354 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-d622-92adaaae229f", null ) ); |
| 355 | + // Next two variants are always invalid as they are currently "undefined": |
| 356 | + // 1110 e |
| 357 | + // 1111 f |
| 358 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-e622-92adaaae229f", null ) ); |
| 359 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-f622-92adaaae229f", null ) ); |
| 360 | + |
| 361 | + descriptorBuilder.setAttribute( "variant", new int[] { 1 } ); |
| 362 | + |
| 363 | + uuidAnnotation = descriptorBuilder.build().getAnnotation(); |
| 364 | + uuidValidator.initialize( uuidAnnotation ); |
| 365 | + |
| 366 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-0622-92adaaae229f", null ) ); |
| 367 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-1622-92adaaae229f", null ) ); |
| 368 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-2622-92adaaae229f", null ) ); |
| 369 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-3622-92adaaae229f", null ) ); |
| 370 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-4622-92adaaae229f", null ) ); |
| 371 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-5622-92adaaae229f", null ) ); |
| 372 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-6622-92adaaae229f", null ) ); |
| 373 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-7622-92adaaae229f", null ) ); |
| 374 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-8622-92adaaae229f", null ) ); |
| 375 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-9622-92adaaae229f", null ) ); |
| 376 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-a622-92adaaae229f", null ) ); |
| 377 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-b622-92adaaae229f", null ) ); |
| 378 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-c622-92adaaae229f", null ) ); |
| 379 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-d622-92adaaae229f", null ) ); |
| 380 | + // Next two variants are always invalid as they are currently "undefined": |
| 381 | + // 1110 e |
| 382 | + // 1111 f |
| 383 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-e622-92adaaae229f", null ) ); |
| 384 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-f622-92adaaae229f", null ) ); |
| 385 | + |
| 386 | + descriptorBuilder.setAttribute( "variant", new int[] { 2 } ); |
292 | 387 |
|
| 388 | + uuidAnnotation = descriptorBuilder.build().getAnnotation(); |
| 389 | + uuidValidator.initialize( uuidAnnotation ); |
| 390 | + |
| 391 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-0622-92adaaae229f", null ) ); |
| 392 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-1622-92adaaae229f", null ) ); |
| 393 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-2622-92adaaae229f", null ) ); |
| 394 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-3622-92adaaae229f", null ) ); |
| 395 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-4622-92adaaae229f", null ) ); |
| 396 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-5622-92adaaae229f", null ) ); |
| 397 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-6622-92adaaae229f", null ) ); |
| 398 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-7622-92adaaae229f", null ) ); |
| 399 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-8622-92adaaae229f", null ) ); |
| 400 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-9622-92adaaae229f", null ) ); |
| 401 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-a622-92adaaae229f", null ) ); |
| 402 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-b622-92adaaae229f", null ) ); |
| 403 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-c622-92adaaae229f", null ) ); |
| 404 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-d622-92adaaae229f", null ) ); |
| 405 | + // Next two variants are always invalid as they are currently "undefined": |
| 406 | + // 1110 e |
| 407 | + // 1111 f |
| 408 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-e622-92adaaae229f", null ) ); |
| 409 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-f622-92adaaae229f", null ) ); |
| 410 | + |
| 411 | + } |
293 | 412 | }
|
0 commit comments