Search in sources :

Example 1 with Project

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

the class LinkResolverTest method nestedFolderJobLinkResolveTest.

@Test
public void nestedFolderJobLinkResolveTest() throws IOException {
    Project f = j.createFreeStyleProject("fstyle1");
    MockFolder folder1 = j.createFolder("folder1");
    Project p1 = folder1.createProject(FreeStyleProject.class, "test1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder2");
    MockFolder folder3 = folder2.createProject(MockFolder.class, "folder3");
    Project p2 = folder2.createProject(FreeStyleProject.class, "test2");
    Project p3 = folder3.createProject(FreeStyleProject.class, "test3");
    WorkflowJob pipelineJob1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    pipelineJob1.setDefinition(new CpsFlowDefinition("stage \"Build\"\n" + "    node {\n" + "       sh \"echo here\"\n" + "    }\n" + "\n"));
    WorkflowJob pipelineJob2 = folder2.createProject(WorkflowJob.class, "pipeline2");
    pipelineJob2.setDefinition(new CpsFlowDefinition("stage \"Build\"\n" + "    node {\n" + "       sh \"echo here\"\n" + "    }\n" + "\n"));
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/pipeline1/", LinkResolver.resolveLink(pipelineJob1).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/pipeline2/", LinkResolver.resolveLink(pipelineJob2).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/fstyle1/", LinkResolver.resolveLink(f).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/", LinkResolver.resolveLink(folder1).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/test1/", LinkResolver.resolveLink(p1).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/", LinkResolver.resolveLink(folder2).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/test2/", LinkResolver.resolveLink(p2).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/folder3/", LinkResolver.resolveLink(folder3).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/folder3/pipelines/test3/", LinkResolver.resolveLink(p3).getHref());
}
Also used : Project(hudson.model.Project) FreeStyleProject(hudson.model.FreeStyleProject) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) MockFolder(org.jvnet.hudson.test.MockFolder) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Test(org.junit.Test)

Example 2 with Project

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

the class ProfileApiTest method createUserFavouriteFolderTest.

// TODO: migrate to FavoritesApiTest after PR receives initial approval (trying to cut down on PR noise)
@Test
public void createUserFavouriteFolderTest() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User user = User.get("alice");
    user.setFullName("Alice Cooper");
    MockFolder folder1 = j.createFolder("folder1");
    Project p = folder1.createProject(FreeStyleProject.class, "pipeline1");
    // String token = getJwtToken(j.jenkins,"alice", "alice");
    Map map = new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/folder1/pipelines/pipeline1/favorite/").authAlice().data(Collections.singletonMap("favorite", true)).build(Map.class);
    validatePipeline(p, (Map) map.get("item"));
    List l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").authAlice().build(List.class);
    assertEquals(1, l.size());
    Map pipeline = (Map) ((Map) l.get(0)).get("item");
    validatePipeline(p, pipeline);
    String href = getHrefFromLinks((Map) l.get(0), "self");
    assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/pipeline1/favorite/", href);
    map = new RequestBuilder(baseUrl).put(href.substring("/blue/rest".length())).authAlice().data(Collections.singletonMap("favorite", false)).build(Map.class);
    validatePipeline(p, (Map) map.get("item"));
    l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").authAlice().build(List.class);
    assertEquals(0, l.size());
    new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/folder1/favorite/").authAlice().data(Collections.singletonMap("favorite", true)).status(405).build(Map.class);
    new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/folder1/favorite/").authAlice().data(Collections.singletonMap("favorite", false)).status(405).build(Map.class);
    l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").authAlice().build(List.class);
    assertEquals(0, l.size());
}
Also used : Project(hudson.model.Project) FreeStyleProject(hudson.model.FreeStyleProject) List(java.util.List) User(hudson.model.User) MockFolder(org.jvnet.hudson.test.MockFolder) Map(java.util.Map) Test(org.junit.Test)

Example 3 with Project

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

the class ContainerFilterTest method customFilter.

@Test
public void customFilter() throws IOException {
    MockFolder folder = j.createFolder("folder1");
    Project p = folder.createProject(FreeStyleProject.class, "test1");
    Collection<Item> items = ContainerFilter.filter(j.getInstance().getAllItems(), "itemgroup-only");
    assertEquals(1, items.size());
    assertEquals(folder.getFullName(), items.iterator().next().getFullName());
}
Also used : Project(hudson.model.Project) FreeStyleProject(hudson.model.FreeStyleProject) Item(hudson.model.Item) MockFolder(org.jvnet.hudson.test.MockFolder) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with Project

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

the class FavoritesApiTest method createAndFavorite.

private Project createAndFavorite(String jobName, String username, String password) throws IOException {
    Project project = j.createFreeStyleProject(jobName);
    new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/" + jobName + "/favorite/").auth(username, password).data(Collections.singletonMap("favorite", true)).build(Map.class);
    return project;
}
Also used : Project(hudson.model.Project)

Example 5 with Project

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

the class FavoritesApiTest method testFavoritePagination.

@Test
public void testFavoritePagination() throws IOException, Favorites.FavoriteException {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User user = User.get("alice");
    Project job1 = j.createFreeStyleProject("job1");
    Project job2 = j.createFreeStyleProject("job2");
    Favorites.addFavorite(user, job1);
    Favorites.addFavorite(user, job2);
    List<Map> favorites = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").auth("alice", "alice").build(List.class);
    assertEquals(2, favorites.size());
    favorites = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/?limit=1").auth("alice", "alice").build(List.class);
    assertEquals(1, favorites.size());
}
Also used : Project(hudson.model.Project) List(java.util.List) User(hudson.model.User) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Project (hudson.model.Project)25 Test (org.junit.Test)23 FreeStyleProject (hudson.model.FreeStyleProject)22 Map (java.util.Map)14 MockFolder (org.jvnet.hudson.test.MockFolder)13 List (java.util.List)7 User (hudson.model.User)4 FreeStyleBuild (hudson.model.FreeStyleBuild)3 Shell (hudson.tasks.Shell)2 BaseTest (io.jenkins.blueocean.service.embedded.BaseTest)2 AbstractProject (hudson.model.AbstractProject)1 Item (hudson.model.Item)1 Run (hudson.model.Run)1 HudsonPrivateSecurityRealm (hudson.security.HudsonPrivateSecurityRealm)1 LegacyAuthorizationStrategy (hudson.security.LegacyAuthorizationStrategy)1 BlueTrendFactory (io.jenkins.blueocean.rest.factory.BlueTrendFactory)1 BlueOrganization (io.jenkins.blueocean.rest.model.BlueOrganization)1 BluePipeline (io.jenkins.blueocean.rest.model.BluePipeline)1 BlueTrend (io.jenkins.blueocean.rest.model.BlueTrend)1 BlueTrendContainer (io.jenkins.blueocean.rest.model.BlueTrendContainer)1