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 11 package com.sun.xml.registry.ebxml; 12 13 import com.sun.xml.registry.client.util.RegistryObjectUtil; 14 15 import junit.framework.Test; 16 import junit.framework.TestCase; 17 import junit.framework.TestSuite; 18 19 import java.net.URL; 20 21 import java.util.ArrayList; 22 23 import javax.activation.DataHandler; 24 25 import javax.xml.registry.BulkResponse; 26 import javax.xml.registry.CapabilityProfile; 27 import javax.xml.registry.Query; 28 import javax.xml.registry.infomodel.Association; 29 import javax.xml.registry.infomodel.Concept; 30 import javax.xml.registry.infomodel.ExtrinsicObject; 31 import javax.xml.registry.infomodel.InternationalString; 32 import javax.xml.registry.infomodel.RegistryObject; 33 import javax.xml.registry.infomodel.RegistryPackage; 34 35 36 /* 37 * First set of JAXR ebXML provider unit tests 38 * 39 * Use following properties to configure parameters: 40 * 41 * jaxr.server.url = URL used to connect to registry server 42 * 43 * $Header: /cvsroot/ebxmlrr/jaxr/test/com/sun/xml/registry/ebxml/EbxmlTest1.java,v 1.19 2003/03/20 12:50:28 ritzmann Exp $ 44 * 45 */ 46 public class EbxmlTest1 extends TestCase { 47 48 static ApelonJAXRTestSetup setup = null; 49 50 /*** 51 * Creates a new EbxmlTest1 object. 52 * 53 * @param testMethod DOCUMENT ME! 54 */ 55 public EbxmlTest1(String testMethod) { 56 super(testMethod); 57 } 58 59 /*** 60 * DOCUMENT ME! 61 * 62 * @return DOCUMENT ME! 63 * 64 * @throws Exception DOCUMENT ME! 65 */ 66 public static Test suite() throws Exception { 67 68 TestSuite suite = new TestSuite(); 69 70 suite.addTest(new EbxmlTest1("testCapabilityLevel")); 71 suite.addTest(new EbxmlTest1("testDeleteAssociation")); 72 suite.addTest(new EbxmlTest1("testSaveObjectsSavesAssociations")); 73 suite.addTest(new EbxmlTest1("testUpdateObjectsRequest")); 74 suite.addTest(new EbxmlTest1("testCreateRemoveAssociationOnClient")); 75 suite.addTest(new EbxmlTest1("testSubmitDeleteExtrinsicObject")); 76 suite.addTest(new EbxmlTest1("testSimpleQuery")); 77 78 setup = new ApelonJAXRTestSetup(suite); 79 80 return setup; 81 } 82 83 /*** 84 * This test is being developed and is not complete! ??eeg 85 * 86 * @throws Exception DOCUMENT ME! 87 */ 88 public void XXXtestConfirmAssociation() throws Exception { 89 90 // Create Association from ParentPackage to ChildPackage 91 RegistryPackage parentPkg = 92 setup.lcm.createRegistryPackage("ParentPackage"); 93 Concept assType = 94 setup.bqm.findConceptByPath("/urn:uuid:6902675f-2f18-44b8-888b-c91db8b96b4d/HasMember"); 95 RegistryPackage childPkg = 96 setup.lcm.createRegistryPackage("ChildPackage"); 97 Association ass = 98 setup.lcm.createAssociation(childPkg, assType); 99 parentPkg.addAssociation(ass); 100 101 // Save "ParentPackage" which should save all its Association-s too 102 ArrayList al = new ArrayList(); 103 al.add(parentPkg); 104 105 BulkResponse br = setup.lcm.saveObjects(al); // => SubmitObjectsRequest 106 assertNull(br.getExceptions()); 107 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 108 109 br = setup.bqm.findAssociations(null, 110 parentPkg.getKey().getId(), 111 null, null); 112 113 //debugUtil.outResponse(br); 114 assertNull(br.getExceptions()); 115 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 116 117 // Now delete all created objects 118 al.clear(); 119 al.add(ass.getKey()); 120 br = setup.lcm.deleteObjects(al); 121 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 122 assertNull(br.getExceptions()); 123 al.clear(); 124 al.add(parentPkg.getKey()); 125 al.add(childPkg.getKey()); 126 br = setup.lcm.deleteObjects(al); 127 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 128 assertNull(br.getExceptions()); 129 } 130 131 /* 132 * Test the capability level 133 */ 134 public void testCapabilityLevel() throws Exception { 135 136 CapabilityProfile profile = 137 setup.service.getCapabilityProfile(); 138 int capabilityLevel = profile.getCapabilityLevel(); 139 assertEquals(capabilityLevel, 1); 140 } 141 142 /*** 143 * Create an Association between two objects and remove it and the 144 * objects 145 * 146 * @throws Exception DOCUMENT ME! 147 */ 148 public void testDeleteAssociation() throws Exception { 149 150 // Create Association from ParentPackage to ChildPackage 151 RegistryPackage parentPkg = 152 setup.lcm.createRegistryPackage("ParentPackage"); 153 Concept assType = 154 setup.bqm.findConceptByPath("/urn:uuid:6902675f-2f18-44b8-888b-c91db8b96b4d/HasMember"); 155 RegistryPackage childPkg = 156 setup.lcm.createRegistryPackage("ChildPackage"); 157 Association ass = 158 setup.lcm.createAssociation(childPkg, assType); 159 parentPkg.addAssociation(ass); 160 161 // Save "ParentPackage" which should save all its Association-s too 162 ArrayList al = new ArrayList(); 163 al.add(parentPkg); 164 165 BulkResponse br = setup.lcm.saveObjects(al); // => SubmitObjectsRequest 166 assertNull(br.getExceptions()); 167 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 168 169 // Now delete all created objects 170 al.clear(); 171 al.add(ass.getKey()); 172 br = setup.lcm.deleteObjects(al); 173 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 174 assertNull(br.getExceptions()); 175 al.clear(); 176 al.add(parentPkg.getKey()); 177 al.add(childPkg.getKey()); 178 br = setup.lcm.deleteObjects(al); 179 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 180 assertNull(br.getExceptions()); 181 } 182 183 /*** 184 * Test that LCM.saveObjects() saves an objects associations as 185 * well as the object itself. 186 * 187 * @throws Exception DOCUMENT ME! 188 */ 189 public void testSaveObjectsSavesAssociations() throws Exception { 190 191 // Create Association from ParentPackage to ChildPackage 192 RegistryPackage parentPkg = 193 setup.lcm.createRegistryPackage("ParentPackage"); 194 Concept assType = 195 setup.bqm.findConceptByPath("/urn:uuid:6902675f-2f18-44b8-888b-c91db8b96b4d/HasMember"); 196 197 RegistryPackage childPkg = 198 setup.lcm.createRegistryPackage("ChildPackage"); 199 Association ass = 200 setup.lcm.createAssociation(childPkg, assType); 201 parentPkg.addAssociation(ass); 202 203 String assId = ass.getKey().getId(); 204 String childPkgId = childPkg.getKey().getId(); 205 206 // Save "ParentPackage" which should save all its Association-s too 207 ArrayList al = new ArrayList(); 208 al.add(parentPkg); 209 210 BulkResponse br = setup.lcm.saveObjects(al); // => SubmitObjectsRequest 211 assertNull(br.getExceptions()); 212 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 213 214 // Verify that the Association object exists and is of the proper type 215 RegistryObject ro = setup.bqm.getRegistryObject(assId); 216 assertEquals(true, ro instanceof Association); 217 218 // Verify that the target object exists and is of the proper type 219 RegistryObject ro2 = setup.bqm.getRegistryObject(childPkgId); 220 assertEquals(true, ro2 instanceof RegistryPackage); 221 222 // Now delete all created objects 223 al.clear(); 224 al.add(ass.getKey()); 225 br = setup.lcm.deleteObjects(al); 226 assertNull(br.getExceptions()); 227 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 228 al.clear(); 229 al.add(childPkg.getKey()); 230 al.add(parentPkg.getKey()); 231 br = setup.lcm.deleteObjects(al); 232 assertNull(br.getExceptions()); 233 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 234 } 235 236 /*** 237 * Test that LCM.saveObjects can send both a SubmitObjectsRequest 238 * or an UpdateObjectsRequest. 239 * 240 * @throws Exception DOCUMENT ME! 241 */ 242 public void testUpdateObjectsRequest() throws Exception { 243 244 // Save a RegistryPackage named "Package1" 245 RegistryPackage pkg1 = 246 setup.lcm.createRegistryPackage("Package1"); 247 String id = pkg1.getKey().getId(); 248 ArrayList al = new ArrayList(); 249 al.add(pkg1); 250 251 BulkResponse br = setup.lcm.saveObjects(al); // => SubmitObjectsRequest 252 assertNull(br.getExceptions()); 253 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 254 255 // Update the name by adding a "NewName" suffix 256 String pkg1Name = pkg1.getName().getValue(); 257 String newName = pkg1Name + "NewName"; 258 InternationalString istr = 259 setup.lcm.createInternationalString(newName); 260 pkg1.setName(istr); 261 al.clear(); 262 al.add(pkg1); 263 br = setup.lcm.saveObjects(al); // => UpdateObjectsRequest 264 assertNull(br.getExceptions()); 265 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 266 267 // Query the object 268 RegistryObject ro = setup.bqm.getRegistryObject(id); 269 assertEquals("Ids should be equal", id, 270 RegistryObjectUtil.toId(ro)); 271 272 // Now delete it 273 al.clear(); 274 al.add(ro.getKey()); 275 br = setup.lcm.deleteObjects(al); 276 assertNull(br.getExceptions()); 277 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 278 279 // Names should be equal 280 assertEquals("Names should be equal", newName, 281 ro.getName().getValue()); 282 } 283 284 /*** 285 * Test createAssociation and removeAssociation w/o saving to 286 * server 287 * 288 * @throws Exception DOCUMENT ME! 289 */ 290 public void testCreateRemoveAssociationOnClient() throws Exception { 291 292 RegistryPackage parentPkg = 293 setup.lcm.createRegistryPackage("ParentPackage"); 294 Concept assType = 295 setup.bqm.findConceptByPath("/urn:uuid:6902675f-2f18-44b8-888b-c91db8b96b4d/HasMember"); 296 RegistryPackage childPkg = 297 setup.lcm.createRegistryPackage("ChildPackage"); 298 Association ass = 299 setup.lcm.createAssociation(childPkg, assType); 300 parentPkg.addAssociation(ass); 301 302 Association ass2 = 303 (Association)RegistryObjectUtil.getFirstObject(parentPkg 304 .getAssociations()); 305 assertEquals("Ids should be equal", 306 RegistryObjectUtil.toId(ass), 307 RegistryObjectUtil.toId(ass2)); 308 parentPkg.removeAssociation(ass); 309 ass2 = 310 (Association)RegistryObjectUtil.getFirstObject(parentPkg 311 .getAssociations()); 312 assertNull("No Associations should have been found", ass2); 313 } 314 315 /*** 316 * Test submit of ExtrinsicObject and remove it 317 * 318 * @throws Exception DOCUMENT ME! 319 */ 320 public void testSubmitDeleteExtrinsicObject() throws Exception { 321 322 DataHandler dh = getSampleDataHandler("duke-wave.gif"); 323 ExtrinsicObject eo = setup.lcm.createExtrinsicObject(dh); 324 ArrayList al = new ArrayList(); 325 al.add(eo); 326 327 BulkResponse br = setup.lcm.saveObjects(al); 328 assertNull(br.getExceptions()); 329 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 330 331 String eoId = RegistryObjectUtil.toId(eo); 332 333 // Query the object 334 RegistryObject ro = setup.bqm.getRegistryObject(eoId); 335 assertEquals("Ids should be equal", eoId, 336 RegistryObjectUtil.toId(ro)); 337 338 assertEquals(true, ro instanceof ExtrinsicObject); 339 340 ExtrinsicObject eo2 = (ExtrinsicObject)ro; 341 DataHandler ri = eo2.getRepositoryItem(); 342 343 // Now delete it 344 al.clear(); 345 al.add(ro.getKey()); 346 br = setup.lcm.deleteObjects(al); 347 assertNull(br.getExceptions()); 348 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 349 350 // Check results of deleteObjects. ??eeg not working 351 // u.outResponse(br); 352 // Collection col = br.getCollection(); 353 // Iterator it = col.iterator(); 354 // assertEquals("Should have one item", true, it.hasNext()); 355 // assertEquals("Ids should be equal#2", eoId, u.toId(it.next())); 356 // Query the object again and check it no longer exists 357 RegistryObject ro2 = setup.bqm.getRegistryObject(eoId); 358 assertNull("RegistryObject should not have been found", ro2); 359 } 360 361 /*** 362 * 363 */ 364 public void testSimpleQuery() throws Exception { 365 366 String qs = "SELECT * FROM ClassificationScheme"; 367 Query query = 368 setup.dqm.createQuery(Query.QUERY_TYPE_SQL, qs); 369 BulkResponse br = setup.dqm.executeQuery(query); 370 assertNull(br.getExceptions()); 371 assertEquals(BulkResponse.STATUS_SUCCESS, br.getStatus()); 372 } 373 374 /*** 375 * DOCUMENT ME! 376 * 377 * @param sampleId a relative path to a sample file. Sample files 378 * are stored as resources. 379 * 380 * @return DataHandler representing sample file 381 * 382 * @throws Exception DOCUMENT ME! 383 */ 384 private DataHandler getSampleDataHandler(String sampleId) 385 throws Exception { 386 387 URL url = getClass().getResource("/resources/" + sampleId); 388 389 if (url == null) { 390 throw new Exception("Resource not found"); 391 } 392 393 DataHandler dh = new DataHandler(url); 394 395 return dh; 396 } 397 }

This page was automatically generated by Maven