forked from jenkinsci/build-blocker-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
119 additions
and
34 deletions.
There are no files selected for viewing
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
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
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
35 changes: 35 additions & 0 deletions
35
src/test/java/hudson/plugins/buildblocker/JenkinsRule.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,35 @@ | ||
package hudson.plugins.buildblocker; | ||
|
||
import hudson.model.Hudson; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.internal.AssumptionViolatedException; | ||
import org.jvnet.hudson.test.JenkinsRecipe; | ||
|
||
import javax.servlet.ServletContext; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Jenkins rule to inject the plugin config file | ||
*/ | ||
public class JenkinsRule extends org.jvnet.hudson.test.JenkinsRule { | ||
|
||
@Override | ||
protected Hudson newHudson() throws Exception { | ||
ServletContext webServer = createWebServer(); | ||
File home = homeLoader.allocate(); | ||
setBlockPluginConfigFile(home); | ||
for (JenkinsRecipe.Runner r : recipes) | ||
r.decorateHome(this,home); | ||
try { | ||
return new Hudson(home, webServer, getPluginManager()); | ||
} catch (InterruptedException x) { | ||
throw new AssumptionViolatedException("Jenkins startup interrupted", x); | ||
} | ||
} | ||
|
||
private void setBlockPluginConfigFile(File home) throws IOException { | ||
File sourceFile = new File(getClass().getResource("/hudson.plugins.buildblocker.BuildBlockerProperty.xml").getFile()); | ||
FileUtils.copyFileToDirectory(sourceFile, home); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/hudson/plugins/buildblocker/PipelineJobListenerTest.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,28 @@ | ||
package hudson.plugins.buildblocker; | ||
|
||
import hudson.model.FreeStyleProject; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class PipelineJobListenerTest { | ||
|
||
@Rule | ||
public JenkinsRule jenkins = new JenkinsRule(); | ||
|
||
@Test | ||
public void should_add_blocking_properties_from_config_file() throws IOException { | ||
FreeStyleProject job1 = jenkins.createFreeStyleProject("testJob"); | ||
|
||
BuildBlockerProperty blockingJobProperty = (BuildBlockerProperty) job1.getProperty(BuildBlockerProperty.class); | ||
|
||
|
||
assertNotNull(blockingJobProperty); | ||
assertEquals(blockingJobProperty.getBlockingJobs(), ".*"); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/test/resources/hudson.plugins.buildblocker.BuildBlockerProperty.xml
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,7 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson.plugins.buildblocker.BuildBlockerProperty_-DescriptorImpl plugin="[email protected]"> | ||
<useBuildBlocker>true</useBuildBlocker> | ||
<blockLevel>GLOBAL</blockLevel> | ||
<scanQueueFor>DISABLED</scanQueueFor> | ||
<blockingJobs>.*</blockingJobs> | ||
</hudson.plugins.buildblocker.BuildBlockerProperty_-DescriptorImpl> |