Java Code Examples for com.squareup.okhttp.mockwebserver.MockWebServer#url()
The following examples show how to use
com.squareup.okhttp.mockwebserver.MockWebServer#url() .
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: IntegrationApiModule.java From android-step-by-step with Apache License 2.0 | 6 votes |
public ApiInterface getApiInterface(MockWebServer mockWebServer) throws IOException { mockWebServer.start(); TestUtils testUtils = new TestUtils(); final Dispatcher dispatcher = new Dispatcher() { @Override public MockResponse dispatch(RecordedRequest request) throws InterruptedException { if (request.getPath().equals("/users/" + TestConst.TEST_OWNER + "/repos")) { return new MockResponse().setResponseCode(200) .setBody(testUtils.readString("json/repos.json")); } else if (request.getPath().equals("/repos/" + TestConst.TEST_OWNER + "/" + TestConst.TEST_REPO + "/branches")) { return new MockResponse().setResponseCode(200) .setBody(testUtils.readString("json/branches.json")); } else if (request.getPath().equals("/repos/" + TestConst.TEST_OWNER + "/" + TestConst.TEST_REPO + "/contributors")) { return new MockResponse().setResponseCode(200) .setBody(testUtils.readString("json/contributors.json")); } return new MockResponse().setResponseCode(404); } }; mockWebServer.setDispatcher(dispatcher); HttpUrl baseUrl = mockWebServer.url("/"); return ApiModule.getApiInterface(baseUrl.toString()); }
Example 2
Source File: BaseRoboTest.java From mobile-sdk-android with Apache License 2.0 | 6 votes |
@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(); }
Example 3
Source File: BaseRoboTest.java From mobile-sdk-android with Apache License 2.0 | 6 votes |
@Before public void setup() { SDKSettings.setExternalExecutor(null); 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(); }
Example 4
Source File: ApiInterfaceTest.java From android-step-by-step with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { super.setUp(); server = new MockWebServer(); server.start(); final Dispatcher dispatcher = new Dispatcher() { @Override public MockResponse dispatch(RecordedRequest request) throws InterruptedException { if (request.getPath().equals("/users/" + TestConst.TEST_OWNER + "/repos")) { return new MockResponse().setResponseCode(200) .setBody(testUtils.readString("json/repos.json")); } else if (request.getPath().equals("/repos/" + TestConst.TEST_OWNER + "/" + TestConst.TEST_REPO + "/branches")) { return new MockResponse().setResponseCode(200) .setBody(testUtils.readString("json/branches.json")); } else if (request.getPath().equals("/repos/" + TestConst.TEST_OWNER + "/" + TestConst.TEST_REPO + "/contributors")) { return new MockResponse().setResponseCode(200) .setBody(testUtils.readString("json/contributors.json")); } return new MockResponse().setResponseCode(404); } }; server.setDispatcher(dispatcher); HttpUrl baseUrl = server.url("/"); apiInterface = ApiModule.getApiInterface(baseUrl.toString()); }
Example 5
Source File: AbstractProxyTest.java From SeaCloudsPlatform with Apache License 2.0 | 5 votes |
@BeforeMethod public final void setUp() throws Exception { mockWebServer = new MockWebServer(); HttpUrl serverUrl = mockWebServer.url("/"); // Override factory endpoint getProxy().setHost(serverUrl.host()); getProxy().setPort(serverUrl.port()); }
Example 6
Source File: NuroMetricTest.java From SeaCloudsPlatform with Apache License 2.0 | 4 votes |
@Test public void nuroMetricTest() throws Exception{ MockWebServer mockWebServer = new MockWebServer(); NuroMetric metric = new NuroMetric(); double sample; for(int i=0; i<=NUMBER_OF_METRICS; i++){ mockWebServer.enqueue(new MockResponse() .setBody(NuroInputExample.EXAMPLE_INPUT) .setHeader("Content-Type", MediaType.APPLICATION_JSON)); } mockWebServer.start(); HttpUrl serverUrl = mockWebServer.url("/sensor.php"); metric.setMonitoredMetric("NUROServerLastMinuteAverageRunTime"); sample = metric.getSample("http://"+serverUrl.host()+":"+serverUrl.port(), TEST_APPLICATION_USER, TEST_APPLICATION_PASSWORD).doubleValue(); Assert.assertTrue(sample == EXPECTED_LAST_MINUTE_AVERAGE_RUNTIME); metric.setMonitoredMetric("NUROServerLastMinuteAverageThroughput"); sample = metric.getSample("http://"+serverUrl.host()+":"+serverUrl.port(), TEST_APPLICATION_USER, TEST_APPLICATION_PASSWORD).doubleValue(); Assert.assertTrue(sample == EXPECTED_LAST_MINUTE_AVERAGE_THROUGHPUT); metric.setMonitoredMetric("NUROServerLastMinutePlayerCount"); sample = metric.getSample("http://"+serverUrl.host()+":"+serverUrl.port(), TEST_APPLICATION_USER, TEST_APPLICATION_PASSWORD).doubleValue(); Assert.assertTrue(sample == EXPECTED_LAST_MINUTE_PLAYER_COUNT); metric.setMonitoredMetric("NUROServerLastMinuteRequestCount"); sample = metric.getSample("http://"+serverUrl.host()+":"+serverUrl.port(), TEST_APPLICATION_USER, TEST_APPLICATION_PASSWORD).doubleValue(); Assert.assertTrue(sample == EXPECTED_LAST_MINUTE_REQUEST_COUNT); metric.setMonitoredMetric("NUROServerLastTenSecondsAverageRunTime"); sample = metric.getSample("http://"+serverUrl.host()+":"+serverUrl.port(), TEST_APPLICATION_USER, TEST_APPLICATION_PASSWORD).doubleValue(); Assert.assertTrue(sample == EXPECTED_LAST_TEN_SECONDS_AVERAGE_RUNTIME); metric.setMonitoredMetric("NUROServerLastTenSecondsAverageThroughput"); sample = metric.getSample("http://"+serverUrl.host()+":"+serverUrl.port(), TEST_APPLICATION_USER, TEST_APPLICATION_PASSWORD).doubleValue(); Assert.assertTrue(sample == EXPECTED_LAST_TEN_SECONDS_AVERAGE_THROUGHPUT); metric.setMonitoredMetric("NUROServerLastTenSecondsPlayerCount"); sample = metric.getSample("http://"+serverUrl.host()+":"+serverUrl.port(), TEST_APPLICATION_USER, TEST_APPLICATION_PASSWORD).doubleValue(); Assert.assertTrue(sample == EXPECTED_LAST_TEN_SECONDS_PLAYER_COUNT); metric.setMonitoredMetric("NUROServerLastTenSecondsRequestCount"); sample = metric.getSample("http://"+serverUrl.host()+":"+serverUrl.port(), TEST_APPLICATION_USER, TEST_APPLICATION_PASSWORD).doubleValue(); Assert.assertTrue(sample == EXPECTED_LAST_TEN_SECONDS_REQUEST_COUNT); mockWebServer.shutdown(); }
Example 7
Source File: ModuleAvailabilityTest.java From SeaCloudsPlatform with Apache License 2.0 | 4 votes |
@Test public void moduleAvailabilityTest() throws Exception { MockWebServer mockWebServer = new MockWebServer(); mockWebServer.enqueue(new MockResponse()); HttpUrl serverUrl = mockWebServer.url("/"); ModuleAvailability metric = new ModuleAvailability(); Number response = metric.getSample("http://"+serverUrl.host()+":"+serverUrl.port(), "", ""); Assert.assertEquals(response, 1); mockWebServer.shutdown(); response = metric.getSample("http://"+serverUrl.host()+":"+serverUrl.port(), "", ""); Assert.assertEquals(response, 0); }