/******************************************************************************
  FTBaseTest
  FT
 
  Copyright (c) 2004, 2005 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

  30.01.2005 ola     initial version
  -------------------------------------------------------------------------
******************************************************************************/
#include "FTBaseTEST.h"


@implementation FTBaseTEST
- setup {
  id returnedSession = nil;
  FTBootstrap *bootstrap;
  self->serverStarted = NO;
  
  NSLog( @"Opening database...." );
  
  bootstrap = [FTBootstrap bootstrap];
  NSLog( @"Starting server process...." );
  //[bootstrap setBaseDataDir: @"." ];
  self->server = [[bootstrap startServer] retain];

  sessionManager = [[server sessionManager] retain];
  ECAssertTrue( nil != sessionManager, @"Could not get session manager!" );
  
  returnedSession = [sessionManager 
    loginAs: @"altum" withPassword: @"silentium"];
  ECAssertTrue( nil != returnedSession, @"Unable to log in as altum!" );
  NSLog( @"Got a valid session." );
  
  ECAssertTrue( [returnedSession 
    conformsToProtocol:@protocol(FTAdministrationSession)],
    @"Session is NOT an administrative session!" );

  self->session = (id <FTAdministrationSession>) returnedSession;
  self->serverStarted = YES;	
  
  return self;
}


- shutdownServer {
  ECAssertTrue( YES == self->serverStarted,
    @"FTBaseTEST::shutdownServer: Server is NOT up!" );
	
  NSLog( @"FTBaseTEST::shutdownServer: Shutting down the server..." );
  [session shutdownServer];
  self->serverStarted = NO;
  return self;
}


- startServer {
  ECAssertTrue( NO == self->serverStarted,
    @"FTBaseTEST::shutdownServer: Server is ALREADY up!" );
	
  [session startServer];
  self->serverStarted = YES;
  
  return self;
}


- cleanup {
  NSLog( @"Closing database..." );

  if( YES == self->serverStarted ) {
    [self shutdownServer];
  }

  [self->session close];
  [self->session release];
  [self->sessionManager release];
  [self->server release];
  
  return self;
}
@end
