Search in sources :

Example 11 with DefaultBranchPropertyStrategy

use of jenkins.branch.DefaultBranchPropertyStrategy 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 = User.get("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) User(hudson.model.User) 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 12 with DefaultBranchPropertyStrategy

use of jenkins.branch.DefaultBranchPropertyStrategy 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 = User.get("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) User(hudson.model.User) 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 13 with DefaultBranchPropertyStrategy

use of jenkins.branch.DefaultBranchPropertyStrategy in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method multiBranchPipelineIndex.

@Test
public void multiBranchPipelineIndex() throws Exception {
    User user = login();
    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());
    }
    Map map = new RequestBuilder(baseUrl).post("/organizations/jenkins/pipelines/p/runs/").jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).data(ImmutableMap.of()).status(200).build(Map.class);
    assertNotNull(map);
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) User(hudson.model.User) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 14 with DefaultBranchPropertyStrategy

use of jenkins.branch.DefaultBranchPropertyStrategy 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 = User.get("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) User(hudson.model.User) 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 15 with DefaultBranchPropertyStrategy

use of jenkins.branch.DefaultBranchPropertyStrategy in project blueocean-plugin by jenkinsci.

the class SseEventTest method multiBranchJobEventsWithCustomOrg.

@Test
public void multiBranchJobEventsWithCustomOrg() throws Exception {
    MockFolder folder = j.createFolder("TestOrgFolderName");
    assertNotNull(folder);
    setupScm();
    final OneShotEvent success = new OneShotEvent();
    final Boolean[] pipelineNameMatched = { null };
    final Boolean[] mbpPipelineNameMatched = { null };
    SSEConnection con = new SSEConnection(j.getURL(), "me", new ChannelSubscriber() {

        @Override
        public void onMessage(@Nonnull Message message) {
            System.out.println(message);
            if ("job".equals(message.get(jenkins_channel))) {
                if ("org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject".equals(message.get(jenkins_object_type))) {
                    if ("pipeline1".equals(message.get(blueocean_job_pipeline_name))) {
                        mbpPipelineNameMatched[0] = true;
                    } else {
                        mbpPipelineNameMatched[0] = false;
                    }
                } else if ("org.jenkinsci.plugins.workflow.job.WorkflowJob".equals(message.get(jenkins_object_type))) {
                    if ("pipeline1".equals(message.get(blueocean_job_pipeline_name))) {
                        pipelineNameMatched[0] = true;
                    } else {
                        pipelineNameMatched[0] = false;
                    }
                }
            }
            if (pipelineNameMatched[0] != null && mbpPipelineNameMatched[0] != null) {
                success.signal();
            }
        }
    });
    con.subscribe("pipeline");
    con.subscribe("job");
    final WorkflowMultiBranchProject mp = folder.createProject(WorkflowMultiBranchProject.class, "pipeline1");
    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());
    }
    mp.scheduleBuild2(0).getFuture().get();
    WorkflowJob p = mp.getItem("master");
    if (p == null) {
        mp.getIndexing().writeWholeLogTo(System.out);
        fail("master project not found");
    }
    j.waitUntilNoActivity();
    WorkflowRun b1 = p.getLastBuild();
    assertEquals(1, b1.getNumber());
    assertEquals(2, mp.getItems().size());
    success.block(5000);
    con.close();
    if (success.isSignaled()) {
        assertTrue(pipelineNameMatched[0]);
        assertTrue(mbpPipelineNameMatched[0]);
    }
}
Also used : Message(org.jenkinsci.plugins.pubsub.Message) ChannelSubscriber(org.jenkinsci.plugins.pubsub.ChannelSubscriber) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) MockFolder(org.jvnet.hudson.test.MockFolder) BranchSource(jenkins.branch.BranchSource) SSEConnection(io.jenkins.blueocean.events.sse.SSEConnection) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) OneShotEvent(hudson.util.OneShotEvent) Test(org.junit.Test)

Aggregations

BranchSource (jenkins.branch.BranchSource)31 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)31 GitSCMSource (jenkins.plugins.git.GitSCMSource)31 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)31 Test (org.junit.Test)29 SCMSource (jenkins.scm.api.SCMSource)28 Map (java.util.Map)21 ImmutableMap (com.google.common.collect.ImmutableMap)20 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)20 ArrayList (java.util.ArrayList)12 List (java.util.List)12 ImmutableList (com.google.common.collect.ImmutableList)11 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)8 User (hudson.model.User)5 MockFolder (org.jvnet.hudson.test.MockFolder)5 Queue (hudson.model.Queue)4 FreeStyleProject (hudson.model.FreeStyleProject)3 OneShotEvent (hudson.util.OneShotEvent)2 SSEConnection (io.jenkins.blueocean.events.sse.SSEConnection)2 Date (java.util.Date)2