1 17 package org.alfresco.example.webservice.repository; 18 19 import javax.xml.rpc.ServiceException ; 20 21 import junit.framework.AssertionFailedError; 22 23 import org.alfresco.example.webservice.BaseWebServiceSystemTest; 24 import org.alfresco.example.webservice.types.ClassDefinition; 25 import org.alfresco.example.webservice.types.NamedValue; 26 import org.alfresco.example.webservice.types.NodeDefinition; 27 import org.alfresco.example.webservice.types.Predicate; 28 import org.alfresco.example.webservice.types.PropertyDefinition; 29 import org.alfresco.example.webservice.types.Query; 30 import org.alfresco.example.webservice.types.QueryConfiguration; 31 import org.alfresco.example.webservice.types.QueryLanguageEnum; 32 import org.alfresco.example.webservice.types.Reference; 33 import org.alfresco.example.webservice.types.ResultSet; 34 import org.alfresco.example.webservice.types.ResultSetRow; 35 import org.alfresco.example.webservice.types.ResultSetRowNode; 36 import org.alfresco.example.webservice.types.Store; 37 import org.alfresco.example.webservice.types.StoreEnum; 38 import org.alfresco.service.cmr.repository.StoreRef; 39 import org.apache.axis.EngineConfiguration; 40 import org.apache.axis.configuration.FileProvider; 41 import org.apache.commons.logging.Log; 42 import org.apache.commons.logging.LogFactory; 43 44 public class RepositoryServiceSystemTest extends BaseWebServiceSystemTest 45 { 46 private static Log logger = LogFactory.getLog(RepositoryServiceSystemTest.class); 47 private static Store STORE = new Store(StoreEnum.workspace, "SpacesStore"); 48 private static StoreRef STORE_REF = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); 49 50 private RepositoryServiceSoapBindingStub repoService; 51 52 @Override 53 protected void setUp() throws Exception 54 { 55 super.setUp(); 56 57 try 58 { 59 EngineConfiguration config = new FileProvider(getResourcesDir(), "client-deploy.wsdd"); 60 this.repoService = (RepositoryServiceSoapBindingStub)new RepositoryServiceLocator(config).getRepositoryService(); 61 } 62 catch (ServiceException jre) 63 { 64 if (jre.getLinkedCause() != null) 65 { 66 jre.getLinkedCause().printStackTrace(); 67 } 68 69 throw new AssertionFailedError("JAX-RPC ServiceException caught: " + jre); 70 } 71 72 assertNotNull("repoService is null", this.repoService); 73 74 this.repoService.setTimeout(60000); 76 } 77 78 83 public void testGetStores() throws Exception 84 { 85 Store[] stores = this.repoService.getStores(); 86 assertNotNull("stores array should not be null", stores); 87 logger.debug("store1 = " + stores[0].getScheme() + ":" + stores[0].getAddress()); 88 logger.debug("store2 = " + stores[1].getScheme() + ":" + stores[1].getAddress()); 89 logger.debug("store3 = " + stores[2].getScheme() + ":" + stores[2].getAddress()); 90 assertTrue("There should be 3 stores", stores.length == 3); 91 } 92 93 98 public void testQuery() throws Exception 99 { 100 Query query = new Query(QueryLanguageEnum.lucene, "( +@\\{http\\://www.alfresco.org/1.0\\}name:test*) OR TEXT:test*"); 102 103 QueryResult queryResult = this.repoService.query(STORE, query, false); 104 assertNotNull("queryResult should not be null", queryResult); 105 106 ResultSet resultSet = queryResult.getResultSet(); 107 assertNotNull("The result set should not be null", resultSet); 108 logger.debug("There are " + resultSet.getTotalRowCount() + " rows:"); 109 110 if (resultSet.getTotalRowCount() > 0) 111 { 112 ResultSetRow[] rows = resultSet.getRows(); 113 for (int x = 0; x < rows.length; x++) 114 { 115 ResultSetRow row = rows[x]; 116 NamedValue[] columns = row.getColumns(); 117 for (int y = 0; y < columns.length; y++) 118 { 119 logger.debug("row " + x + ": " + row.getColumns(y).getName() + " = " + row.getColumns(y).getValue()); 120 } 121 } 122 } 123 else 124 { 125 logger.debug("The query returned no results"); 126 fail("The query returned no results"); 127 } 128 } 129 130 135 public void testQuerySession() throws Exception 136 { 137 Query query = new Query(QueryLanguageEnum.lucene, "*"); 139 140 int batchSize = 75; 142 QueryConfiguration queryCfg = new QueryConfiguration(); 143 queryCfg.setFetchSize(batchSize); 144 this.repoService.setHeader(new RepositoryServiceLocator().getServiceName().getNamespaceURI(), "QueryHeader", queryCfg); 145 146 QueryResult queryResult = this.repoService.query(STORE, query, false); 148 assertNotNull("queryResult should not be null", queryResult); 149 String querySession = queryResult.getQuerySession(); 150 String origQuerySession = querySession; 151 assertNotNull("querySession should not be null", querySession); 152 153 ResultSet resultSet = queryResult.getResultSet(); 154 assertNotNull("The result set should not be null", resultSet); 155 logger.debug("There are " + resultSet.getTotalRowCount() + " rows in total"); 156 logger.debug("There are " + resultSet.getRows().length + " rows in the first set"); 157 assertEquals("The result set size should be " + batchSize, batchSize, resultSet.getRows().length); 158 159 queryResult = this.repoService.fetchMore(querySession); 161 assertNotNull("queryResult should not be null", queryResult); 162 querySession = queryResult.getQuerySession(); 163 assertNotNull("querySession should not be null", querySession); 164 165 ResultSet resultSet2 = queryResult.getResultSet(); 166 assertNotNull("The second result set should not be null", resultSet2); 167 logger.debug("There are " + resultSet2.getRows().length + " rows in the second set"); 168 assertEquals("The result set size should be " + batchSize, batchSize, resultSet2.getRows().length); 169 170 while (querySession != null) 172 { 173 queryResult = this.repoService.fetchMore(querySession); 174 assertNotNull("queryResult returned in loop should not be null", queryResult); 175 querySession = queryResult.getQuerySession(); 176 logger.debug("There were another " + queryResult.getResultSet().getRows().length + " rows returned"); 177 } 178 179 try 181 { 182 queryResult = this.repoService.fetchMore(origQuerySession); 183 fail("We should have seen an error as all the results have been returned"); 184 } 185 catch (Exception e) 186 { 187 } 189 } 190 191 196 public void testQueryParents() throws Exception 197 { 198 Reference node = new Reference(); 200 node.setStore(STORE); 201 node.setUuid(rootId); logger.debug("Retrieving children for node: " + rootId + "...."); 203 QueryResult rootChildren = this.repoService.queryChildren(node); 204 205 assertNotNull("rootChildren should not be null", rootChildren); 206 ResultSet rootChildrenResults = rootChildren.getResultSet(); 207 assertNotNull("rootChildrenResults should not be null", rootChildrenResults); 208 assertTrue("There should be at least one child of the root node", 209 rootChildrenResults.getRows().length > 0); 210 211 ResultSetRow firstRow = rootChildrenResults.getRows(0); 213 assertNotNull("getColumns() should not return null", firstRow.getColumns()); 214 String id = firstRow.getNode().getId(); 215 logger.debug("Retrieving parents for first node found: " + id + "...."); 216 217 node = new Reference(); 218 node.setStore(STORE); 219 node.setUuid(id); 220 QueryResult parents = this.repoService.queryParents(node); 221 222 assertNotNull("parents should not be null", parents); 223 ResultSet parentsResults = parents.getResultSet(); 224 assertNotNull("parentsResults should not be null", parentsResults); 225 assertTrue("There should be at least one parent", parentsResults.getRows().length > 0); 226 227 boolean rootFound = false; 229 ResultSetRow[] rows = parentsResults.getRows(); 230 for (int x = 0; x < rows.length; x++) 231 { 232 ResultSetRow row = rows[x]; 233 assertNotNull("getColumns() should not return null", row.getColumns()); 234 ResultSetRowNode rowNode = row.getNode(); 235 String nodeId = rowNode.getId(); 236 logger.debug("parent node = " + nodeId + ", type = " + rowNode.getType()); 237 238 if (nodeId.equals(rootId)) 239 { 240 rootFound = true; 241 } 242 } 243 244 assertTrue("The root node was not found as one of the parents!!", rootFound); 246 } 247 248 253 public void testQueryAssociated() throws Exception 254 { 255 try 256 { 257 this.repoService.queryAssociated(null, null); 258 fail("This method should have thrown a repository fault"); 259 } 260 catch (RepositoryFault rf) 261 { 262 } 264 } 265 266 271 public void testDescribe() throws Exception 272 { 273 Query query = new Query(QueryLanguageEnum.lucene, "( +@\\{http\\://www.alfresco.org/1.0\\}name:test*) OR TEXT:test*"); 275 QueryResult queryResult = this.repoService.query(STORE, query, false); 276 assertNotNull("queryResult should not be null", queryResult); 277 ResultSet resultSet = queryResult.getResultSet(); 278 assertNotNull("The result set should not be null", resultSet); 279 assertTrue("There should be at least one result", resultSet.getTotalRowCount() > 0); 280 String id = resultSet.getRows(0).getNode().getId(); 281 assertNotNull("Id of Alfresco Tutorial PDF should not be null", id); 282 283 Reference ref = new Reference(); 285 ref.setStore(STORE); 286 ref.setUuid(id); 287 Predicate predicate = new Predicate(new Reference[] {ref}, null, null); 288 289 NodeDefinition[] nodeDefs = this.repoService.describe(predicate); 291 assertNotNull("nodeDefs should not be null", nodeDefs); 292 assertTrue("There should only be one result", nodeDefs.length == 1); 293 294 NodeDefinition nodeDef = nodeDefs[0]; 296 assertNotNull("The nodeDef should not be null", nodeDef); 297 ClassDefinition typeDef = nodeDef.getType(); 298 assertNotNull("Type definition should not be null", typeDef); 299 300 assertEquals("Type name is incorrect", "{http://www.alfresco.org/model/content/1.0}content", typeDef.getName()); 301 assertEquals("Superclass type name is incorrect", "{http://www.alfresco.org/model/content/1.0}cmobject", typeDef.getSuperClass()); 302 assertEquals("Type title is incorrect", "Content", typeDef.getTitle()); 303 assertEquals("Type description is incorrect", null, typeDef.getDescription()); 304 assertFalse("Type is an aspect and it shouldn't be", typeDef.isIsAspect()); 305 assertNull("There should not be any associations", typeDef.getAssociations()); 306 assertNotNull("Properties should not be null", typeDef.getProperties()); 307 assertEquals("There should be 5 properties", 5, typeDef.getProperties().length); 308 309 assertEquals("Property1 name is incorrect", "{http://www.alfresco.org/model/content/1.0}encoding", 311 typeDef.getProperties(0).getName()); 312 assertEquals("Property1 type name is incorrect", "{http://www.alfresco.org/model/dictionary/1.0}text", 313 typeDef.getProperties(0).getDataType()); 314 315 assertEquals("Property2 name is incorrect", "{http://www.alfresco.org/model/content/1.0}size", 316 typeDef.getProperties(1).getName()); 317 assertEquals("Property2 type name is incorrect", "{http://www.alfresco.org/model/dictionary/1.0}long", 318 typeDef.getProperties(1).getDataType()); 319 320 assertEquals("Property3 name is incorrect", "{http://www.alfresco.org/model/content/1.0}contentUrl", 321 typeDef.getProperties(2).getName()); 322 assertEquals("Property3 type name is incorrect", "{http://www.alfresco.org/model/dictionary/1.0}text", 323 typeDef.getProperties(2).getDataType()); 324 325 assertEquals("Property4 name is incorrect", "{http://www.alfresco.org/model/content/1.0}name", 326 typeDef.getProperties(3).getName()); 327 assertEquals("Property4 type name is incorrect", "{http://www.alfresco.org/model/dictionary/1.0}text", 328 typeDef.getProperties(3).getDataType()); 329 330 assertEquals("Property5 name is incorrect", "{http://www.alfresco.org/model/content/1.0}mimetype", 331 typeDef.getProperties(4).getName()); 332 assertEquals("Property5 type name is incorrect", "{http://www.alfresco.org/model/dictionary/1.0}text", 333 typeDef.getProperties(4).getDataType()); 334 335 ClassDefinition[] aspects = nodeDef.getAspects(); 337 assertNotNull("aspects should not be null", aspects); 338 assertEquals("There should be 2 aspects", 2, aspects.length); 339 340 ClassDefinition aspect1 = aspects[0]; 342 assertEquals("Aspect1 name is incorrect", "{http://www.alfresco.org/model/system/1.0}referencable", aspect1.getName()); 343 assertTrue("Aspect1 should be an aspect", aspect1.isIsAspect()); 344 assertNotNull("Aspect1 should have properties", aspect1.getProperties()); 345 assertEquals("Aspect1 has wrong number of properties", 3, aspect1.getProperties().length); 346 347 ClassDefinition aspect2 = aspects[1]; 349 assertEquals("Aspect2 name is incorrect", "{http://www.alfresco.org/model/content/1.0}auditable", aspect2.getName()); 350 assertTrue("Aspect2 should be an aspect", aspect2.isIsAspect()); 351 assertNotNull("Aspect2 should have properties", aspect2.getProperties()); 352 assertEquals("Aspect2 has wrong number of properties", 5, aspect2.getProperties().length); 353 } 354 355 360 public void testPredicateQuery() throws Exception 361 { 362 Query query = new Query(QueryLanguageEnum.lucene, "( +@\\{http\\://www.alfresco.org/1.0\\}name:test*) OR TEXT:test*"); 364 365 Predicate predicate = new Predicate(); 366 predicate.setQuery(query); 367 predicate.setStore(STORE); 368 369 NodeDefinition[] nodeDefs = this.repoService.describe(predicate); 371 assertNotNull("nodeDefs should not be null", nodeDefs); 372 assertTrue("There should be at least one result", nodeDefs.length > 0); 373 374 NodeDefinition nodeDef = nodeDefs[0]; 375 assertNotNull("The nodeDef should not be null", nodeDef); 376 ClassDefinition typeDef = nodeDef.getType(); 377 assertNotNull("Type definition should not be null", typeDef); 378 379 logger.debug("type name = " + typeDef.getName()); 380 logger.debug("is aspect = " + typeDef.isIsAspect()); 381 PropertyDefinition[] propDefs = typeDef.getProperties(); 382 if (propDefs != null) 383 { 384 logger.debug("There are " + propDefs.length + " properties:"); 385 for (int x = 0; x < propDefs.length; x++) 386 { 387 PropertyDefinition propDef = propDefs[x]; 388 logger.debug("name = " + propDef.getName() + " type = " + propDef.getDataType()); 389 } 390 } 391 } 392 393 398 public void testPathReference() throws Exception 399 { 400 Reference ref = new Reference(); 402 ref.setStore(STORE); 403 ref.setPath("//*[@cm:name = 'Company Home']"); 404 Predicate predicate = new Predicate(); 405 predicate.setNodes(new Reference[] {ref}); 406 407 NodeDefinition[] nodeDefs = this.repoService.describe(predicate); 409 assertNotNull("nodeDefs should not be null", nodeDefs); 410 assertTrue("There should be at least one result", nodeDefs.length > 0); 411 412 NodeDefinition nodeDef = nodeDefs[0]; 413 assertNotNull("The nodeDef should not be null", nodeDef); 414 ClassDefinition typeDef = nodeDef.getType(); 415 assertNotNull("Type definition should not be null", typeDef); 416 417 logger.debug("type name = " + typeDef.getName()); 418 assertEquals("Type is incorrect", "{http://www.alfresco.org/model/content/1.0}folder", typeDef.getName()); 419 logger.debug("is aspect = " + typeDef.isIsAspect()); 420 assertFalse("Item should not be an aspect", typeDef.isIsAspect()); 421 PropertyDefinition[] propDefs = typeDef.getProperties(); 422 if (propDefs != null) 423 { 424 logger.debug("There are " + propDefs.length + " properties:"); 425 for (int x = 0; x < propDefs.length; x++) 426 { 427 PropertyDefinition propDef = propDefs[x]; 428 logger.debug("name = " + propDef.getName() + " type = " + propDef.getDataType()); 429 } 430 } 431 } 432 433 438 public void testUpdate() throws Exception 439 { 440 try 441 { 442 this.repoService.update(null); 443 fail("This method should have thrown a repository fault"); 444 } 445 catch (RepositoryFault rf) 446 { 447 } 449 } 450 } 451 | Popular Tags |