Search in sources :

Example 6 with MockFolder

use of org.jvnet.hudson.test.MockFolder in project blueocean-plugin by jenkinsci.

the class ProfileApiTest method createUserFavouriteFolderTest.

@Test
public void createUserFavouriteFolderTest() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    hudson.model.User user = j.jenkins.getUser("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/").jwtToken(token).data(ImmutableMap.of("favorite", true)).build(Map.class);
    validatePipeline(p, (Map) map.get("item"));
    List l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).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())).jwtToken(token).data(ImmutableMap.of("favorite", false)).build(Map.class);
    validatePipeline(p, (Map) map.get("item"));
    l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
    assertEquals(0, l.size());
    new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/folder1/favorite/").jwtToken(token).data(ImmutableMap.of("favorite", true)).status(405).build(Map.class);
    new RequestBuilder(baseUrl).put("/organizations/jenkins/pipelines/folder1/favorite/").jwtToken(token).data(ImmutableMap.of("favorite", false)).status(405).build(Map.class);
    l = new RequestBuilder(baseUrl).get("/users/" + user.getId() + "/favorites/").jwtToken(token).build(List.class);
    assertEquals(0, l.size());
}
Also used : Project(hudson.model.Project) FreeStyleProject(hudson.model.FreeStyleProject) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) User(hudson.model.User) MockFolder(org.jvnet.hudson.test.MockFolder) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 7 with MockFolder

use of org.jvnet.hudson.test.MockFolder in project blueocean-plugin by jenkinsci.

the class BlueOceanWebURLBuilderTest method test_freestyle.

@Test
public void test_freestyle() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = jenkinsRule.createFolder("folder1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder two with spaces");
    FreeStyleProject freestyleProject = folder2.createProject(FreeStyleProject.class, "freestyle with spaces");
    String blueOceanURL;
    blueOceanURL = BlueOceanWebURLBuilder.toBlueOceanURL(freestyleProject);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Ffreestyle%20with%20spaces", blueOceanURL);
    FreeStyleBuild run = freestyleProject.scheduleBuild2(0).get();
    blueOceanURL = BlueOceanWebURLBuilder.toBlueOceanURL(run);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Ffreestyle%20with%20spaces/detail/freestyle%20with%20spaces/1", blueOceanURL);
}
Also used : FreeStyleBuild(hudson.model.FreeStyleBuild) MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 8 with MockFolder

use of org.jvnet.hudson.test.MockFolder in project promoted-builds-plugin by jenkinsci.

the class PromotedEnvVarTokenMacroTest method testEnvironmentVariableExpansion.

@Test
public void testEnvironmentVariableExpansion() throws Exception {
    // Assemble
    r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
    User u = User.get("foo");
    u.setFullName("Foobar");
    SecurityContextHolder.getContext().setAuthentication(u.impersonate());
    MockFolder parent = r.createFolder("Folder");
    FreeStyleProject project = parent.createProject(FreeStyleProject.class, "Project");
    JobPropertyImpl promotionProperty = new JobPropertyImpl(project);
    PromotionProcess promotionProcess = promotionProperty.addProcess("promo");
    promotionProcess.conditions.clear();
    ManualCondition manualCondition = new ManualCondition();
    manualCondition.getParameterDefinitions().add(new StringParameterDefinition("PROMOTION_PARAM", "defaultValue"));
    promotionProcess.conditions.add(manualCondition);
    Action approvalAction = new ManualCondition.ManualApproval(promotionProcess.getName(), new LinkedList<ParameterValue>());
    TokenMacroExpressionRecorder recorder = new TokenMacroExpressionRecorder("${PROMOTION_ENV,var=\"PROMOTION_PARAM\"}");
    promotionProcess.getBuildSteps().add(recorder);
    // Act & promote
    FreeStyleBuild build = project.scheduleBuild2(0).get();
    build.addAction(approvalAction);
    build.save();
    Promotion promotion = promotionProcess.considerPromotion2(build, Arrays.asList((ParameterValue) new StringParameterValue("PROMOTION_PARAM", "FOO"))).get();
    // Check results
    EnvVars env = promotion.getEnvironment(TaskListener.NULL);
    assertEquals("The PROMOTION_PARAM variable has not been injected", "FOO", env.get("PROMOTION_PARAM"));
    assertEquals("The promotion variable value has not been resolved by the PROMOTION_PARAM macro", "FOO", recorder.getCaptured());
}
Also used : Action(hudson.model.Action) User(hudson.model.User) StringParameterDefinition(hudson.model.StringParameterDefinition) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) StringParameterValue(hudson.model.StringParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) EnvVars(hudson.EnvVars) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Test(org.junit.Test)

Example 9 with MockFolder

use of org.jvnet.hudson.test.MockFolder in project promoted-builds-plugin by jenkinsci.

the class ItemPathResolverTest method shouldCorrectlyResolveItemsWithEqualNames.

@Test
public void shouldCorrectlyResolveItemsWithEqualNames() throws Exception {
    // FOO exists on both top level and within the folder
    final MockFolder folder = rule.createFolder("F");
    final FreeStyleProject prjInRoot = rule.createFreeStyleProject("FOO");
    final FreeStyleProject prjInFolder = folder.createProject(FreeStyleProject.class, "FOO");
    // Additional spot-checks for the absolute addressing
    assertsPath("F/FOO", null, prjInFolder);
    assertsPath("/F/FOO", null, prjInFolder);
    assertsPath("/FOO", null, prjInRoot);
}
Also used : MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 10 with MockFolder

use of org.jvnet.hudson.test.MockFolder in project promoted-builds-plugin by jenkinsci.

the class PromotionEnvironmentVariablesTest method shouldSetJobAndJobFullNames.

@Test
public void shouldSetJobAndJobFullNames() throws Descriptor.FormException, IOException, InterruptedException, ExecutionException, Exception {
    // Assemble
    r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
    User u = User.get("foo");
    u.setFullName("Foobar");
    SecurityContextHolder.getContext().setAuthentication(u.impersonate());
    MockFolder parent = r.createFolder("Folder");
    FreeStyleProject project = parent.createProject(FreeStyleProject.class, "Project");
    JobPropertyImpl promotionProperty = new JobPropertyImpl(project);
    PromotionProcess promotionProcess = promotionProperty.addProcess("promo");
    promotionProcess.conditions.clear();
    promotionProcess.conditions.add(new ManualCondition());
    Action approvalAction = new ManualCondition.ManualApproval(promotionProcess.getName(), new ArrayList<ParameterValue>());
    // Act
    FreeStyleBuild build = project.scheduleBuild2(0).get();
    build.setDisplayName("1234");
    build.addAction(approvalAction);
    build.save();
    Promotion promotion = promotionProcess.considerPromotion2(build).get();
    EnvVars env = promotion.getEnvironment(TaskListener.NULL);
    // Assert
    assertEquals("Folder/Project", env.get("PROMOTED_JOB_FULL_NAME"));
    assertEquals("Project", env.get("PROMOTED_JOB_NAME"));
    assertEquals("Foobar", env.get("PROMOTED_USER_NAME"));
    assertEquals("foo", env.get("PROMOTED_USER_ID"));
    assertEquals("1234", env.get("PROMOTED_DISPLAY_NAME"));
    project.delete();
    parent.delete();
}
Also used : Action(hudson.model.Action) User(hudson.model.User) ParameterValue(hudson.model.ParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) EnvVars(hudson.EnvVars) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)22 MockFolder (org.jvnet.hudson.test.MockFolder)22 FreeStyleProject (hudson.model.FreeStyleProject)18 Project (hudson.model.Project)11 ImmutableMap (com.google.common.collect.ImmutableMap)10 Map (java.util.Map)10 FreeStyleBuild (hudson.model.FreeStyleBuild)4 BranchSource (jenkins.branch.BranchSource)4 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)4 GitSCMSource (jenkins.plugins.git.GitSCMSource)4 SCMSource (jenkins.scm.api.SCMSource)4 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)4 User (hudson.model.User)3 ImmutableList (com.google.common.collect.ImmutableList)2 EnvVars (hudson.EnvVars)2 Action (hudson.model.Action)2 ParameterValue (hudson.model.ParameterValue)2 ManualCondition (hudson.plugins.promoted_builds.conditions.ManualCondition)2 HudsonPrivateSecurityRealm (hudson.security.HudsonPrivateSecurityRealm)2 LegacyAuthorizationStrategy (hudson.security.LegacyAuthorizationStrategy)2