當前位置: 首頁>>代碼示例>>Java>>正文


Java MockWebServer.url方法代碼示例

本文整理匯總了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();
}
 
開發者ID:appnexus,項目名稱:mobile-sdk-android,代碼行數:26,代碼來源:BaseRoboTest.java

示例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());
}
 
開發者ID:andrey7mel,項目名稱:android-step-by-step,代碼行數:27,代碼來源:IntegrationApiModule.java

示例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);
}
 
開發者ID:kpi-ua,項目名稱:ecampus-client-android,代碼行數:22,代碼來源:UserServiceTest.java

示例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();
}
 
開發者ID:appnexus,項目名稱:mobile-sdk-android,代碼行數:25,代碼來源:BaseRoboTest.java

示例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());
}
 
開發者ID:andrey7mel,項目名稱:android-step-by-step,代碼行數:29,代碼來源:ApiInterfaceTest.java

示例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);
}
 
開發者ID:andrey7mel,項目名稱:android-simple-architecture,代碼行數:33,代碼來源:ApiInterfaceTest.java

示例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());
}
 
開發者ID:SeaCloudsEU,項目名稱:SeaCloudsPlatform,代碼行數:10,代碼來源:AbstractProxyTest.java

示例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);
}
 
開發者ID:kpi-ua,項目名稱:ecampus-client-android,代碼行數:42,代碼來源:BulletinServiceTest.java

示例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();

}
 
開發者ID:SeaCloudsEU,項目名稱:SeaCloudsPlatform,代碼行數:54,代碼來源:NuroMetricTest.java

示例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);
    

}
 
開發者ID:SeaCloudsEU,項目名稱:SeaCloudsPlatform,代碼行數:21,代碼來源:ModuleAvailabilityTest.java


注:本文中的com.squareup.okhttp.mockwebserver.MockWebServer.url方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。