Search in sources :

Example 76 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class GitPipelineCreateRequestTest method createPipeline.

@Test
public void createPipeline() throws UnirestException, IOException {
    User user = login("vivek", "Vivek Pandey", "vivek.pandey@gmail.com");
    Map r = new PipelineBaseTest.RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).post("/organizations/jenkins/pipelines/").data(ImmutableMap.of("name", "pipeline1", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", ImmutableMap.of("id", GitScm.ID, "uri", sampleRepo.toString()))).build(Map.class);
    assertNotNull(r);
    assertEquals("pipeline1", r.get("name"));
    MultiBranchProject mbp = (MultiBranchProject) j.getInstance().getItem("pipeline1");
    GitSCMSource source = (GitSCMSource) mbp.getSCMSources().get(0);
    List<SCMSourceTrait> traits = source.getTraits();
    Assert.assertNotNull(SCMTrait.find(traits, BranchDiscoveryTrait.class));
    Assert.assertNotNull(SCMTrait.find(traits, CleanAfterCheckoutTrait.class));
    Assert.assertNotNull(SCMTrait.find(traits, CleanBeforeCheckoutTrait.class));
    Assert.assertNotNull(SCMTrait.find(traits, LocalBranchTrait.class));
}
Also used : User(hudson.model.User) CleanAfterCheckoutTrait(jenkins.plugins.git.traits.CleanAfterCheckoutTrait) SCMSourceTrait(jenkins.scm.api.trait.SCMSourceTrait) CleanBeforeCheckoutTrait(jenkins.plugins.git.traits.CleanBeforeCheckoutTrait) MultiBranchProject(jenkins.branch.MultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) LocalBranchTrait(jenkins.plugins.git.traits.LocalBranchTrait) BranchDiscoveryTrait(jenkins.plugins.git.traits.BranchDiscoveryTrait) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 77 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class GitScmTest method shouldGetForbiddenForBadCredentialIdOnCreate2.

@Test
public void shouldGetForbiddenForBadCredentialIdOnCreate2() throws IOException, UnirestException {
    User user = login();
    this.jwtToken = getJwtToken(j.jenkins, user.getId(), user.getId());
    Map resp = createCredentials(user, ImmutableMap.of("credentials", new ImmutableMap.Builder<String, Object>().put("password", "abcd").put("stapler-class", "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").put("scope", "USER").put("domain", "blueocean-git-domain").put("description", "joe desc").put("$class", "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").put("username", "joe").build()));
    String credentialId = (String) resp.get("id");
    Assert.assertNotNull(credentialId);
    post("/organizations/" + getOrgName() + "/pipelines/", ImmutableMap.of("name", "demo", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", ImmutableMap.of("uri", "git@github.com:vivek/capability-annotation.git", "credentialId", credentialId)), 400);
}
Also used : User(hudson.model.User) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 78 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class GitScmTest method shouldGetForbiddenForBadCredentialIdOnCreate1.

@Test
public void shouldGetForbiddenForBadCredentialIdOnCreate1() throws IOException, UnirestException {
    User user = login();
    this.jwtToken = getJwtToken(j.jenkins, user.getId(), user.getId());
    Map resp = createCredentials(user, ImmutableMap.of("credentials", new ImmutableMap.Builder<String, Object>().put("privateKeySource", ImmutableMap.of("privateKey", "abcabc1212", "stapler-class", "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource")).put("passphrase", "ssh2").put("scope", "USER").put("domain", "blueocean-git-domain").put("description", "ssh2 desc").put("$class", "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey").put("username", "ssh2").build()));
    String credentialId = (String) resp.get("id");
    Assert.assertNotNull(credentialId);
    post("/organizations/" + getOrgName() + "/pipelines/", ImmutableMap.of("name", "demo", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", ImmutableMap.of("uri", "git@github.com:vivek/capability-annotation.git", "credentialId", credentialId)), 400);
}
Also used : User(hudson.model.User) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 79 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class GitScmTest method shouldFailForBadCredentialIdOnCreate.

@Test
public void shouldFailForBadCredentialIdOnCreate() throws IOException, UnirestException {
    User user = login();
    Map resp = createCredentials(user, ImmutableMap.of("credentials", new ImmutableMap.Builder<String, Object>().put("privateKeySource", ImmutableMap.of("privateKey", "abcabc1212", "stapler-class", "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource")).put("passphrase", "ssh2").put("scope", "USER").put("domain", "blueocean-git-domain").put("description", "ssh2 desc").put("$class", "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey").put("username", "ssh2").build()));
    String credentialId = (String) resp.get("id");
    Assert.assertNotNull(credentialId);
    resp = new RequestBuilder(baseUrl).status(400).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).post("/organizations/" + getOrgName() + "/pipelines/").data(ImmutableMap.of("name", "demo", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", ImmutableMap.of("uri", "git@github.com:vivek/capability-annotation.git", "credentialId", credentialId))).build(Map.class);
    assertEquals(resp.get("code"), 400);
    List<Map> errors = (List<Map>) resp.get("errors");
    assertEquals(1, errors.size());
    assertEquals("scmConfig.credentialId", errors.get(0).get("field"));
    assertEquals("INVALID", errors.get(0).get("code"));
}
Also used : User(hudson.model.User) List(java.util.List) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 80 with User

use of hudson.model.User in project blueocean-plugin by jenkinsci.

the class GitScmTest method shouldCreateWithRemoteGitRepo.

@Test
public void shouldCreateWithRemoteGitRepo() throws IOException, UnirestException {
    String accessToken = needsGithubAccessToken();
    User user = login();
    this.jwtToken = getJwtToken(j.jenkins, user.getId(), user.getId());
    Map resp = createCredentials(user, ImmutableMap.of("credentials", new ImmutableMap.Builder<String, Object>().put("password", accessToken).put("stapler-class", "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").put("scope", "USER").put("domain", "blueocean-git-domain").put("description", "joe desc").put("$class", "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl").put("username", "joe").build()));
    String credentialId = (String) resp.get("id");
    Assert.assertNotNull(credentialId);
    Map r = new RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).post("/organizations/" + getOrgName() + "/pipelines/").data(ImmutableMap.of("name", "demo", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", ImmutableMap.of("uri", "https://github.com/vivek/test-no-jenkins-file.git", "credentialId", credentialId))).build(Map.class);
    assertEquals("demo", r.get("name"));
}
Also used : User(hudson.model.User) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Aggregations

User (hudson.model.User)105 Test (org.junit.Test)71 Map (java.util.Map)42 ImmutableMap (com.google.common.collect.ImmutableMap)38 PipelineBaseTest (io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest)26 Mailer (hudson.tasks.Mailer)24 ServiceException (io.jenkins.blueocean.commons.ServiceException)21 StaplerRequest (org.kohsuke.stapler.StaplerRequest)14 MultiBranchProject (jenkins.branch.MultiBranchProject)13 List (java.util.List)12 JSONObject (net.sf.json.JSONObject)12 GitContent (io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent)8 IOException (java.io.IOException)8 Domain (com.cloudbees.plugins.credentials.domains.Domain)7 BlueOceanDomainRequirement (io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanDomainRequirement)7 Authentication (org.acegisecurity.Authentication)7 CredentialsStore (com.cloudbees.plugins.credentials.CredentialsStore)6 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)6 BufferedReader (java.io.BufferedReader)6 StringReader (java.io.StringReader)6