@Test public void testWithResponseCompression() throws IOException { ByteArrayOutputStream capturedOutput = hookAlmostRealInterpretResponseStream(mMockEventReporter); byte[] uncompressedData = repeat(".", 1024).getBytes(); byte[] compressedData = compress(uncompressedData); MockWebServer server = new MockWebServer(); server.start(); server.enqueue(new MockResponse() .setBody(new Buffer().write(compressedData)) .addHeader("Content-Encoding: gzip")); Request request = new Request.Builder() .url(server.url("/")) .build(); Response response = mClientWithInterceptor.newCall(request).execute(); // Verify that the final output and the caller both saw the uncompressed stream. assertArrayEquals(uncompressedData, response.body().bytes()); assertArrayEquals(uncompressedData, capturedOutput.toByteArray()); // And verify that the StethoInterceptor was able to see both. Mockito.verify(mMockEventReporter) .dataReceived( anyString(), eq(compressedData.length), eq(uncompressedData.length)); server.shutdown(); }
@Test public void testExport() throws Exception { server.enqueue(new MockResponse().setBody(CALENDARS_RESPONSE)); server.enqueue(new MockResponse().setBody(CALENDAR1_EVENTS_RESPONSE)); server.enqueue(new MockResponse().setBody(CALENDAR2_EVENTS_RESPONSE)); server.start(); HttpUrl baseUrl = server.url(""); MicrosoftCalendarExporter exporter = new MicrosoftCalendarExporter(baseUrl.toString(), client, mapper, transformerService); ExportResult<CalendarContainerResource> resource = exporter .export(UUID.randomUUID(), token, Optional.empty()); CalendarContainerResource calendarResource = resource.getExportedData(); Assert.assertEquals(2, calendarResource.getCalendars().size()); Assert.assertFalse( calendarResource .getCalendars() .stream() .anyMatch(c -> "Calendar1".equals(c.getId()) && "Calendar2".equals(c.getId()))); Assert.assertEquals(2, calendarResource.getEvents().size()); Assert.assertFalse( calendarResource .getEvents() .stream() .anyMatch( e -> "Test Appointment 1".equals(e.getTitle()) && "Test Appointment 2".equals(e.getTitle()))); }
server.enqueue(new MockResponse().setBody(BATCH_CALENDAR_RESPONSE)); server.enqueue(new MockResponse().setResponseCode(201).setBody(BATCH_EVENT_RESPONSE)); server.start();
server.start(); server.enqueue(new MockResponse() .setBody("Success!"));
server.enqueue(content2Response); server.start();
/** Equivalent to {@code start(0)}. */ public void start() throws IOException { start(0); }
private synchronized void maybeStart() { if (started) return; try { start(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Starts the server on the given address and port. * * @param inetAddress the address to create the server socket on * * @param port the port to listen to, or 0 for any available port. Automated * tests should always use port 0 to avoid flakiness when a specific port * is unavailable. */ public void start(InetAddress inetAddress, int port) throws IOException { start(new InetSocketAddress(inetAddress, port)); }
/** * Starts the server on the loopback interface for the given port. * * @param port the port to listen to, or 0 for any available port. Automated * tests should always use port 0 to avoid flakiness when a specific port * is unavailable. */ public void start(int port) throws IOException { start(InetAddress.getByName("localhost"), port); }
/** * Create a MockWebServer with an initial bread-crumb response. * * @return instance of MockWebServer * @throws IOException * if unable to start/play server */ public static MockWebServer mockWebServer() throws IOException { final MockWebServer server = new MockWebServer(); server.start(); return server; }
/** * Create a MockWebServer. * * @return instance of MockWebServer * @throws IOException * if unable to start/play server */ public static MockWebServer mockWebServer() throws IOException { final MockWebServer server = new MockWebServer(); server.start(); return server; }
@Before public void setUp() throws Exception { System.setProperty("user.timezone", ANY_TIME_ZONE); MockitoAnnotations.initMocks(this); this.server = new MockWebServer(); this.server.start(); }
private void runMockServer() throws IOException { server = new MockWebServer(); server.setDispatcher(dispatcher); server.start(0); } }
private void runMockServer() throws IOException { server = new MockWebServer(); server.setDispatcher(dispatcher); server.start(0); } }
@Before public void setup() throws IOException { server = new MockWebServer(); server.start(); shapeShift = new ShapeShift(); shapeShift.baseUrl = server.getUrl("/").toString(); shapeShift.client.setConnectionSpecs(Collections.singletonList(ConnectionSpec.CLEARTEXT)); }
@Before public void setup() throws IOException { server = new MockWebServer(); server.start(); shapeShift = new ShapeShift(); shapeShift.baseUrl = server.getUrl("/").toString(); shapeShift.client.setConnectionSpecs(Collections.singletonList(ConnectionSpec.CLEARTEXT)); }
@Before public void setUp() throws Exception { server = new MockWebServer(); server.start(); PlivoClient.BASE_URL = server.url("/").toString(); Plivo.init(authId, authToken); Plivo.getClient().setTesting(true); }
@Override protected void setUp() throws Exception { super.setUp(); RxSnappy.init(getContext()); mockWebServer = new MockWebServer(); mockWebServer.start(9812); OkHttpClient okHttpClient = new OkHttpClient(); RestAdapter restAdapter = new RestAdapter.Builder() .setClient(new OkClient(okHttpClient)) .setEndpoint(mockWebServer.getUrl("/").toString()) .build(); testRestAdapter = restAdapter.create(TestRestAdapter.class); rxSnappyClient = new RxSnappyClient(); }
@Before public void setup() { Robolectric.getBackgroundThreadScheduler().reset(); Robolectric.getForegroundThreadScheduler().reset(); ShadowLog.stream = System.out; activity = Robolectric.buildActivity(MockMainActivity.class).create().start().resume().visible().get(); shadowOf(activity).grantPermissions("android.permission.INTERNET"); server= new MockWebServer(); try { server.start(); HttpUrl url= server.url("/"); UTConstants.REQUEST_BASE_URL_UT = url.toString(); System.out.println(UTConstants.REQUEST_BASE_URL_UT); ShadowSettings.setTestURL(url.toString()); } catch (IOException e) { System.out.print("IOException"); } bgScheduler = Robolectric.getBackgroundThreadScheduler(); uiScheduler = Robolectric.getForegroundThreadScheduler(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); bgScheduler.pause(); uiScheduler.pause(); }
@Before public void setup() { Robolectric.getBackgroundThreadScheduler().reset(); Robolectric.getForegroundThreadScheduler().reset(); ShadowLog.stream = System.out; activity = Robolectric.buildActivity(MockMainActivity.class).create().start().resume().visible().get(); shadowOf(activity).grantPermissions("android.permission.INTERNET"); server= new MockWebServer(); try { server.start(); HttpUrl url= server.url("/"); UTConstants.REQUEST_BASE_URL_UT = url.toString(); System.out.println(UTConstants.REQUEST_BASE_URL_UT); ShadowSettings.setTestURL(url.toString()); TestResponsesUT.setTestURL(url.toString()); } catch (IOException e) { System.out.print("IOException"); } bgScheduler = Robolectric.getBackgroundThreadScheduler(); uiScheduler = Robolectric.getForegroundThreadScheduler(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); bgScheduler.pause(); uiScheduler.pause(); }