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


Java MockWebServer類代碼示例

本文整理匯總了Java中com.squareup.okhttp.mockwebserver.MockWebServer的典型用法代碼示例。如果您正苦於以下問題:Java MockWebServer類的具體用法?Java MockWebServer怎麽用?Java MockWebServer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MockWebServer類屬於com.squareup.okhttp.mockwebserver包,在下文中一共展示了MockWebServer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: setup

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入依賴的package包/類
@Before
    public void setup() {
        activity = Robolectric.buildActivity(MockMainActivity.class).create().get();
//        activity = Robolectric.setupActivity(MockMainActivity.class);
        shadowOf(activity).grantPermissions("android.permission.INTERNET");
        server = new MockWebServer();
        try {
            server.start();
            successfulMockServerStarted = true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        FakeHttp.getFakeHttpLayer().interceptHttpRequests(true);
        FakeHttp.getFakeHttpLayer().interceptResponseContent(true);
        bgScheduler = Robolectric.getBackgroundThreadScheduler();
        uiScheduler = Robolectric.getForegroundThreadScheduler();
        Robolectric.flushBackgroundThreadScheduler();
        Robolectric.flushForegroundThreadScheduler();
        bgScheduler.pause();
        uiScheduler.pause();
    }
 
開發者ID:prebid,項目名稱:prebid-mobile-android,代碼行數:22,代碼來源:BaseSetup.java

示例3: setup

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入依賴的package包/類
@Before
public void setup() throws IOException {
    mockWebServer = new MockWebServer();
    mockWebServer.start();

    ObjectMapper objectMapper = new ObjectMapper().disable(
            MapperFeature.AUTO_DETECT_CREATORS,
            MapperFeature.AUTO_DETECT_FIELDS,
            MapperFeature.AUTO_DETECT_GETTERS,
            MapperFeature.AUTO_DETECT_IS_GETTERS)
            .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);

    DeltaApi deltaApi = new Retrofit.Builder()
            .baseUrl(mockWebServer.url("").toString())
            .addConverterFactory(JacksonConverterFactory.create(objectMapper))
            .build()
            .create(DeltaApi.class);

    apiClient = new DeltaApiClient(deltaApi);
}
 
開發者ID:Covata,項目名稱:delta-sdk-java,代碼行數:21,代碼來源:DeltaApiClientTest.java

示例4: setup

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入依賴的package包/類
@Before
public void setup() throws IOException {
    MockWebServer mockWebServer = new MockWebServer();
    mockWebServer.start();

    JacksonConverterFactory converterFactory = JacksonConverterFactory.create(new ObjectMapper());

    mockDeltaApi = new Retrofit.Builder()
            .baseUrl(mockWebServer.url(MOCK_HOST).toString())
            .addConverterFactory(converterFactory)
            .build().create(MockDeltaApi.class);

    CreateIdentityRequest createIdentityRequest =
            new CreateIdentityRequest(SIGNING_PUBLIC_KEY, ENCRYPTION_PUBLIC_KEY, null, null);
    Call<CreateIdentityResponse> call
            = mockDeltaApi.register(REQUEST_DATE,
            "example.server", IDENTITY_ID, "sampleQueryParamValue", createIdentityRequest);
    request = call.request()
            .newBuilder() // fix as okhttp removes content-type header
            .addHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString())
            .build();
}
 
開發者ID:Covata,項目名稱:delta-sdk-java,代碼行數:23,代碼來源:AuthorizationUtilTest.java

示例5: testGetListUserByGroup

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入依賴的package包/類
public void testGetListUserByGroup() throws Exception {
    final MockWebServer server = mockWebServer();

    server.enqueue(new MockResponse()
            .setBody(payloadFromResource("/admin-list-user-by-group.json"))
            .setResponseCode(200));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
        
        final UserPage up = baseApi.adminApi().listUsersByGroup(localContext, null, 0, 2);
        assertThat(up).isNotNull();
        assertThat(up.errors()).isEmpty();
        assertThat(up.size() == 2).isTrue();
        assertThat(up.values().get(0).slug().equals("bob123")).isTrue();

        final Map<String, ?> queryParams = ImmutableMap.of("context", localContext, limitKeyword, 2, startKeyword, 0);
        assertSent(server, getMethod, restApiPath + BitbucketApiMetadata.API_VERSION
                + "/admin/groups/more-members", queryParams);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:22,代碼來源:AdminApiMockTest.java

示例6: testGetListUserByGroupOnError

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入依賴的package包/類
public void testGetListUserByGroupOnError() throws Exception {
    final MockWebServer server = mockWebServer();

    server.enqueue(new MockResponse()
            .setBody(payloadFromResource("/admin-list-user-by-group-error.json"))
            .setResponseCode(401));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
        
        final UserPage up = baseApi.adminApi().listUsersByGroup(localContext, null, 0, 2);
        assertThat(up).isNotNull();
        assertThat(up.errors()).isNotEmpty();

        final Map<String, ?> queryParams = ImmutableMap.of("context", localContext, limitKeyword, 2, startKeyword, 0);
        assertSent(server, getMethod, restApiPath + BitbucketApiMetadata.API_VERSION
                + "/admin/groups/more-members", queryParams);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:20,代碼來源:AdminApiMockTest.java

示例7: testGetStatusOnError

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入依賴的package包/類
public void testGetStatusOnError() throws Exception {
    final MockWebServer server = mockWebServer();

    server.enqueue(new MockResponse().setBody(payloadFromResource("/build-status-error.json")).setResponseCode(200));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
        
        final StatusPage statusPage = baseApi.buildStatusApi().status(commitHash, 0, 100);
        assertThat(statusPage).isNotNull();
        assertThat(statusPage.values()).isEmpty();
        assertThat(statusPage.errors().size() == 1).isTrue();

        final Map<String, ?> queryParams = ImmutableMap.of("limit", 100, "start", 0);
        assertSent(server, "GET", restBuildStatusPath + BitbucketApiMetadata.API_VERSION
                + commitPath, queryParams);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:19,代碼來源:BuildStatusApiMockTest.java

示例8: testGetSummary

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入依賴的package包/類
public void testGetSummary() throws Exception {
    final MockWebServer server = mockWebServer();

    server.enqueue(new MockResponse().setBody(payloadFromResource("/build-summary.json")).setResponseCode(200));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
        
        final Summary summary = baseApi.buildStatusApi().summary(commitHash);
        assertThat(summary).isNotNull();
        assertThat(summary.failed() == 1).isTrue();
        assertThat(summary.inProgress() == 2).isTrue();
        assertThat(summary.successful() == 3).isTrue();

        assertSent(server, "GET", restBuildStatusPath + BitbucketApiMetadata.API_VERSION
                + "/commits/stats/306bcf274566f2e89f75ae6f7faf10beff38382012");
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:19,代碼來源:BuildStatusApiMockTest.java

示例9: testAddBuildStatus

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入依賴的package包/類
public void testAddBuildStatus() throws Exception {
    final MockWebServer server = mockWebServer();

    server.enqueue(new MockResponse().setBody(payloadFromResource("/build-status-post.json")).setResponseCode(204));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
        
        final CreateBuildStatus cbs = CreateBuildStatus.create(CreateBuildStatus.STATE.SUCCESSFUL, 
                                "REPO-MASTER", 
                                "REPO-MASTER-42", 
                                "https://bamboo.example.com/browse/REPO-MASTER-42", 
                                "Changes by John Doe");
        final RequestStatus success = baseApi.buildStatusApi().add(commitHash, cbs);
        assertThat(success).isNotNull();
        assertThat(success.value()).isTrue();
        assertThat(success.errors()).isEmpty();
        
        assertSent(server, "POST", restBuildStatusPath + BitbucketApiMetadata.API_VERSION
                + commitPath);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:23,代碼來源:BuildStatusApiMockTest.java

示例10: testAddBuildStatusOnError

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入依賴的package包/類
public void testAddBuildStatusOnError() throws Exception {
    final MockWebServer server = mockWebServer();

    server.enqueue(new MockResponse().setBody(payloadFromResource("/errors.json")).setResponseCode(404));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
        
        final CreateBuildStatus cbs = CreateBuildStatus.create(CreateBuildStatus.STATE.SUCCESSFUL, 
                                "REPO-MASTER", 
                                "REPO-MASTER-42", 
                                "https://bamboo.example.com/browse/REPO-MASTER-42", 
                                "Changes by John Doe");
        final RequestStatus success = baseApi.buildStatusApi().add(commitHash, cbs);
        assertThat(success).isNotNull();
        assertThat(success.value()).isFalse();
        assertThat(success.errors()).isNotEmpty();
        
        assertSent(server, "POST", restBuildStatusPath + BitbucketApiMetadata.API_VERSION
                + commitPath);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:23,代碼來源:BuildStatusApiMockTest.java

示例11: testGetCommit

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入依賴的package包/類
public void testGetCommit() throws Exception {
    final MockWebServer server = mockWebServer();

    server.enqueue(new MockResponse().setBody(payloadFromResource("/commit.json")).setResponseCode(200));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {

        final Commit commit = baseApi.commitsApi().get(projectKey, repoKey, commitHash, null);
        assertThat(commit).isNotNull();
        assertThat(commit.errors().isEmpty()).isTrue();
        assertThat(commit.id().equalsIgnoreCase(commitHash)).isTrue();

        assertSent(server, getMethod, restBasePath + BitbucketApiMetadata.API_VERSION
                + "/projects/" + projectKey + "/repos/" + repoKey + "/commits/" + commitHash);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:18,代碼來源:CommitsApiMockTest.java

示例12: testGetCommitNonExistent

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入依賴的package包/類
public void testGetCommitNonExistent() throws Exception {
    final MockWebServer server = mockWebServer();

    server.enqueue(new MockResponse().setBody(payloadFromResource("/commit-error.json")).setResponseCode(404));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {

        final Commit commit = baseApi.commitsApi().get(projectKey, repoKey, commitHash, null);
        assertThat(commit).isNotNull();
        assertThat(commit.errors().size() > 0).isTrue();

        assertSent(server, getMethod, restBasePath + BitbucketApiMetadata.API_VERSION
                + "/projects/" + projectKey + "/repos/" + repoKey + "/commits/" + commitHash);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:17,代碼來源:CommitsApiMockTest.java

示例13: testGetPullRequestChanges

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入依賴的package包/類
public void testGetPullRequestChanges() throws Exception {
    final MockWebServer server = mockWebServer();

    server.enqueue(new MockResponse()
            .setBody(payloadFromResource("/pull-request-changes.json"))
            .setResponseCode(200));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {

        final ChangePage changePage = baseApi.commitsApi().listChanges(projectKey, repoKey, commitHash, 12, null);
        assertThat(changePage).isNotNull();
        assertThat(changePage.errors()).isEmpty();
        assertThat(changePage.values()).hasSize(1);

        final Map<String, ?> queryParams = ImmutableMap.of(limitKeyword, 12);
        assertSent(server, getMethod, restApiPath + BitbucketApiMetadata.API_VERSION
                + "/projects/PRJ/repos/myrepo/commits/abcdef0123abcdef4567abcdef8987abcdef6543/changes", queryParams);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:21,代碼來源:CommitsApiMockTest.java

示例14: testGetPullRequestChangesOnError

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入依賴的package包/類
public void testGetPullRequestChangesOnError() throws Exception {
    final MockWebServer server = mockWebServer();

    server.enqueue(new MockResponse()
            .setBody(payloadFromResource("/commit-error.json"))
            .setResponseCode(404));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {

        final ChangePage changePage = baseApi.commitsApi().listChanges(projectKey, repoKey, commitHash, 1, 12);
        assertThat(changePage).isNotNull();
        assertThat(changePage.errors()).isNotEmpty();

        final Map<String, ?> queryParams = ImmutableMap.of(limitKeyword, 1, "start", 12);
        assertSent(server, getMethod, restApiPath + BitbucketApiMetadata.API_VERSION
                + "/projects/PRJ/repos/myrepo/commits/abcdef0123abcdef4567abcdef8987abcdef6543/changes", queryParams);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:20,代碼來源:CommitsApiMockTest.java

示例15: testListCommits

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入依賴的package包/類
public void testListCommits() throws Exception {
    final MockWebServer server = mockWebServer();

    server.enqueue(new MockResponse().setBody(payloadFromResource("/pull-request-commits.json"))
            .setResponseCode(200));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {

        final CommitPage pcr = baseApi.commitsApi().list(projectKey, repoKey, true, null, null, null, null, null, null, 1, null);
        assertThat(pcr).isNotNull();
        assertThat(pcr.errors()).isEmpty();
        assertThat(pcr.values()).hasSize(1);
        assertThat(pcr.totalCount()).isEqualTo(1);

        final Map<String, ?> queryParams = ImmutableMap.of("withCounts", true, limitKeyword, 1);
        assertSent(server, getMethod, restApiPath + BitbucketApiMetadata.API_VERSION
                + "/projects/PRJ/repos/myrepo/commits", queryParams);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:21,代碼來源:CommitsApiMockTest.java


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