ASIS3RequestTests.m 22.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
//
//  ASIS3RequestTests.m
//  Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
//
//  Created by Ben Copsey on 12/07/2009.
//  Copyright 2009 All-Seeing Interactive. All rights reserved.
//

#import "ASIS3RequestTests.h"
#import "ASIS3ListRequest.h"
#import "ASINetworkQueue.h"
#import "ASIS3BucketObject.h"


// Fill in these to run the tests that actually connect and manipulate objects on S3
static NSString *secretAccessKey = @"";
static NSString *accessKey = @"";
static NSString *bucket = @"";



// Used for subclass test
@interface ASIS3RequestSubclass : ASIS3Request {}
@end
@implementation ASIS3RequestSubclass;
@end
@interface ASIS3ListRequestSubclass : ASIS3ListRequest {}
@end
@implementation ASIS3ListRequestSubclass;
@end
@interface ASIS3BucketObjectSubclass : ASIS3BucketObject {}
@end
@implementation ASIS3BucketObjectSubclass;
@end

@implementation ASIS3RequestTests

// All these tests are based on Amazon's examples at: http://docs.amazonwebservices.com/AmazonS3/2006-03-01/
- (void)testAuthenticationHeaderGeneration
{
	NSString *exampleSecretAccessKey = @"uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o";
	NSString *exampleAccessKey = @"0PN5J17HBGZHT7JJ3X82";
	NSString *exampleBucket = @"johnsmith";
	
	// Test GET
	NSString *path = @"/photos/puppy.jpg";
	NSString *dateString = @"Tue, 27 Mar 2007 19:36:42 +0000";
	ASIS3Request *request = [ASIS3Request requestWithBucket:exampleBucket path:path];
	[request setDateString:dateString];
	[request setSecretAccessKey:exampleSecretAccessKey];
	[request setAccessKey:exampleAccessKey];
	[request buildRequestHeaders];
	BOOL success = [[[request requestHeaders] valueForKey:@"Authorization"] isEqualToString:@"AWS 0PN5J17HBGZHT7JJ3X82:xXjDGYUmKxnwqr5KXNPGldn5LbA="];
	GHAssertTrue(success,@"Failed to generate the correct authorisation header for a GET request");
	
	// Test PUT
	path = @"/photos/puppy.jpg";
	dateString = @"Tue, 27 Mar 2007 21:15:45 +0000";
	request = [ASIS3Request requestWithBucket:exampleBucket path:path];
	[request setRequestMethod:@"PUT"];
	[request setMimeType:@"image/jpeg"];
	[request setDateString:dateString];
	[request setSecretAccessKey:exampleSecretAccessKey];
	[request setAccessKey:exampleAccessKey];
	[request buildRequestHeaders];
	success = [[[request requestHeaders] valueForKey:@"Authorization"] isEqualToString:@"AWS 0PN5J17HBGZHT7JJ3X82:hcicpDDvL9SsO6AkvxqmIWkmOuQ="];
	GHAssertTrue(success,@"Failed to generate the correct authorisation header for a PUT request");	
	
	// Test List
	dateString = @"Tue, 27 Mar 2007 19:42:41 +0000";
	ASIS3ListRequest *listRequest = [ASIS3ListRequest listRequestWithBucket:exampleBucket];
	[listRequest setPrefix:@"photos"];
	[listRequest setMaxResultCount:50];
	[listRequest setMarker:@"puppy"];
	[listRequest setDateString:dateString];
	[listRequest setSecretAccessKey:exampleSecretAccessKey];
	[listRequest setAccessKey:exampleAccessKey];
	[listRequest buildRequestHeaders];
	success = [[[listRequest requestHeaders] valueForKey:@"Authorization"] isEqualToString:@"AWS 0PN5J17HBGZHT7JJ3X82:jsRt/rhG+Vtp88HrYL706QhE4w4="];
	GHAssertTrue(success,@"Failed to generate the correct authorisation header for a list request");
	
	// Test fetch ACL
	path = @"/?acl";
	dateString = @"Tue, 27 Mar 2007 19:44:46 +0000";
	request = [ASIS3Request requestWithBucket:exampleBucket path:path];
	[request setDateString:dateString];
	[request setSecretAccessKey:exampleSecretAccessKey];
	[request setAccessKey:exampleAccessKey];
	[request buildRequestHeaders];
	success = [[[request requestHeaders] valueForKey:@"Authorization"] isEqualToString:@"AWS 0PN5J17HBGZHT7JJ3X82:thdUi9VAkzhkniLj96JIrOPGi0g="];
	GHAssertTrue(success,@"Failed to generate the correct authorisation header for a list request");	
	
	// Test Unicode keys
	// (I think Amazon's name for this example is misleading since this test actually only uses URL encoded strings)
	exampleBucket = @"dictionary";
	path = @"/fran%C3%A7ais/pr%c3%a9f%c3%a8re";
	dateString = @"Wed, 28 Mar 2007 01:49:49 +0000";
	request = [ASIS3Request requestWithBucket:exampleBucket path:path];
	[request setDateString:dateString];
	[request setSecretAccessKey:exampleSecretAccessKey];
	[request setAccessKey:exampleAccessKey];
	[request buildRequestHeaders];
	success = [[[request requestHeaders] valueForKey:@"Authorization"] isEqualToString:@"AWS 0PN5J17HBGZHT7JJ3X82:dxhSBHoI6eVSPcXJqEghlUzZMnY="];
	GHAssertTrue(success,@"Failed to generate the correct authorisation header for a list request");		
}

- (void)testFailure
{
	// Needs expanding to cover more failure states - this is just a test to ensure Amazon's error description is being added to the error
	
	// We're actually going to try with the Amazon example details, but the request will fail because the date is old
	NSString *exampleSecretAccessKey = @"uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o";
	NSString *exampleAccessKey = @"0PN5J17HBGZHT7JJ3X82";
	NSString *exampleBucket = @"johnsmith";
	NSString *path = @"/photos/puppy.jpg";
	NSString *dateString = @"Tue, 27 Mar 2007 19:36:42 +0000";
	ASIS3Request *request = [ASIS3Request requestWithBucket:exampleBucket path:path];
	[request setDateString:dateString];
	[request setSecretAccessKey:exampleSecretAccessKey];
	[request setAccessKey:exampleAccessKey];
	[request startSynchronous];
	GHAssertNotNil([request error],@"Failed to generate an error when the request was not correctly signed");
	
	BOOL success = ([[request error] code] == ASIS3ResponseErrorType);
	GHAssertTrue(success,@"Generated error had the wrong error code");	
	
	success = ([[[request error] localizedDescription] isEqualToString:@"The difference between the request time and the current time is too large."]);
	GHAssertTrue(success,@"Generated error had the wrong description");	
	
}

// To run this test, uncomment and fill in your S3 access details
- (void)testREST
{

	BOOL success = (![secretAccessKey isEqualToString:@""] && ![accessKey isEqualToString:@""] && ![bucket isEqualToString:@""]);
	GHAssertTrue(success,@"You need to supply your S3 access details to run the REST test (see the top of ASIS3RequestTests.m)");
	
	NSString *path = @"/test";
	
	// Create the file
	NSString *text = @"This is my content";
	NSString *filePath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"testfile.txt"];
	[[text dataUsingEncoding:NSUTF8StringEncoding] writeToFile:filePath atomically:NO];
	
	// PUT the file
	ASIS3Request *request = [ASIS3Request PUTRequestForFile:filePath withBucket:bucket path:path];
	[request setSecretAccessKey:secretAccessKey];
	[request setAccessKey:accessKey];
	[request startSynchronous];
	success = [[request responseString] isEqualToString:@""];
	GHAssertTrue(success,@"Failed to PUT a file to S3");	

	// GET the file
	request = [ASIS3Request requestWithBucket:bucket path:path];
	[request setSecretAccessKey:secretAccessKey];
	[request setAccessKey:accessKey];
	[request startSynchronous];
	success = [[request responseString] isEqualToString:@"This is my content"];
	GHAssertTrue(success,@"Failed to GET the correct data from S3");
	
	// COPY the file
	request = [ASIS3Request COPYRequestFromBucket:bucket path:path toBucket:bucket path:@"/test-copy"];
	[request setSecretAccessKey:secretAccessKey];
	[request setAccessKey:accessKey];
	[request startSynchronous];
	GHAssertNil([request error],@"Failed to COPY a file");
	
	// GET the copy
	request = [ASIS3Request requestWithBucket:bucket path:@"/test-copy"];
	[request setSecretAccessKey:secretAccessKey];
	[request setAccessKey:accessKey];
	[request startSynchronous];
	success = [[request responseString] isEqualToString:@"This is my content"];
	GHAssertTrue(success,@"Failed to GET the correct data from S3");	
	
	
	// HEAD the copy
	request = [ASIS3Request HEADRequestWithBucket:bucket path:@"/test-copy"];
	[request setSecretAccessKey:secretAccessKey];
	[request setAccessKey:accessKey];
	[request startSynchronous];
	success = [[request responseString] isEqualToString:@""];
	GHAssertTrue(success,@"Got a response body for a HEAD request");
	
	// Get a list of files
	ASIS3ListRequest *listRequest = [ASIS3ListRequest listRequestWithBucket:bucket];
	[listRequest setPrefix:@"test"];
	[listRequest setSecretAccessKey:secretAccessKey];
	[listRequest setAccessKey:accessKey];
	[listRequest startSynchronous];
	GHAssertNil([listRequest error],@"Failed to download a list from S3");
	success = [[listRequest bucketObjects] count];
	GHAssertTrue(success,@"The file didn't show up in the list");	

	// DELETE the file
	request = [ASIS3Request requestWithBucket:bucket path:path];
	[request setSecretAccessKey:secretAccessKey];
	[request setRequestMethod:@"DELETE"];
	[request setAccessKey:accessKey];
	[request startSynchronous];
	success = [[request responseString] isEqualToString:@""];
	GHAssertTrue(success,@"Failed to DELETE the file from S3");	
	
	// (Also DELETE the copy we made)
	request = [ASIS3Request requestWithBucket:bucket path:@"/test-copy"];
	[request setSecretAccessKey:secretAccessKey];
	[request setRequestMethod:@"DELETE"];
	[request setAccessKey:accessKey];
	[request startSynchronous];
	success = [[request responseString] isEqualToString:@""];
	GHAssertTrue(success,@"Failed to DELETE the copy from S3");	
	
	// Attempt to COPY the file, even though it is no longer there
	request = [ASIS3Request COPYRequestFromBucket:bucket path:path toBucket:bucket path:@"/test-copy"];
	[request setSecretAccessKey:secretAccessKey];
	[request setAccessKey:accessKey];
	[request startSynchronous];
	GHAssertNotNil([request error],@"Failed generate an error for what should have been a failed COPY");
	
	success = [[[request error] localizedDescription] isEqualToString:@"The specified key does not exist."];
	GHAssertTrue(success, @"Got the wrong error message");	
	
	// PUT some data
	NSData *data = [@"Hello" dataUsingEncoding:NSUTF8StringEncoding];
	request = [ASIS3Request PUTRequestForData:data withBucket:bucket path:path];
	[request setMimeType:@"text/plain"];
	[request setSecretAccessKey:secretAccessKey];
	[request setAccessKey:accessKey];
	[request start];
	success = [[request responseString] isEqualToString:@""];
	GHAssertTrue(success,@"Failed to PUT data to S3");
	
	// GET the data to check it uploaded properly
	request = [ASIS3Request requestWithBucket:bucket path:path];
	[request setSecretAccessKey:secretAccessKey];
	[request setAccessKey:accessKey];
	[request start];
	success = [[request responseString] isEqualToString:@"Hello"];
	GHAssertTrue(success,@"Failed to GET the correct data from S3");	
	
	// clean up (Delete it)
	request = [ASIS3Request requestWithBucket:bucket path:path];
	[request setSecretAccessKey:secretAccessKey];
	[request setRequestMethod:@"DELETE"];
	[request setAccessKey:accessKey];
	[request start];
	success = [[request responseString] isEqualToString:@""];
	GHAssertTrue(success,@"Failed to DELETE the file from S3");	
	
	
}

// Will upload a file to S3, gzipping it before uploading
// The file will be stored deflate, and automatically inflated when downloaded
// This means the file will take up less storage space, and will upload and download faster
// The file should still be accessible by any HTTP client that supports gzipped responses (eg browsers, NSURLConnection, etc)
- (void)testGZippedContent
{
	
	BOOL success = (![secretAccessKey isEqualToString:@""] && ![accessKey isEqualToString:@""] && ![bucket isEqualToString:@""]);
	GHAssertTrue(success,@"You need to supply your S3 access details to run the gzipped put test (see the top of ASIS3RequestTests.m)");
	
	// Create the file
	NSString *text = @"This is my content This is my content This is my content This is my content This is my content This is my content";
	NSString *filePath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"testfile.txt"];
	[[text dataUsingEncoding:NSUTF8StringEncoding] writeToFile:filePath atomically:NO];
	
	NSString *path = @"/gzipped-data";
	ASIS3Request *request = [ASIS3Request PUTRequestForFile:filePath withBucket:bucket path:path];
	[request setSecretAccessKey:secretAccessKey];
	[request setAccessKey:accessKey];
	[request setShouldCompressRequestBody:YES];
	[request setAccessPolicy:ASIS3AccessPolicyPublicRead]; // We'll make it public
	[request startSynchronous];
	success = [[request responseString] isEqualToString:@""];
	GHAssertTrue(success,@"Failed to PUT the gzipped file");		
	
	// GET the file
	request = [ASIS3Request requestWithBucket:bucket path:path];
	[request setSecretAccessKey:secretAccessKey];
	[request setAccessKey:accessKey];
	[request startSynchronous];
	success = [[request responseString] isEqualToString:text];
	GHAssertTrue(success,@"Failed to GET the correct data from S3");	
	
	success = [[[request responseHeaders] valueForKey:@"Content-Encoding"] isEqualToString:@"gzip"];
	GHAssertTrue(success,@"Failed to GET the correct data from S3");	
	
	// Now grab the data using something other than ASIHTTPRequest to ensure other HTTP clients can parse the gzipped content
	NSData *data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@.s3.amazonaws.com/gzipped-data",bucket]]] returningResponse:NULL error:NULL];
	NSString *string = [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding] autorelease];
	success = [string isEqualToString:text];
	GHAssertTrue(success,@"Failed to GET the correct data from S3");		
	
}


- (void)testListRequest
{	

	BOOL success = (![secretAccessKey isEqualToString:@""] && ![accessKey isEqualToString:@""] && ![bucket isEqualToString:@""]);
	GHAssertTrue(success,@"You need to supply your S3 access details to run the list test (see the top of ASIS3RequestTests.m)");
	
	// Firstly, create and upload 5 files
	int i;
	for (i=0; i<5; i++) {
		NSString *text = [NSString stringWithFormat:@"This is the content of file #%hi",i];
		NSString *filePath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:[NSString stringWithFormat:@"%hi.txt",i]];
		[[text dataUsingEncoding:NSUTF8StringEncoding] writeToFile:filePath atomically:NO];
		NSString *path = [NSString stringWithFormat:@"/test-file/%hi",i];
		ASIS3Request *request = [ASIS3Request PUTRequestForFile:filePath withBucket:bucket path:path];
		[request setSecretAccessKey:secretAccessKey];
		[request setAccessKey:accessKey];
		[request startSynchronous];
		GHAssertNil([request error],@"Give up on list request test - failed to upload a file");	
	}
	
	// Now get a list of the files
	ASIS3ListRequest *listRequest = [ASIS3ListRequest listRequestWithBucket:bucket];
	[listRequest setPrefix:@"test-file"];
	[listRequest setSecretAccessKey:secretAccessKey];
	[listRequest setAccessKey:accessKey];
	[listRequest startSynchronous];
	GHAssertNil([listRequest error],@"Failed to download a list from S3");
	success = ([[listRequest bucketObjects] count] == 5);
	GHAssertTrue(success,@"List did not contain all files");
	
	// Please don't use an autoreleased operation queue with waitUntilAllOperationsAreFinished in your own code unless you're writing a test like this one
	// (The end result is no better than using synchronous requests) thx - Ben :)
	ASINetworkQueue *queue = [[[ASINetworkQueue alloc] init] autorelease];
	
	// Test fetching all the items
	[queue setRequestDidFinishSelector:@selector(GETRequestDone:)];
	[queue setRequestDidFailSelector:@selector(GETRequestFailed:)];
	[queue setDelegate:self];
	for (ASIS3BucketObject *object in [listRequest bucketObjects]) {
		ASIS3Request *request = [object GETRequest];
		[request setAccessKey:accessKey];
		[request setSecretAccessKey:secretAccessKey];
		[queue addOperation:request];
	}
	[queue go];
	[queue waitUntilAllOperationsAreFinished];
	
	
	// Test uploading new files for all the items
	[queue setRequestDidFinishSelector:@selector(PUTRequestDone:)];
	[queue setRequestDidFailSelector:@selector(PUTRequestFailed:)];
	[queue setDelegate:self];
	i=0;
	// For each one, we'll just upload the same content again
	for (ASIS3BucketObject *object in [listRequest bucketObjects]) {
		NSString *oldFilePath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:[NSString stringWithFormat:@"%hi.txt",i]];;
		ASIS3Request *request = [object PUTRequestWithFile:oldFilePath];
		[request setAccessKey:accessKey];
		[request setSecretAccessKey:secretAccessKey];
		[queue addOperation:request];
		i++;
	}
	[queue go];
	[queue waitUntilAllOperationsAreFinished];
	
	
	// Test deleting all the items
	[queue setRequestDidFinishSelector:@selector(DELETERequestDone:)];
	[queue setRequestDidFailSelector:@selector(DELETERequestFailed:)];
	[queue setDelegate:self];
	i=0;

	for (ASIS3BucketObject *object in [listRequest bucketObjects]) {
		ASIS3Request *request = [object DELETERequest];
		[request setAccessKey:accessKey];
		[request setSecretAccessKey:secretAccessKey];
		[queue addOperation:request];
		i++;
	}
	[queue go];
	[queue waitUntilAllOperationsAreFinished];
	
	// Grab the list again, it should be empty now
	listRequest = [ASIS3ListRequest listRequestWithBucket:bucket];
	[listRequest setPrefix:@"test-file"];
	[listRequest setSecretAccessKey:secretAccessKey];
	[listRequest setAccessKey:accessKey];
	[listRequest startSynchronous];
	GHAssertNil([listRequest error],@"Failed to download a list from S3");
	success = ([[listRequest bucketObjects] count] == 0);
	GHAssertTrue(success,@"List contained files that should have been deleted");
	
}

- (void)GETRequestDone:(ASIS3Request *)request
{
	NSString *expectedContent = [NSString stringWithFormat:@"This is the content of file #%@",[[[request url] absoluteString] lastPathComponent]];
	BOOL success = ([[request responseString] isEqualToString:expectedContent]);
	GHAssertTrue(success,@"Got the wrong content when downloading one of the files");
	
}

- (void)GETRequestFailed:(ASIS3Request *)request
{
	GHAssertTrue(NO,@"GET request failed for one of the items in the list");
}

- (void)PUTRequestDone:(ASIS3Request *)request
{
}

- (void)PUTRequestFailed:(ASIS3Request *)request
{
	GHAssertTrue(NO,@"PUT request failed for one of the items in the list");
}

- (void)DELETERequestDone:(ASIS3Request *)request
{
}

- (void)DELETERequestFailed:(ASIS3Request *)request
{
	GHAssertTrue(NO,@"DELETE request failed for one of the items in the list");
}


// Ensure class convenience constructors return an instance of our subclass
- (void)testSubclasses
{
	ASIS3RequestSubclass *instance = [ASIS3RequestSubclass requestWithBucket:@"bucket" path:@"path"];
	BOOL success = [instance isKindOfClass:[ASIS3RequestSubclass class]];
	GHAssertTrue(success,@"Convenience constructor failed to return an instance of the correct class");	

	instance = [ASIS3RequestSubclass PUTRequestForFile:@"/file" withBucket:@"bucket" path:@"path"];
	success = [instance isKindOfClass:[ASIS3RequestSubclass class]];
	GHAssertTrue(success,@"Convenience constructor failed to return an instance of the correct class");	
	
	instance = [ASIS3RequestSubclass DELETERequestWithBucket:@"bucket" path:@"path"];
	success = [instance isKindOfClass:[ASIS3RequestSubclass class]];
	GHAssertTrue(success,@"Convenience constructor failed to return an instance of the correct class");	
	
	instance = [ASIS3RequestSubclass COPYRequestFromBucket:@"bucket" path:@"path" toBucket:@"bucket" path:@"path2"];
	success = [instance isKindOfClass:[ASIS3RequestSubclass class]];
	GHAssertTrue(success,@"Convenience constructor failed to return an instance of the correct class");	
	
	instance = [ASIS3RequestSubclass HEADRequestWithBucket:@"bucket" path:@"path"];
	success = [instance isKindOfClass:[ASIS3RequestSubclass class]];
	GHAssertTrue(success,@"Convenience constructor failed to return an instance of the correct class");	
	
	ASIS3ListRequestSubclass *instance2 = [ASIS3ListRequestSubclass listRequestWithBucket:@"bucket"];
	success = [instance2 isKindOfClass:[ASIS3ListRequestSubclass class]];
	GHAssertTrue(success,@"Convenience constructor failed to return an instance of the correct class");	
	
	ASIS3BucketObjectSubclass *instance3 = [ASIS3BucketObjectSubclass objectWithBucket:@"bucket"];
	success = [instance3 isKindOfClass:[ASIS3BucketObjectSubclass class]];
	GHAssertTrue(success,@"Convenience constructor failed to return an instance of the correct class");	
}


- (void)s3RequestFailed:(ASIHTTPRequest *)request
{
	GHFail(@"Request failed - cannot continue with test");
	[[self networkQueue] cancelAllOperations];
}

- (void)s3QueueFinished:(ASINetworkQueue *)queue
{
	BOOL success = (progress == 1.0);
	GHAssertTrue(success,@"Failed to update progress properly");
}


- (void)testQueueProgress
{
	[[self networkQueue] cancelAllOperations];
	[self setNetworkQueue:[ASINetworkQueue queue]];
	[[self networkQueue] setDelegate:self];
	[[self networkQueue] setRequestDidFailSelector:@selector(s3RequestFailed:)];
	[[self networkQueue] setQueueDidFinishSelector:@selector(s3QueueFinished:)];	
	[[self networkQueue] setDownloadProgressDelegate:self];
	[[self networkQueue] setShowAccurateProgress:YES];
	
	int i;
	for (i=0; i<5; i++) {
		NSString *path = [NSString stringWithFormat:@"/images/%hi.jpg",i+1];
		ASIS3Request *s3Request = [ASIS3Request requestWithBucket:bucket path:path];
		[s3Request setSecretAccessKey:secretAccessKey];
		[s3Request setAccessKey:accessKey];
		NSString *downloadPath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:[NSString stringWithFormat:@"%hi.jpg",i+1]];
		[s3Request setDownloadDestinationPath:downloadPath];
		[[self networkQueue] addOperation:s3Request];
	}
	
	[[self networkQueue] go];

}
	
// Will be called on Mac OS
- (void)setDoubleValue:(double)newProgress;
{
	progress = (float)newProgress;
}

 - (void)setProgress:(float)newProgress;
{
	progress = newProgress;
}


- (void)testCopy
{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

	ASIS3Request *request = [ASIS3Request requestWithBucket:@"foo" path:@"eep"];
	ASIS3Request *request2 = [request copy];
	GHAssertNotNil(request2,@"Failed to create a copy");
	
	[pool release];
	
	BOOL success = ([request2 retainCount] > 0);
	GHAssertTrue(success,@"Failed to create a retained copy");
	success = ([request2 isKindOfClass:[ASIS3Request class]]);
	GHAssertTrue(success,@"Copy is of wrong class");
	
	pool = [[NSAutoreleasePool alloc] init];

	
	ASIS3ListRequest *request3 = [ASIS3ListRequest listRequestWithBucket:@"foo"];
	ASIS3ListRequest *request4 = [request3 copy];
	GHAssertNotNil(request4,@"Failed to create a copy");
	
	[pool release];
	
	success = ([request4 retainCount] > 0);
	GHAssertTrue(success,@"Failed to create a retained copy");
	success = ([request4 isKindOfClass:[ASIS3ListRequest class]]);
	GHAssertTrue(success,@"Copy is of wrong class");
	
	pool = [[NSAutoreleasePool alloc] init];

	
	ASIS3BucketObject *bucketObject = [ASIS3BucketObject objectWithBucket:@"foo"];
	ASIS3BucketObject *bucketObject2 = [bucketObject copy];
	GHAssertNotNil(bucketObject2,@"Failed to create a copy");
	
	[pool release];
	
	success = ([bucketObject2 retainCount] > 0);
	GHAssertTrue(success,@"Failed to create a retained copy");
}

@synthesize networkQueue;

@end