aboutsummaryrefslogtreecommitdiffstats
path: root/UnitTests
diff options
context:
space:
mode:
Diffstat (limited to 'UnitTests')
-rw-r--r--UnitTests/SPDatabaseCopyTest.h36
-rw-r--r--UnitTests/SPDatabaseCopyTest.m100
-rw-r--r--UnitTests/SPDatabaseInfoTest.h23
-rw-r--r--UnitTests/SPDatabaseInfoTest.m67
-rw-r--r--UnitTests/SPDatabaseRenameTest.h35
-rw-r--r--UnitTests/SPDatabaseRenameTest.m91
-rw-r--r--UnitTests/SPTableCopyTest.h21
-rw-r--r--UnitTests/SPTableCopyTest.m45
8 files changed, 418 insertions, 0 deletions
diff --git a/UnitTests/SPDatabaseCopyTest.h b/UnitTests/SPDatabaseCopyTest.h
new file mode 100644
index 00000000..31885c05
--- /dev/null
+++ b/UnitTests/SPDatabaseCopyTest.h
@@ -0,0 +1,36 @@
+//
+// $Id: $
+//
+// DatabaseCopyTest.h
+// sequel-pro
+//
+// Created by David Rekowski
+// Copyright (c) 2010 David Rekowski. All rights reserved.
+//
+// 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
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#define USE_APPLICATION_UNIT_TEST 1
+
+#import <SenTestingKit/SenTestingKit.h>
+
+@interface SPDatabaseCopyTest : SenTestCase {
+}
+- (void) testCopyDatabase;
+- (void) testCopyDatabaseTables;
+- (void) testCreateDatabase;
+
+@end
diff --git a/UnitTests/SPDatabaseCopyTest.m b/UnitTests/SPDatabaseCopyTest.m
new file mode 100644
index 00000000..bb90d35d
--- /dev/null
+++ b/UnitTests/SPDatabaseCopyTest.m
@@ -0,0 +1,100 @@
+//
+// $Id: $
+//
+// DatabaseCopyTest.m
+// sequel-pro
+//
+// Created by David Rekowski
+// Copyright (c) 2010 David Rekowski. All rights reserved.
+//
+// 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
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import <OCMock/OCMock.h>
+#import "SPAlertSheets.h"
+#import "SPDatabaseCopyTest.h"
+#import "SPDatabaseCopy.h"
+#import "SPTableCopy.h"
+#import "MCPConnection.h"
+#import "SPDatabaseInfo.h"
+#import "SPStringAdditions.h"
+#import "SPLogger.h"
+
+@implementation SPDatabaseCopyTest
+
+- (SPDatabaseCopy *) getDatabaseCopyFixture {
+ SPDatabaseCopy *dbCopy = [[SPDatabaseCopy alloc] init];
+ return [dbCopy autorelease];
+}
+
+- (SPTableCopy *) getTableCopyFixture {
+ SPTableCopy *tableCopy = [[SPTableCopy alloc] init];
+ return [tableCopy autorelease];
+}
+
+- (id) getMockConnection {
+ id mockConnection = [OCMockObject niceMockForClass:[MCPConnection class]];
+ return mockConnection;
+}
+
+- (id) getMockDBInfo {
+ id mockDBInfo = [OCMockObject niceMockForClass:[SPDatabaseInfo class]];
+ return mockDBInfo;
+}
+
+- (void) testCopyDatabase {
+
+ SPDatabaseCopy *dbCopy = [self getDatabaseCopyFixture];
+ id mockConnection = [self getMockConnection];
+ [[mockConnection expect] queryString:@"CREATE DATABASE `target_name`"];
+ [[mockConnection expect] listTablesFromDB:@"source_name"];
+ [[[mockConnection stub] andReturn:[[NSArray alloc] init]] listTablesFromDB:@"source_name"];
+ [dbCopy setConnection:mockConnection];
+
+ id mockDBInfo = [self getMockDBInfo];
+
+ BOOL varNo = NO;
+ BOOL varYes = YES;
+ [[[mockDBInfo expect] andReturnValue:[NSValue value:&varYes withObjCType:@encode(BOOL)]] databaseExists:@"source_name"];
+
+ [[[mockDBInfo expect] andReturnValue:[NSValue value:&varNo withObjCType:@encode(BOOL)]] databaseExists:@"target_name"];
+
+ [dbCopy setDbInfo:mockDBInfo];
+
+ NSString *source = [[NSString alloc] initWithString:@"source_name"];
+ NSString *target = [[NSString alloc] initWithString:@"target_name"];
+ [dbCopy copyDatabaseFrom:source to:target withContent:YES];
+
+ [mockConnection verify];
+ [source release];
+ [target release];
+}
+
+- (void) testCopyDatabaseTables {
+ SPDatabaseCopy *dbCopy = [self getDatabaseCopyFixture];
+ SPTableCopy *tableCopy = [self getTableCopyFixture];
+ STAssertTrue([tableCopy copyTable:@"table_one" from: @"source_db" to: @"target_db"],
+ @"Should have copied database table table_one.");
+ STAssertTrue([tableCopy copyTable:@"table_two" from: @"source_db" to: @"target_db"],
+ @"Should have copied database table table_two.");
+}
+
+- (void) testCreateDatabase {
+ SPDatabaseCopy *dbCopy = [self getDatabaseCopyFixture];
+ // test missing :)
+}
+
+@end
diff --git a/UnitTests/SPDatabaseInfoTest.h b/UnitTests/SPDatabaseInfoTest.h
new file mode 100644
index 00000000..2c31cf1e
--- /dev/null
+++ b/UnitTests/SPDatabaseInfoTest.h
@@ -0,0 +1,23 @@
+//
+// SPDatabaseInfoTest.h
+// sequel-pro
+//
+// Created by David Rekowski on 22.04.10.
+// Copyright 2010 Papaya Software GmbH. All rights reserved.
+//
+
+#define USE_APPLICATION_UNIT_TEST 1
+
+#import <SenTestingKit/SenTestingKit.h>
+
+
+@interface SPDatabaseInfoTest : SenTestCase {
+
+}
+
+- (void)testDatabaseExists;
+- (void)testListDBs;
+- (void)testListDBsLike;
+
+
+@end
diff --git a/UnitTests/SPDatabaseInfoTest.m b/UnitTests/SPDatabaseInfoTest.m
new file mode 100644
index 00000000..0e813350
--- /dev/null
+++ b/UnitTests/SPDatabaseInfoTest.m
@@ -0,0 +1,67 @@
+//
+// SPDatabaseInfoTest.m
+// sequel-pro
+//
+// Created by David Rekowski on 22.04.10.
+// Copyright 2010 Papaya Software GmbH. All rights reserved.
+//
+
+#import <OCMock/OCMock.h>
+#import "SPDatabaseInfo.h"
+#import "SPDatabaseInfoTest.h"
+
+
+@implementation SPDatabaseInfoTest
+
+- (SPDatabaseInfo *)getDatabaseInfoFixture {
+ SPDatabaseInfo *dbInfo = [[SPDatabaseInfo alloc] init];
+ return dbInfo;
+}
+
+- (id) getMockConnection {
+ id mockConnection = [OCMockObject niceMockForClass:[MCPConnection class]];
+ return mockConnection;
+}
+
+- (id) getMockMCPResult {
+ id mockResult = [OCMockObject niceMockForClass:[MCPResult class]];
+ return mockResult;
+}
+
+- (void)testDatabaseExists {
+ SPDatabaseInfo *dbInfo = [self getDatabaseInfoFixture];
+
+ NSArray *tables = [[NSArray alloc] initWithObjects: @"db_one", nil];
+ id mockMCPResult = [self getMockMCPResult];
+ [[mockMCPResult expect] numOfRows];
+ [[[mockMCPResult stub] andReturn:[[NSNumber alloc] initWithInt:1]] numOfRows];
+ [[mockMCPResult expect] fetchRowAsArray];
+ [[[mockMCPResult stub] andReturn:tables] fetchRowAsArray];
+ id mockConnection = [self getMockConnection];
+
+ [[[mockConnection expect] andReturn:mockMCPResult] queryString:@"SHOW DATABASES"];
+ [dbInfo setConnection:mockConnection];
+ [dbInfo databaseExists:@"db_one"];
+ [mockConnection verify];
+}
+
+- (void)testListDBs {
+ SPDatabaseInfo *dbInfo = [self getDatabaseInfoFixture];
+ id mockConnection = [self getMockConnection];
+ [[mockConnection expect] queryString:@"SHOW DATABASES"];
+ [dbInfo setConnection:mockConnection];
+ [dbInfo listDBs];
+ [mockConnection verify];
+}
+
+- (void)testListDBsLike {
+ SPDatabaseInfo *dbInfo = [self getDatabaseInfoFixture];
+ id mockConnection = [self getMockConnection];
+ [[mockConnection expect] queryString:@"SHOW DATABASES LIKE `test_db`"];
+ [dbInfo setConnection:mockConnection];
+ [dbInfo listDBsLike:@"test_db"];
+ [mockConnection verify];
+}
+
+
+@end
diff --git a/UnitTests/SPDatabaseRenameTest.h b/UnitTests/SPDatabaseRenameTest.h
new file mode 100644
index 00000000..a6f92ac1
--- /dev/null
+++ b/UnitTests/SPDatabaseRenameTest.h
@@ -0,0 +1,35 @@
+//
+// $Id: $
+//
+// SPDatabaseRenameTest.h
+// sequel-pro
+//
+// Created by David Rekowski
+// Copyright (c) 2010 David Rekowski. All rights reserved.
+//
+// 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
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#define USE_APPLICATION_UNIT_TEST 1
+
+#import <SenTestingKit/SenTestingKit.h>
+
+@interface SPDatabaseRenameTest : SenTestCase {
+}
+- (void) testRenameDatabase;
+- (void) testCreateDatabase;
+
+@end
diff --git a/UnitTests/SPDatabaseRenameTest.m b/UnitTests/SPDatabaseRenameTest.m
new file mode 100644
index 00000000..ae3f1ab2
--- /dev/null
+++ b/UnitTests/SPDatabaseRenameTest.m
@@ -0,0 +1,91 @@
+//
+// $Id: $
+//
+// SPDatabaseRenameTest.m
+// sequel-pro
+//
+// Created by David Rekowski
+// Copyright (c) 2010 David Rekowski. All rights reserved.
+//
+// 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
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import <OCMock/OCMock.h>
+#import "SPDatabaseRenameTest.h"
+#import "SPDatabaseRename.h"
+#import "SPTableCopy.h"
+#import "MCPConnection.h"
+#import "SPDatabaseInfo.h"
+#import "SPStringAdditions.h"
+#import "SPLogger.h"
+
+
+@implementation SPDatabaseRenameTest
+
+- (SPDatabaseRename *) getDatabaseRenameFixture {
+ SPDatabaseRename *dbRename = [[SPDatabaseRename alloc] init];
+ return [dbRename autorelease];
+}
+
+- (SPTableCopy *) getTableCopyFixture {
+ SPTableCopy *tableCopy = [[SPTableCopy alloc] init];
+ return [tableCopy autorelease];
+}
+
+- (id) getMockConnection {
+ id mockConnection = [OCMockObject niceMockForClass:[MCPConnection class]];
+ return mockConnection;
+}
+
+- (id) getMockDBInfo {
+ id mockDBInfo = [OCMockObject niceMockForClass:[SPDatabaseInfo class]];
+ return mockDBInfo;
+}
+
+- (void) testRenameDatabase {
+
+ SPDatabaseRename *dbRename = [self getDatabaseRenameFixture];
+
+ id mockConnection = [self getMockConnection];
+ [[mockConnection expect] queryString:@"CREATE DATABASE `target_name`"];
+ [[mockConnection expect] listTablesFromDB:@"source_name"];
+ [[[mockConnection stub] andReturn:[[NSArray alloc] init]] listTablesFromDB:@"source_name"];
+ [dbRename setConnection:mockConnection];
+
+ id mockDBInfo = [self getMockDBInfo];
+
+ BOOL varNo = NO;
+ BOOL varYes = YES;
+ [[[mockDBInfo expect] andReturnValue:[NSValue value:&varYes withObjCType:@encode(BOOL)]] databaseExists:@"source_name"];
+
+ [[[mockDBInfo expect] andReturnValue:[NSValue value:&varNo withObjCType:@encode(BOOL)]] databaseExists:@"target_name"];
+
+ [dbRename setDbInfo:mockDBInfo];
+
+ NSString *source = [[NSString alloc] initWithString:@"source_name"];
+ NSString *target = [[NSString alloc] initWithString:@"target_name"];
+ [dbRename renameDatabaseFrom:source to:target];
+
+ [mockConnection verify];
+ [source release];
+ [target release];
+}
+
+- (void) testCreateDatabase {
+ SPDatabaseRename *dbRename = [self getDatabaseRenameFixture];
+}
+
+@end
diff --git a/UnitTests/SPTableCopyTest.h b/UnitTests/SPTableCopyTest.h
new file mode 100644
index 00000000..84cb6552
--- /dev/null
+++ b/UnitTests/SPTableCopyTest.h
@@ -0,0 +1,21 @@
+//
+// SPTableCopyTest.h
+// sequel-pro
+//
+// Created by David Rekowski on 22.04.10.
+// Copyright 2010 Papaya Software GmbH. All rights reserved.
+//
+
+#define USE_APPLICATION_UNIT_TEST 1
+
+#import <SenTestingKit/SenTestingKit.h>
+
+@interface SPTableCopyTest : SenTestCase {
+
+}
+
+- (void)testCopyTableFromTo;
+- (void)testCopyTableFromToWithData;
+
+
+@end
diff --git a/UnitTests/SPTableCopyTest.m b/UnitTests/SPTableCopyTest.m
new file mode 100644
index 00000000..8d989ccf
--- /dev/null
+++ b/UnitTests/SPTableCopyTest.m
@@ -0,0 +1,45 @@
+//
+// SPTableCopyTest.m
+// sequel-pro
+//
+// Created by David Rekowski on 22.04.10.
+// Copyright 2010 Papaya Software GmbH. All rights reserved.
+//
+
+#import <OCMock/OCMock.h>
+#import "SPTableCopy.h"
+#import "SPTableCopyTest.h"
+
+
+@implementation SPTableCopyTest
+
+- (SPTableCopy *)getTableCopyFixture {
+ SPTableCopy *tableCopy = [[SPTableCopy alloc] init];
+ return tableCopy;
+}
+
+- (id) getMockConnection {
+ id mockConnection = [OCMockObject niceMockForClass:[MCPConnection class]];
+ return mockConnection;
+}
+
+- (void)testCopyTableFromTo {
+ id tableCopy = [self getTableCopyFixture];
+ id mockConnection = [self getMockConnection];
+ [[mockConnection expect] queryString:@"CREATE TABLE `target_db`.`table_name` LIKE `source_db`.`table_name`"];
+ [tableCopy setConnection:mockConnection];
+ [tableCopy copyTable: @"table_name" from: @"source_db" to: @"target_db"];
+ [mockConnection verify];
+}
+
+- (void)testCopyTableFromToWithData {
+ id tableCopy = [self getTableCopyFixture];
+ id mockConnection = [self getMockConnection];
+ [[mockConnection expect] queryString:@"CREATE TABLE `target_db`.`table_name` LIKE `source_db`.`table_name`"];
+ [[mockConnection expect] queryString:@"INSERT INTO `target_db`.`table_name` SELECT * FROM `source_db`.`table_name`"];
+ [tableCopy setConnection:mockConnection];
+ [tableCopy copyTable: @"table_name" from: @"source_db" to: @"target_db" withContent: YES];
+ [mockConnection verify];
+}
+
+@end