AsyncHttpClient) with that number port for testing purpose. Note: Please, set HttpClient of your code (e.g. MockWebServer proxy = new MockWebServer() MockResponse response = MockResponse().setResponseCode(statusCode).setBody(responseBody).addHeader(contentType) I don't know if it's useful, but you can simulate a timeout with MockWebServer: String contentType = "Content-type: application/json" Really I don't know how your code is, but I hope this is useful The SAP replica server is logically part of the SAP central services, although it always runs on a different node from the other servers in the SAP central services. to simulate this, set to the adapter an incorrect end point.ĬonnectException - mockwebserver can throw a timeout exception. UnknownHostException - When you don't have internet or unknown host. To be clear with whe types of exceptions here you can see the differences: The following examples show how to use can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. By default the amount of time for the error to be thrown is anywhere from 0 to 3x the delay. In your test, you can call setErrorPercentage(100) to guarantee that a network error will occur. MockWebServer Dependencies To use MockWebServer, you need two dependencies. You may check out the related API usage on. This will allow us to test things like what our system returns when getting a 500 error from their dependencies and other complex scenarios. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. setErrorPercentage - Set the percentage of calls to calculateIsFailure() that return true. shutdown () The following examples show how to use shutdown ().setVariancePercentage - Set the plus-or-minus variance percentage of the network round trip delay.setDelay - Set the network round trip delay, in milliseconds.You can rate examples to help us improve the quality of examples. You can see a full example in the samples/mock-github-client/ folder of the repo: These are the top rated real world Java examples of okhttp3.OkHttpClient extracted from open source projects. This is a used in conjunction with the normal RestAdapter to create an instance of your service. Import za.co. has a retrofit-mock module which offers a MockRestAdapter class whose purpose is to simulate network delay and errors. When a successful response is received from the server, the quote is displayed otherwise a retry button is shown with an error message. In the code below, the service gets created and the activity asynchronously calls getQuoteOfTheDay(). I am writing a junit test using okhttp3.mockwebserver for a retrofit2 rest api.
0 Comments
Leave a Reply. |