use of jenkins.branch.MultiBranchProject in project blueocean-plugin by jenkinsci.
the class BitbucketServerScmContentProviderTest method unauthorizedSaveContentShouldFail.
@Test
public void unauthorizedSaveContentShouldFail() throws UnirestException, IOException {
User alice = User.get("alice");
alice.setFullName("Alice Cooper");
alice.addProperty(new Mailer.UserProperty("alice@jenkins-ci.org"));
String aliceCredentialId = createCredential(BitbucketServerScm.ID, alice);
StaplerRequest staplerRequest = mockStapler();
MultiBranchProject mbp = mockMbp(aliceCredentialId, alice);
GitContent content = new GitContent.Builder().autoCreateBranch(true).base64Data("bm9kZXsKICBlY2hvICdoZWxsbyB3b3JsZCEnCn0K").branch("master").message("new commit").owner("TESTP").path("README.md").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\" : \"README.md\",\n" + " \"branch\" : \"master\",\n" + " \"repo\" : \"pipeline-demo-test\",\n" + " \"base64Data\" : " + "\"bm9kZXsKICBlY2hvICdoZWxsbyB3b3JsZCEnCn0K\"" + " }\n" + "}";
when(staplerRequest.getReader()).thenReturn(new BufferedReader(new StringReader(request), request.length()));
try {
new BitbucketServerScmContentProvider().saveContent(staplerRequest, mbp);
} catch (ServiceException.PreconditionRequired e) {
assertEquals("Can't access content from Bitbucket: no credential found", e.getMessage());
return;
}
fail("Should have failed with PreConditionException");
}
use of jenkins.branch.MultiBranchProject in project blueocean-plugin by jenkinsci.
the class BitbucketServerScmContentProviderTest method getContent.
@Test
public void getContent() throws UnirestException, IOException {
String credentialId = createCredential(BitbucketServerScm.ID);
StaplerRequest staplerRequest = mockStapler();
MultiBranchProject mbp = mockMbp(credentialId);
ScmFile<GitContent> content = (ScmFile<GitContent>) new BitbucketServerScmContentProvider().getContent(staplerRequest, mbp);
assertEquals("Jenkinsfile", content.getContent().getName());
assertEquals("0bae0ddbed2e897d3b44abc3aca9ba26e2f61710", content.getContent().getCommitId());
assertEquals("pipeline-demo-test", content.getContent().getRepo());
assertEquals("TESTP", content.getContent().getOwner());
}
use of jenkins.branch.MultiBranchProject 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'.");
}
use of jenkins.branch.MultiBranchProject in project blueocean-plugin by jenkinsci.
the class BitbucketServerScmContentProviderTest method checkScmProperties.
@Test
public void checkScmProperties() throws Exception {
// ensure server provider works with server multibranch pipeline
String credentialId = createCredential(BitbucketServerScm.ID, authenticatedUser);
MultiBranchProject mbp = mockMbp(credentialId);
ScmContentProvider provider = new BitbucketServerScmContentProvider();
assertTrue(provider.support(mbp));
assertEquals(provider.getScmId(), BitbucketServerScm.ID);
assertEquals(provider.getApiUrl(mbp), apiUrl);
// ensure cloud provider doesn't work with server multibranch pipeline
provider = new BitbucketCloudScmContentProvider();
assertFalse(provider.support(mbp));
}
use of jenkins.branch.MultiBranchProject in project blueocean-plugin by jenkinsci.
the class BitbucketCloudScmContentProviderTest method newContent.
@Test
public void newContent() throws UnirestException, IOException {
String credentialId = createCredential(BitbucketCloudScm.ID);
StaplerRequest staplerRequest = mockStapler();
MultiBranchProject mbp = mockMbp(credentialId);
GitContent content = new GitContent.Builder().autoCreateBranch(true).base64Data("VGhpcyBpcyB0ZXN0IGNvbnRlbnQgaW4gbmV3IGZpbGUK").branch("master").message("new commit").owner(BbCloudWireMock.USER_UUID).path("foo").repo("demo1").build();
when(staplerRequest.bindJSON(Mockito.eq(BitbucketScmSaveFileRequest.class), Mockito.any(JSONObject.class))).thenReturn(new BitbucketScmSaveFileRequest(content));
String request = "{\n" + " \"content\" : {\n" + " \"message\" : \"first commit\",\n" + " \"path\" : \"foo\",\n" + " \"branch\" : \"master\",\n" + " \"repo\" : \"demo1\",\n" + " \"base64Data\" : " + "\"VGhpcyBpcyB0ZXN0IGNvbnRlbnQgaW4gbmV3IGZpbGUK\"" + " }\n" + "}";
when(staplerRequest.getReader()).thenReturn(new BufferedReader(new StringReader(request), request.length()));
ScmFile<GitContent> respContent = (ScmFile<GitContent>) new BitbucketCloudScmContentProvider().saveContent(staplerRequest, mbp);
assertEquals("foo", respContent.getContent().getName());
assertEquals(respContent.getContent().getCommitId(), respContent.getContent().getCommitId());
assertEquals("demo1", respContent.getContent().getRepo());
assertEquals(BbCloudWireMock.USER_UUID, respContent.getContent().getOwner());
assertEquals("master", respContent.getContent().getBranch());
}
Aggregations