Search in sources :

Example 6 with BitbucketScmSaveFileRequest

use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.BitbucketScmSaveFileRequest in project blueocean-plugin by jenkinsci.

the class BitbucketServerScmContentProviderTest method handleSaveErrorsWithEmptyStatusLine.

@Test
public void handleSaveErrorsWithEmptyStatusLine() throws UnirestException, IOException {
    String credentialId = createCredential(BitbucketServerScm.ID);
    StaplerRequest staplerRequest = mockStapler();
    MultiBranchProject mbp = mockMbp(credentialId);
    GitContent content = new GitContent.Builder().autoCreateBranch(true).base64Data("bm9kZXsKICBlY2hvICdoZWxsbyB3b3JsZCEnCn0K").branch("master").message("new commit").owner("TESTP").path("SomeFile").repo("pipeline-demo-test").build();
    when(staplerRequest.bindJSON(Mockito.eq(BitbucketScmSaveFileRequest.class), Mockito.any(JSONObject.class))).thenReturn(new BitbucketScmSaveFileRequest(content));
    String request = "{\n" + "  \"content\" : {\n" + "    \"message\" : \"new commit\",\n" + "    \"path\" : \"SomeFile\",\n" + "    \"branch\" : \"master\",\n" + "    \"repo\" : \"pipeline-demo-test\",\n" + "    \"base64Data\" : " + "\"bm9kZXsKICBlY2hvICdoZWxsbyB3b3JsZCEnCn0K\"" + "  }\n" + "}";
    when(staplerRequest.getReader()).thenReturn(new BufferedReader(new StringReader(request), request.length()));
    try {
        // Should get mocked response from:
        // bitbucket_rest_api_10_projects_testp_repos_pipeline-demo-test_browse_somefile-7269cd83-1af6-4134-9161-82360d678dcc.json
        new BitbucketServerScmContentProvider().saveContent(staplerRequest, mbp);
    } catch (ServiceException e) {
        assertEquals("File editing canceled for 'SomeFile' on 'master'.", e.getMessage());
        return;
    }
    fail("Should have failed with message: File editing canceled for 'SomeFile' on 'master'.");
}
Also used : JSONObject(net.sf.json.JSONObject) ServiceException(io.jenkins.blueocean.commons.ServiceException) StaplerRequest(org.kohsuke.stapler.StaplerRequest) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) BitbucketScmSaveFileRequest(io.jenkins.blueocean.blueocean_bitbucket_pipeline.BitbucketScmSaveFileRequest) MultiBranchProject(jenkins.branch.MultiBranchProject) GitContent(io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

BitbucketScmSaveFileRequest (io.jenkins.blueocean.blueocean_bitbucket_pipeline.BitbucketScmSaveFileRequest)6 GitContent (io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent)6 BufferedReader (java.io.BufferedReader)6 StringReader (java.io.StringReader)6 MultiBranchProject (jenkins.branch.MultiBranchProject)6 JSONObject (net.sf.json.JSONObject)6 Test (org.junit.Test)6 StaplerRequest (org.kohsuke.stapler.StaplerRequest)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ServiceException (io.jenkins.blueocean.commons.ServiceException)3 ScmFile (io.jenkins.blueocean.rest.impl.pipeline.scm.ScmFile)3 User (hudson.model.User)2 Mailer (hudson.tasks.Mailer)2