Search in sources :

Example 51 with User

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

the class ProfileApiTest method putMimeFailTest.

@Test
public void putMimeFailTest() throws Exception {
    User system = User.get("SYSTEM");
    put("/users/" + system.getId(), "", "text/plain", 415);
}
Also used : User(hudson.model.User) Test(org.junit.Test)

Example 52 with User

use of hudson.model.User 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 53 with User

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

the class ProfileApiTest method getUserTest.

@Test
public void getUserTest() throws Exception {
    User system = User.get("SYSTEM");
    get("/users/", List.class);
    Map response = get("/users/" + system.getId());
    assertEquals(system.getId(), response.get("id"));
    assertEquals(system.getFullName(), response.get("fullName"));
    assertEquals("http://avatar.example/i/img.png", response.get("avatar"));
}
Also used : User(hudson.model.User) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 54 with User

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

the class ProfileApiTest method putMimeTest.

// UX-159
@Test
@Ignore
public void putMimeTest() throws Exception {
    User system = User.get("SYSTEM");
    Map response = put("/users/" + system.getId() + "/", Collections.emptyMap());
    assertEquals(system.getId(), response.get("id"));
    assertEquals(system.getFullName(), response.get("fullName"));
}
Also used : User(hudson.model.User) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 55 with User

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

the class ProfileApiTest method postCrumbFailTest.

// UX-159
@Test
public void postCrumbFailTest() throws Exception {
    User system = User.get("SYSTEM");
    post("/users/" + system.getId() + "/", "", "text/plain", 403);
}
Also used : User(hudson.model.User) Test(org.junit.Test)

Aggregations

User (hudson.model.User)105 Test (org.junit.Test)71 Map (java.util.Map)42 ImmutableMap (com.google.common.collect.ImmutableMap)38 PipelineBaseTest (io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest)26 Mailer (hudson.tasks.Mailer)24 ServiceException (io.jenkins.blueocean.commons.ServiceException)21 StaplerRequest (org.kohsuke.stapler.StaplerRequest)14 MultiBranchProject (jenkins.branch.MultiBranchProject)13 List (java.util.List)12 JSONObject (net.sf.json.JSONObject)12 GitContent (io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent)8 IOException (java.io.IOException)8 Domain (com.cloudbees.plugins.credentials.domains.Domain)7 BlueOceanDomainRequirement (io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanDomainRequirement)7 Authentication (org.acegisecurity.Authentication)7 CredentialsStore (com.cloudbees.plugins.credentials.CredentialsStore)6 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)6 BufferedReader (java.io.BufferedReader)6 StringReader (java.io.StringReader)6