Restkit Testing Managed Object Requests - ios

Does somebody know, how a managed object request (RKManagedObjectRequestOperation) can be tested in Restkit? Normal Request Operations are easy to test as described here https://github.com/RestKit/RestKit/wiki/Unit-Testing-with-RestKit#testing-object-request-operations

Related

How to use RestKit without response description mapping?

I have a existing project which is using RestKit and now I need to update some API requests. The problem is I have a post request which doesn't need to care the response body. I just want to know the response status code is 200 or not. So I don't add RKResponseDescriptor then RestKit reports error:"No response descriptors match the response loaded.".How could I send request without any response descriptors? Any idea? Thanks
Use restkit to create the request but then run the request yourself. If restkit isn't running the request then it isn't involved in the response processing.

Restarting an RKObjectRequestOperation with new authentication

Hi guys,
Do you know if you can "restart" an RKObjectRequestOperation with a new authentication in RestKit 0.20.3?
If the first one fails, I want to change the authentication of the RKObjectRequestOperation and start it from the beginning.
It isn't documented as reusable so even if it did work now you couldn't guarantee that it will continue to work in the future. The request and the response descriptors you use to create the operation are immutable so you can easily extract those to create a new operation instance and set your new auth details.
As an aside, the operation contains a state machine and internally utilises several other asynchronous operations. Don't rely on reusability.

How can you use OCMock with NSURLConnection/delegate for a series of mock network connections?

I've implemented the code in this posting:how to unit test a NSURLConnection Delegate?
and have managed to get a test case going with my code where I simulate sending a server package of data via the mock classes.
This is ok to test a simple single client post / server response type situation but I want to test a conversation scenario where my code makes a post, the server sends a reply, my code makes another response, the server sends another reply etc.
Has anybody done anything similar to this?

AFNetworking AFHTTPClient Different content types for success and Fail

I am trying to access a web service, via an AFHTTPClient subclass, that has a complication
If the request succeeds, the content is returned as JSON. If it fails for some reason, the error from the server is returned formatted as XML.
At the moment, the only way I figure I can deal with this is the not attempt to use the specific XML/JSON RequestOperations, and purely treat everything as a plain HTTP request, and then attempt to parse it manually myself, depending upon what the response looks like.
Sadly, I have no control over the web service, or I'd make sure it was all JSON.
Does anybody have any better suggestions for handling this?
[EDIT]
I guess one way of making it slightly cleaner, would be creating a new subclass of AFHTTPRequestOperation, that handled the detection of content type internally, and then passed back either parsed JSON or a GDataXML object depending upon what was returned from the server.
Thanks
This might not be the cleanest or most optimal solution, but you could do a check with an existing JSON library that the response is in fact valid JSON. If it is, proceed as usual; if it isn't, treat it with your hand-carved parsing solution.

RestKit handling different HTTP status codes

I've just started to try out RestKit for an iOS app i'm building. I normally use ASIHttpRequest, but I want to test out RestKit mostly for its object mapping between JSON and CoreData. There are some great things about RestKit, but I've run into an issue that really makes it feel deficient, unless I'm doing something wrong or have missed something. I hope someone here can guide me on that.
I'm using RKObjectLoader to make async & sync calls to a REST API. My service is designed to send back proper HTTP status codes, along with some sort of description, a 401 being an example of when the API needs an authenticated user.
My problem is that RestKit stops acting normally if i get a 401 error back. The RKResponse object has a status code of 0, even though it has a payload in it. I'm pretty sure this comes down to NSURLConnection's poor handling of HTTP statuses, but I would expect RestKit to wrap around this somehow. Especially since the RKResponse class has quite a few wrapper functions to determine the status code of the response (isOK, isCreated, isForbidden, isUnauthorized, etc.).
In comparison, ASIHttpRequest doesn't use NSURLConnection, but instead uses the lower level CFNetwork code. ASIHttpRequest allows me to see exactly what came back over HTTP without sending out errors left & right.
Question is, am I doing something wrong, or is this the expected behavior out of RestKit? Has anyone successfully been able to make a calls to [RKResponse isAuthenticated]? Although its inconclusive to me, is there any difference between running in async and sync mode in this regard. I did read somewhere that NSURLConnection run in sync mode will act a bit differently, even though the underlying code is just calling the async operations. Does this have more to do with me using RKObjectLoader as opposed to just RKRequest? Perhaps the fact that the payload can't map to a model causes anger, but it seems that the code is breaking earlier within RKRequest.sendSynchronously, prior to when mapping actually takes place.
Bottom line is my code needs to be able to freely read HTTP status codes. Any guidance would be most appreciated.
Haider
The common way for RestKit 0.20.x is to subclass RKObjectRequestOperation.
I wrote a blog article about this problem which can be found here:
http://blog.higgsboson.tk/2013/09/03/global-request-management-with-restkit/
See http://groups.google.com/group/restkit/msg/839b84452f4b3e26
"... when authentication fails, the authentication challenge gets cancelled and that effectively voids the request."
UPDATE:
RestKit already includes a delegate method for this:
(void)request:(RKRequest *)request didFailAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
Triggers before
(void)objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error
When HTTP Basic authentication fails, so we can use this instead.

Resources