From 8748004f19ce90c5abcf0a0c69aa488eefdd219f Mon Sep 17 00:00:00 2001 From: Oliver Letterer Date: Thu, 16 May 2013 20:53:23 +0200 Subject: [PATCH 1/5] Adds testDefaultHeaders. --- Tests/AFHTTPClientTests.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/AFHTTPClientTests.m b/Tests/AFHTTPClientTests.m index f572814..2b7247e 100644 --- a/Tests/AFHTTPClientTests.m +++ b/Tests/AFHTTPClientTests.m @@ -35,6 +35,14 @@ #pragma mark - +- (void)testDefaultHeaders { + [self.client setDefaultHeader:@"x-some-key" value:@"SomeValue"]; + expect([self.client defaultValueForHeader:@"x-some-key"]).to.equal(@"SomeValue"); + + NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil]; + expect([request valueForHTTPHeaderField:@"x-some-key"]).to.equal(@"SomeValue"); +} + - (void)testThatTheDefaultStringEncodingIsUTF8 { expect(self.client.stringEncoding).to.equal(NSUTF8StringEncoding); } From 221e7c3abe98c2c5f0d9ac80d200569fd10aa62e Mon Sep 17 00:00:00 2001 From: Oliver Letterer Date: Thu, 16 May 2013 21:00:10 +0200 Subject: [PATCH 2/5] Adds testJSONRequestOperationContruction. --- Tests/AFHTTPClientTests.m | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Tests/AFHTTPClientTests.m b/Tests/AFHTTPClientTests.m index 2b7247e..5795627 100644 --- a/Tests/AFHTTPClientTests.m +++ b/Tests/AFHTTPClientTests.m @@ -43,6 +43,19 @@ expect([request valueForHTTPHeaderField:@"x-some-key"]).to.equal(@"SomeValue"); } +- (void)testJSONRequestOperationContruction { + NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil]; + [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; + + AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; + expect([operation class]).to.equal([AFHTTPRequestOperation class]); + + expect([AFJSONRequestOperation canProcessRequest:request]).to.beTruthy(); + [self.client registerHTTPOperationClass:[AFJSONRequestOperation class]]; + operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; + expect([operation class]).to.equal([AFJSONRequestOperation class]); +} + - (void)testThatTheDefaultStringEncodingIsUTF8 { expect(self.client.stringEncoding).to.equal(NSUTF8StringEncoding); } From 15b79263644e9310d2b976a882e7583ebb8b0dbb Mon Sep 17 00:00:00 2001 From: Oliver Letterer Date: Thu, 16 May 2013 21:01:02 +0200 Subject: [PATCH 3/5] Adds testXMLRequestOperationContruction. --- Tests/AFHTTPClientTests.m | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Tests/AFHTTPClientTests.m b/Tests/AFHTTPClientTests.m index 5795627..821c59e 100644 --- a/Tests/AFHTTPClientTests.m +++ b/Tests/AFHTTPClientTests.m @@ -56,6 +56,19 @@ expect([operation class]).to.equal([AFJSONRequestOperation class]); } +- (void)testXMLRequestOperationContruction { + NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil]; + [request setValue:@"application/xml" forHTTPHeaderField:@"Accept"]; + + AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; + expect([operation class]).to.equal([AFHTTPRequestOperation class]); + + expect([AFXMLRequestOperation canProcessRequest:request]).to.beTruthy(); + [self.client registerHTTPOperationClass:[AFXMLRequestOperation class]]; + operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; + expect([operation class]).to.equal([AFXMLRequestOperation class]); +} + - (void)testThatTheDefaultStringEncodingIsUTF8 { expect(self.client.stringEncoding).to.equal(NSUTF8StringEncoding); } From 12ed16151002c61a7dff7d933b3a8fd8c364228a Mon Sep 17 00:00:00 2001 From: Oliver Letterer Date: Thu, 16 May 2013 21:02:06 +0200 Subject: [PATCH 4/5] Adds testImageRequestOperationContruction. --- Tests/AFHTTPClientTests.m | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Tests/AFHTTPClientTests.m b/Tests/AFHTTPClientTests.m index 821c59e..71b6bfb 100644 --- a/Tests/AFHTTPClientTests.m +++ b/Tests/AFHTTPClientTests.m @@ -69,6 +69,19 @@ expect([operation class]).to.equal([AFXMLRequestOperation class]); } +- (void)testImageRequestOperationContruction { + NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil]; + [request setValue:@"image/png" forHTTPHeaderField:@"Accept"]; + + AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; + expect([operation class]).to.equal([AFHTTPRequestOperation class]); + + expect([AFImageRequestOperation canProcessRequest:request]).to.beTruthy(); + [self.client registerHTTPOperationClass:[AFImageRequestOperation class]]; + operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; + expect([operation class]).to.equal([AFImageRequestOperation class]); +} + - (void)testThatTheDefaultStringEncodingIsUTF8 { expect(self.client.stringEncoding).to.equal(NSUTF8StringEncoding); } From 4e72a84b7685cf909b8e5e759bff9e4db21fe6d4 Mon Sep 17 00:00:00 2001 From: Oliver Letterer Date: Thu, 16 May 2013 21:03:09 +0200 Subject: [PATCH 5/5] Adds test for unregistering HTTPOperation class. --- Tests/AFHTTPClientTests.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/AFHTTPClientTests.m b/Tests/AFHTTPClientTests.m index 71b6bfb..7f4a4a9 100644 --- a/Tests/AFHTTPClientTests.m +++ b/Tests/AFHTTPClientTests.m @@ -54,6 +54,10 @@ [self.client registerHTTPOperationClass:[AFJSONRequestOperation class]]; operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; expect([operation class]).to.equal([AFJSONRequestOperation class]); + + [self.client unregisterHTTPOperationClass:[AFJSONRequestOperation class]]; + operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; + expect([operation class]).to.equal([AFHTTPRequestOperation class]); } - (void)testXMLRequestOperationContruction {