com.squareup.okhttp.mockwebserver.MockWebServer Java Examples

The following examples show how to use com.squareup.okhttp.mockwebserver.MockWebServer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InsightsApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
public void testDeleteAnnotation() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final String reportKey = qwertyKeyword;
        final RequestStatus success = baseApi.insightsApi().deleteAnnotation(projectKey, repoKey, commitHash, reportKey, null);
        assertThat(success).isNotNull();
        assertThat(success.value()).isTrue();
        assertThat(success.errors()).isEmpty();

        assertSent(server,
                   deleteMethod,
                   restApiPath + BitbucketApiMetadata.API_VERSION
                       + projectsKeyword + projectKey
                       + repoKeyword + repoKey
                       + commitKeyword + commitHash
                       + reportsKeyword + "/" + reportKey
                       + annotationsKeyword);
    } finally {
        server.shutdown();
    }
}
 
Example #2
Source File: BranchApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
public void testGetBranchInfo() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final BranchPage branchPage = baseApi.branchApi().info(projectKey, repoKey, commitId);
        assertThat(branchPage).isNotNull();
        assertThat(branchPage.errors().isEmpty()).isTrue();
        assertThat(branchPage.size() > 0).isTrue();
        assertSent(server, localGetMethod, localRestPath + BitbucketApiMetadata.API_VERSION
                + localProjectsPath + projectKey + localReposPath + repoKey + localInfoPath + "/" + commitId);
    } finally {
        server.shutdown();
    }
}
 
Example #3
Source File: BranchApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #4
Source File: SyncApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
public void testStatusAt() throws Exception {
    final MockWebServer server = mockWebServer();
    server.enqueue(new MockResponse().setBody(payloadFromResource("/sync-enabled.json")).setResponseCode(200));

    try (final BitbucketApi baseApi = api(server.getUrl("/"));) {

        final SyncStatus status = baseApi.syncApi().status(projectKey, repoKey, "somereference");
        assertThat(status.available()).isTrue();
        assertThat(status.enabled()).isTrue();
        assertThat(status.divergedRefs()).isNotEmpty();
        assertThat(status.divergedRefs().get(0).state()).isEqualTo("DIVERGED");
        assertThat(status.errors()).isEmpty();

        final Map<String, ?> queryParams = ImmutableMap.of("at", "somereference");
        assertSent(server, "GET", restApiPath + BitbucketApiMetadata.API_VERSION + syncPath, queryParams);
    } finally {
        server.shutdown();
    }
}
 
Example #5
Source File: BranchApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
public void testDeleteBranchModelConfiguration() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final RequestStatus success = baseApi.branchApi().deleteModelConfiguration(projectKey, repoKey);
        assertThat(success).isNotNull();
        assertThat(success.value()).isTrue();
        assertThat(success.errors()).isEmpty();
        assertSent(server, localDeleteMethod, localRestPath + BitbucketApiMetadata.API_VERSION
                + localProjectsPath + projectKey + localReposPath + repoKey + branchModelPath);
    } finally {
        server.shutdown();
    }
}
 
Example #6
Source File: SyncApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
public void testDisabled() throws Exception {
    final MockWebServer server = mockWebServer();
    server.enqueue(new MockResponse().setResponseCode(204));

    try (final BitbucketApi baseApi = api(server.getUrl("/"));) {

        final SyncStatus status = baseApi.syncApi().enable(projectKey, repoKey, true);
        assertThat(status.available()).isTrue();
        assertThat(status.enabled()).isFalse();
        assertThat(status.divergedRefs()).isEmpty();
        assertThat(status.errors()).isEmpty();

        assertSent(server, postMethod, restApiPath + BitbucketApiMetadata.API_VERSION + syncPath);
    } finally {
        server.shutdown();
    }
}
 
Example #7
Source File: AdminApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #8
Source File: AdminApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #9
Source File: SyncApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
public void testEnabled() throws Exception {
    final MockWebServer server = mockWebServer();
    server.enqueue(new MockResponse().setBody(payloadFromResource("/sync-enabled.json")).setResponseCode(200));

    try (final BitbucketApi baseApi = api(server.getUrl("/"));) {

        final SyncStatus status = baseApi.syncApi().enable(projectKey, repoKey, true);
        assertThat(status.available()).isTrue();
        assertThat(status.enabled()).isTrue();
        assertThat(status.divergedRefs()).isNotEmpty();
        assertThat(status.divergedRefs().get(0).state()).isEqualTo("DIVERGED");
        assertThat(status.errors()).isEmpty();

        assertSent(server, postMethod, restApiPath + BitbucketApiMetadata.API_VERSION + syncPath);
    } finally {
        server.shutdown();
    }
}
 
Example #10
Source File: BuildStatusApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
public void testGetStatus() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final Map<String, ?> queryParams = ImmutableMap.of("limit", 100, "start", 0);
        assertSent(server, "GET", restBuildStatusPath + BitbucketApiMetadata.API_VERSION
                + commitPath, queryParams);
    } finally {
        server.shutdown();
    }
}
 
Example #11
Source File: BuildStatusApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #12
Source File: BuildStatusApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #13
Source File: DenominatorD.java    From denominator with Apache License 2.0 6 votes vote down vote up
static void setupLogging() {
  final long start = currentTimeMillis();
  ConsoleHandler handler = new ConsoleHandler();
  handler.setLevel(Level.FINE);
  handler.setFormatter(new Formatter() {
    @Override
    public String format(LogRecord record) {
      return String.format("%7d - %s%n", record.getMillis() - start, record.getMessage());
    }
  });

  Logger[] loggers = {
      Logger.getLogger(DenominatorD.class.getPackage().getName()),
      Logger.getLogger(feign.Logger.class.getName()),
      Logger.getLogger(MockWebServer.class.getName())
  };

  for (Logger logger : loggers) {
    logger.setLevel(Level.FINE);
    logger.setUseParentHandlers(false);
    logger.addHandler(handler);
  }
}
 
Example #14
Source File: BuildStatusApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #15
Source File: InsightsApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
public void testDeleteReport() throws Exception {
    final MockWebServer server = mockWebServer();

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

        final String reportKey = qwertyKeyword;
        final RequestStatus success = baseApi.insightsApi().deleteReport(projectKey, repoKey, commitHash, reportKey);
        assertThat(success).isNotNull();
        assertThat(success.value()).isTrue();
        assertThat(success.errors()).isEmpty();

        assertSent(server,
                   deleteMethod,
                   restApiPath + BitbucketApiMetadata.API_VERSION
                       + projectsKeyword + projectKey + repoKeyword + repoKey + commitKeyword + commitHash + reportsKeyword + "/" + reportKey);
    } finally {
        server.shutdown();
    }
}
 
Example #16
Source File: BranchApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #17
Source File: CommitsApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #18
Source File: CommitsApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #19
Source File: CommentsApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #20
Source File: CommitsApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #21
Source File: CommentsApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
public void testGetCommentOnError() 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 Comments pr = baseApi.commentsApi().get(projectKey, repoKey, 101, 1);
        assertThat(pr).isNotNull();
        assertThat(pr.errors()).isNotEmpty();

        assertSent(server, getMethod, restApiPath + BitbucketApiMetadata.API_VERSION
                + "/projects/PRJ/repos/my-repo/pull-requests/101/comments/1");
    } finally {
        server.shutdown();
    }
}
 
Example #22
Source File: CommitsApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #23
Source File: ProjectApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #24
Source File: BranchApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #25
Source File: ProjectApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #26
Source File: ProjectApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #27
Source File: ProjectApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #28
Source File: ProjectApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #29
Source File: ProjectApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #30
Source File: BranchApiMockTest.java    From bitbucket-rest with Apache License 2.0 6 votes vote down vote up
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();
    }
}