/*! @header FTServiceTEST @abstract Module of FT @availability OS X, GNUstep @copyright 2004, 2005 Free Software Foundation, Inc. Author: Oliver Langer This program 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 of the License, or (at your option) any later version. This program 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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  -------------------------------------------------------------------------
  Modification history

  06.10.05 ola     initial version
  -------------------------------------------------------------------------
  
*/ #include #include @implementation FTServiceTEST - evaluateNode: (id ) aNode { id dictionaryService; id allKeys; NSLog( @"Evaluating node with id=%@", [aNode nodeId] ); dictionaryService = (id ) [aNode serviceWithId: @"FTDictionaryService"]; ECAssertTrue( nil != dictionaryService, @"Unable to get service "\ "FTDictionaryService!" ); allKeys = [dictionaryService allKeys]; while( [allKeys hasNext] ) { id nextKey = [allKeys next]; NSLog( @"Found key=%@ with value=%@", nextKey, [dictionaryService objectForKey: nextKey]); } [dictionaryService close]; return self; } - setObject: (id ) anObject forKey: (id ) aKey forNode: (id ) aNode { id dictionaryService; NSLog( @"KEY=%@", aKey); dictionaryService = (id ) [aNode serviceWithId: @"FTDictionaryService"]; ECAssertTrue( nil != dictionaryService, @"Unable to get service "\ "FTDictionaryService!" ); [dictionaryService setObject: anObject forKey: aKey ]; [dictionaryService close]; return self; } - objectForKey: (id ) aKey forNode: (id ) aNode { id dictionaryService; id toReturn = nil; dictionaryService = (id ) [aNode serviceWithId: @"FTDictionaryService"]; ECAssertTrue( nil != dictionaryService, @"Unable to get service "\ "FTDictionaryService!" ); NSLog( @"KEY=%@", aKey); toReturn = [dictionaryService objectForKey: aKey ]; [dictionaryService close]; return toReturn; } - testServices { id graphManager; id graph; id graphId; id objectToIdMapper; id transaction; id graphIdMapper; id nid; id node; id nodeIterator; NSString *value; NSLog( @"FTServiceTEST::testServices: BEGINNING..." ); EC_AUTORELEASEPOOL_BEGIN objectToIdMapper = [session defaultObjectToIdMapper]; graphManager = [session graphManager]; NSLog( @"Now creating graph..." ); transaction = [session beginTransactionWithParent: nil withSettings: nil]; graphId = [objectToIdMapper mapObject: @"serviceTestGraph"]; graph = [graphManager createGraphWithId: graphId]; ECAssertTrue( nil != graph, @"Graph creation failed!" ); graphIdMapper = [[graph objectToIdMapper] retain]; nid = [graphIdMapper mapObject: @"nodeA"]; node = [graph createNodeWithId: nid]; NSLog( @"FTServiceTEST::testServices: Adding entries..." ); [self setObject: @"testValue1" forKey: @"testKey1" forNode: node]; nid = [graphIdMapper mapObject: @"nodeB"]; node = [graph createNodeWithId: nid]; [self setObject: @"testValue1ForB" forKey: @"testKey1" forNode: node]; [transaction commit]; [graph close]; /* find objects by their keys: */ graphId = [objectToIdMapper mapObject: @"serviceTestGraph"]; graph = [graphManager graphWithId: graphId]; graphIdMapper = [[graph objectToIdMapper] retain]; NSLog( @"Now reading graph..." ); transaction = [session beginTransactionWithParent: nil withSettings: nil]; nid = [graphIdMapper mapObject: @"nodeA"]; node = [graph nodeWithId: nid]; value = [self objectForKey: @"testKey1" forNode: node]; NSLog( @"FTServiceTEST::testServices: Got \"%@\" for key=\"testkey1\"", value ); ECAssertTrue( [value isEqual: @"testValue1"], @"Values differ!" ); nid = [graphIdMapper mapObject: @"nodeB"]; node = [graph nodeWithId: nid]; value = [self objectForKey: @"testKey1" forNode: node]; NSLog( @"FTServiceTEST::testServices: Got \"%@\" for key=\"testkey1\"", value ); ECAssertTrue( [value isEqual: @"testValue1ForB"], @"Values differ!" ); NSLog( @"FTServiceTEST::testServices: Closing FTDictionaryService..." ); [transaction commit]; [graph close]; EC_AUTORELEASEPOOL_END /* find objects indirectly using the key iterator: */ EC_AUTORELEASEPOOL_BEGIN NSLog( @"Now using key iterator..." ); graphId = [objectToIdMapper mapObject: @"serviceTestGraph"]; graph = [graphManager graphWithId: graphId]; graphIdMapper = [[graph objectToIdMapper] retain]; transaction = [session beginTransactionWithParent: nil withSettings: nil]; nodeIterator = [graph nodeIterator]; while( [nodeIterator hasNext] ) { [self evaluateNode: [nodeIterator next]]; } [transaction commit]; [graph close]; EC_AUTORELEASEPOOL_END NSLog( @"FTServiceTEST::testServices: FINISHED!" ); return self; } @end