Java 类com.squareup.okhttp.mockwebserver.MockWebServer 实例源码

项目:mobile-sdk-android    文件:BaseRoboTest.java   
@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();
}
项目:prebid-mobile-android    文件:BaseSetup.java   
@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();
    }
项目:delta-sdk-java    文件:DeltaApiClientTest.java   
@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);
}
项目:delta-sdk-java    文件:AuthorizationUtilTest.java   
@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();
}
项目:bitbucket-rest    文件:AdminApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:AdminApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:BuildStatusApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:BuildStatusApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:BuildStatusApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:BuildStatusApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:CommitsApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:CommitsApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:CommitsApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:CommitsApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:CommitsApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:CommitsApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:ProjectApiMockTest.java   
public void testCreateProject() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final String projectKey = "HELLO";
        final CreateProject createProject = CreateProject.create(projectKey, null, null, null);
        final Project project = baseApi.projectApi().create(createProject);

        assertThat(project).isNotNull();
        assertThat(project.errors()).isEmpty();
        assertThat(project.key()).isEqualToIgnoringCase(projectKey);
        assertThat(project.name()).isEqualToIgnoringCase(projectKey);
        assertThat(project.links()).isNotNull();
        assertSent(server, "POST", restBasePath + BitbucketApiMetadata.API_VERSION + localPath);
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:ProjectApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:ProjectApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:ProjectApiMockTest.java   
public void testGetProjectNonExistent() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final String projectKey = "HelloWorld";
        final Project project = baseApi.projectApi().get(projectKey);

        assertThat(project).isNotNull();
        assertThat(project.errors()).isNotEmpty();
        assertSent(server, localMethod, restBasePath + BitbucketApiMetadata.API_VERSION + localPath + "/" + projectKey);
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:ProjectApiMockTest.java   
public void testDeleteProject() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final String projectKey = "HELLO";
        final RequestStatus success = baseApi.projectApi().delete(projectKey);
        assertThat(success).isNotNull();
        assertThat(success.value()).isTrue();
        assertThat(success.errors()).isEmpty();
        assertSent(server, "DELETE", "/rest/api/" + BitbucketApiMetadata.API_VERSION + "/projects/" + projectKey);
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:ProjectApiMockTest.java   
public void testDeleteProjectNonExistent() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final String projectKey = "NOTEXIST";
        final RequestStatus success = baseApi.projectApi().delete(projectKey);
        assertThat(success).isNotNull();
        assertThat(success.value()).isFalse();
        assertThat(success.errors()).isNotEmpty();
        assertSent(server, "DELETE", "/rest/api/" + BitbucketApiMetadata.API_VERSION + "/projects/" + projectKey);
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:ProjectApiMockTest.java   
public void testGetProjectList() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final ProjectPage projectPage = baseApi.projectApi().list(null, null, null, null);

        assertThat(projectPage).isNotNull();
        assertThat(projectPage.errors()).isEmpty();

        assertThat(projectPage.size()).isLessThanOrEqualTo(projectPage.limit());
        assertThat(projectPage.start()).isEqualTo(0);
        assertThat(projectPage.isLastPage()).isTrue();

        assertThat(projectPage.values()).hasSize(projectPage.size());
        assertThat(projectPage.values()).hasOnlyElementsOfType(Project.class);
        assertSent(server, localMethod, restBasePath + BitbucketApiMetadata.API_VERSION + localPath);
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:ProjectApiMockTest.java   
public void testGetProjectListNonExistent() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final ProjectPage projectPage = baseApi.projectApi().list(null, null, null, null);

        assertThat(projectPage).isNotNull();
        assertThat(projectPage.errors()).isNotEmpty();
        assertSent(server, localMethod, restBasePath + BitbucketApiMetadata.API_VERSION + localPath);
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:DefaultReviewersApiMockTest.java   
public void testListConditions() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final List<Condition> conditions = baseApi.defaultReviewersApi().listConditions(projectKey, repoKey);
        assertThat(conditions).isNotNull();
        assertThat(conditions.size()).isEqualTo(3);

        assertSent(server, "GET", defaultReviewersPath + BitbucketApiMetadata.API_VERSION
                + projectsPath + projectKey + reposPath + repoKey + "/conditions");
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:DefaultReviewersApiMockTest.java   
public void testCreateCondition() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final Long requiredApprover = 1L;
        final Matcher matcherSrc = Matcher.create(Matcher.MatcherId.ANY, true);
        final Matcher matcherDst = Matcher.create(Matcher.MatcherId.ANY, true);
        final List<User> listUser = new ArrayList<>();
        listUser.add(User.create(projectKey, testEmail, 1, projectKey, true, projectKey, normalKeyword));
        final CreateCondition condition = CreateCondition.create(null, matcherSrc, matcherDst, listUser, requiredApprover);

        final Condition returnCondition = baseApi.defaultReviewersApi().createCondition(projectKey, repoKey, condition);
        assertThat(returnCondition).isNotNull();
        assertThat(returnCondition.errors()).isEmpty();
        assertThat(returnCondition.id()).isEqualTo(3L);

        assertSent(server, "POST", defaultReviewersPath + BitbucketApiMetadata.API_VERSION
                + projectsPath + projectKey + reposPath + repoKey + "/condition");
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:DefaultReviewersApiMockTest.java   
public void testCreateConditionOnError() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final Long requiredApprover = 1L;
        final Matcher matcherSrc = Matcher.create(Matcher.MatcherId.ANY, true);
        final Matcher matcherDst = Matcher.create(Matcher.MatcherId.ANY, true);
        final List<User> listUser = new ArrayList<>();
        listUser.add(User.create(projectKey, testEmail, 1, projectKey, true, projectKey, normalKeyword));
        final CreateCondition condition = CreateCondition.create(null, matcherSrc, matcherDst, listUser, requiredApprover);

        final Condition returnCondition = baseApi.defaultReviewersApi().createCondition(projectKey, "123456", condition);
        assertThat(returnCondition).isNotNull();
        assertThat(returnCondition.errors()).isNotEmpty();
        assertThat(returnCondition.errors().size()).isEqualTo(1);

        assertSent(server, "POST", defaultReviewersPath + BitbucketApiMetadata.API_VERSION
                + projectsPath + projectKey + "/repos/123456/condition");
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:DefaultReviewersApiMockTest.java   
public void testUpdateCondition() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final Long requiredApprover = 1L;
        final Matcher matcherSrc = Matcher.create(Matcher.MatcherId.ANY, true);
        final Matcher matcherDst = Matcher.create(Matcher.MatcherId.ANY, true);
        final List<User> listUser = new ArrayList<>();
        listUser.add(User.create(projectKey, testEmail, 1, projectKey, true, projectKey, normalKeyword));
        final CreateCondition condition = CreateCondition.create(10L, matcherSrc, matcherDst, listUser, requiredApprover);

        final Condition returnCondition = baseApi.defaultReviewersApi().updateCondition(projectKey, repoKey, 10L, condition);
        assertThat(returnCondition).isNotNull();
        assertThat(returnCondition.errors()).isEmpty();
        assertThat(returnCondition.id()).isEqualTo(3L);

        assertSent(server, "PUT", defaultReviewersPath + BitbucketApiMetadata.API_VERSION
                + projectsPath + projectKey + reposPath + repoKey + "/condition/10");
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:DefaultReviewersApiMockTest.java   
public void testUpdateConditionOnError() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final Long requiredApprover = 1L;
        final Matcher matcherSrc = Matcher.create(Matcher.MatcherId.ANY, true);
        final Matcher matcherDst = Matcher.create(Matcher.MatcherId.ANY, true);
        final List<User> listUser = new ArrayList<>();
        listUser.add(User.create(projectKey, testEmail, 1, projectKey, true, projectKey, normalKeyword));
        final CreateCondition condition = CreateCondition.create(10L, matcherSrc, matcherDst, listUser, requiredApprover);

        final Condition returnCondition = baseApi.defaultReviewersApi().updateCondition(projectKey, "123456", 10L, condition);
        assertThat(returnCondition).isNotNull();
        assertThat(returnCondition.errors()).isNotEmpty();
        assertThat(returnCondition.errors().size()).isEqualTo(1);

        assertSent(server, "PUT", defaultReviewersPath + BitbucketApiMetadata.API_VERSION
                + projectsPath + projectKey + "/repos/123456/condition/10");
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:DefaultReviewersApiMockTest.java   
public void testDeleteCondition() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final RequestStatus success = baseApi.defaultReviewersApi().deleteCondition(projectKey, repoKey, 10L);
        assertThat(success).isNotNull();
        assertThat(success.value()).isTrue();
        assertThat(success.errors()).isEmpty();
        assertSent(server, "DELETE", defaultReviewersPath + BitbucketApiMetadata.API_VERSION
                + projectsPath + projectKey + reposPath + repoKey + "/condition/10");
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:DefaultReviewersApiMockTest.java   
public void testDeleteConditionOnError() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final RequestStatus success = baseApi.defaultReviewersApi().deleteCondition(projectKey, repoKey, 10L);
        assertThat(success).isNotNull();
        assertThat(success.value()).isFalse();
        assertThat(success.errors()).isNotEmpty();
        assertSent(server, "DELETE", defaultReviewersPath + BitbucketApiMetadata.API_VERSION
                + projectsPath + projectKey + reposPath + repoKey + "/condition/10");
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:BranchApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:BranchApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:BranchApiMockTest.java   
public void testGetBranchModel() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final BranchModel branchModel = baseApi.branchApi().model(projectKey, repoKey);
        assertThat(branchModel).isNotNull();
        System.out.println(branchModel.errors());
        assertThat(branchModel.errors().isEmpty()).isTrue();
        assertThat(branchModel.types().size() > 0).isTrue();
        assertSent(server, localGetMethod, localRestPath + BitbucketApiMetadata.API_VERSION
                + localProjectsPath + projectKey + localReposPath + repoKey + "/branchmodel");
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:BranchApiMockTest.java   
public void testDeleteBranch() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final RequestStatus success = baseApi.branchApi().delete(projectKey, repoKey, "refs/heads/some-branch-name");
        assertThat(success).isNotNull();
        assertThat(success.value()).isTrue();
        assertThat(success.errors()).isEmpty();
        assertSent(server, localDeleteMethod, localRestPath + BitbucketApiMetadata.API_VERSION
                + localProjectsPath + projectKey + localReposPath + repoKey + "/branches");
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:BranchApiMockTest.java   
public void testGetDefaultBranch() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final Branch branch = baseApi.branchApi().getDefault(projectKey, repoKey);
        assertThat(branch).isNotNull();
        assertThat(branch.errors().isEmpty()).isTrue();
        assertThat(branch.id()).isNotNull();
        assertSent(server, localGetMethod, restBasePath + BitbucketApiMetadata.API_VERSION
                + localProjectsPath + projectKey + localReposPath + repoKey + localBranchesPath + "/default");
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:BranchApiMockTest.java   
public void testUpdateDefaultBranch() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final RequestStatus success = baseApi.branchApi().updateDefault(projectKey, repoKey, "refs/heads/my-new-default-branch");
        assertThat(success).isNotNull();
        assertThat(success.value()).isTrue();
        assertThat(success.errors()).isEmpty();
        assertSent(server, "PUT", "/rest/api/" + BitbucketApiMetadata.API_VERSION
                + localProjectsPath + projectKey + localReposPath + repoKey + "/branches/default");
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:BranchApiMockTest.java   
public void testListBranchePermissions() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final BranchRestrictionPage branch = baseApi.branchApi().listBranchRestriction(projectKey, repoKey, null, 1);
        assertThat(branch).isNotNull();
        assertThat(branch.errors().isEmpty()).isTrue();
        assertThat(branch.values().size() > 0).isTrue();
        assertThat(839L == branch.values().get(0).id()).isTrue();
        assertThat(2 == branch.values().get(0).accessKeys().size()).isTrue();

        final Map<String, ?> queryParams = ImmutableMap.of(localLimit, 1);
        assertSent(server, localGetMethod, branchPermissionsPath
                + localProjectsPath + projectKey + localReposPath + repoKey + "/restrictions", queryParams);
    } finally {
        server.shutdown();
    }
}
项目:bitbucket-rest    文件:BranchApiMockTest.java   
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();
    }
}
项目:bitbucket-rest    文件:BranchApiMockTest.java   
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();
    }
}