use of io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent in project blueocean-plugin by jenkinsci.
the class GithubScmContentProviderTest method saveContentToMbpGHE.
@Test
public void saveContentToMbpGHE() throws UnirestException, IOException {
String credentialId = createGithubEnterpriseCredential();
StaplerRequest staplerRequest = mockStapler(GithubEnterpriseScm.ID);
GitContent content = new GitContent.Builder().autoCreateBranch(true).base64Data("c2xlZXAgMTUKbm9kZSB7CiAgY2hlY2tvdXQgc2NtCiAgc2ggJ2xzIC1sJwp9\\nCnNsZWVwIDE1Cg==\\n").branch("test1").message("another commit").owner("cloudbeers").path("Jankinsfile").repo("PR-demo").sha("e23b8ef5c2c4244889bf94db6c05cc08ea138aef").build();
when(staplerRequest.bindJSON(Mockito.eq(GithubScmSaveFileRequest.class), Mockito.any(JSONObject.class))).thenReturn(new GithubScmSaveFileRequest(content));
MultiBranchProject mbp = mockMbp(credentialId, user, GithubEnterpriseScm.DOMAIN_NAME);
String request = "{\n" + " \"content\" : {\n" + " \"message\" : \"first commit\",\n" + " \"path\" : \"Jenkinsfile\",\n" + " \"branch\" : \"test1\",\n" + " \"repo\" : \"PR-demo\",\n" + " \"sha\" : \"e23b8ef5c2c4244889bf94db6c05cc08ea138aef\",\n" + " \"base64Data\" : " + "\"c2xlZXAgMTUKbm9kZSB7CiAgY2hlY2tvdXQgc2NtCiAgc2ggJ2xzIC1sJwp9\\nCnNsZWVwIDE1Cg==\\n\"" + " }\n" + "}";
when(staplerRequest.getReader()).thenReturn(new BufferedReader(new StringReader(request), request.length()));
GithubFile file = (GithubFile) new GithubScmContentProvider().saveContent(staplerRequest, mbp);
assertEquals("Jenkinsfile", file.getContent().getName());
assertEquals("e23b8ef5c2c4244889bf94db6c05cc08ea138aef", file.getContent().getSha());
assertEquals("PR-demo", file.getContent().getRepo());
assertEquals("cloudbeers", file.getContent().getOwner());
}
use of io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent in project blueocean-plugin by jenkinsci.
the class GithubScmContentProviderTest method unauthorizedSaveContentToOrgFolderGHEShouldFail.
@Test
public void unauthorizedSaveContentToOrgFolderGHEShouldFail() throws UnirestException, IOException {
User alice = User.get("alice");
alice.setFullName("Alice Cooper");
alice.addProperty(new Mailer.UserProperty("alice@jenkins-ci.org"));
String aliceCredentialId = createGithubEnterpriseCredential(alice);
StaplerRequest staplerRequest = mockStapler(GithubEnterpriseScm.ID);
GitContent content = new GitContent.Builder().autoCreateBranch(true).base64Data("c2xlZXAgMTUKbm9kZSB7CiAgY2hlY2tvdXQgc2NtCiAgc2ggJ2xzIC1sJwp9\\nCnNsZWVwIDE1Cg==\\n").branch("test1").message("another commit").owner("cloudbeers").path("Jankinsfile").repo("PR-demo").sha("e23b8ef5c2c4244889bf94db6c05cc08ea138aef").build();
when(staplerRequest.bindJSON(Mockito.eq(GithubScmSaveFileRequest.class), Mockito.any(JSONObject.class))).thenReturn(new GithubScmSaveFileRequest(content));
MultiBranchProject mbp = mockMbp(aliceCredentialId, user, GithubEnterpriseScm.DOMAIN_NAME);
String request = "{\n" + " \"content\" : {\n" + " \"message\" : \"first commit\",\n" + " \"path\" : \"Jenkinsfile\",\n" + " \"branch\" : \"test1\",\n" + " \"repo\" : \"PR-demo\",\n" + " \"sha\" : \"e23b8ef5c2c4244889bf94db6c05cc08ea138aef\",\n" + " \"base64Data\" : " + "\"c2xlZXAgMTUKbm9kZSB7CiAgY2hlY2tvdXQgc2NtCiAgc2ggJ2xzIC1sJwp9\\nCnNsZWVwIDE1Cg==\\n\"" + " }\n" + "}";
when(staplerRequest.getReader()).thenReturn(new BufferedReader(new StringReader(request), request.length()));
try {
// Bob trying to access content but his credential is not setup so should fail
new GithubScmContentProvider().saveContent(staplerRequest, mbp);
} catch (ServiceException.PreconditionRequired e) {
assertEquals("Can't access content from github: no credential found", e.getMessage());
return;
}
fail("Should have failed with PreConditionException");
}
use of io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent 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("vivekp7").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("vivekp7", respContent.getContent().getOwner());
assertEquals("master", respContent.getContent().getBranch());
}
use of io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent in project blueocean-plugin by jenkinsci.
the class BitbucketCloudScmContentProviderTest method getContent.
@Test
public void getContent() throws UnirestException, IOException {
String credentialId = createCredential(BitbucketCloudScm.ID);
StaplerRequest staplerRequest = mockStapler();
MultiBranchProject mbp = mockMbp(credentialId);
ScmFile<GitContent> content = (ScmFile<GitContent>) new BitbucketCloudScmContentProvider().getContent(staplerRequest, mbp);
assertEquals("Jenkinsfile", content.getContent().getName());
assertEquals("04553981a05754d4bffef56a59d9d996d500301c", content.getContent().getCommitId());
assertEquals("demo1", content.getContent().getRepo());
assertEquals("vivekp7", content.getContent().getOwner());
}
use of io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent 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());
}
Aggregations