Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[JENKINS-40683] Create functional tests for BUILD_NUMBER, JENKINS_URL…
…, PROJECT_NAME and PROJECT_URL tokens. (#27)
- Loading branch information
Showing
4 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/test/java/org/jenkinsci/plugins/tokenmacro/impl/BuildNumberMacroTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}")); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/java/org/jenkinsci/plugins/tokenmacro/impl/JenkinsUrlMacroTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}")); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/org/jenkinsci/plugins/tokenmacro/impl/ProjectNameMacroTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/test/java/org/jenkinsci/plugins/tokenmacro/impl/ProjectUrlMacroTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}")); | ||
} | ||
} |