34 NSError *(^errorForResponse)(NSInteger code) = ^(NSInteger code) {
35 return [
ARConnection errorForResponse:[[
ARHTTPResponse alloc] initWithHTTPURLResponse:[[NSHTTPURLResponse alloc] initWithURL:ActiveResourceKitTestsBaseURL() statusCode:code HTTPVersion:@"HTTP/1.1" headerFields:nil] body:nil]];
38 for (NSNumber *code in [NSArray arrayWithObjects:[NSNumber numberWithInt:200], [NSNumber numberWithInt:299], [NSNumber numberWithInt:300], [NSNumber numberWithInt:399], nil])
40 STAssertNil(errorForResponse([code integerValue]), nil);
43 NSArray *redirectCodes = [NSArray arrayWithObjects:[NSNumber numberWithInt:301], [NSNumber numberWithInt:302], [NSNumber numberWithInt:303], [NSNumber numberWithInt:307], nil];
44 NSArray *redirectDescriptions = [NSArray arrayWithObjects:@"moved permanently", @"found", @"see other", @"temporarily redirected", nil];
45 NSDictionary *redirectDescriptionForCode = [NSDictionary dictionaryWithObjects:redirectDescriptions forKeys:redirectCodes];
46 for (NSNumber *code in redirectCodes)
48 NSError *error = errorForResponse([code integerValue]);
49 STAssertNotNil(error, nil);
51 STAssertEqualObjects([[error userInfo] objectForKey:NSLocalizedDescriptionKey], [redirectDescriptionForCode objectForKey:code], nil);
59 clientCodesAndErrors[] =
70 for (NSUInteger i = 0; i <
ARDimOf(clientCodesAndErrors); i++)
72 STAssertEquals([errorForResponse(clientCodesAndErrors[i].statusCode) code], clientCodesAndErrors[i].errorCode, nil);
74 for (NSInteger statusCode = 402; statusCode <= 499; statusCode++)
77 for (i = 0; i <
ARDimOf(clientCodesAndErrors) && statusCode != clientCodesAndErrors[i].statusCode; i++);
78 if (i ==
ARDimOf(clientCodesAndErrors))
80 STAssertEquals([errorForResponse(statusCode) code], (NSInteger)
ARClientErrorCode, nil);
84 for (NSInteger statusCode = 500; statusCode <= 599; statusCode++)
86 STAssertEquals([errorForResponse(statusCode) code], (NSInteger)
ARServerErrorCode, nil);
93 NSHTTPURLResponse *__autoreleasing response = nil;
94 NSError *__autoreleasing error = nil;
97 NSDictionary *matz = [[connection
format] decode:data error:&error];
98 STAssertEqualObjects(
@"Matz", [matz valueForKey:
@"name"], nil);
106 NSHTTPURLResponse *response = nil;
110 STAssertEquals([data length], (NSUInteger)0, nil);
111 STAssertEquals([response statusCode], (NSInteger)200, nil);
117 NSHTTPURLResponse *response = nil;
118 NSDictionary *headers = [NSDictionary dictionaryWithObject:@"value" forKey:@"key"];
135 NSDictionary *david = [[connection
format] decode:data error:NULL];
136 STAssertEqualObjects(
@"David", [david valueForKey:
@"name"], nil);
141 NSHTTPURLResponse *response = nil;
145 STAssertNotNil([[response allHeaderFields] objectForKey:
@"Location"], nil);