Skip to content
Permalink
Browse files

[JENKINS-40683] Create functional tests for BUILD_NUMBER, JENKINS_URL…

…, PROJECT_NAME and PROJECT_URL tokens. (#27)
  • Loading branch information
varyvol authored and slide committed Dec 27, 2016
1 parent 13af177 commit 553232ec945f67c56f010909b25debcbdafe435c
@@ -0,0 +1,36 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package org.jenkinsci.plugins.tokenmacro.impl;

import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.util.StreamTaskListener;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static junit.framework.TestCase.assertEquals;

/**
*
* @author egutierrez
*/
public class BuildNumberMacroTest {

@Rule
public final JenkinsRule j = new JenkinsRule();

@Test
public void testBuildNumberMacro() throws Exception {
FreeStyleProject p = j.createFreeStyleProject("foo");
FreeStyleBuild b = p.scheduleBuild2(0).get();

String expectedBuildNumber = String.valueOf(b.getNumber());
assertEquals(expectedBuildNumber, TokenMacro.expand(b, StreamTaskListener.fromStdout(),"${BUILD_NUMBER}"));
}
}
@@ -0,0 +1,37 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package org.jenkinsci.plugins.tokenmacro.impl;

import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.util.StreamTaskListener;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static junit.framework.TestCase.assertEquals;

/**
*
* @author egutierrez
*/
public class JenkinsUrlMacroTest {

@Rule
public final JenkinsRule j = new JenkinsRule();

@Test
public void testJenkinsUrlMacro() throws Exception {
FreeStyleProject p = j.createFreeStyleProject("foo");
FreeStyleBuild b = p.scheduleBuild2(0).get();

String expectedJenkinsUrl = j.getURL().toExternalForm();
assertEquals(expectedJenkinsUrl, TokenMacro.expand(b, StreamTaskListener.fromStdout(),"${JENKINS_URL}"));
assertEquals(expectedJenkinsUrl, TokenMacro.expand(b, StreamTaskListener.fromStdout(),"${HUDSON_URL}"));
}
}
@@ -0,0 +1,47 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package org.jenkinsci.plugins.tokenmacro.impl;

import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.util.StreamTaskListener;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockFolder;

import static junit.framework.TestCase.assertEquals;

/**
*
* @author egutierrez
*/
public class ProjectNameMacroTest {

private final static String FOLDER_DISPLAY_NAME = "folderdisplay";
private final static String JOB_DISPLAY_NAME = "jobdisplay";

@Rule
public final JenkinsRule j = new JenkinsRule();

@Test
public void testProjectNameMacro() throws Exception {
MockFolder folder = j.createFolder("foofolder");
folder.setDisplayName(FOLDER_DISPLAY_NAME);

FreeStyleProject p = folder.createProject(FreeStyleProject.class, "foojob");
p.setDisplayName(JOB_DISPLAY_NAME);
FreeStyleBuild b = p.scheduleBuild2(0).get();

String projectDisplayName = TokenMacro.expand(b, StreamTaskListener.fromStdout(),"${PROJECT_DISPLAY_NAME}");
String projectName = TokenMacro.expand(b, StreamTaskListener.fromStdout(),"${PROJECT_NAME}");

assertEquals(JOB_DISPLAY_NAME, projectDisplayName);
assertEquals(String.format("%s » %s", FOLDER_DISPLAY_NAME, JOB_DISPLAY_NAME), projectName);
}
}
@@ -0,0 +1,39 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package org.jenkinsci.plugins.tokenmacro.impl;

import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.util.StreamTaskListener;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static junit.framework.TestCase.assertEquals;

/**
*
* @author egutierrez
*/
public class ProjectUrlMacroTest {

private final static String JOB_NAME = "foo";

@Rule
public final JenkinsRule j = new JenkinsRule();

@Test
public void testProjectUrlMacro() throws Exception {
FreeStyleProject p = j.createFreeStyleProject(JOB_NAME);
FreeStyleBuild b = p.scheduleBuild2(0).get();

String jenkinsUrl = j.getURL().toExternalForm();
String expectedProjectUrl = String.format("%sjob/%s/", jenkinsUrl, JOB_NAME);
assertEquals(expectedProjectUrl, TokenMacro.expand(b, StreamTaskListener.fromStdout(),"${PROJECT_URL}"));
}
}

0 comments on commit 553232e

Please sign in to comment.
You can’t perform that action at this time.