Java Code Examples for okhttp3.mockwebserver.MockResponse#setHeader()
The following examples show how to use
okhttp3.mockwebserver.MockResponse#setHeader() .
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. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalTestServerContext.java From google-maps-services-java with Apache License 2.0 | 6 votes |
LocalTestServerContext(BufferedImage image) throws IOException { this.server = new MockWebServer(); Buffer buffer = new Buffer(); ImageIO.write(image, "png", buffer.outputStream()); MockResponse response = new MockResponse(); response.setHeader("Content-Type", "image/png"); response.setBody(buffer); server.enqueue(response); server.start(); this.context = new GeoApiContext.Builder() .apiKey("AIzaFakeKey") .baseUrlOverride("http://127.0.0.1:" + server.getPort()) .build(); }
Example 2
Source File: AbstractMockWebServerTestCase.java From spring-analysis-note with MIT License | 5 votes |
private MockResponse getRequest(RecordedRequest request, byte[] body, String contentType) { if (request.getMethod().equals("OPTIONS")) { return new MockResponse().setResponseCode(200).setHeader("Allow", "GET, OPTIONS, HEAD, TRACE"); } Buffer buf = new Buffer(); buf.write(body); MockResponse response = new MockResponse() .setHeader("Content-Length", body.length) .setBody(buf) .setResponseCode(200); if (contentType != null) { response = response.setHeader("Content-Type", contentType); } return response; }
Example 3
Source File: AbstractMockWebServerTestCase.java From java-technology-stack with MIT License | 5 votes |
private MockResponse getRequest(RecordedRequest request, byte[] body, String contentType) { if (request.getMethod().equals("OPTIONS")) { return new MockResponse().setResponseCode(200).setHeader("Allow", "GET, OPTIONS, HEAD, TRACE"); } Buffer buf = new Buffer(); buf.write(body); MockResponse response = new MockResponse() .setHeader("Content-Length", body.length) .setBody(buf) .setResponseCode(200); if (contentType != null) { response = response.setHeader("Content-Type", contentType); } return response; }
Example 4
Source File: Dhis2MockServer.java From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void enqueueMockResponse(String fileName, Date dateHeader) { MockResponse response = createMockResponse(fileName); DateFormat rfc1123 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US); rfc1123.setLenient(false); rfc1123.setTimeZone(UTC); String dateHeaderValue = rfc1123.format(dateHeader); response.setHeader("Date", dateHeaderValue); server.enqueue(response); }
Example 5
Source File: LocalTestServerContext.java From google-maps-services-java with Apache License 2.0 | 5 votes |
LocalTestServerContext(String responseBody) throws IOException { this.server = new MockWebServer(); MockResponse response = new MockResponse(); response.setHeader("Content-Type", "application/json"); response.setBody(responseBody); server.enqueue(response); server.start(); this.context = new GeoApiContext.Builder() .apiKey("AIzaFakeKey") .baseUrlOverride("http://127.0.0.1:" + server.getPort()) .build(); }