Search in sources :

Example 6 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) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 7 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(ImmutableMap.of("favorite", true)).build(Map.class);
    return project;
}
Also used : Project(hudson.model.Project)

Example 8 with Project

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

the class PipelineApiTest method findAllPipelineByGlob.

@Test
public void findAllPipelineByGlob() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = j.createFolder("folder1");
    j.createFolder("afolder");
    Project p1 = folder1.createProject(FreeStyleProject.class, "test1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder2");
    folder1.createProject(MockFolder.class, "folder3");
    folder2.createProject(FreeStyleProject.class, "test2");
    folder2.createProject(FreeStyleProject.class, "coolPipeline");
    List<Map> resp = get("/search?q=type:pipeline;pipeline:*TEST*", List.class);
    assertEquals(2, resp.size());
    resp = get("/search?q=type:pipeline;pipeline:*cool*", List.class);
    assertEquals(1, resp.size());
    resp = get("/search?q=type:pipeline;pipeline:*nothing*", List.class);
    assertEquals(0, resp.size());
    resp = get("/search?q=type:pipeline;pipeline:*f*", List.class);
    assertEquals(7, resp.size());
}
Also used : Project(hudson.model.Project) FreeStyleProject(hudson.model.FreeStyleProject) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) MockFolder(org.jvnet.hudson.test.MockFolder) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 9 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(ImmutableMap.of("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(ImmutableMap.of("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(ImmutableMap.of("favorite", true)).status(405).build(Map.class);
    new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/folder1/favorite/").authAlice().data(ImmutableMap.of("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) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) User(hudson.model.User) MockFolder(org.jvnet.hudson.test.MockFolder) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 10 with Project

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

the class LinkResolverTest method runLinkResolveTest.

@Test
public void runLinkResolveTest() throws IOException, ExecutionException, InterruptedException {
    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");
    Run r = (Run) f.scheduleBuild2(0).get();
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/fstyle1/runs/" + r.getId() + "/", LinkResolver.resolveLink(r).getHref());
    r = (Run) p1.scheduleBuild2(0).get();
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/test1/runs/" + r.getId() + "/", LinkResolver.resolveLink(r).getHref());
    r = (Run) p2.scheduleBuild2(0).get();
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/test2/runs/" + r.getId() + "/", LinkResolver.resolveLink(r).getHref());
    r = (Run) p3.scheduleBuild2(0).get();
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/folder3/pipelines/test3/runs/" + r.getId() + "/", LinkResolver.resolveLink(r).getHref());
}
Also used : Project(hudson.model.Project) FreeStyleProject(hudson.model.FreeStyleProject) Run(hudson.model.Run) MockFolder(org.jvnet.hudson.test.MockFolder) Test(org.junit.Test)

Aggregations

Project (hudson.model.Project)25 Test (org.junit.Test)23 FreeStyleProject (hudson.model.FreeStyleProject)22 ImmutableMap (com.google.common.collect.ImmutableMap)14 Map (java.util.Map)14 MockFolder (org.jvnet.hudson.test.MockFolder)13 List (java.util.List)7 ImmutableList (com.google.common.collect.ImmutableList)5 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