本文整理匯總了Java中com.squareup.okhttp.mockwebserver.MockWebServer.url方法的典型用法代碼示例。如果您正苦於以下問題:Java MockWebServer.url方法的具體用法?Java MockWebServer.url怎麽用?Java MockWebServer.url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.squareup.okhttp.mockwebserver.MockWebServer
的用法示例。
在下文中一共展示了MockWebServer.url方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setup
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@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_V2 = url.toString();
System.out.println(UTConstants.REQUEST_BASE_URL_UT_V2);
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();
}
示例2: getApiInterface
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
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());
}
示例3: setUp
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@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("/account/info")) {
return new MockResponse().setResponseCode(200)
.setBody(jsonReader.readString("json/user.json"));
}
return new MockResponse().setResponseCode(404);
}
};
server.setDispatcher(dispatcher);
HttpUrl baseUrl = server.url("/");
service = ServiceCreator.createTestService(baseUrl.toString(),
UserService.class);
}
示例4: setup
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@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_V2 = url.toString();
System.out.println(UTConstants.REQUEST_BASE_URL_UT_V2);
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();
}
示例5: setUp
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@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());
}
示例6: setUp
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
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"));
} else if (request.getPath().equals("/repos/" + TestConst.TEST_OWNER + "/" + TestConst.TEST_REPO + "/branches")) {
return new MockResponse().setResponseCode(200)
.setBody(testUtils.readString("json/branches"));
} else if (request.getPath().equals("/repos/" + TestConst.TEST_OWNER + "/" + TestConst.TEST_REPO + "/contributors")) {
return new MockResponse().setResponseCode(200)
.setBody(testUtils.readString("json/contributors"));
}
return new MockResponse().setResponseCode(404);
}
};
server.setDispatcher(dispatcher);
HttpUrl baseUrl = server.url("/");
Retrofit.Builder builder = new Retrofit.Builder().
baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create());
apiInterface = builder.build().create(ApiInterface.class);
}
示例7: setUp
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@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());
}
示例8: setUp
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@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 {
String p = request.getPath();
MockResponse response = new MockResponse().setResponseCode(200);
if (p.matches("/board/all.*") ||
p.matches("/board/moderator/all.*")) {
return response.setBody(jsonReader.readString
("json/bulletins.json"));
} else if (p.equals("/board") ||
p.equals("/board/" + BULLETIN_ID)) {
return response.setBody(jsonReader.readString
("json/ok.json"));
} else if (p.equals("/board/" + BULLETIN_ID + "/recipient")) {
return response.setBody(jsonReader.readString
("json/bull_recipients.json"));
} else if (p.equals("/subdivision/" + SUBDIV_ID +
"/children")) {
return response.setBody(jsonReader.readString
("json/desc_subdivision.json"));
} else if (p.equals("/roles")) {
return response.setBody(jsonReader.readString("json/roles" +
".json"));
} else if (p.equals("/subdivision/" + SUBDIV_ID + "/group")) {
return response.setBody(jsonReader.readString
("json/groups.json"));
}
return new MockResponse().setResponseCode(404);
}
};
server.setDispatcher(dispatcher);
HttpUrl baseUrl = server.url("/");
service = ServiceCreator.createTestService(baseUrl.toString(),
BulletinService.class);
}
示例9: nuroMetricTest
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@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();
}
示例10: moduleAvailabilityTest
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@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);
}