/*!
  @header FTGraphManagementTEST
  @abstract Module of FT
 
  @availability OS X, GNUstep
  @copyright 2004, 2005, 2006 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

  <pre>
  -------------------------------------------------------------------------
  Modification history

  19.08.06 ola     initial version
  -------------------------------------------------------------------------
  </pre>
*/

#include "FTGraphManagementTEST.h"
#include <Encore/Encore.h>

@implementation FTGraphManagementTEST
- (BOOL) searchForGraphId: (id <FTId>) aGraphId 
  graphManager: (id <FTGraphManager>) aGraphManager {
  id <ECIterator> graphIdIterator;
  BOOL result = NO;
  
  graphIdIterator = [aGraphManager allGraphIds];
  while( [graphIdIterator hasNext] ) {
    id <FTId> foundGraphId = [graphIdIterator next];
    
    NSLog( @"FTGraphManagementTEST: Found graphId=%@", foundGraphId );
    
    if( [foundGraphId isEqual: aGraphId] ) {
      result = YES;
    }
  }
  
  return result;
}


- testGraphmanagement {
  id <FTGraphManager> graphManager;
  id <FTGraph> graph;
  id <FTId> graphId;
  id <FTObjectToIdMapper> objectToIdMapper;
  id <FTTransaction> transaction;
  BOOL graphIdFound;
  
  NSLog( @"FTGraphManagementTEST::testGraphmanagement: BEGINNING....." );
  
  objectToIdMapper = [session defaultObjectToIdMapper];
  graphManager = [session graphManager];

  NSLog( @"Now creating graph graphManagementTest..." );
  transaction = [session beginTransactionWithParent: nil
    withSettings: nil];
  
  graphId = [objectToIdMapper mapObject: @"graphManagementTest"];
  graph = [graphManager createGraphWithId: graphId];
  ECAssertTrue( nil != graph, @"Graph creation failed!" );
  [graph close];
  
  NSLog( @"FTGraphManagementTEST: Now fetching list of all graphs..." );
  graphIdFound = [self 
    searchForGraphId: graphId
    graphManager: graphManager];
  
  ECAssertTrue( graphIdFound, @"Graph with id=%@ NOT found!" );
  
  NSLog( @"FTGraphManagementTEST: Now removing graph with id=%@", graphId );
  [graphManager removeGraphWithId: graphId];
  
  graphIdFound = [self 
    searchForGraphId: graphId
    graphManager: graphManager];
  
  ECAssertFalse( graphIdFound, @"Graph with id=%@ still EXISTS!" );

  NSLog( @"FTGraphManagementTEST::testGraphmanagement: FINISHED" );
  
  return self;
}
@end
