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());
}
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());
}
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());
}
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;
}
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());
}
Aggregations