You need to sign in to do that
Don't have an account?
Patrick Mayer 4
Difficult test class http requests
I am having an extremely difficult time coming up with a test class for this.
I am using a multimock for mock data, but I cannot figure out how to set cookies for that.
Http httpProtocol1 = new Http(); Http httpProtocol2 = new Http(); // Create HTTP request to send. HttpRequest request1 = new HttpRequest(); HttpRequest request2 = new HttpRequest(); // Set the endpoint URL. String endpoint1 = 'https://web.com/Login.json?user=user%40web.com&pass=secr'; String endpoint2 = 'https://web.com/info.json'; request1.setEndPoint(endpoint1); request2.setEndPoint(endpoint2); // Set the HTTP verbs request1.setMethod('POST'); request2.setMethod('GET'); // Send the HTTP requests and get the responses HttpResponse response1 = httpProtocol1.send(request1); String cookie = response1.getHeader('Set-Cookie'); request2.setHeader('cookie', cookie); HttpResponse response2 = httpProtocol2.send(request2); String jsonStr = response2.getBody();
Then in your test class you set the mock up like this: