1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 * 10 * $Revision: 1.8 $ 11 */ 12 13 package com.sun.xml.registry.ebxml; 14 15 import java.util.ArrayList; 16 import java.util.Collection; 17 import java.util.Iterator; 18 import javax.xml.registry.BulkResponse; 19 import javax.xml.registry.infomodel.*; 20 21 import javax.xml.registry.FindQualifier; 22 23 24 public class ApelonJAXRTest extends junit.framework.TestCase { 25 static ApelonJAXRTestSetup setup = null; 26 27 public static junit.framework.Test suite() throws Exception { 28 // These tests need to be ordered for purposes of read/write/delete. 29 // Do not change order of tests, erroneous errors will result. 30 junit.framework.TestSuite suite= new junit.framework.TestSuite(); 31 32 // Test creating and retrieving 2 internal schemes and 1 external scheme 33 suite.addTest(new ApelonJAXRTest("testCreateInternalSchemes")); 34 suite.addTest(new ApelonJAXRTest("testCreateExternalScheme")); 35 suite.addTest(new ApelonJAXRTest("testRetrieveInternalSchemes")); 36 suite.addTest(new ApelonJAXRTest("testRetrieveExternalScheme")); 37 38 // Test creating and modifiying registry package (implicit retrieve test) 39 suite.addTest(new ApelonJAXRTest("testCreateRegistryPackage")); 40 suite.addTest(new ApelonJAXRTest("testUpdateRegistryPackage")); 41 42 // Test inspection of RegistryPackage Auditable events 43 suite.addTest(new ApelonJAXRTest("testInspectRegistryPackageAuditableEvents")); 44 45 // Test creating and adding ExtrinsicObject to package 46 suite.addTest(new ApelonJAXRTest("testCreateExtrinsicObject")); 47 suite.addTest(new ApelonJAXRTest("testAddExtrinsicObjectToRegistryPackage")); 48 suite.addTest(new ApelonJAXRTest("testInspectRegistryPackageExtrinsicObjects")); 49 50 // Test adding slots 51 suite.addTest(new ApelonJAXRTest("testAddSlotsToRegistryPackage")); 52 suite.addTest(new ApelonJAXRTest("testInspectRegistryPackageSlots")); 53 54 // Tests to create internal and external context sensitive 55 // classifications, initial creation works now 56 suite.addTest(new ApelonJAXRTest("testClassifyRegistryPackage")); 57 suite.addTest(new ApelonJAXRTest("testInspectRegistryPackageClassifications")); 58 59 // NOTE Running these again gives example of how context sensitive 60 // classifications and primary external cls ClassificationScheme are 61 // wiped out after updating a RegistryObject 62 suite.addTest(new ApelonJAXRTest("testUpdateRegistryPackage")); 63 suite.addTest(new ApelonJAXRTest("testInspectRegistryPackageClassificationsPostPkgUpdate")); 64 65 // Test adding and retrieving ExternalLinks on a package 66 suite.addTest(new ApelonJAXRTest("testAddRegistryPackageExternalLinks")); 67 suite.addTest(new ApelonJAXRTest("testInspectRegistryPackageExternalLinks")); 68 69 // Test deleting everything, cleanup for test suite 70 System.err.println("testDeleteRegistryPackage"); 71 suite.addTest(new ApelonJAXRTest("testDeleteRegistryPackage")); 72 System.err.println("testDeleteExtrinsicObject"); 73 suite.addTest(new ApelonJAXRTest("testDeleteExtrinsicObject")); 74 System.err.println("testDeleteInternalSchemes"); 75 suite.addTest(new ApelonJAXRTest("testDeleteInternalSchemes")); 76 System.err.println("testDeleteExternalScheme"); 77 suite.addTest(new ApelonJAXRTest("testDeleteExternalScheme")); 78 79 setup = new ApelonJAXRTestSetup(suite); 80 81 return setup; 82 } 83 84 public ApelonJAXRTest(String testMethod) { 85 super(testMethod); 86 } 87 88 /*** 89 * Asserts that: 90 * We cannot find InternalScheme (1 and 2) 91 * We can create InternalScheme (1 and 2) with 2 nodes each 92 * 93 * @throws Exception 94 */ 95 public void testCreateInternalSchemes() 96 throws Exception { 97 testCreateInternalScheme(1); 98 testCreateInternalScheme(2); 99 } 100 101 /*** 102 * Asserts that: 103 * We cannot find InternalScheme (1 and 2) 104 * We can create InternalScheme (1 and 2) with 2 nodes each 105 * 106 * @throws Exception 107 */ 108 public void testCreateInternalScheme(int schemeNum) 109 throws Exception { 110 ArrayList findQualifiers = new ArrayList(); 111 findQualifiers.add(FindQualifier.CASE_SENSITIVE_MATCH); 112 ClassificationScheme scheme = setup.bqm.findClassificationSchemeByName(findQualifiers,"InternalScheme" + schemeNum); 113 114 if(scheme != null) 115 fail("InternalScheme" + schemeNum + " already exists in registry"); 116 else { 117 scheme = setup.lcm.createClassificationScheme("InternalScheme" + schemeNum,"InternalScheme" + schemeNum); 118 scheme.setValueType(ClassificationScheme.VALUE_TYPE_UNIQUE); 119 Concept con1 = setup.lcm.createConcept(scheme,"InternalScheme" + schemeNum + "-Node1","InternalScheme" + schemeNum + "-Node1"); 120 Concept con2 = setup.lcm.createConcept(scheme,"InternalScheme" + schemeNum + "-Node2","InternalScheme" + schemeNum + "-Node2"); 121 scheme.addChildConcept(con1); 122 scheme.addChildConcept(con2); 123 ArrayList objs = new ArrayList(); 124 objs.add(scheme); 125 126 //Following is not necessary but is being done to test that duplicates are eliminated during marshal 127 objs.add(con1); 128 objs.add(con2); 129 130 System.err.println("\nSaving 1 scheme and 2 concepts"); 131 BulkResponse br = setup.lcm.saveObjects(objs); 132 assertTrue("Scheme" + schemeNum + " Creation Failed", br.getStatus() == BulkResponse.STATUS_SUCCESS); 133 } 134 } 135 136 public void testRetrieveInternalSchemes() 137 throws Exception { 138 testRetrieveInternalScheme(1); 139 testRetrieveInternalScheme(2); 140 } 141 142 /*** 143 * Asserts that: 144 * We can find InternalScheme (1 and 2) 145 * 146 * @throws Exception 147 */ 148 public void testRetrieveInternalScheme(int schemeNum) 149 throws Exception { 150 ArrayList findQualifiers = new ArrayList(); 151 findQualifiers.add(FindQualifier.CASE_SENSITIVE_MATCH); 152 ClassificationScheme scheme = setup.bqm.findClassificationSchemeByName(findQualifiers, "InternalScheme" + schemeNum); 153 154 if(scheme == null) 155 fail("InternalScheme" + schemeNum + " could not be found in registry"); 156 else { 157 assertEquals("InternalScheme" + schemeNum + " node count incorrect", scheme.getChildConceptCount(),2); 158 } 159 } 160 161 /*** 162 * Asserts that: 163 * We can find InternalScheme (1 and 2) 164 * We can delete InternalScheme (1 and 2) 165 * 166 * @throws Exception 167 */ 168 public void testDeleteInternalSchemes() 169 throws Exception { 170 testDeleteInternalScheme(1); 171 testDeleteInternalScheme(2); 172 } 173 174 /*** 175 * Asserts that: 176 * We can find InternalScheme (1 and 2) 177 * We can delete InternalScheme (1 and 2) 178 * 179 * @throws Exception 180 */ 181 public void testDeleteInternalScheme(int schemeNum) 182 throws Exception { 183 ArrayList findQualifiers = new ArrayList(); 184 findQualifiers.add(FindQualifier.CASE_SENSITIVE_MATCH); 185 ClassificationScheme scheme = setup.bqm.findClassificationSchemeByName(findQualifiers, "InternalScheme" + schemeNum); 186 if(scheme == null) 187 fail("InternalScheme" + schemeNum + " could not be found in registry"); 188 else { 189 ArrayList al = new ArrayList(); 190 al.add(scheme.getKey()); 191 Iterator it = scheme.getChildrenConcepts().iterator(); 192 while(it.hasNext()) { 193 al.add(((javax.xml.registry.infomodel.RegistryObject)it.next()).getKey()); 194 } 195 BulkResponse br = setup.lcm.deleteObjects(al); 196 assertTrue("Delete InternalScheme" + schemeNum + " did not Succeed",br.getStatus() == BulkResponse.STATUS_SUCCESS); 197 } 198 } 199 200 /*** 201 * Asserts that: 202 * We cannot find ExternalScheme 203 * We can create ExternalScheme 204 * 205 * @throws Exception 206 */ 207 public void testCreateExternalScheme() 208 throws Exception { 209 ArrayList findQualifiers = new ArrayList(); 210 findQualifiers.add(FindQualifier.CASE_SENSITIVE_MATCH); 211 ClassificationScheme scheme = setup.bqm.findClassificationSchemeByName(findQualifiers, "ExternalScheme"); 212 if(scheme != null) 213 fail("ExternalScheme already exists in registry"); 214 else { 215 scheme = setup.lcm.createClassificationScheme("ExternalScheme","ExternalScheme"); 216 scheme.setValueType(ClassificationScheme.VALUE_TYPE_UNIQUE); 217 ((com.sun.xml.registry.ebxml.infomodel.ClassificationSchemeImpl)scheme).setExternal(true); 218 ArrayList al = new ArrayList(); 219 al.add(scheme); 220 System.err.println("\nSaving 1 ext scheme"); 221 BulkResponse br = setup.lcm.saveObjects(al); 222 assertTrue("ExternalScheme creation Failed", br.getStatus() == BulkResponse.STATUS_SUCCESS); 223 } 224 } 225 226 /*** 227 * Asserts that: 228 * We can find ExternalScheme 229 * 230 * @throws Exception 231 */ 232 public void testRetrieveExternalScheme() 233 throws Exception { 234 ArrayList findQualifiers = new ArrayList(); 235 findQualifiers.add(FindQualifier.CASE_SENSITIVE_MATCH); 236 ClassificationScheme scheme = setup.bqm.findClassificationSchemeByName(findQualifiers, "ExternalScheme"); 237 238 if(scheme == null) 239 fail("ExternalScheme could not be found in registry"); 240 else 241 assertEquals("ExternalScheme is external", true, scheme.isExternal()); 242 } 243 244 /*** 245 * Asserts that: 246 * We can find ExternalScheme 247 * We can delete ExternalScheme 248 * 249 * @throws Exception 250 */ 251 public void testDeleteExternalScheme() 252 throws Exception { 253 ArrayList findQualifiers = new ArrayList(); 254 findQualifiers.add(FindQualifier.CASE_SENSITIVE_MATCH); 255 ClassificationScheme scheme = setup.bqm.findClassificationSchemeByName(findQualifiers, "ExternalScheme"); 256 if(scheme == null) 257 fail("ExternalScheme could not be found in registry"); 258 else { 259 ArrayList al = new ArrayList(); 260 al.add(scheme.getKey()); 261 BulkResponse br = setup.lcm.deleteObjects(al); 262 assertTrue("Delete ExternalScheme did not Succeed",br.getStatus() == BulkResponse.STATUS_SUCCESS); 263 } 264 } 265 266 /*** 267 * Asserts that: 268 * We cannot find testPackage 269 * We can create testPackage 270 * 271 * @throws Exception 272 */ 273 public void testCreateRegistryPackage() 274 throws Exception { 275 RegistryPackage pkg = (RegistryPackage)findRegistryObject("testPackage","RegistryPackage"); 276 if(pkg != null) 277 fail("testPackage already exists in the registry"); 278 else { 279 pkg = setup.lcm.createRegistryPackage("testPackage"); 280 pkg.setDescription(setup.lcm.createInternationalString("testPackage description")); 281 ArrayList al = new ArrayList(); 282 al.add(pkg); 283 System.err.println("\nSaving 1 RegistryPackage"); 284 BulkResponse br = setup.lcm.saveObjects(al); 285 assertTrue("testPackage creation Failed", br.getStatus() == BulkResponse.STATUS_SUCCESS); 286 } 287 } 288 289 /*** 290 * Asserts that: 291 * We can find testPackage 292 * We can update testPackage's description 293 * 294 * @throws Exception 295 */ 296 public void testUpdateRegistryPackage() 297 throws Exception { 298 RegistryPackage pkg = (RegistryPackage)findRegistryObject("testPackage","RegistryPackage"); 299 if(pkg == null) 300 fail("testPackage could not be found in the registry"); 301 else { 302 String newDesc = pkg.getDescription().getValue() + " updated"; 303 pkg.setDescription(setup.lcm.createInternationalString(newDesc)); 304 ArrayList al = new ArrayList(); 305 al.add(pkg); 306 System.err.println("\nSaving existing RegistryPackage after updating it."); 307 BulkResponse br = setup.lcm.saveObjects(al); 308 assertTrue("testPackage update failed", br.getStatus() == BulkResponse.STATUS_SUCCESS); 309 } 310 } 311 312 /*** 313 * Asserts that: 314 * We can find and delete testPackage 315 * 316 * @throws Exception 317 */ 318 public void testDeleteRegistryPackage() 319 throws Exception { 320 RegistryPackage pkg = (RegistryPackage)findRegistryObject("testPackage","RegistryPackage"); 321 if(pkg == null) 322 fail("testPackage could not be found in the registry"); 323 else { 324 // Delete package associations first Is this correct though? 325 // Should we have to del associations first? 326 Iterator it = pkg.getAssociations().iterator(); 327 ArrayList al = new ArrayList(); 328 while(it.hasNext()) { 329 javax.xml.registry.infomodel.Association a = (javax.xml.registry.infomodel.Association)it.next(); 330 al.add(a.getKey()); 331 } 332 BulkResponse br = setup.lcm.deleteObjects(al); 333 assertTrue("testPackage delete associations failed", br.getStatus() == BulkResponse.STATUS_SUCCESS); 334 335 al.clear(); 336 al.add(pkg.getKey()); 337 br = setup.lcm.deleteObjects(al); 338 assertTrue("testPackage deletion Failed", br.getStatus() == BulkResponse.STATUS_SUCCESS); 339 } 340 } 341 342 /*** 343 * Asserts that: 344 * We can create testExtObj ExtrinsicObject 345 * 346 * @throws Exception 347 */ 348 public void testCreateExtrinsicObject() 349 throws Exception { 350 ExtrinsicObject extObj = (ExtrinsicObject)findRegistryObject("testExtObj", "ExtrinsicObject"); 351 if(extObj != null) 352 fail("testExtObj already exists in the registry"); 353 else { 354 String path = System.getProperty("user.home") + System.getProperty("file.separator") + "jaxr-ebxml.properties"; 355 java.io.File f = new java.io.File(path); 356 357 // using URLs causes "cannot sign the payload error" 358 // DataHandler dh = new DataHandler(f.toURL()); 359 javax.activation.DataHandler dh = new javax.activation.DataHandler(new javax.activation.FileDataSource(f)); 360 361 extObj = setup.lcm.createExtrinsicObject(dh); 362 extObj.setName(setup.lcm.createInternationalString("testExtObj")); 363 extObj.setDescription(setup.lcm.createInternationalString("jaxr-ebxml.properties")); 364 ArrayList al = new ArrayList(); 365 al.add(extObj); 366 System.err.println("\nSaving 1 ExtrinsicObject with a repository item"); 367 BulkResponse br = setup.lcm.saveObjects(al); 368 assertTrue("testExtObj creation Failed", br.getStatus() == BulkResponse.STATUS_SUCCESS); 369 } 370 } 371 372 /*** 373 * Asserts that: 374 * We can find testExtObj 375 * We can delete testExtObj 376 * 377 * @throws Exception 378 */ 379 public void testDeleteExtrinsicObject() 380 throws Exception { 381 ExtrinsicObject extObj = (ExtrinsicObject)findRegistryObject("testExtObj", "ExtrinsicObject"); 382 if(extObj == null) 383 fail("testExtObj could not be found in the registry"); 384 else { 385 ArrayList al = new ArrayList(); 386 al.add(extObj.getKey()); 387 BulkResponse br = setup.lcm.deleteObjects(al); 388 assertTrue("testExtObj deletion Failed", br.getStatus() == BulkResponse.STATUS_SUCCESS); 389 } 390 } 391 392 /*** 393 * Asserts that: 394 * We can find testPackage 395 * We can find testExtObj 396 * We can add testExtObj to testPackage 397 * 398 * @throws Exception 399 */ 400 public void testAddExtrinsicObjectToRegistryPackage() 401 throws Exception { 402 ExtrinsicObject extObj = (ExtrinsicObject)findRegistryObject("testExtObj", "ExtrinsicObject"); 403 RegistryPackage pkg = (RegistryPackage)findRegistryObject("testPackage","RegistryPackage"); 404 if(pkg == null) 405 fail("testPackage could not be found in the registry"); 406 else if(extObj == null) 407 fail("testExtObj could not be found in the registry"); 408 else { 409 pkg.addRegistryObject(extObj); 410 411 ArrayList al = new ArrayList(); 412 al.add(pkg); 413 System.err.println("Adding ass between existing RegistryPackage and ExtrinsicObject"); 414 BulkResponse br = setup.lcm.saveObjects(al); 415 assertTrue("Adding ExtObj to RegPkg failed", br.getStatus() == BulkResponse.STATUS_SUCCESS); 416 } 417 } 418 419 420 /*** 421 * Asserts that: 422 * We can find testPackage 423 * The package has 2 auditable events 424 * The events are the expected types 425 * The events have user populated 426 * 427 * @throws Exception 428 */ 429 public void testInspectRegistryPackageAuditableEvents() 430 throws Exception { 431 RegistryPackage pkg = (RegistryPackage)findRegistryObject("testPackage","RegistryPackage"); 432 if(pkg == null) 433 fail("testPackage could not be found in the registry"); 434 else { 435 boolean bFoundCreated = false; 436 boolean bFoundUpdated = false; 437 Collection events = pkg.getAuditTrail(); 438 assertEquals("RegistryPackage should have 2 AudiatableEvents",2,events.size()); 439 Iterator it = events.iterator(); 440 441 // This should be the create event.. 442 AuditableEvent ae = (AuditableEvent)it.next(); 443 assertTrue("AuditableEvent 'Create' user is null",ae.getUser()!=null); 444 assertTrue("AuditableEvent 'Create' user name is null",ae.getUser().getName().getValue()!=null); 445 if(ae.getEventType() == AuditableEvent.EVENT_TYPE_CREATED) 446 bFoundCreated = true; 447 else if(ae.getEventType() == AuditableEvent.EVENT_TYPE_UPDATED) 448 bFoundUpdated = true; 449 450 // This should be the modify event... 451 ae = (AuditableEvent)it.next(); 452 assertTrue("AuditableEvent 'Update' user is null",ae.getUser()!=null); 453 assertTrue("AuditableEvent 'Update' user name is null",ae.getUser().getName().getValue()!=null); 454 if(ae.getEventType() == AuditableEvent.EVENT_TYPE_CREATED) 455 bFoundCreated = true; 456 else if(ae.getEventType() == AuditableEvent.EVENT_TYPE_UPDATED) 457 bFoundUpdated = true; 458 459 assertTrue("'Created' AuditableEvent event type not found",bFoundCreated); 460 assertTrue("'Updated' AuditableEvent event type not found",bFoundUpdated); 461 } 462 } 463 464 /*** 465 * Asserts that: 466 * We can find testPackage 467 * The pkg has one association to an ExtrinsicObject 468 * The ExtObj has the right name 469 * The ExtObj has one AuditableEvent of type Created 470 * The one ExtObj AuditableEvent has the user populated 471 * 472 * @throws Exception 473 */ 474 public void testInspectRegistryPackageExtrinsicObjects() 475 throws Exception { 476 RegistryPackage pkg = (RegistryPackage)findRegistryObject("testPackage","RegistryPackage"); 477 if(pkg == null) 478 fail("testPackage could not be found in the registry"); 479 else { 480 Collection files = pkg.getAssociatedObjects(); 481 assertEquals("RegistryPackage should have 1 Association",1,files.size()); 482 Iterator fileIter = files.iterator(); 483 javax.xml.registry.infomodel.Association assoc = (javax.xml.registry.infomodel.Association)fileIter.next(); 484 ExtrinsicObject eo = (ExtrinsicObject)assoc.getTargetObject(); 485 assertTrue("ExtrinsicObject name incorrect",eo.getName().getValue().equals("testExtObj")); 486 487 Collection edits = eo.getAuditTrail(); 488 489 //??This assertion is failing because there is only 1 auditable event found. 490 //Commenting out for now as it is not essential. 491 //assertEquals("ExtrinsicObject should have 2 AuditableEvent",2,edits.size()); 492 //??assertGreaterThanOrEquals("ExtrinsicObject should have 2 AuditableEvent",1,edits.size()); 493 494 495 Iterator it = edits.iterator(); 496 AuditableEvent ae = (AuditableEvent)it.next(); 497 498 assertTrue("AuditableEvent type is 'Created'",ae.getEventType() == AuditableEvent.EVENT_TYPE_CREATED); 499 500 // NOTE This is where I was seeing intermittent problem of the user 501 // object on the AE not being populated, returning null. 502 assertTrue("AuditableEvent 'Created' user is null",ae.getUser()!=null); 503 assertTrue("AuditableEvent 'Created' user name is null",ae.getUser().getName().getValue()!=null); 504 } 505 } 506 507 /*** 508 * Asserts that: 509 * We can find testPackage 510 * We can add 3 slots to the package 511 * 512 * @throws Exception 513 */ 514 public void testAddSlotsToRegistryPackage() 515 throws Exception { 516 RegistryPackage pkg = (RegistryPackage)findRegistryObject("testPackage","RegistryPackage"); 517 if(pkg == null) 518 fail("testPackage could not be found in the registry"); 519 else { 520 Slot slotA = setup.lcm.createSlot("SlotA", "SlotA Value","TestSlots"); 521 Slot slotB = setup.lcm.createSlot("SlotB", "SlotB Value","TestSlots"); 522 Slot slotC = setup.lcm.createSlot("SlotC", "SlotC Value","TestSlots"); 523 524 pkg.addSlot(slotA); 525 pkg.addSlot(slotB); 526 pkg.addSlot(slotC); 527 528 ArrayList al = new ArrayList(); 529 al.add(pkg); 530 531 System.err.println("\nSaving existing RegistryPackage after adding 3 SLots to it."); 532 BulkResponse br = setup.lcm.saveObjects(al); 533 assertTrue("Slot creation and addition to package failed", br.getStatus() == BulkResponse.STATUS_SUCCESS); 534 } 535 } 536 537 /*** 538 * Asserts that: 539 * We can find testPackage 540 * Pkg has 3 slots, and vals are correct 541 * 542 * @throws Exception 543 */ 544 public void testInspectRegistryPackageSlots() 545 throws Exception { 546 RegistryPackage pkg = (RegistryPackage)findRegistryObject("testPackage","RegistryPackage"); 547 if(pkg == null) 548 fail("testPackage could not be found in the registry"); 549 else { 550 String val = null; 551 Slot slotA = pkg.getSlot("SlotA"); 552 assertTrue("Slot A not found", slotA != null); 553 val = (String)slotA.getValues().iterator().next(); 554 assertTrue("Slot A incorrect value", val.equals("SlotA Value")); 555 Slot slotB = pkg.getSlot("SlotB"); 556 val = (String)slotB.getValues().iterator().next(); 557 assertTrue("Slot B incorrect value", val.equals("SlotB Value")); 558 Slot slotC = pkg.getSlot("SlotC"); 559 val = (String)slotC.getValues().iterator().next(); 560 assertTrue("Slot C incorrect value", val.equals("SlotC Value")); 561 } 562 } 563 564 /*** 565 * Asserts that: 566 * We can find testPackage 567 * We can find node InternalScheme1-Node1 568 * We can find node InternalScheme2-Node1 569 * We can find scheme ExternalScheme 570 * We can create primary classifications on internal scheme node 571 * We can create secondary cls on above primary cls 572 * We can create primary classifications on external scheme 573 * We can create secondary cls on above primary cls 574 * 575 * @throws Exception 576 */ 577 public void testClassifyRegistryPackage() 578 throws Exception { 579 RegistryPackage pkg = (RegistryPackage)findRegistryObject("testPackage","RegistryPackage"); 580 Concept primaryInternalCon = (Concept)findRegistryObject("InternalScheme1-Node1", "ClassificationNode"); 581 Concept ctxSensitiveCon = (Concept)findRegistryObject("InternalScheme2-Node1", "ClassificationNode"); 582 ArrayList findQualifiers = new ArrayList(); 583 findQualifiers.add(FindQualifier.CASE_SENSITIVE_MATCH); 584 ClassificationScheme extScheme = setup.bqm.findClassificationSchemeByName(findQualifiers, "ExternalScheme"); 585 586 if(pkg == null) 587 fail("testPackage could not be found in the registry"); 588 else if(primaryInternalCon == null) 589 fail("InternalScheme1-Node1 could not be found in the registry"); 590 else if(ctxSensitiveCon == null) 591 fail("InternalScheme2-Node1 could not be found in the registry"); 592 else if(extScheme == null) 593 fail("ExternalScheme could not be found in the registry"); 594 else { 595 // Create primary internal classification 596 Classification primaryInternalCls = setup.lcm.createClassification(primaryInternalCon); 597 primaryInternalCls.setClassifiedObject(pkg); 598 599 // Now create the secondary classification to the classification created above 600 Classification internalCtxSensCls = setup.lcm.createClassification(ctxSensitiveCon); 601 internalCtxSensCls.setClassifiedObject(primaryInternalCls); 602 603 // create primary external classification 604 Classification primaryExternalCls = setup.lcm.createClassification(extScheme,"externalName","externalCode"); 605 primaryExternalCls.setClassifiedObject(pkg); 606 607 // Now create the secondary classification to the classification created above 608 Classification externalCtxSensCls = setup.lcm.createClassification(ctxSensitiveCon); 609 externalCtxSensCls.setClassifiedObject(primaryExternalCls); 610 611 ArrayList al = new ArrayList(); 612 al.add(primaryInternalCls); 613 al.add(internalCtxSensCls); 614 al.add(primaryExternalCls); 615 al.add(externalCtxSensCls); 616 617 System.err.println("Add 2 Classifications to existing RegistryPackage. Each Classification has 1 contextual Classification."); 618 BulkResponse br = setup.lcm.saveObjects(al); 619 assertTrue("Classification failed", br.getStatus() == BulkResponse.STATUS_SUCCESS); 620 } 621 } 622 623 // Wrapper so test ui will indicate failure in appropriate 624 // test suite context 625 public void testInspectRegistryPackageClassificationsPostPkgUpdate() 626 throws Exception { 627 testInspectRegistryPackageClassifications(); 628 } 629 630 /*** 631 * This test reproduces two problems: 632 * 1) Retrieving a RegistryObject's classifications does not return 633 * classifications of the RO's classifcations (context sensitive classifications) 634 * You can however, get them via code commented out below. 635 * 636 * 2) After updating a RegistryObject, the context sensitive classifications 637 * are deleted from the db, and primary external classifications have the 638 * "ClassificationScheme" attribute deleted. 639 * 640 * Asserts that: 641 * We can find testPackage 642 * It has two primary classifications, one internal one external 643 * The external classification has the classification scheme 644 * Each primary classification has a secondary classification 645 * 646 * @throws Exception 647 */ 648 public void testInspectRegistryPackageClassifications() 649 throws Exception { 650 RegistryPackage pkg = (RegistryPackage)findRegistryObject("testPackage","RegistryPackage"); 651 if(pkg == null) 652 fail("testPackage could not be found in the registry"); 653 else { 654 boolean bFoundInternalCls = false; 655 boolean bFoundInternalClsConcept = false; 656 boolean bFoundInternalConSensCls = false; 657 boolean bFoundInternalConSensClsConcept = false; 658 boolean bFoundExternalCls = false; 659 boolean bFoundExternalClsScheme = false; 660 boolean bFoundExternalConSensCls = false; 661 boolean bFoundExternalConSensClsConcept = false; 662 663 Collection clses = pkg.getClassifications(); 664 assertEquals("testPackage should have two Classifications",2,clses.size()); 665 Iterator it = clses.iterator(); 666 667 while(it.hasNext()) { 668 Classification cls = (Classification)it.next(); 669 if(cls.isExternal()) { 670 bFoundExternalCls = true; 671 // NOTE This returns null for cs after an update is 672 // made to the RegistryObject 673 ClassificationScheme cs = cls.getClassificationScheme(); 674 if(cs!=null) 675 bFoundExternalClsScheme = true; 676 677 Collection conSensClses = cls.getClassifications(); 678 if(conSensClses.size()==1) { 679 bFoundExternalConSensCls = true; 680 Classification cls2 = (Classification)conSensClses.iterator().next(); 681 Concept con = cls2.getConcept(); 682 if(con != null) 683 bFoundExternalConSensClsConcept = true; 684 } 685 } 686 else { 687 bFoundInternalCls = true; 688 bFoundInternalClsConcept = cls.getConcept() != null; 689 690 Collection conSensClses = cls.getClassifications(); 691 if(conSensClses.size()==1) { 692 bFoundInternalConSensCls = true; 693 Classification cls2 = (Classification)conSensClses.iterator().next(); 694 Concept con = cls2.getConcept(); 695 if(con != null) 696 bFoundInternalConSensClsConcept = true; 697 } 698 } 699 } 700 assertTrue("Could not find Internal Classification",bFoundInternalCls); 701 assertTrue("Could not find context sensitive Internal Classification",bFoundInternalConSensCls); 702 assertTrue("Could not find External Classification",bFoundExternalCls); 703 assertTrue("Could not find External Classification Scheme",bFoundExternalClsScheme); 704 assertTrue("Could not find context sensitive External Classification",bFoundExternalConSensCls); 705 706 assertTrue("Could not find Internal Classification Concept",bFoundInternalClsConcept); 707 assertTrue("Could not find context sensitive Internal Classification Concept",bFoundInternalConSensClsConcept); 708 assertTrue("Could not find context sensitive External Classification Concept",bFoundExternalConSensClsConcept); 709 } 710 } 711 712 /*** 713 * Asserts that: 714 * We can find testPackage 715 * We can create a www.yahoo.com ExternalLink 716 * We can add to testPackage and save successfully 717 */ 718 public void testAddRegistryPackageExternalLinks() 719 throws Exception { 720 RegistryPackage pkg = (RegistryPackage)findRegistryObject("testPackage","RegistryPackage"); 721 if(pkg == null) 722 fail("testPackage could not be found in the registry"); 723 else { 724 javax.xml.registry.infomodel.ExternalLink link = setup.lcm.createExternalLink("www.yahoo.com","External Link"); 725 pkg.addExternalLink(link); 726 ArrayList al = new ArrayList(); 727 al.add(pkg); 728 //al.add(link);//No need now that links are implicitly saved 729 System.err.println("Add ExtrenalLink to existing Package"); 730 BulkResponse br = setup.lcm.saveObjects(al); 731 assertTrue("ExternalLink creation failed", br.getStatus() == BulkResponse.STATUS_SUCCESS); 732 } 733 } 734 735 /*** 736 * Asserts that: 737 * We can find testPackage 738 * It has one ExternalLink 739 * The ExternalLink URI is "www.yahoo.com" 740 * 741 * @throws Exception 742 */ 743 public void testInspectRegistryPackageExternalLinks() 744 throws Exception { 745 RegistryPackage pkg = (RegistryPackage)findRegistryObject("testPackage","RegistryPackage"); 746 if(pkg == null) 747 fail("testPackage could not be found in the registry"); 748 else { 749 Collection links = pkg.getExternalLinks(); 750 assertEquals("Package should have 1 ExternalLink",1,links.size()); 751 javax.xml.registry.infomodel.ExternalLink link = (javax.xml.registry.infomodel.ExternalLink)links.iterator().next(); 752 assertTrue("ExternalLink has wrong url",link.getExternalURI().equals("www.yahoo.com")); 753 } 754 } 755 756 /*** 757 * Utility method to lookup registry object based on name and type 758 */ 759 public javax.xml.registry.infomodel.RegistryObject findRegistryObject(String roName, String roType) throws Exception { 760 javax.xml.registry.infomodel.RegistryObject retVal = null; 761 762 String query = "select * from registryobject, name_ where id = parent and name_.value = '" + roName + "'" + 763 " and objecttype = '" + roType + "'"; 764 765 javax.xml.registry.Query q = setup.dqm.createQuery(javax.xml.registry.Query.QUERY_TYPE_SQL, query); 766 BulkResponse br = setup.dqm.executeQuery(q); 767 if(br.getStatus() == BulkResponse.STATUS_SUCCESS) { 768 Collection c = br.getCollection(); 769 Iterator it = c.iterator(); 770 if(it.hasNext()) 771 retVal = (javax.xml.registry.infomodel.RegistryObject)it.next(); 772 } 773 else { 774 throw new Exception("findRegistryObject Failed!"); 775 } 776 777 return retVal; 778 } 779 }

This page was automatically generated by Maven