Search in sources :

Example 1 with WorkflowMultiBranchProject

use of org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject in project blueocean-plugin by jenkinsci.

the class BranchContainerImplTest method testBranchOrdering.

@Test
public void testBranchOrdering() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User user = j.jenkins.getUser("alice");
    user.setFullName("Alice Cooper");
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();
    String token = getJwtToken(j.jenkins, "alice", "alice");
    new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/p/branches/feature2/favorite").jwtToken(token).data(ImmutableMap.of("favorite", true)).build(Map.class);
    new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/p/branches/feature4/favorite").jwtToken(token).data(ImmutableMap.of("favorite", true)).build(Map.class);
    List l = request().get("/organizations/jenkins/pipelines/p/branches/").jwtToken(token).build(List.class);
    Assert.assertEquals(4, l.size());
    Map o = (Map) l.get(1);
    Map o2 = (Map) l.get(0);
    Assert.assertTrue(o.get("name").equals("feature2") || o.get("name").equals("feature4"));
    WorkflowJob j1 = findBranchProject(mp, (String) o.get("name"));
    j.waitForCompletion(j1.getLastBuild());
    j.waitForCompletion(j1.scheduleBuild2(0).waitForStart());
    WorkflowJob j2 = findBranchProject(mp, (String) o2.get("name"));
    j.waitForCompletion(j2.getLastBuild());
    List l2 = request().get("/organizations/jenkins/pipelines/p/branches/").jwtToken(token).build(List.class);
    Assert.assertEquals(4, l.size());
    Map o1 = (Map) l2.get(0);
    Map o3 = (Map) l2.get(1);
    Assert.assertEquals(o.get("name"), o1.get("name"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with WorkflowMultiBranchProject

use of org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method parameterizedBranchTest.

@Test
public void parameterizedBranchTest() throws Exception {
    setupParameterizedScm();
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo2.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    WorkflowJob p = scheduleAndFindBranchProject(mp, branches[1]);
    j.waitUntilNoActivity();
    Map resp = get("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(branches[1]) + "/", Map.class);
    List<Map<String, Object>> parameters = (List<Map<String, Object>>) resp.get("parameters");
    Assert.assertEquals(1, parameters.size());
    Assert.assertEquals("param1", parameters.get(0).get("name"));
    Assert.assertEquals("StringParameterDefinition", parameters.get(0).get("type"));
    Assert.assertEquals("string param", parameters.get(0).get("description"));
    Assert.assertEquals("xyz", ((Map) parameters.get(0).get("defaultParameterValue")).get("value"));
    resp = post("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(branches[1]) + "/runs/", ImmutableMap.of("parameters", ImmutableList.of(ImmutableMap.of("name", "param1", "value", "abc"))), 200);
    Assert.assertEquals(branches[1], resp.get("pipeline"));
    Thread.sleep(1000);
    resp = get("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(branches[1]) + "/runs/2/");
    Assert.assertEquals("SUCCESS", resp.get("result"));
    Assert.assertEquals("FINISHED", resp.get("state"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 3 with WorkflowMultiBranchProject

use of org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method createUserFavouriteMultibranchBranchTest.

@Test
public void createUserFavouriteMultibranchBranchTest() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User user = j.jenkins.getUser("alice");
    user.setFullName("Alice Cooper");
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();
    WorkflowJob p1 = scheduleAndFindBranchProject(mp, "feature2");
    String token = getJwtToken(j.jenkins, "alice", "alice");
    Map map = new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/p/branches/feature2/favorite").jwtToken(token).data(ImmutableMap.of("favorite", true)).build(Map.class);
    validatePipeline(p1, (Map) map.get("item"));
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature2/favorite/", getHrefFromLinks(map, "self"));
    List l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
    Assert.assertEquals(1, l.size());
    Map branch = (Map) ((Map) l.get(0)).get("item");
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature2/favorite/", getHrefFromLinks((Map) l.get(0), "self"));
    validatePipeline(p1, branch);
    String c = (String) branch.get("_class");
    Assert.assertEquals(BranchImpl.class.getName(), c);
    map = new RequestBuilder(baseUrl).put(getUrlFromHref(getHrefFromLinks((Map) l.get(0), "self"))).jwtToken(token).data(ImmutableMap.of("favorite", false)).build(Map.class);
    validatePipeline(p1, (Map) map.get("item"));
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature2/favorite/", getHrefFromLinks(map, "self"));
    l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
    Assert.assertEquals(0, l.size());
    new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(getJwtToken(j.jenkins, "bob", "bob")).status(403).build(String.class);
}
Also used : GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 4 with WorkflowMultiBranchProject

use of org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method favoritedFromClassicTest.

@Test
public void favoritedFromClassicTest() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User user = j.jenkins.getUser("alice");
    user.setFullName("Alice Cooper");
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();
    Favorites.toggleFavorite(user, p);
    user.save();
    String token = getJwtToken(j.jenkins, "alice", "alice");
    List l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
    Assert.assertEquals(1, l.size());
    Map branch = (Map) ((Map) l.get(0)).get("item");
    validatePipeline(p, branch);
    String c = (String) branch.get("_class");
    Assert.assertEquals(BranchImpl.class.getName(), c);
    String href = getHrefFromLinks((Map) l.get(0), "self");
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/master/favorite/", href);
    Map m = new RequestBuilder(baseUrl).put(getUrlFromHref(getUrlFromHref(href))).jwtToken(token).data(ImmutableMap.of("favorite", false)).build(Map.class);
    branch = (Map) m.get("item");
    validatePipeline(p, branch);
    c = (String) branch.get("_class");
    Assert.assertEquals(BranchImpl.class.getName(), c);
    l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
    Assert.assertEquals(0, l.size());
}
Also used : GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 5 with WorkflowMultiBranchProject

use of org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method createUserFavouriteMultibranchTopLevelTest.

@Test
public void createUserFavouriteMultibranchTopLevelTest() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User user = j.jenkins.getUser("alice");
    user.setFullName("Alice Cooper");
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();
    String token = getJwtToken(j.jenkins, "alice", "alice");
    Map m = new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/p/favorite").jwtToken(token).data(ImmutableMap.of("favorite", true)).build(Map.class);
    Map branch = (Map) m.get("item");
    validatePipeline(p, branch);
    String c = (String) branch.get("_class");
    Assert.assertEquals(BranchImpl.class.getName(), c);
    List l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
    Assert.assertEquals(1, l.size());
    branch = (Map) ((Map) l.get(0)).get("item");
    validatePipeline(p, branch);
    c = (String) branch.get("_class");
    Assert.assertEquals(BranchImpl.class.getName(), c);
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/master/favorite/", getHrefFromLinks((Map) l.get(0), "self"));
    String ref = getHrefFromLinks((Map) l.get(0), "self");
    m = new RequestBuilder(baseUrl).put(getUrlFromHref(ref)).jwtToken(token).data(ImmutableMap.of("favorite", false)).build(Map.class);
    branch = (Map) m.get("item");
    validatePipeline(p, branch);
    c = (String) branch.get("_class");
    Assert.assertEquals(BranchImpl.class.getName(), c);
    l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
    Assert.assertEquals(0, l.size());
    new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(getJwtToken(j.jenkins, "bob", "bob")).status(403).build(String.class);
}
Also used : GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)28 BranchSource (jenkins.branch.BranchSource)27 GitSCMSource (jenkins.plugins.git.GitSCMSource)27 SCMSource (jenkins.scm.api.SCMSource)25 Test (org.junit.Test)24 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)23 Map (java.util.Map)22 ImmutableMap (com.google.common.collect.ImmutableMap)21 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)18 List (java.util.List)12 ImmutableList (com.google.common.collect.ImmutableList)11 ArrayList (java.util.ArrayList)10 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)7 MockFolder (org.jvnet.hudson.test.MockFolder)4 FreeStyleProject (hudson.model.FreeStyleProject)3 Queue (hudson.model.Queue)2 RunList (hudson.util.RunList)2 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)2 Domain (com.cloudbees.plugins.credentials.domains.Domain)1 Cause (hudson.model.Cause)1