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