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


Java MockWebServer.enqueue方法代碼示例

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


在下文中一共展示了MockWebServer.enqueue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testDeleteComment

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

    server.enqueue(new MockResponse().setResponseCode(204));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
        
        final RequestStatus success = baseApi.commentsApi().delete(projectKey, repoKey, 101, 1, 1);
        assertThat(success).isNotNull();
        assertThat(success.value()).isTrue();
        assertThat(success.errors()).isEmpty();
        
        final Map<String, ?> queryParams = ImmutableMap.of("version", 1);
        assertSent(server, "DELETE", restApiPath + BitbucketApiMetadata.API_VERSION
                + "/projects/PRJ/repos/my-repo/pull-requests/101/comments/1", queryParams);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:19,代碼來源:CommentsApiMockTest.java

示例2: testUpdateBranchModelConfiguration

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

    server.enqueue(new MockResponse().setBody(payloadFromResource("/branch-model-configuration.json")).setResponseCode(200));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
        
        final BranchConfiguration branchConfiguration = BranchConfiguration.create(testKeyword, false);
        final List<Type> types = Lists.newArrayList(Type.create(Type.TypeId.BUGFIX, testKeyword, testKeyword, true));

        final CreateBranchModelConfiguration bcm = CreateBranchModelConfiguration.create(branchConfiguration, null, types);

        final BranchModelConfiguration configuration = baseApi.branchApi().updateModelConfiguration(projectKey, repoKey, bcm);
        assertThat(configuration).isNotNull();
        assertThat(configuration.errors().isEmpty()).isTrue();
        assertThat(configuration.types().size() > 0).isTrue();
        assertSent(server, "PUT", localRestPath + BitbucketApiMetadata.API_VERSION
                + localProjectsPath + projectKey + localReposPath + repoKey + branchModelPath);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:22,代碼來源:BranchApiMockTest.java

示例3: testCreateComment

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

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

        final Parent parent = Parent.create(1);
        final Anchor anchor = Anchor.create(1, Anchor.LineType.CONTEXT, Anchor.FileType.FROM, "path/to/file", "path/to/file");
        final CreateComment createComment = CreateComment.create(measuredReplyKeyword, parent, anchor);
        final Comments pr = baseApi.commentsApi().create(projectKey, repoKey, 101, createComment);
        assertThat(pr).isNotNull();
        assertThat(pr.errors()).isEmpty();
        assertThat(pr.text()).isEqualTo(measuredReplyKeyword);
        assertThat(pr.links()).isNull();
        assertSent(server, "POST", restApiPath + BitbucketApiMetadata.API_VERSION
                + "/projects/PRJ/repos/my-repo/pull-requests/101/comments");
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:21,代碼來源:CommentsApiMockTest.java

示例4: testUpdateBranchesPermissions

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

    server.enqueue(new MockResponse().setResponseCode(204));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {

        final List<String> groupPermission = new ArrayList<>();
        groupPermission.add("Test12354");
        final List<Long> listAccessKey = new ArrayList<>();
        listAccessKey.add(123L);
        final List<BranchRestriction> listBranchPermission = new ArrayList<>();
        listBranchPermission.add(BranchRestriction.createWithId(839L, BranchRestrictionEnumType.FAST_FORWARD_ONLY,
                Matcher.create(Matcher.MatcherId.RELEASE, true), new ArrayList<User>(), groupPermission,
                listAccessKey));

        final RequestStatus success = baseApi.branchApi().createBranchRestriction(projectKey, repoKey, listBranchPermission);
        assertThat(success).isNotNull();
        assertThat(success.value()).isTrue();
        assertThat(success.errors()).isEmpty();
        assertSent(server, "POST", branchPermissionsPath
                + localProjectsPath + projectKey + localReposPath + repoKey + "/restrictions");
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:26,代碼來源:BranchApiMockTest.java

示例5: 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

示例6: testListBranchesPermissionsNonExistent

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

    server.enqueue(new MockResponse().setBody(payloadFromResource("/branch-permission-list-error.json")).setResponseCode(404));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
        
        final BranchRestrictionPage branch = baseApi.branchApi().listBranchRestriction(projectKey, repoKey, null, 1);
        assertThat(branch).isNotNull();
        assertThat(branch.errors().size() > 0).isTrue();

        final Map<String, ?> queryParams = ImmutableMap.of(localLimit, 1);
        assertSent(server, localGetMethod, branchPermissionsPath
                + localProjectsPath + projectKey + localReposPath + repoKey + "/restrictions", queryParams);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:18,代碼來源:BranchApiMockTest.java

示例7: testGetBranchModelConfiguration

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

    server.enqueue(new MockResponse().setBody(payloadFromResource("/branch-model-configuration.json")).setResponseCode(200));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
        
        final BranchModelConfiguration configuration = baseApi.branchApi().getModelConfiguration(projectKey, repoKey);
        assertThat(configuration).isNotNull();
        assertThat(configuration.errors().isEmpty()).isTrue();
        assertThat(configuration.types().size() > 0).isTrue();
        assertThat(configuration.development().refId().equals("refs/heads/master")).isTrue();
        assertThat(configuration.production()).isNull();
        assertSent(server, localGetMethod, localRestPath + BitbucketApiMetadata.API_VERSION
                + localProjectsPath + projectKey + localReposPath + repoKey + branchModelPath);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:19,代碼來源:BranchApiMockTest.java

示例8: testCreateBranch

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

    server.enqueue(new MockResponse().setBody(payloadFromResource("/branch.json")).setResponseCode(200));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
        
        final String branchName = "dev-branch";
        final String commitHash = "8d351a10fb428c0c1239530256e21cf24f136e73";

        final CreateBranch createBranch = CreateBranch.create(branchName, commitHash, null);
        final Branch branch = baseApi.branchApi().create(projectKey, repoKey, createBranch);
        assertThat(branch).isNotNull();
        assertThat(branch.errors().isEmpty()).isTrue();
        assertThat(branch.id().endsWith(branchName)).isTrue();
        assertThat(commitHash.equalsIgnoreCase(branch.latestChangeset())).isTrue();
        assertSent(server, "POST", localRestPath + BitbucketApiMetadata.API_VERSION
                + localProjectsPath + projectKey + localReposPath + repoKey + localBranchesPath);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:22,代碼來源:BranchApiMockTest.java

示例9: testListBranchesNonExistent

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

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

        final BranchPage branch = baseApi.branchApi().list(projectKey, repoKey, null, null, null, null, null, 1);
        assertThat(branch).isNotNull();
        assertThat(branch.errors().size() > 0).isTrue();
        final List<Veto> vetoes = branch.errors().get(0).vetoes();
        assertThat(vetoes.size() > 0).isTrue();
        assertThat(vetoes.get(0).summaryMessage()).isEqualTo("some short message");
        assertThat(vetoes.get(0).detailedMessage()).isEqualTo("some detailed message");
        final Map<String, ?> queryParams = ImmutableMap.of("limit", 1);
        assertSent(server, "GET", "/rest/api/" + BitbucketApiMetadata.API_VERSION
                + localProjectsPath + projectKey + localReposPath + repoKey + "/branches", queryParams);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:21,代碼來源:BranchApiMockTest.java

示例10: 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

示例11: testListCommitsOnError

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

    server.enqueue(new MockResponse().setBody(payloadFromResource("/commit-error.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()).isNotEmpty();

        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,代碼行數:19,代碼來源:CommitsApiMockTest.java

示例12: testComment

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

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

        final Comments pr = baseApi.commentsApi().comment(projectKey, repoKey, 101, measuredReplyKeyword);
        assertThat(pr).isNotNull();
        assertThat(pr.errors()).isEmpty();
        assertThat(pr.text()).isEqualTo(measuredReplyKeyword);
        assertThat(pr.links()).isNull();
        assertSent(server, "POST", restApiPath + BitbucketApiMetadata.API_VERSION
                + "/projects/PRJ/repos/my-repo/pull-requests/101/comments");
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:18,代碼來源:CommentsApiMockTest.java

示例13: testCreateProjectWithIllegalName

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

    server.enqueue(new MockResponse()
            .setBody(payloadFromResource("/project-create-fail.json"))
            .setResponseCode(400));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
        
        final String projectKey = "9999";
        final CreateProject createProject = CreateProject.create(projectKey, null, null, null);
        final Project project = baseApi.projectApi().create(createProject);
        
        assertThat(project).isNotNull();
        assertThat(project.errors()).isNotEmpty();
        assertSent(server, "POST", restBasePath + BitbucketApiMetadata.API_VERSION + localPath);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:20,代碼來源:ProjectApiMockTest.java

示例14: testGetProject

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

    server.enqueue(new MockResponse()
            .setBody(payloadFromResource("/project.json"))
            .setResponseCode(200));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
        
        final String projectKey = "HELLO";
        final Project project = baseApi.projectApi().get(projectKey);
        
        assertThat(project).isNotNull();
        assertThat(project.errors()).isEmpty();
        assertThat(project.key()).isEqualToIgnoringCase(projectKey);
        assertThat(project.links()).isNotNull();
        assertSent(server, localMethod, restBasePath + BitbucketApiMetadata.API_VERSION + localPath + "/" + projectKey);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:21,代碼來源:ProjectApiMockTest.java

示例15: testGetBranchModelConfigurationOnError

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

    server.enqueue(new MockResponse().setBody(payloadFromResource("/branch-model-configuration-error.json")).setResponseCode(404));
    try (final BitbucketApi baseApi = api(server.getUrl("/"))) {
        
        final BranchModelConfiguration configuration = baseApi.branchApi().getModelConfiguration(projectKey, repoKey);
        assertThat(configuration).isNotNull();
        assertThat(configuration.errors()).isNotEmpty();
        assertThat(configuration.production()).isNull();
        assertThat(configuration.development()).isNull();
        assertSent(server, localGetMethod, localRestPath + BitbucketApiMetadata.API_VERSION
                + localProjectsPath + projectKey + localReposPath + repoKey + branchModelPath);
    } finally {
        server.shutdown();
    }
}
 
開發者ID:cdancy,項目名稱:bitbucket-rest,代碼行數:18,代碼來源:BranchApiMockTest.java


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