/*!
  @header FTConfigTEST
  @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

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

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

#include <Encore/Encore.h>
#include <FTConfigTEST.h>
#include <FT/FTConfig.h>
@implementation FTConfigTEST

- testConfigReader {
  NSLog( @"FTConfigTEST::testConfigReader: BEGIN..." );
  
  EC_AUTORELEASEPOOL_BEGIN
  NSURL *fileURL;
  ECXMLControl *xmlControl;
  id configObjects;
  id databaseNames;
  NSDictionary *serviceLoaders;
  NSEnumerator *loaders;
  id currentLoader;
  
  fileURL = [NSURL fileURLWithPath: @"../tests/ftconfig.xml"];
  xmlControl = [[[ECXMLControl alloc] initWithContentsOfURL: fileURL]
    autorelease];
  
  [xmlControl parseXML];
  configObjects = [xmlControl rootUserObject];
  
  ECAssertTrue( nil != configObjects, @"No config objects available..." );

  ECAssertTrue( [configObjects isKindOfClass: [FTConfig class]],
    @"Root object is not of type FTControl!" );

  ECAssertTrue( nil != [configObjects databaseNames],
    @"No database names configured!" );

  databaseNames = [[configObjects databaseNames] allDatabaseNames];
  ECAssertTrue( nil != databaseNames, 
    @"Unable to get iterator over database names!" );

  while( [databaseNames hasNext] ) {
    id current = [databaseNames next];
    NSLog( @"Configured database name: %@", current );
  }
  
  ECAssertTrue( nil != [configObjects services],
    @"Unable to get configured services!" );

  serviceLoaders = [[configObjects services] serviceLoaders];
  ECAssertTrue( nil != serviceLoaders,
    @"service config does not return any service loaders!" );

  loaders = [serviceLoaders objectEnumerator];
  ECAssertTrue( nil != loaders,
    @"No service loaders configured!" );

  while( (currentLoader = [loaders nextObject]) ) {
    NSLog( @"Configured ServiceLoader: %@", [currentLoader serviceId] );
  }
  EC_AUTORELEASEPOOL_END
  NSLog( @"FTConfigTEST::testConfigReader: FINISHED" );
  return self;
}
@end
