Java Code Examples for okhttp3.mockwebserver.MockWebServer#start()
The following examples show how to use
okhttp3.mockwebserver.MockWebServer#start() .
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: Benchmark.java From jus with Apache License 2.0 | 7 votes |
private MockWebServer startServer(States.GenericState state) throws IOException { Logger.getLogger(MockWebServer.class.getName()).setLevel(Level.WARNING); MockWebServer server = new MockWebServer(); if (state.tls) { SslClient sslClient = SslClient.localhost(); server.useHttps(sslClient.socketFactory, false); server.setProtocols(state.protocols); } final MockResponse response = newResponse(state); server.setDispatcher(new Dispatcher() { @Override public MockResponse dispatch(RecordedRequest request) { return response; } }); server.start(); return server; }
Example 2
Source File: FederationServerTest.java From java-stellar-sdk with Apache License 2.0 | 6 votes |
@Test public void testNameFederationSuccessWithMemo() throws IOException { MockWebServer mockWebServer = new MockWebServer(); mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(successResponseWithMemo)); mockWebServer.start(); HttpUrl baseUrl = mockWebServer.url(""); FederationServer server = new FederationServer( baseUrl.toString(), "stellar.org" ); FederationResponse response = server.resolveAddress("bob*stellar.org"); assertEquals(response.getStellarAddress(), "bob*stellar.org"); assertEquals(response.getAccountId(), "GCW667JUHCOP5Y7KY6KGDHNPHFM4CS3FCBQ7QWDUALXTX3PGXLSOEALY"); assertEquals(response.getMemoType(), "text"); assertEquals(response.getMemo(), "test"); }
Example 3
Source File: ServerTest.java From java-stellar-sdk with Apache License 2.0 | 6 votes |
@Test public void testCheckMemoRequiredWithMemo() throws IOException, AccountRequiresMemoException { MockWebServer mockWebServer = new MockWebServer(); mockWebServer.setDispatcher(buildTestCheckMemoRequiredMockDispatcher()); mockWebServer.start(); HttpUrl baseUrl = mockWebServer.url(""); Server server = new Server(baseUrl.toString()); KeyPair source = KeyPair.fromSecretSeed("SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY"); Account account = new Account(source.getAccountId(), 1L); Transaction transaction = new Transaction.Builder(account, Network.PUBLIC) .addOperation(new PaymentOperation.Builder(DESTINATION_ACCOUNT_MEMO_REQUIRED_A, new AssetTypeNative(), "10").build()) .addOperation(new PathPaymentStrictReceiveOperation.Builder(new AssetTypeNative(), "10", DESTINATION_ACCOUNT_MEMO_REQUIRED_B, new AssetTypeCreditAlphaNum4("BTC", "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2"), "5").build()) .addOperation(new PathPaymentStrictSendOperation.Builder(new AssetTypeNative(), "10", DESTINATION_ACCOUNT_MEMO_REQUIRED_C, new AssetTypeCreditAlphaNum4("BTC", "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2"), "5").build()) .addOperation(new AccountMergeOperation.Builder(DESTINATION_ACCOUNT_MEMO_REQUIRED_D).build()) .setTimeout(Transaction.Builder.TIMEOUT_INFINITE) .addMemo(new MemoText("Hello, Stellar.")) .setBaseFee(100) .build(); transaction.sign(source); server.submitTransaction(transaction); server.submitTransaction(feeBump(transaction)); }
Example 4
Source File: PushGatewayProviderTest.java From graylog-plugin-metrics-reporter with GNU General Public License v3.0 | 6 votes |
@Test public void getReturnsPushGatewayProvider() throws Exception { final MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_ACCEPTED)); server.start(); final MetricsPrometheusReporterConfiguration configuration = new MetricsPrometheusReporterConfiguration() { @Override public HostAndPort getAddress() { return HostAndPort.fromParts(server.getHostName(), server.getPort()); } }; final PushGatewayProvider provider = new PushGatewayProvider(configuration); final PushGateway pushGateway = provider.get(); pushGateway.push(CollectorRegistry.defaultRegistry, "test"); final RecordedRequest request = server.takeRequest(); assertEquals("PUT", request.getMethod()); assertEquals("/metrics/job/test", request.getPath()); assertEquals("text/plain; version=0.0.4; charset=utf-8", request.getHeader("Content-Type")); assertEquals(0L, request.getBodySize()); }
Example 5
Source File: ExchangeRateTest.java From xmrwallet with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { mockWebServer = new MockWebServer(); mockWebServer.start(); waiter = new Waiter(); MockitoAnnotations.initMocks(this); exchangeApi = new ExchangeApiImpl(okHttpClient, mockWebServer.url("/")); }
Example 6
Source File: TestQueryExecutor.java From presto with Apache License 2.0 | 5 votes |
@BeforeMethod public void setup() throws IOException { server = new MockWebServer(); server.start(); }
Example 7
Source File: FetchAccessTokenRequestExecutorTest.java From github-oauth-authorization-plugin with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { mockWebServer = new MockWebServer(); mockWebServer.start(); fetchAccessTokenRequest = mock(FetchAccessTokenRequest.class); authConfig = mock(AuthConfig.class); gitHubConfiguration = mock(GitHubConfiguration.class); when(authConfig.gitHubConfiguration()).thenReturn(gitHubConfiguration); executor = new FetchAccessTokenRequestExecutor(fetchAccessTokenRequest); }
Example 8
Source File: SettingsBlockToggleTest.java From focus-android with Mozilla Public License 2.0 | 5 votes |
@Override protected void beforeActivityLaunched() { super.beforeActivityLaunched(); Context appContext = InstrumentationRegistry.getInstrumentation() .getTargetContext() .getApplicationContext(); PreferenceManager.getDefaultSharedPreferences(appContext) .edit() .putBoolean(FIRSTRUN_PREF, true) .apply(); // This test runs on both GV and WV. // Klar is used to test Geckoview. make sure it's set to Gecko TestHelper.selectGeckoForKlar(); webServer = new MockWebServer(); try { webServer.enqueue(new MockResponse() .setBody(TestHelper.readTestAsset("plain_test.html"))); webServer.enqueue(new MockResponse() .setBody(TestHelper.readTestAsset("plain_test.html"))); webServer.start(); } catch (IOException e) { throw new AssertionError("Could not start web server", e); } }
Example 9
Source File: XmrToApiQueryOrderTest.java From xmrwallet with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { mockWebServer = new MockWebServer(); mockWebServer.start(); waiter = new Waiter(); MockitoAnnotations.initMocks(this); xmrToApi = new XmrToApiImpl(okHttpClient, mockWebServer.url("/")); }
Example 10
Source File: AbstractTestMainActivity.java From vb-android-app-quality with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { mMockWebServer = new MockWebServer(); try { mMockWebServer.start(Integer.parseInt(mActivityRule.getActivity().getString(R.string.port))); } catch (IOException e) { throw e; } }
Example 11
Source File: XmrToApiCreateOrderTest.java From xmrwallet with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { mockWebServer = new MockWebServer(); mockWebServer.start(); waiter = new Waiter(); MockitoAnnotations.initMocks(this); xmrToApi = new XmrToApiImpl(okHttpClient, mockWebServer.url("/")); }
Example 12
Source File: CookieHandlerTest.java From Ok2Curl with Apache License 2.0 | 5 votes |
@Before public void setUpOkHttp() throws IOException { logger = mock(FakeLogger.class); server = new MockWebServer(); server.start(); server.enqueue(new MockResponse().setBody("ok")); url = server.url("/test").toString(); }
Example 13
Source File: DirectionsWaypointTest.java From mapbox-java with MIT License | 5 votes |
@Before public void setUp() throws IOException { server = new MockWebServer(); server.setDispatcher(new okhttp3.mockwebserver.Dispatcher() { @Override public MockResponse dispatch(RecordedRequest request) throws InterruptedException { // Switch response on geometry parameter (only false supported, so nice and simple) String resource = DIRECTIONS_V5_FIXTURE; if (request.getPath().contains("geometries=polyline6")) { resource = DIRECTIONS_V5_PRECISION6_FIXTURE; } if (request.getPath().contains("driving-traffic")) { resource = DIRECTIONS_TRAFFIC_FIXTURE; } if (request.getPath().contains("-77.04430")) { resource = DIRECTIONS_ROTARY_FIXTURE; } if (request.getPath().contains("annotations")) { resource = DIRECTIONS_V5_ANNOTATIONS_FIXTURE; } try { String body = loadJsonFixture(resource); return new MockResponse().setBody(body); } catch (IOException ioException) { throw new RuntimeException(ioException); } } }); server.start(); mockUrl = server.url(""); }
Example 14
Source File: ZooniverseClientTest.java From android-galaxyzoo with GNU General Public License v3.0 | 5 votes |
@Test public void testUploadWithFailure() throws IOException { final MockWebServer server = new MockWebServer(); final MockResponse response = new MockResponse(); response.setResponseCode(HttpURLConnection.HTTP_UNAUTHORIZED); response.setBody("test nonsense failure message"); server.enqueue(response); server.start(); final ZooniverseClient client = createZooniverseClient(server); final List<HttpUtils.NameValuePair> values = new ArrayList<>(); values.add(new HttpUtils.NameValuePair("test nonsense", "12345")); try { final boolean result = client.uploadClassificationSync("testAuthName", "testAuthApiKey", TEST_GROUP_ID, values); assertFalse(result); } catch (final ZooniverseClient.UploadException e) { //This is (at least with okhttp.mockwebserver) a normal //event if the upload was refused via an error response code. assertTrue(e.getCause() instanceof IOException); } server.shutdown(); }
Example 15
Source File: ITMonitoringAlerting.java From influxdb-client-java with MIT License | 5 votes |
@BeforeEach void startSlackServer() { mockServer = new MockWebServer(); try { mockServer.start(); } catch (IOException e) { throw new RuntimeException(e); } }
Example 16
Source File: ExonumHttpClientIntegrationTest.java From exonum-java-binding with Apache License 2.0 | 5 votes |
@BeforeEach void start() throws IOException { server = new MockWebServer(); server.start(); exonumClient = ExonumClient.newBuilder() .setExonumHost(server.url("/").url()) .build(); }
Example 17
Source File: MarathonBuilderImplTest.java From marathon-plugin with Apache License 2.0 | 4 votes |
@Before public void setUp() throws IOException { httpServer = new MockWebServer(); httpServer.start(); }
Example 18
Source File: MockServer.java From auth0-java with MIT License | 4 votes |
public MockServer() throws Exception { server = new MockWebServer(); server.start(); }
Example 19
Source File: NetworkBlogUrlValidatorTest.java From quill with MIT License | 4 votes |
@Before public void setupMockServer() throws IOException { server = new MockWebServer(); server.start(); }
Example 20
Source File: BaseMockServerTest.java From atlassian-jira-software-cloud-plugin with Apache License 2.0 | 4 votes |
@Before public void setup() throws IOException { super.setup(); server = new MockWebServer(); server.start(); }